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();
Imp.Quest.reset();
Generator.reset();
Generator.fullReset();
hero = new Hero();
hero.live();

View File

@ -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();

View File

@ -470,22 +470,28 @@ public class Generator {
};
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()) {
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);