v0.8.2: Fixed generator reset incorrectly clearing all category decks

This commit is contained in:
Evan Debenham 2020-07-09 14:09:01 -04:00
parent 2478e18ba6
commit 0b568f5a58
3 changed files with 14 additions and 8 deletions

View File

@ -212,7 +212,7 @@ public class Dungeon {
Blacksmith.Quest.reset(); Blacksmith.Quest.reset();
Imp.Quest.reset(); Imp.Quest.reset();
Generator.reset(); Generator.fullReset();
hero = new Hero(); hero = new Hero();
hero.live(); hero.live();

View File

@ -173,7 +173,7 @@ public enum Rankings {
Actor.clear(); Actor.clear();
Dungeon.hero = null; Dungeon.hero = null;
Dungeon.level = null; Dungeon.level = null;
Generator.reset(); Generator.fullReset();
Notes.reset(); Notes.reset();
Dungeon.quickslot.reset(); Dungeon.quickslot.reset();
QuickSlotButton.reset(); QuickSlotButton.reset();

View File

@ -471,21 +471,27 @@ public class Generator {
private static HashMap<Category,Float> categoryProbs = new LinkedHashMap<>(); private static HashMap<Category,Float> 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()) { for (Category cat : Category.values()) {
categoryProbs.put( cat, cat.prob ); categoryProbs.put( cat, cat.prob );
if (cat.defaultProbs != null) cat.probs = cat.defaultProbs.clone();
} }
} }
public static void reset(Category cat){ public static void reset(Category cat){
cat.probs = cat.defaultProbs.clone(); if (cat.defaultProbs != null) cat.probs = cat.defaultProbs.clone();
} }
public static Item random() { public static Item random() {
Category cat = Random.chances( categoryProbs ); Category cat = Random.chances( categoryProbs );
if (cat == null){ if (cat == null){
reset(); generalReset();
cat = Random.chances( categoryProbs ); cat = Random.chances( categoryProbs );
} }
categoryProbs.put( cat, categoryProbs.get( cat ) - 1); categoryProbs.put( cat, categoryProbs.get( cat ) - 1);
@ -640,7 +646,7 @@ public class Generator {
} }
public static void restoreFromBundle(Bundle bundle) { public static void restoreFromBundle(Bundle bundle) {
reset(); fullReset();
if (bundle.contains(GENERAL_PROBS)){ if (bundle.contains(GENERAL_PROBS)){
float[] probs = bundle.getFloatArray(GENERAL_PROBS); float[] probs = bundle.getFloatArray(GENERAL_PROBS);