From 49543e301cefe1cbca12a73c6176b2dcda4c90d6 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Mon, 12 Jun 2017 23:23:53 -0400 Subject: [PATCH] v0.6.1: overhauled bestiary logic for improved consistency --- .../actors/mobs/Bestiary.java | 347 ++++++++++-------- .../items/armor/curses/Multiplicity.java | 3 +- .../levels/CavesBossLevel.java | 9 +- .../levels/CityBossLevel.java | 9 +- .../levels/DeadEndLevel.java | 8 +- .../levels/HallsBossLevel.java | 6 + .../levels/LastLevel.java | 8 +- .../levels/LastShopLevel.java | 6 + .../shatteredpixeldungeon/levels/Level.java | 5 +- .../levels/PrisonBossLevel.java | 7 +- .../levels/RegularLevel.java | 27 +- .../levels/SewerBossLevel.java | 10 +- .../levels/traps/SummoningTrap.java | 3 +- 13 files changed, 275 insertions(+), 173 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Bestiary.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Bestiary.java index 75614422d..a2801eb56 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Bestiary.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Bestiary.java @@ -21,165 +21,208 @@ package com.shatteredpixel.shatteredpixeldungeon.actors.mobs; -import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.watabou.utils.Random; -public class Bestiary { +import java.util.ArrayList; +import java.util.Arrays; - public static Mob mob( int depth ) { - @SuppressWarnings("unchecked") - Class cl = (Class)mobClass( depth ); - try { - return cl.newInstance(); - } catch (Exception e) { - ShatteredPixelDungeon.reportException(e); - return null; +public class Bestiary { + + public static ArrayList> getMobRotation( int depth ){ + ArrayList> mobs = standardMobRotation( depth ); + addRareMobs(depth, mobs); + swapMobAlts(mobs); + Random.shuffle(mobs); + return mobs; + } + + //returns a rotation of standard mobs, unshuffled. + private static ArrayList> standardMobRotation( int depth ){ + switch(depth){ + + // Sewers + case 1: default: + //10x rat + return new ArrayList>(Arrays.asList( + Rat.class, Rat.class, Rat.class, Rat.class, Rat.class, + Rat.class, Rat.class, Rat.class, Rat.class, Rat.class)); + case 2: + //3x rat, 3x gnoll + return new ArrayList<>(Arrays.asList(Rat.class, Rat.class, Rat.class, + Gnoll.class, Gnoll.class, Gnoll.class)); + case 3: + //2x rat, 4x gnoll, 1x crab, 1x swarm + return new ArrayList<>(Arrays.asList(Rat.class, Rat.class, + Gnoll.class, Gnoll.class, Gnoll.class, Gnoll.class, + Crab.class, Swarm.class)); + case 4: + //1x rat, 2x gnoll, 3x crab, 1x swarm + return new ArrayList<>(Arrays.asList(Rat.class, + Gnoll.class, Gnoll.class, + Crab.class, Crab.class, Crab.class, + Swarm.class)); + + // Prison + case 6: + //3x skeleton, 1x thief, 1x swarm + return new ArrayList<>(Arrays.asList(Skeleton.class, Skeleton.class, Skeleton.class, + Thief.class, + Swarm.class)); + case 7: + //3x skeleton, 1x thief, 1x shaman, 1x guard + return new ArrayList<>(Arrays.asList(Skeleton.class, Skeleton.class, Skeleton.class, + Thief.class, + Shaman.class, + Guard.class)); + case 8: + //3x skeleton, 1x thief, 2x shaman, 2x guard + return new ArrayList<>(Arrays.asList(Skeleton.class, Skeleton.class, Skeleton.class, + Thief.class, + Shaman.class, Shaman.class, + Guard.class, Guard.class)); + case 9: + //3x skeleton, 1x thief, 2x shaman, 3x guard + return new ArrayList<>(Arrays.asList(Skeleton.class, Skeleton.class, Skeleton.class, + Thief.class, + Shaman.class, Shaman.class, + Guard.class, Guard.class, Guard.class)); + + // Caves + case 11: + //5x bat, 1x brute + return new ArrayList<>(Arrays.asList( + Bat.class, Bat.class, Bat.class, Bat.class, Bat.class, + Brute.class)); + case 12: + //5x bat, 5x brute, 1x spinner + return new ArrayList<>(Arrays.asList( + Bat.class, Bat.class, Bat.class, Bat.class, Bat.class, + Brute.class, Brute.class, Brute.class, Brute.class, Brute.class, + Spinner.class)); + case 13: + //1x bat, 3x brute, 1x shaman, 1x spinner + return new ArrayList<>(Arrays.asList( + Bat.class, + Brute.class, Brute.class, Brute.class, + Shaman.class, + Spinner.class)); + case 14: + //1x bat, 3x brute, 1x shaman, 4x spinner + return new ArrayList<>(Arrays.asList( + Bat.class, + Brute.class, Brute.class, Brute.class, + Shaman.class, + Spinner.class, Spinner.class, Spinner.class, Spinner.class)); + + // City + case 16: + //5x elemental, 5x warlock, 1x monk + return new ArrayList<>(Arrays.asList( + Elemental.class, Elemental.class, Elemental.class, Elemental.class, Elemental.class, + Warlock.class, Warlock.class, Warlock.class, Warlock.class, Warlock.class, + Monk.class)); + case 17: + //2x elemental, 2x warlock, 2x monk + return new ArrayList<>(Arrays.asList( + Elemental.class, Elemental.class, + Warlock.class, Warlock.class, + Monk.class, Monk.class)); + case 18: + //1x elemental, 1x warlock, 2x monk, 1x golem + return new ArrayList<>(Arrays.asList( + Elemental.class, + Warlock.class, + Monk.class, Monk.class, + Golem.class)); + case 19: + //1x elemental, 1x warlock, 2x monk, 3x golem + return new ArrayList<>(Arrays.asList( + Elemental.class, + Warlock.class, + Monk.class, Monk.class, + Golem.class, Golem.class, Golem.class)); + + // Halls + case 22: + //3x succubus, 3x evil eye + return new ArrayList<>(Arrays.asList( + Succubus.class, Succubus.class, Succubus.class, + Eye.class, Eye.class, Eye.class)); + case 23: + //2x succubus, 4x evil eye, 2x scorpio + return new ArrayList<>(Arrays.asList( + Succubus.class, Succubus.class, + Eye.class, Eye.class, Eye.class, Eye.class, + Scorpio.class, Scorpio.class)); + case 24: + //1x succubus, 2x evil eye, 3x scorpio + return new ArrayList<>(Arrays.asList( + Succubus.class, + Eye.class, Eye.class, + Scorpio.class, Scorpio.class, Scorpio.class)); + } + + } + + //has a chance to add a rarely spawned mobs to the rotation + public static void addRareMobs( int depth, ArrayList> rotation ){ + + switch (depth){ + + // Sewers + default: + return; + case 4: + if (Random.Float() < 0.01f) rotation.add(Skeleton.class); + if (Random.Float() < 0.01f) rotation.add(Thief.class); + return; + + // Prison + case 6: + if (Random.Float() < 0.2f) rotation.add(Shaman.class); + return; + case 8: + if (Random.Float() < 0.02f) rotation.add(Bat.class); + return; + case 9: + if (Random.Float() < 0.02f) rotation.add(Bat.class); + if (Random.Float() < 0.01f) rotation.add(Brute.class); + return; + + // Caves + case 13: + if (Random.Float() < 0.02f) rotation.add(Elemental.class); + return; + case 14: + if (Random.Float() < 0.02f) rotation.add(Elemental.class); + if (Random.Float() < 0.01f) rotation.add(Monk.class); + return; + + // City + case 19: + if (Random.Float() < 0.02f) rotation.add(Succubus.class); + return; } } - public static Mob mutable( int depth ) { - @SuppressWarnings("unchecked") - Class cl = (Class)mobClass( depth ); - - if (Random.Int( 30 ) == 0) { - if (cl == Rat.class) { - cl = Albino.class; - } else if (cl == Thief.class) { - cl = Bandit.class; - } else if (cl == Brute.class) { - cl = Shielded.class; - } else if (cl == Monk.class) { - cl = Senior.class; - } else if (cl == Scorpio.class) { - cl = Acidic.class; + //switches out regular mobs for their alt versions when appropriate + private static void swapMobAlts(ArrayList> rotation){ + for (int i = 0; i < rotation.size(); i++){ + if (Random.Int( 50 ) == 0) { + Class cl = rotation.get(i); + if (cl == Rat.class) { + cl = Albino.class; + } else if (cl == Thief.class) { + cl = Bandit.class; + } else if (cl == Brute.class) { + cl = Shielded.class; + } else if (cl == Monk.class) { + cl = Senior.class; + } else if (cl == Scorpio.class) { + cl = Acidic.class; + } + rotation.set(i, cl); } } - - try { - return cl.newInstance(); - } catch (Exception e) { - ShatteredPixelDungeon.reportException(e); - return null; - } - } - - private static Class mobClass( int depth ) { - - float[] chances; - Class[] classes; - - switch (depth) { - case 1: - chances = new float[]{ 1 }; - classes = new Class[]{ Rat.class }; - break; - case 2: - chances = new float[]{ 1, 1 }; - classes = new Class[]{ Rat.class, Gnoll.class }; - break; - case 3: - chances = new float[]{ 2, 4, 1, 1 }; - classes = new Class[]{ Rat.class, Gnoll.class, Crab.class, Swarm.class }; - break; - case 4: - chances = new float[]{ 1, 2, 3, 1, 0.01f, 0.01f }; - classes = new Class[]{ Rat.class, Gnoll.class, Crab.class, Swarm.class, Skeleton.class, Thief.class }; - break; - - case 5: - chances = new float[]{ 1 }; - classes = new Class[]{ Goo.class }; - break; - - case 6: - chances = new float[]{ 3, 1, 1, 0.2f }; - classes = new Class[]{ Skeleton.class, Thief.class, Swarm.class, Shaman.class }; - break; - case 7: - chances = new float[]{ 3, 1, 1, 1 }; - classes = new Class[]{ Skeleton.class, Shaman.class, Thief.class, Guard.class }; - break; - case 8: - chances = new float[]{ 3, 2, 2, 1, 0.02f }; - classes = new Class[]{ Skeleton.class, Shaman.class, Guard.class, Thief.class, Bat.class }; - break; - case 9: - chances = new float[]{ 3, 3, 2, 1, 0.02f, 0.01f }; - classes = new Class[]{ Skeleton.class, Guard.class, Shaman.class, Thief.class, Bat.class, Brute.class }; - break; - - case 10: - chances = new float[]{ 1 }; - classes = new Class[]{ Tengu.class }; - break; - - case 11: - chances = new float[]{ 1, 0.2f }; - classes = new Class[]{ Bat.class, Brute.class }; - break; - case 12: - chances = new float[]{ 1, 1, 0.2f }; - classes = new Class[]{ Bat.class, Brute.class, Spinner.class }; - break; - case 13: - chances = new float[]{ 1, 3, 1, 1, 0.02f }; - classes = new Class[]{ Bat.class, Brute.class, Shaman.class, Spinner.class, Elemental.class }; - break; - case 14: - chances = new float[]{ 1, 3, 1, 4, 0.02f, 0.01f }; - classes = new Class[]{ Bat.class, Brute.class, Shaman.class, Spinner.class, Elemental.class, Monk.class }; - break; - - case 15: - chances = new float[]{ 1 }; - classes = new Class[]{ DM300.class }; - break; - - case 16: - chances = new float[]{ 1, 1, 0.2f }; - classes = new Class[]{ Elemental.class, Warlock.class, Monk.class }; - break; - case 17: - chances = new float[]{ 1, 1, 1 }; - classes = new Class[]{ Elemental.class, Monk.class, Warlock.class }; - break; - case 18: - chances = new float[]{ 1, 2, 1, 1 }; - classes = new Class[]{ Elemental.class, Monk.class, Golem.class, Warlock.class }; - break; - case 19: - chances = new float[]{ 1, 2, 3, 1, 0.02f }; - classes = new Class[]{ Elemental.class, Monk.class, Golem.class, Warlock.class, Succubus.class }; - break; - - case 20: - chances = new float[]{ 1 }; - classes = new Class[]{ King.class }; - break; - - case 22: - chances = new float[]{ 1, 1 }; - classes = new Class[]{ Succubus.class, Eye.class }; - break; - case 23: - chances = new float[]{ 1, 2, 1 }; - classes = new Class[]{ Succubus.class, Eye.class, Scorpio.class }; - break; - case 24: - chances = new float[]{ 1, 2, 3 }; - classes = new Class[]{ Succubus.class, Eye.class, Scorpio.class }; - break; - - case 25: - chances = new float[]{ 1 }; - classes = new Class[]{ Yog.class }; - break; - - default: - chances = new float[]{ 1 }; - classes = new Class[]{ Eye.class }; - } - - return classes[ Random.chances( chances )]; } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/curses/Multiplicity.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/curses/Multiplicity.java index 69f54ad03..686aa8be4 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/curses/Multiplicity.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/curses/Multiplicity.java @@ -26,7 +26,6 @@ import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; -import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Bestiary; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mimic; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Statue; @@ -71,7 +70,7 @@ public class Multiplicity extends Armor.Glyph { //FIXME should probably have a mob property for this if (attacker.properties().contains(Char.Property.BOSS) || attacker.properties().contains(Char.Property.MINIBOSS) || attacker instanceof Mimic || attacker instanceof Statue){ - m = Bestiary.mutable(Dungeon.depth % 5 == 0 ? Dungeon.depth - 1 : Dungeon.depth); + m = Dungeon.level.createMob(); } else { try { m = (Mob)attacker.getClass().newInstance(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CavesBossLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CavesBossLevel.java index 3c52e108a..da69c572d 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CavesBossLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CavesBossLevel.java @@ -26,7 +26,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Bones; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; -import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Bestiary; +import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.DM300; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob; import com.shatteredpixel.shatteredpixeldungeon.effects.CellEmitter; import com.shatteredpixel.shatteredpixeldungeon.effects.Speck; @@ -201,6 +201,11 @@ public class CavesBossLevel extends Level { return true; } + @Override + public Mob createMob() { + return null; + } + @Override protected void createMobs() { } @@ -240,7 +245,7 @@ public class CavesBossLevel extends Level { enteredArena = true; seal(); - Mob boss = Bestiary.mob( Dungeon.depth ); + DM300 boss = new DM300(); boss.state = boss.WANDERING; do { boss.pos = Random.Int( length() ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CityBossLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CityBossLevel.java index 2d0e64f7c..f69899cbc 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CityBossLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CityBossLevel.java @@ -26,7 +26,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Bones; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; -import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Bestiary; +import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.King; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob; import com.shatteredpixel.shatteredpixeldungeon.items.Heap; import com.shatteredpixel.shatteredpixeldungeon.items.Item; @@ -153,6 +153,11 @@ public class CityBossLevel extends Level { } } + @Override + public Mob createMob() { + return null; + } + @Override protected void createMobs() { } @@ -194,7 +199,7 @@ public class CityBossLevel extends Level { enteredArena = true; seal(); - Mob boss = Bestiary.mob( Dungeon.depth ); + King boss = new King(); boss.state = boss.WANDERING; int count = 0; do { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/DeadEndLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/DeadEndLevel.java index f114ae10c..3761b20b0 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/DeadEndLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/DeadEndLevel.java @@ -23,6 +23,7 @@ package com.shatteredpixel.shatteredpixeldungeon.levels; import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; +import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob; public class DeadEndLevel extends Level { @@ -71,7 +72,12 @@ public class DeadEndLevel extends Level { return true; } - + + @Override + public Mob createMob() { + return null; + } + @Override protected void createMobs() { } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/HallsBossLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/HallsBossLevel.java index 6555f04c8..8b2f50a01 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/HallsBossLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/HallsBossLevel.java @@ -26,6 +26,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Bones; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; +import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Yog; import com.shatteredpixel.shatteredpixeldungeon.effects.CellEmitter; import com.shatteredpixel.shatteredpixeldungeon.effects.particles.FlameParticle; @@ -141,6 +142,11 @@ public class HallsBossLevel extends Level { return true; } + @Override + public Mob createMob() { + return null; + } + @Override protected void createMobs() { } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/LastLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/LastLevel.java index ad7bf0025..13e6886d0 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/LastLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/LastLevel.java @@ -23,6 +23,7 @@ package com.shatteredpixel.shatteredpixeldungeon.levels; import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; +import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob; import com.shatteredpixel.shatteredpixeldungeon.items.Amulet; import com.shatteredpixel.shatteredpixeldungeon.levels.painters.Painter; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; @@ -112,7 +113,12 @@ public class LastLevel extends Level { return true; } - + + @Override + public Mob createMob() { + return null; + } + @Override protected void createMobs() { } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/LastShopLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/LastShopLevel.java index 875c194f1..b433d6367 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/LastShopLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/LastShopLevel.java @@ -24,6 +24,7 @@ package com.shatteredpixel.shatteredpixeldungeon.levels; import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.Bones; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; +import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob; import com.shatteredpixel.shatteredpixeldungeon.items.Heap; import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.levels.builders.Builder; @@ -99,6 +100,11 @@ public class LastShopLevel extends RegularLevel { .setGrass( 0.10f, 3 ); } + @Override + public Mob createMob() { + return null; + } + @Override protected void createMobs() { } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java index 6dc136340..9d6470f06 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java @@ -39,7 +39,6 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.MindVision; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Shadows; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.HeroClass; -import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Bestiary; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob; import com.shatteredpixel.shatteredpixeldungeon.effects.particles.FlowParticle; import com.shatteredpixel.shatteredpixeldungeon.effects.particles.WindParticle; @@ -460,6 +459,8 @@ public abstract class Level implements Bundlable { } abstract protected boolean build(); + + abstract public Mob createMob(); abstract protected void createMobs(); @@ -519,7 +520,7 @@ public abstract class Level implements Bundlable { protected boolean act() { if (mobs.size() < nMobs()) { - Mob mob = Bestiary.mutable( Dungeon.depth ); + Mob mob = createMob(); mob.state = mob.WANDERING; mob.pos = randomRespawnCell(); if (Dungeon.hero.isAlive() && mob.pos != -1 && distance(Dungeon.hero.pos, mob.pos) >= 4) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/PrisonBossLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/PrisonBossLevel.java index af47ba3c3..80c035306 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/PrisonBossLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/PrisonBossLevel.java @@ -134,7 +134,12 @@ public class PrisonBossLevel extends Level { return true; } - + + @Override + public Mob createMob() { + return null; + } + @Override protected void createMobs() { tengu = new Tengu(); //We want to keep track of tengu independently of other mobs, he's not always in the level. diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/RegularLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/RegularLevel.java index 997e55906..b66ea4d7a 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/RegularLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/RegularLevel.java @@ -24,6 +24,7 @@ package com.shatteredpixel.shatteredpixeldungeon.levels; import com.shatteredpixel.shatteredpixeldungeon.Badges; import com.shatteredpixel.shatteredpixeldungeon.Bones; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; +import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Bestiary; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob; @@ -191,6 +192,21 @@ public abstract class RegularLevel extends Level { } } + private ArrayList> mobsToSpawn = new ArrayList<>(); + + @Override + public Mob createMob() { + if (mobsToSpawn == null || mobsToSpawn.isEmpty()) + mobsToSpawn = Bestiary.getMobRotation(Dungeon.depth); + + try { + return mobsToSpawn.remove(0).newInstance(); + } catch (Exception e) { + ShatteredPixelDungeon.reportException(e); + return null; + } + } + @Override protected void createMobs() { //on floor 1, 10 rats are created so the player can get level 2. @@ -215,7 +231,7 @@ public abstract class RegularLevel extends Level { stdRoomIter = stdRooms.iterator(); Room roomToSpawn = stdRoomIter.next(); - Mob mob = Bestiary.mob( Dungeon.depth ); + Mob mob = createMob(); mob.pos = pointToCell(roomToSpawn.random()); if (findMob(mob.pos) == null && Level.passable[mob.pos]) { @@ -224,7 +240,7 @@ public abstract class RegularLevel extends Level { //TODO: perhaps externalize this logic into a method. Do I want to make mobs more likely to clump deeper down? if (mobsToSpawn > 0 && Random.Int(4) == 0){ - mob = Bestiary.mob( Dungeon.depth ); + mob = createMob(); mob.pos = pointToCell(roomToSpawn.random()); if (findMob(mob.pos) == null && Level.passable[mob.pos]) { @@ -420,6 +436,7 @@ public abstract class RegularLevel extends Level { public void storeInBundle( Bundle bundle ) { super.storeInBundle( bundle ); bundle.put( "rooms", rooms ); + bundle.put( "mobs_to_spawn", mobsToSpawn.toArray(new Class[0])); } @SuppressWarnings("unchecked") @@ -436,6 +453,12 @@ public abstract class RegularLevel extends Level { roomExit = r; } } + + if (bundle.contains( "mobs_to_spawn" )) { + for (Class mob : bundle.getClassArray("mobs_to_spawn")) { + if (mob != null) mobsToSpawn.add(mob); + } + } } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/SewerBossLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/SewerBossLevel.java index ca9852c71..04c717aee 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/SewerBossLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/SewerBossLevel.java @@ -22,10 +22,8 @@ package com.shatteredpixel.shatteredpixeldungeon.levels; import com.shatteredpixel.shatteredpixeldungeon.Bones; -import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; -import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Bestiary; -import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob; +import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Goo; import com.shatteredpixel.shatteredpixeldungeon.items.Heap; import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.levels.builders.Builder; @@ -115,13 +113,13 @@ public class SewerBossLevel extends SewerLevel { @Override protected void createMobs() { - Mob mob = Bestiary.mob( Dungeon.depth ); + Goo boss = new Goo(); Room room; do { room = randomRoom(StandardRoom.class); } while (room == roomEntrance); - mob.pos = pointToCell(room.random()); - mobs.add( mob ); + boss.pos = pointToCell(room.random()); + mobs.add( boss ); } public Actor respawner() { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/SummoningTrap.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/SummoningTrap.java index c0eeaa116..78ce4b481 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/SummoningTrap.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/SummoningTrap.java @@ -23,7 +23,6 @@ package com.shatteredpixel.shatteredpixeldungeon.levels.traps; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; -import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Bestiary; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob; import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfTeleportation; import com.shatteredpixel.shatteredpixeldungeon.levels.Level; @@ -78,7 +77,7 @@ public class SummoningTrap extends Trap { ArrayList mobs = new ArrayList<>(); for (Integer point : respawnPoints) { - Mob mob = Bestiary.mob( Dungeon.depth ); + Mob mob = Dungeon.level.createMob(); mob.state = mob.WANDERING; mob.pos = point; GameScene.add( mob, DELAY );