v0.9.0b: improved logic for awarding win badges:

- fixed a bug where win/chal badges wouldn't save in rare cases
- fixed win/chal badges not being displayed in many cases
This commit is contained in:
Evan Debenham 2020-10-11 22:07:05 -04:00
parent 6d038edb2b
commit 77329f6d86
5 changed files with 37 additions and 12 deletions

View File

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

View File

@ -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){

View File

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

View File

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

View File

@ -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;
@ -160,11 +162,13 @@ public class WelcomeScene extends PixelScene {
//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);