From 0b568f5a58994567125d2337c149ecb0fd613c10 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Thu, 9 Jul 2020 14:09:01 -0400 Subject: [PATCH] v0.8.2: Fixed generator reset incorrectly clearing all category decks --- .../shatteredpixeldungeon/Dungeon.java | 2 +- .../shatteredpixeldungeon/Rankings.java | 2 +- .../shatteredpixeldungeon/items/Generator.java | 18 ++++++++++++------ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java index 5c54fdcde..226036090 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java @@ -212,7 +212,7 @@ public class Dungeon { Blacksmith.Quest.reset(); Imp.Quest.reset(); - Generator.reset(); + Generator.fullReset(); hero = new Hero(); hero.live(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Rankings.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Rankings.java index ee18d225e..5c4292e47 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Rankings.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Rankings.java @@ -173,7 +173,7 @@ public enum Rankings { Actor.clear(); Dungeon.hero = null; Dungeon.level = null; - Generator.reset(); + Generator.fullReset(); Notes.reset(); Dungeon.quickslot.reset(); QuickSlotButton.reset(); 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 0a42582fa..436fed9ca 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Generator.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Generator.java @@ -470,22 +470,28 @@ public class Generator { }; private static HashMap categoryProbs = new LinkedHashMap<>(); - - public static void reset() { + + public static void fullReset() { + generalReset(); + for (Category cat : Category.values()) { + reset(cat); + } + } + + public static void generalReset(){ for (Category cat : Category.values()) { categoryProbs.put( cat, cat.prob ); - if (cat.defaultProbs != null) cat.probs = cat.defaultProbs.clone(); } } public static void reset(Category cat){ - cat.probs = cat.defaultProbs.clone(); + if (cat.defaultProbs != null) cat.probs = cat.defaultProbs.clone(); } public static Item random() { Category cat = Random.chances( categoryProbs ); if (cat == null){ - reset(); + generalReset(); cat = Random.chances( categoryProbs ); } categoryProbs.put( cat, categoryProbs.get( cat ) - 1); @@ -640,7 +646,7 @@ public class Generator { } public static void restoreFromBundle(Bundle bundle) { - reset(); + fullReset(); if (bundle.contains(GENERAL_PROBS)){ float[] probs = bundle.getFloatArray(GENERAL_PROBS);