From 8b442d556cc329bfbc323b2d8892019bdd76e98c Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Sat, 16 May 2020 17:10:57 -0400 Subject: [PATCH] v0.8.1: fixed generator class being rearranged by IDE --- .../items/Generator.java | 577 +++++++++--------- 1 file changed, 288 insertions(+), 289 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Generator.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Generator.java index f4dc6b22b..b92209543 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Generator.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Generator.java @@ -178,7 +178,290 @@ import java.util.LinkedHashMap; public class Generator { - private static final String CATEGORY_PROBS = "_probs"; + public enum Category { + WEAPON ( 6, MeleeWeapon.class), + WEP_T1 ( 0, MeleeWeapon.class), + WEP_T2 ( 0, MeleeWeapon.class), + WEP_T3 ( 0, MeleeWeapon.class), + WEP_T4 ( 0, MeleeWeapon.class), + WEP_T5 ( 0, MeleeWeapon.class), + + ARMOR ( 4, Armor.class ), + + MISSILE ( 3, MissileWeapon.class ), + MIS_T1 ( 0, MissileWeapon.class ), + MIS_T2 ( 0, MissileWeapon.class ), + MIS_T3 ( 0, MissileWeapon.class ), + MIS_T4 ( 0, MissileWeapon.class ), + MIS_T5 ( 0, MissileWeapon.class ), + + WAND ( 3, Wand.class ), + RING ( 1, Ring.class ), + ARTIFACT( 1, Artifact.class), + + FOOD ( 0, Food.class ), + + POTION ( 20, Potion.class ), + SEED ( 0, Plant.Seed.class ), //dropped by grass + + SCROLL ( 20, Scroll.class ), + STONE ( 2, Runestone.class), + + GOLD ( 18, Gold.class ); + + public Class[] classes; + + //some item types use a deck-based system, where the probs decrement as items are picked + // until they are all 0, and then they reset. Those generator classes should define + // defaultProbs. If defaultProbs is null then a deck system isn't used. + //Artifacts in particular don't reset, no duplicates! + public float[] probs; + public float[] defaultProbs = null; + + public float prob; + public Class superClass; + + private Category( float prob, Class superClass ) { + this.prob = prob; + this.superClass = superClass; + } + + public static int order( Item item ) { + for (int i=0; i < values().length; i++) { + if (values()[i].superClass.isInstance( item )) { + return i; + } + } + + return item instanceof Bag ? Integer.MAX_VALUE : Integer.MAX_VALUE - 1; + } + + static { + GOLD.classes = new Class[]{ + Gold.class }; + GOLD.probs = new float[]{ 1 }; + + POTION.classes = new Class[]{ + PotionOfStrength.class, //2 drop every chapter, see Dungeon.posNeeded() + PotionOfHealing.class, + PotionOfMindVision.class, + PotionOfFrost.class, + PotionOfLiquidFlame.class, + PotionOfToxicGas.class, + PotionOfHaste.class, + PotionOfInvisibility.class, + PotionOfLevitation.class, + PotionOfParalyticGas.class, + PotionOfPurity.class, + PotionOfExperience.class}; + POTION.defaultProbs = new float[]{ 0, 6, 4, 3, 3, 3, 2, 2, 2, 2, 2, 1 }; + POTION.probs = POTION.defaultProbs.clone(); + + SEED.classes = new Class[]{ + Rotberry.Seed.class, //quest item + Sungrass.Seed.class, + Fadeleaf.Seed.class, + Icecap.Seed.class, + Firebloom.Seed.class, + Sorrowmoss.Seed.class, + Swiftthistle.Seed.class, + Blindweed.Seed.class, + Stormvine.Seed.class, + Earthroot.Seed.class, + Dreamfoil.Seed.class, + Starflower.Seed.class}; + //TODO adjust these + SEED.defaultProbs = new float[]{ 0, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 1 }; + SEED.probs = SEED.defaultProbs.clone(); + + SCROLL.classes = new Class[]{ + ScrollOfUpgrade.class, //3 drop every chapter, see Dungeon.souNeeded() + ScrollOfIdentify.class, + ScrollOfRemoveCurse.class, + ScrollOfMirrorImage.class, + ScrollOfRecharging.class, + ScrollOfTeleportation.class, + ScrollOfLullaby.class, + ScrollOfMagicMapping.class, + ScrollOfRage.class, + ScrollOfRetribution.class, + ScrollOfTerror.class, + ScrollOfTransmutation.class + }; + SCROLL.defaultProbs = new float[]{ 0, 6, 4, 3, 3, 3, 2, 2, 2, 2, 2, 1 }; + SCROLL.probs = SCROLL.defaultProbs.clone(); + + STONE.classes = new Class[]{ + StoneOfEnchantment.class, //1 is guaranteed to drop on floors 6-19 + StoneOfIntuition.class, //1 additional stone is also dropped on floors 1-3 + StoneOfDisarming.class, + StoneOfFlock.class, + StoneOfShock.class, + StoneOfBlink.class, + StoneOfDeepenedSleep.class, + StoneOfClairvoyance.class, + StoneOfAggression.class, + StoneOfBlast.class, + StoneOfAffection.class, + StoneOfAugmentation.class //1 is also sold in each shop + }; + //TODO adjust these + STONE.defaultProbs = new float[]{ 0, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 0 }; + STONE.probs = STONE.defaultProbs.clone(); + + WAND.classes = new Class[]{ + WandOfMagicMissile.class, + WandOfLightning.class, + WandOfDisintegration.class, + WandOfFireblast.class, + WandOfCorrosion.class, + WandOfBlastWave.class, + WandOfLivingEarth.class, + WandOfFrost.class, + WandOfPrismaticLight.class, + WandOfWarding.class, + WandOfTransfusion.class, + WandOfCorruption.class, + WandOfRegrowth.class }; + WAND.probs = new float[]{ 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3 }; + + //see generator.randomWeapon + WEAPON.classes = new Class[]{}; + WEAPON.probs = new float[]{}; + + WEP_T1.classes = new Class[]{ + WornShortsword.class, + Gloves.class, + Dagger.class, + MagesStaff.class + }; + WEP_T1.probs = new float[]{ 1, 1, 1, 0 }; + + WEP_T2.classes = new Class[]{ + Shortsword.class, + HandAxe.class, + Spear.class, + Quarterstaff.class, + Dirk.class + }; + WEP_T2.probs = new float[]{ 6, 5, 5, 4, 4 }; + + WEP_T3.classes = new Class[]{ + Sword.class, + Mace.class, + Scimitar.class, + RoundShield.class, + Sai.class, + Whip.class + }; + WEP_T3.probs = new float[]{ 6, 5, 5, 4, 4, 4 }; + + WEP_T4.classes = new Class[]{ + Longsword.class, + BattleAxe.class, + Flail.class, + RunicBlade.class, + AssassinsBlade.class, + Crossbow.class + }; + WEP_T4.probs = new float[]{ 6, 5, 5, 4, 4, 4 }; + + WEP_T5.classes = new Class[]{ + Greatsword.class, + WarHammer.class, + Glaive.class, + Greataxe.class, + Greatshield.class, + Gauntlet.class + }; + WEP_T5.probs = new float[]{ 6, 5, 5, 4, 4, 4 }; + + //see Generator.randomArmor + ARMOR.classes = new Class[]{ + ClothArmor.class, + LeatherArmor.class, + MailArmor.class, + ScaleArmor.class, + PlateArmor.class }; + ARMOR.probs = new float[]{ 0, 0, 0, 0, 0 }; + + //see Generator.randomMissile + MISSILE.classes = new Class[]{}; + MISSILE.probs = new float[]{}; + + MIS_T1.classes = new Class[]{ + ThrowingStone.class, + ThrowingKnife.class + }; + MIS_T1.probs = new float[]{ 6, 5 }; + + MIS_T2.classes = new Class[]{ + FishingSpear.class, + ThrowingClub.class, + Shuriken.class + }; + MIS_T2.probs = new float[]{ 6, 5, 4 }; + + MIS_T3.classes = new Class[]{ + ThrowingSpear.class, + Kunai.class, + Bolas.class + }; + MIS_T3.probs = new float[]{ 6, 5, 4 }; + + MIS_T4.classes = new Class[]{ + Javelin.class, + Tomahawk.class, + HeavyBoomerang.class + }; + MIS_T4.probs = new float[]{ 6, 5, 4 }; + + MIS_T5.classes = new Class[]{ + Trident.class, + ThrowingHammer.class, + ForceCube.class + }; + MIS_T5.probs = new float[]{ 6, 5, 4 }; + + FOOD.classes = new Class[]{ + Food.class, + Pasty.class, + MysteryMeat.class }; + FOOD.probs = new float[]{ 4, 1, 0 }; + + RING.classes = new Class[]{ + RingOfAccuracy.class, + RingOfEvasion.class, + RingOfElements.class, + RingOfForce.class, + RingOfFuror.class, + RingOfHaste.class, + RingOfEnergy.class, + RingOfMight.class, + RingOfSharpshooting.class, + RingOfTenacity.class, + RingOfWealth.class}; + RING.probs = new float[]{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; + + ARTIFACT.classes = new Class[]{ + CapeOfThorns.class, + ChaliceOfBlood.class, + CloakOfShadows.class, + HornOfPlenty.class, + MasterThievesArmband.class, + SandalsOfNature.class, + TalismanOfForesight.class, + TimekeepersHourglass.class, + UnstableSpellbook.class, + AlchemistsToolkit.class, + DriedRose.class, + LloydsBeacon.class, + EtherealChains.class + }; + ARTIFACT.defaultProbs = new float[]{ 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}; + ARTIFACT.probs = ARTIFACT.defaultProbs.clone(); + } + } private static final float[][] floorSetTierProbs = new float[][] { {0, 70, 20, 8, 2}, @@ -332,7 +615,8 @@ public class Generator { } private static final String GENERAL_PROBS = "general_probs"; - + private static final String CATEGORY_PROBS = "_probs"; + public static void storeInBundle(Bundle bundle) { Float[] genProbs = categoryProbs.values().toArray(new Float[0]); float[] storeProbs = new float[genProbs.length]; @@ -356,7 +640,7 @@ public class Generator { } } } - + public static void restoreFromBundle(Bundle bundle) { reset(); @@ -387,291 +671,6 @@ public class Generator { } } } - - } - - public enum Category { - WEAPON ( 6, MeleeWeapon.class), - WEP_T1 ( 0, MeleeWeapon.class), - WEP_T2 ( 0, MeleeWeapon.class), - WEP_T3 ( 0, MeleeWeapon.class), - WEP_T4 ( 0, MeleeWeapon.class), - WEP_T5 ( 0, MeleeWeapon.class), - - ARMOR ( 4, Armor.class ), - - MISSILE ( 3, MissileWeapon.class ), - MIS_T1 ( 0, MissileWeapon.class ), - MIS_T2 ( 0, MissileWeapon.class ), - MIS_T3 ( 0, MissileWeapon.class ), - MIS_T4 ( 0, MissileWeapon.class ), - MIS_T5 ( 0, MissileWeapon.class ), - - WAND ( 3, Wand.class ), - RING ( 1, Ring.class ), - ARTIFACT( 1, Artifact.class), - - FOOD ( 0, Food.class ), - - POTION ( 20, Potion.class ), - SEED ( 0, Plant.Seed.class ), //dropped by grass - - SCROLL ( 20, Scroll.class ), - STONE ( 2, Runestone.class), - - GOLD ( 18, Gold.class ); - - public Class[] classes; - - static { - GOLD.classes = new Class[]{ - Gold.class }; - GOLD.probs = new float[]{ 1 }; - - POTION.classes = new Class[]{ - PotionOfStrength.class, //2 drop every chapter, see Dungeon.posNeeded() - PotionOfHealing.class, - PotionOfMindVision.class, - PotionOfFrost.class, - PotionOfLiquidFlame.class, - PotionOfToxicGas.class, - PotionOfHaste.class, - PotionOfInvisibility.class, - PotionOfLevitation.class, - PotionOfParalyticGas.class, - PotionOfPurity.class, - PotionOfExperience.class}; - POTION.defaultProbs = new float[]{ 0, 6, 4, 3, 3, 3, 2, 2, 2, 2, 2, 1 }; - POTION.probs = POTION.defaultProbs.clone(); - - SEED.classes = new Class[]{ - Rotberry.Seed.class, //quest item - Sungrass.Seed.class, - Fadeleaf.Seed.class, - Icecap.Seed.class, - Firebloom.Seed.class, - Sorrowmoss.Seed.class, - Swiftthistle.Seed.class, - Blindweed.Seed.class, - Stormvine.Seed.class, - Earthroot.Seed.class, - Dreamfoil.Seed.class, - Starflower.Seed.class}; - //TODO adjust these - SEED.defaultProbs = new float[]{ 0, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 1 }; - SEED.probs = SEED.defaultProbs.clone(); - - SCROLL.classes = new Class[]{ - ScrollOfUpgrade.class, //3 drop every chapter, see Dungeon.souNeeded() - ScrollOfIdentify.class, - ScrollOfRemoveCurse.class, - ScrollOfMirrorImage.class, - ScrollOfRecharging.class, - ScrollOfTeleportation.class, - ScrollOfLullaby.class, - ScrollOfMagicMapping.class, - ScrollOfRage.class, - ScrollOfRetribution.class, - ScrollOfTerror.class, - ScrollOfTransmutation.class - }; - SCROLL.defaultProbs = new float[]{ 0, 6, 4, 3, 3, 3, 2, 2, 2, 2, 2, 1 }; - SCROLL.probs = SCROLL.defaultProbs.clone(); - - STONE.classes = new Class[]{ - StoneOfEnchantment.class, //1 is guaranteed to drop on floors 6-19 - StoneOfIntuition.class, //1 additional stone is also dropped on floors 1-3 - StoneOfDisarming.class, - StoneOfFlock.class, - StoneOfShock.class, - StoneOfBlink.class, - StoneOfDeepenedSleep.class, - StoneOfClairvoyance.class, - StoneOfAggression.class, - StoneOfBlast.class, - StoneOfAffection.class, - StoneOfAugmentation.class //1 is also sold in each shop - }; - //TODO adjust these - STONE.defaultProbs = new float[]{ 0, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 0 }; - STONE.probs = STONE.defaultProbs.clone(); - - WAND.classes = new Class[]{ - WandOfMagicMissile.class, - WandOfLightning.class, - WandOfDisintegration.class, - WandOfFireblast.class, - WandOfCorrosion.class, - WandOfBlastWave.class, - WandOfLivingEarth.class, - WandOfFrost.class, - WandOfPrismaticLight.class, - WandOfWarding.class, - WandOfTransfusion.class, - WandOfCorruption.class, - WandOfRegrowth.class }; - WAND.probs = new float[]{ 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3 }; - - //see generator.randomWeapon - WEAPON.classes = new Class[]{}; - WEAPON.probs = new float[]{}; - - WEP_T1.classes = new Class[]{ - WornShortsword.class, - Gloves.class, - Dagger.class, - MagesStaff.class - }; - WEP_T1.probs = new float[]{ 1, 1, 1, 0 }; - - WEP_T2.classes = new Class[]{ - Shortsword.class, - HandAxe.class, - Spear.class, - Quarterstaff.class, - Dirk.class - }; - WEP_T2.probs = new float[]{ 6, 5, 5, 4, 4 }; - - WEP_T3.classes = new Class[]{ - Sword.class, - Mace.class, - Scimitar.class, - RoundShield.class, - Sai.class, - Whip.class - }; - WEP_T3.probs = new float[]{ 6, 5, 5, 4, 4, 4 }; - - WEP_T4.classes = new Class[]{ - Longsword.class, - BattleAxe.class, - Flail.class, - RunicBlade.class, - AssassinsBlade.class, - Crossbow.class - }; - WEP_T4.probs = new float[]{ 6, 5, 5, 4, 4, 4 }; - - WEP_T5.classes = new Class[]{ - Greatsword.class, - WarHammer.class, - Glaive.class, - Greataxe.class, - Greatshield.class, - Gauntlet.class - }; - WEP_T5.probs = new float[]{ 6, 5, 5, 4, 4, 4 }; - - //see Generator.randomArmor - ARMOR.classes = new Class[]{ - ClothArmor.class, - LeatherArmor.class, - MailArmor.class, - ScaleArmor.class, - PlateArmor.class }; - ARMOR.probs = new float[]{ 0, 0, 0, 0, 0 }; - - //see Generator.randomMissile - MISSILE.classes = new Class[]{}; - MISSILE.probs = new float[]{}; - - MIS_T1.classes = new Class[]{ - ThrowingStone.class, - ThrowingKnife.class - }; - MIS_T1.probs = new float[]{ 6, 5 }; - - MIS_T2.classes = new Class[]{ - FishingSpear.class, - ThrowingClub.class, - Shuriken.class - }; - MIS_T2.probs = new float[]{ 6, 5, 4 }; - - MIS_T3.classes = new Class[]{ - ThrowingSpear.class, - Kunai.class, - Bolas.class - }; - MIS_T3.probs = new float[]{ 6, 5, 4 }; - - MIS_T4.classes = new Class[]{ - Javelin.class, - Tomahawk.class, - HeavyBoomerang.class - }; - MIS_T4.probs = new float[]{ 6, 5, 4 }; - - MIS_T5.classes = new Class[]{ - Trident.class, - ThrowingHammer.class, - ForceCube.class - }; - MIS_T5.probs = new float[]{ 6, 5, 4 }; - - FOOD.classes = new Class[]{ - Food.class, - Pasty.class, - MysteryMeat.class }; - FOOD.probs = new float[]{ 4, 1, 0 }; - - RING.classes = new Class[]{ - RingOfAccuracy.class, - RingOfEvasion.class, - RingOfElements.class, - RingOfForce.class, - RingOfFuror.class, - RingOfHaste.class, - RingOfEnergy.class, - RingOfMight.class, - RingOfSharpshooting.class, - RingOfTenacity.class, - RingOfWealth.class}; - RING.probs = new float[]{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; - - ARTIFACT.classes = new Class[]{ - CapeOfThorns.class, - ChaliceOfBlood.class, - CloakOfShadows.class, - HornOfPlenty.class, - MasterThievesArmband.class, - SandalsOfNature.class, - TalismanOfForesight.class, - TimekeepersHourglass.class, - UnstableSpellbook.class, - AlchemistsToolkit.class, - DriedRose.class, - LloydsBeacon.class, - EtherealChains.class - }; - ARTIFACT.defaultProbs = new float[]{ 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}; - ARTIFACT.probs = ARTIFACT.defaultProbs.clone(); - } - - //some item types use a deck-based system, where the probs decrement as items are picked - // until they are all 0, and then they reset. Those generator classes should define - // defaultProbs. If defaultProbs is null then a deck system isn't used. - //Artifacts in particular don't reset, no duplicates! - public float[] probs; - - public float prob; - public Class superClass; - - private Category( float prob, Class superClass ) { - this.prob = prob; - this.superClass = superClass; - } - - public static int order( Item item ) { - for (int i=0; i < values().length; i++) { - if (values()[i].superClass.isInstance( item )) { - return i; - } - } - - return item instanceof Bag ? Integer.MAX_VALUE : Integer.MAX_VALUE - 1; - } - public float[] defaultProbs = null; + } }