SteamWar/MissileWars
Archiviert
13
0

Fix SpecialItem.getRandomItem
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2024-07-22 10:46:59 +02:00
Ursprung b137aaec24
Commit 3f5784cecb

Datei anzeigen

@ -40,7 +40,8 @@ import java.util.Random;
public abstract class SpecialItem {
private static final Random random = new Random();
private static boolean lastItemWasSupportItem = false;
private static long missileCount = 0;
private static long supportCount = 0;
private static List<SpecialItem> supportItems = new ArrayList<>();
private static List<SpecialItem> missileItems = new ArrayList<>();
@ -110,11 +111,21 @@ public abstract class SpecialItem {
}
public static ItemStack getRandomItem() {
if (!lastItemWasSupportItem && random.nextDouble() > Config.MissileChance) {
lastItemWasSupportItem = true;
return supportItems.get(random.nextInt(supportItems.size())).getItem();
double missile = missileCount * Config.MissileChance;
double support = supportCount;
double missileChance;
if (missile == 0 && support == 0) {
missileChance = 0.5;
} else {
missileChance = support / (support + missile);
}
if (random.nextDouble() > missileChance) {
supportCount++;
return supportItems.get(random.nextInt(supportItems.size())).getItem();
} else {
missileCount++;
return missileItems.get(random.nextInt(missileItems.size())).getItem();
}
lastItemWasSupportItem = false;
return missileItems.get(random.nextInt(missileItems.size())).getItem();
}
}