diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Badges.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Badges.java index 729a4358c..1b27671a6 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Badges.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Badges.java @@ -803,6 +803,7 @@ public class Badges { } public static void validateChampion( int challenges ) { + if (challenges == 0) return; Badge badge = null; if (challenges >= 1) { badge = Badge.CHAMPION_1; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Challenges.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Challenges.java index 8eeecebfa..225bed431 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Challenges.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Challenges.java @@ -53,6 +53,14 @@ public class Challenges { CHAMPION_ENEMIES, NO_FOOD, NO_ARMOR, NO_HEALING, NO_HERBALISM, SWARM_INTELLIGENCE, DARKNESS, NO_SCROLLS }; + public static int activeChallenges(){ + int chCount = 0; + for (int ch : Challenges.MASKS){ + if ((Dungeon.challenges & ch) != 0) chCount++; + } + return chCount; + } + public static boolean isItemBlocked( Item item ){ if (Dungeon.isChallenged(NO_HERBALISM) && item instanceof Dewdrop){ diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java index 1d6f12e2b..9612bf184 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java @@ -690,15 +690,6 @@ public class Dungeon { hero.belongings.identify(); - int chCount = 0; - for (int ch : Challenges.MASKS){ - if ((challenges & ch) != 0) chCount++; - } - - if (chCount != 0) { - Badges.validateChampion(chCount); - } - Rankings.INSTANCE.submit( true, cause ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Amulet.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Amulet.java index a390adeee..7852bf974 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Amulet.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Amulet.java @@ -22,6 +22,7 @@ package com.shatteredpixel.shatteredpixeldungeon.items; import com.shatteredpixel.shatteredpixeldungeon.Badges; +import com.shatteredpixel.shatteredpixeldungeon.Challenges; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.Statistics; @@ -67,7 +68,6 @@ public class Amulet extends Item { if (!Statistics.amuletObtained) { Statistics.amuletObtained = true; - Badges.validateVictory(); hero.spend(-TIME_TO_PICK_UP); //add a delayed actor here so pickup behaviour can fully process. @@ -91,7 +91,19 @@ public class Amulet extends Item { try { Dungeon.saveAll(); AmuletScene.noText = !showText; - Game.switchScene( AmuletScene.class ); + Game.switchScene( AmuletScene.class, new Game.SceneChangeCallback() { + @Override + public void beforeCreate() { + + } + + @Override + public void afterCreate() { + Badges.validateVictory(); + Badges.validateChampion(Challenges.activeChallenges()); + Badges.saveGlobal(); + } + }); } catch (IOException e) { ShatteredPixelDungeon.reportException(e); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/WelcomeScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/WelcomeScene.java index e8668795d..a932ca66b 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/WelcomeScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/WelcomeScene.java @@ -21,6 +21,8 @@ package com.shatteredpixel.shatteredpixeldungeon.scenes; +import com.shatteredpixel.shatteredpixeldungeon.Badges; +import com.shatteredpixel.shatteredpixeldungeon.Challenges; import com.shatteredpixel.shatteredpixeldungeon.Chrome; import com.shatteredpixel.shatteredpixeldungeon.GamesInProgress; import com.shatteredpixel.shatteredpixeldungeon.Rankings; @@ -157,14 +159,16 @@ public class WelcomeScene extends PixelScene { } private void updateVersion(int previousVersion){ - + //update rankings, to update any data which may be outdated if (previousVersion < LATEST_UPDATE){ + int highestChalInRankings = 0; try { Rankings.INSTANCE.load(); for (Rankings.Record rec : Rankings.INSTANCE.records.toArray(new Rankings.Record[0])){ try { Rankings.INSTANCE.loadGameData(rec); + highestChalInRankings = Math.max(highestChalInRankings, Challenges.activeChallenges()); Rankings.INSTANCE.saveGameData(rec); } catch (Exception e) { //if we encounter a fatal per-record error, then clear that record @@ -178,6 +182,15 @@ public class WelcomeScene extends PixelScene { FileUtils.deleteFile( Rankings.RANKINGS_FILE ); ShatteredPixelDungeon.reportException(e); } + + //fixes a bug from v0.9.0- where champion badges would rarely not save + if (highestChalInRankings > 0){ + Badges.loadGlobal(); + if (highestChalInRankings >= 1) Badges.addGlobal(Badges.Badge.CHAMPION_1); + if (highestChalInRankings >= 3) Badges.addGlobal(Badges.Badge.CHAMPION_2); + if (highestChalInRankings >= 6) Badges.addGlobal(Badges.Badge.CHAMPION_3); + Badges.saveGlobal(); + } } SPDSettings.version(ShatteredPixelDungeon.versionCode);