From f23962ec5649ffccddc69f53b34665ed0278fd7f Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Sun, 7 Apr 2024 16:02:57 -0400 Subject: [PATCH] v2.4.0: fixed very rare cases of hourglass affecting levelgen --- .../levels/CityBossLevel.java | 2 +- .../levels/rooms/special/ShopRoom.java | 22 +++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) 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 f055e1740..23b3a828a 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CityBossLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CityBossLevel.java @@ -366,7 +366,7 @@ public class CityBossLevel extends Level { } private void spawnShop(){ - while (impShop.itemCount() >= 7*(impShop.height()-2)){ + while (impShop.spacesNeeded() >= 7*(impShop.height()-2)){ impShop.bottom++; } impShop.spawnShop(this); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/special/ShopRoom.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/special/ShopRoom.java index 0bcd51d46..c13761058 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/special/ShopRoom.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/special/ShopRoom.java @@ -68,17 +68,31 @@ public class ShopRoom extends SpecialRoom { @Override public int minWidth() { - return Math.max(7, (int)(Math.sqrt(itemCount())+3)); + return Math.max(7, (int)(Math.sqrt(spacesNeeded())+3)); } @Override public int minHeight() { - return Math.max(7, (int)(Math.sqrt(itemCount())+3)); + return Math.max(7, (int)(Math.sqrt(spacesNeeded())+3)); } - public int itemCount(){ + public int spacesNeeded(){ if (itemsToSpawn == null) itemsToSpawn = generateItems(); - return itemsToSpawn.size(); + + //sandbags spawn based on current level of an hourglass the player may be holding + // so, to avoid rare cases of min sizes differing based on that, we ignore all sandbags + // and then add 4 items in all cases, which is max number of sandbags that can be in the shop + int spacesNeeded = itemsToSpawn.size(); + for (Item i : itemsToSpawn){ + if (i instanceof TimekeepersHourglass.sandBag){ + spacesNeeded--; + } + } + spacesNeeded += 4; + + //we also add 1 more space, for the shopkeeper + spacesNeeded++; + return spacesNeeded; } public void paint( Level level ) {