mirror of
https://github.com/ProjectSWGCore/NGECore2.git
synced 2026-10-17 07:02:53 -04:00
Added tryChance method to MathUtilities
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
package resources.common;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Random;
|
||||
|
||||
import engine.resources.scene.*;
|
||||
|
||||
@@ -68,4 +69,25 @@ public class MathUtilities {
|
||||
BigDecimal dec = new BigDecimal(seconds);
|
||||
return dec.remainder(new BigDecimal(3600)).divide(new BigDecimal(60), BigDecimal.ROUND_FLOOR).intValue();
|
||||
}
|
||||
|
||||
public static boolean tryChance(int chance) {
|
||||
if (chance <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (chance >= 100) {
|
||||
return true;
|
||||
}
|
||||
|
||||
chance = (100 - chance);
|
||||
|
||||
Random random = new Random();
|
||||
|
||||
if (random.nextInt(chance + 1) == 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user