v2.5.0: merged spawning logic into one class (freeing up bestiary)

This commit is contained in:
Evan Debenham
2024-06-13 16:20:57 -04:00
parent a3f2ab7a89
commit 16977c4181
4 changed files with 63 additions and 59 deletions
@@ -48,6 +48,11 @@ public class ShatteredPixelDungeon extends Game {
public ShatteredPixelDungeon( PlatformSupport platform ) { public ShatteredPixelDungeon( PlatformSupport platform ) {
super( sceneClass == null ? WelcomeScene.class : sceneClass, platform ); super( sceneClass == null ? WelcomeScene.class : sceneClass, platform );
//pre-v2.5.0
com.watabou.utils.Bundle.addAlias(
com.shatteredpixel.shatteredpixeldungeon.actors.mobs.MobSpawner.class,
"com.shatteredpixel.shatteredpixeldungeon.levels.Level$Respawner" );
//pre-v2.4.0 //pre-v2.4.0
com.watabou.utils.Bundle.addAlias( com.watabou.utils.Bundle.addAlias(
com.shatteredpixel.shatteredpixeldungeon.items.potions.brews.UnstableBrew.class, com.shatteredpixel.shatteredpixeldungeon.items.potions.brews.UnstableBrew.class,
@@ -21,15 +21,44 @@
package com.shatteredpixel.shatteredpixeldungeon.actors.mobs; package com.shatteredpixel.shatteredpixeldungeon.actors.mobs;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
import com.shatteredpixel.shatteredpixeldungeon.items.trinkets.RatSkull; import com.shatteredpixel.shatteredpixeldungeon.items.trinkets.RatSkull;
import com.watabou.utils.Random; import com.watabou.utils.Random;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
public class Bestiary { public class MobSpawner extends Actor {
{
actPriority = BUFF_PRIO; //as if it were a buff.
}
public static ArrayList<Class<? extends Mob>> getMobRotation( int depth ){ @Override
protected boolean act() {
if (Dungeon.level.mobCount() < Dungeon.level.mobLimit()) {
if (Dungeon.level.spawnMob(12)){
spend(Dungeon.level.respawnCooldown());
} else {
//try again in 1 turn
spend(TICK);
}
} else {
spend(Dungeon.level.respawnCooldown());
}
return true;
}
public void resetCooldown(){
spend(-cooldown());
spend(Dungeon.level.respawnCooldown());
}
public static ArrayList<Class<? extends Mob>> getMobRotation(int depth ){
ArrayList<Class<? extends Mob>> mobs = standardMobRotation( depth ); ArrayList<Class<? extends Mob>> mobs = standardMobRotation( depth );
addRareMobs(depth, mobs); addRareMobs(depth, mobs);
swapMobAlts(mobs); swapMobAlts(mobs);
@@ -211,9 +240,9 @@ public class Bestiary {
} }
//switches out regular mobs for their alt versions when appropriate //switches out regular mobs for their alt versions when appropriate
private static void swapMobAlts(ArrayList<Class<?extends Mob>> rotation){ private static void swapMobAlts(ArrayList<Class<?extends Mob>> rotation) {
float altChance = 1/50f * RatSkull.exoticChanceMultiplier(); float altChance = 1 / 50f * RatSkull.exoticChanceMultiplier();
for (int i = 0; i < rotation.size(); i++){ for (int i = 0; i < rotation.size(); i++) {
if (Random.Float() < altChance) { if (Random.Float() < altChance) {
Class<? extends Mob> cl = rotation.get(i); Class<? extends Mob> cl = rotation.get(i);
if (cl == Rat.class) { if (cl == Rat.class) {
@@ -222,7 +251,7 @@ public class Bestiary {
cl = CausticSlime.class; cl = CausticSlime.class;
} else if (cl == Thief.class) { } else if (cl == Thief.class) {
cl = Bandit.class; cl = Bandit.class;
} else if (cl == Necromancer.class){ } else if (cl == Necromancer.class) {
cl = SpectralNecromancer.class; cl = SpectralNecromancer.class;
} else if (cl == Brute.class) { } else if (cl == Brute.class) {
cl = ArmoredBrute.class; cl = ArmoredBrute.class;
@@ -47,10 +47,10 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.HeroSubClass; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.HeroSubClass;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Talent; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Talent;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.abilities.huntress.SpiritHawk; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.abilities.huntress.SpiritHawk;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Bestiary;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.GnollGeomancer; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.GnollGeomancer;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mimic; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mimic;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.MobSpawner;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Piranha; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Piranha;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.YogFist; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.YogFist;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.Blacksmith; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.Blacksmith;
@@ -68,10 +68,10 @@ import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfStrength;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfUpgrade; import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfUpgrade;
import com.shatteredpixel.shatteredpixeldungeon.items.stones.StoneOfEnchantment; import com.shatteredpixel.shatteredpixeldungeon.items.stones.StoneOfEnchantment;
import com.shatteredpixel.shatteredpixeldungeon.items.stones.StoneOfIntuition; import com.shatteredpixel.shatteredpixeldungeon.items.stones.StoneOfIntuition;
import com.shatteredpixel.shatteredpixeldungeon.items.trinkets.DimensionalSundial;
import com.shatteredpixel.shatteredpixeldungeon.items.trinkets.EyeOfNewt; import com.shatteredpixel.shatteredpixeldungeon.items.trinkets.EyeOfNewt;
import com.shatteredpixel.shatteredpixeldungeon.items.trinkets.MimicTooth; import com.shatteredpixel.shatteredpixeldungeon.items.trinkets.MimicTooth;
import com.shatteredpixel.shatteredpixeldungeon.items.trinkets.MossyClump; import com.shatteredpixel.shatteredpixeldungeon.items.trinkets.MossyClump;
import com.shatteredpixel.shatteredpixeldungeon.items.trinkets.DimensionalSundial;
import com.shatteredpixel.shatteredpixeldungeon.items.trinkets.TrapMechanism; import com.shatteredpixel.shatteredpixeldungeon.items.trinkets.TrapMechanism;
import com.shatteredpixel.shatteredpixeldungeon.items.trinkets.TrinketCatalyst; import com.shatteredpixel.shatteredpixeldungeon.items.trinkets.TrinketCatalyst;
import com.shatteredpixel.shatteredpixeldungeon.items.wands.WandOfRegrowth; import com.shatteredpixel.shatteredpixeldungeon.items.wands.WandOfRegrowth;
@@ -430,7 +430,7 @@ public abstract class Level implements Bundlable {
} }
if (bundle.contains( "respawner" )){ if (bundle.contains( "respawner" )){
respawner = (Respawner) bundle.get("respawner"); respawner = (MobSpawner) bundle.get("respawner");
} }
buildFlagMaps(); buildFlagMaps();
@@ -490,7 +490,7 @@ public abstract class Level implements Bundlable {
public Mob createMob() { public Mob createMob() {
if (mobsToSpawn == null || mobsToSpawn.isEmpty()) { if (mobsToSpawn == null || mobsToSpawn.isEmpty()) {
mobsToSpawn = Bestiary.getMobRotation(Dungeon.depth); mobsToSpawn = MobSpawner.getMobRotation(Dungeon.depth);
} }
Mob m = Reflection.newInstance(mobsToSpawn.remove(0)); Mob m = Reflection.newInstance(mobsToSpawn.remove(0));
@@ -671,11 +671,11 @@ public abstract class Level implements Bundlable {
return null; return null;
} }
private Respawner respawner; private MobSpawner respawner;
public Actor addRespawner() { public Actor addRespawner() {
if (respawner == null){ if (respawner == null){
respawner = new Respawner(); respawner = new MobSpawner();
Actor.addDelayed(respawner, respawnCooldown()); Actor.addDelayed(respawner, respawnCooldown());
} else { } else {
Actor.add(respawner); Actor.add(respawner);
@@ -686,36 +686,6 @@ public abstract class Level implements Bundlable {
return respawner; return respawner;
} }
public static class Respawner extends Actor {
{
actPriority = BUFF_PRIO; //as if it were a buff.
}
@Override
protected boolean act() {
if (Dungeon.level.mobCount() < Dungeon.level.mobLimit()) {
if (Dungeon.level.spawnMob(12)){
spend(Dungeon.level.respawnCooldown());
} else {
//try again in 1 turn
spend(TICK);
}
} else {
spend(Dungeon.level.respawnCooldown());
}
return true;
}
protected void resetCooldown(){
spend(-cooldown());
spend(Dungeon.level.respawnCooldown());
}
}
public float respawnCooldown(){ public float respawnCooldown(){
float cooldown; float cooldown;
if (Statistics.amuletObtained){ if (Statistics.amuletObtained){
@@ -29,12 +29,12 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Acidic;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Albino; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Albino;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.ArmoredBrute; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.ArmoredBrute;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Bandit; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Bandit;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Bestiary;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.CausticSlime; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.CausticSlime;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.DM201; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.DM201;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Elemental; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Elemental;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mimic; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mimic;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.MobSpawner;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Piranha; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Piranha;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Senior; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Senior;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Statue; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Statue;
@@ -111,7 +111,7 @@ public class DistortionTrap extends Trap{
do { do {
floor = Random.Int(25); floor = Random.Int(25);
} while( Dungeon.bossLevel(floor)); } while( Dungeon.bossLevel(floor));
mob = Reflection.newInstance(Bestiary.getMobRotation(floor).get(0)); mob = Reflection.newInstance(MobSpawner.getMobRotation(floor).get(0));
break; break;
case 2: case 2:
switch (2){ switch (2){