Restructure game over logic to save before clear
This commit is contained in:
parent
acb61d6fb7
commit
9cfc09f673
|
@ -1978,7 +1978,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"frameIndex": 0,
|
"frameIndex": 0,
|
||||||
"resourceName": "PRAS- Sketch and Lick",
|
"resourceName": "PRAS- Sketch + Lick",
|
||||||
"bgX": 0,
|
"bgX": 0,
|
||||||
"bgY": 0,
|
"bgY": 0,
|
||||||
"opacity": 0,
|
"opacity": 0,
|
||||||
|
|
|
@ -759,6 +759,8 @@ export default class BattleScene extends SceneBase {
|
||||||
|
|
||||||
this.newArena(Overrides.STARTING_BIOME_OVERRIDE || Biome.TOWN);
|
this.newArena(Overrides.STARTING_BIOME_OVERRIDE || Biome.TOWN);
|
||||||
|
|
||||||
|
this.field.setVisible(true);
|
||||||
|
|
||||||
this.arenaBgTransition.setPosition(0, 0);
|
this.arenaBgTransition.setPosition(0, 0);
|
||||||
this.arenaPlayer.setPosition(300, 0);
|
this.arenaPlayer.setPosition(300, 0);
|
||||||
this.arenaPlayerTransition.setPosition(0, 0);
|
this.arenaPlayerTransition.setPosition(0, 0);
|
||||||
|
|
117
src/phases.ts
117
src/phases.ts
|
@ -3484,19 +3484,14 @@ export class GameOverModifierRewardPhase extends ModifierRewardPhase {
|
||||||
return new Promise<void>(resolve => {
|
return new Promise<void>(resolve => {
|
||||||
const newModifier = this.modifierType.newModifier();
|
const newModifier = this.modifierType.newModifier();
|
||||||
this.scene.addModifier(newModifier).then(() => {
|
this.scene.addModifier(newModifier).then(() => {
|
||||||
this.scene.gameData.saveSystem().then(success => {
|
this.scene.playSound('level_up_fanfare');
|
||||||
if (success) {
|
this.scene.ui.setMode(Mode.MESSAGE);
|
||||||
this.scene.playSound('level_up_fanfare');
|
this.scene.arenaBg.setVisible(false);
|
||||||
this.scene.ui.setMode(Mode.MESSAGE);
|
this.scene.ui.fadeIn(250).then(() => {
|
||||||
this.scene.arenaBg.setVisible(false);
|
this.scene.ui.showText(`You received\n${newModifier.type.name}!`, null, () => {
|
||||||
this.scene.ui.fadeIn(250).then(() => {
|
this.scene.time.delayedCall(1500, () => this.scene.arenaBg.setVisible(true));
|
||||||
this.scene.ui.showText(`You received\n${newModifier.type.name}!`, null, () => {
|
resolve();
|
||||||
this.scene.time.delayedCall(1500, () => this.scene.arenaBg.setVisible(true));
|
}, null, true, 1500);
|
||||||
resolve();
|
|
||||||
}, null, true, 1500);
|
|
||||||
});
|
|
||||||
} else
|
|
||||||
this.scene.reset(true);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
@ -3516,18 +3511,13 @@ export class RibbonModifierRewardPhase extends ModifierRewardPhase {
|
||||||
return new Promise<void>(resolve => {
|
return new Promise<void>(resolve => {
|
||||||
const newModifier = this.modifierType.newModifier();
|
const newModifier = this.modifierType.newModifier();
|
||||||
this.scene.addModifier(newModifier).then(() => {
|
this.scene.addModifier(newModifier).then(() => {
|
||||||
this.scene.gameData.saveSystem().then(success => {
|
this.scene.playSound('level_up_fanfare');
|
||||||
if (success) {
|
this.scene.ui.setMode(Mode.MESSAGE);
|
||||||
this.scene.playSound('level_up_fanfare');
|
this.scene.arenaBg.setVisible(false);
|
||||||
this.scene.ui.setMode(Mode.MESSAGE);
|
this.scene.ui.fadeIn(250).then(() => {
|
||||||
this.scene.arenaBg.setVisible(false);
|
this.scene.ui.showText(`${this.species.name} beat ${this.scene.gameMode.getName()} Mode for the first time!\nYou received ${newModifier.type.name}!`, null, () => {
|
||||||
this.scene.ui.fadeIn(250).then(() => {
|
resolve();
|
||||||
this.scene.ui.showText(`${this.species.name} beat ${this.scene.gameMode.getName()} Mode for the first time!\nYou received ${newModifier.type.name}!`, null, () => {
|
}, null, true, 1500);
|
||||||
resolve();
|
|
||||||
}, null, true, 1500);
|
|
||||||
});
|
|
||||||
} else
|
|
||||||
this.scene.reset(true);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
@ -3548,7 +3538,7 @@ export class GameOverPhase extends BattlePhase {
|
||||||
super.start();
|
super.start();
|
||||||
|
|
||||||
if (this.victory || !this.scene.enableRetries)
|
if (this.victory || !this.scene.enableRetries)
|
||||||
this.handleClearSession();
|
this.handleGameOver();
|
||||||
else {
|
else {
|
||||||
this.scene.ui.showText(`Would you like to retry from the start of the battle?`, null, () => {
|
this.scene.ui.showText(`Would you like to retry from the start of the battle?`, null, () => {
|
||||||
this.scene.ui.setMode(Mode.CONFIRM, () => {
|
this.scene.ui.setMode(Mode.CONFIRM, () => {
|
||||||
|
@ -3573,18 +3563,16 @@ export class GameOverPhase extends BattlePhase {
|
||||||
this.end();
|
this.end();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}, () => this.handleClearSession(), false, 0, 0, 1000);
|
}, () => this.handleGameOver(), false, 0, 0, 1000);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleClearSession(): void {
|
handleGameOver(): void {
|
||||||
this.scene.gameData.tryClearSession(this.scene, this.scene.sessionSlotId).then((success: boolean | [boolean, boolean]) => {
|
const doGameOver = (newClear: boolean) => {
|
||||||
if (!success[0])
|
|
||||||
return this.scene.reset(true);
|
|
||||||
this.scene.time.delayedCall(1000, () => {
|
this.scene.time.delayedCall(1000, () => {
|
||||||
let firstClear = false;
|
let firstClear = false;
|
||||||
if (this.victory && success[1]) {
|
if (this.victory && newClear) {
|
||||||
if (this.scene.gameMode.isClassic) {
|
if (this.scene.gameMode.isClassic) {
|
||||||
firstClear = this.scene.validateAchv(achvs.CLASSIC_VICTORY);
|
firstClear = this.scene.validateAchv(achvs.CLASSIC_VICTORY);
|
||||||
this.scene.gameData.gameStats.sessionsWon++;
|
this.scene.gameData.gameStats.sessionsWon++;
|
||||||
|
@ -3595,29 +3583,37 @@ export class GameOverPhase extends BattlePhase {
|
||||||
this.awardRibbon(pokemon, true);
|
this.awardRibbon(pokemon, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (this.scene.gameMode.isDaily && success[1])
|
} else if (this.scene.gameMode.isDaily && newClear)
|
||||||
this.scene.gameData.gameStats.dailyRunSessionsWon++;
|
this.scene.gameData.gameStats.dailyRunSessionsWon++;
|
||||||
}
|
}
|
||||||
this.scene.gameData.saveSystem();
|
|
||||||
const fadeDuration = this.victory ? 10000 : 5000;
|
const fadeDuration = this.victory ? 10000 : 5000;
|
||||||
this.scene.fadeOutBgm(fadeDuration, true);
|
this.scene.fadeOutBgm(fadeDuration, true);
|
||||||
|
const activeBattlers = this.scene.getField().filter(p => p?.isActive(true));
|
||||||
|
activeBattlers.map(p => p.hideInfo());
|
||||||
this.scene.ui.fadeOut(fadeDuration).then(() => {
|
this.scene.ui.fadeOut(fadeDuration).then(() => {
|
||||||
|
[ this.scene.field, ...activeBattlers ].map(a => a.setVisible(false));
|
||||||
this.scene.setFieldScale(1, true);
|
this.scene.setFieldScale(1, true);
|
||||||
this.scene.clearPhaseQueue();
|
this.scene.clearPhaseQueue();
|
||||||
this.scene.ui.clearText();
|
this.scene.ui.clearText();
|
||||||
this.handleUnlocks();
|
if (newClear)
|
||||||
if (this.victory && success[1]) {
|
this.handleUnlocks();
|
||||||
|
if (this.victory && newClear) {
|
||||||
for (let species of this.firstRibbons)
|
for (let species of this.firstRibbons)
|
||||||
this.scene.unshiftPhase(new RibbonModifierRewardPhase(this.scene, modifierTypes.VOUCHER_PLUS, species));
|
this.scene.unshiftPhase(new RibbonModifierRewardPhase(this.scene, modifierTypes.VOUCHER_PLUS, species));
|
||||||
if (!firstClear)
|
if (!firstClear)
|
||||||
this.scene.unshiftPhase(new GameOverModifierRewardPhase(this.scene, modifierTypes.VOUCHER_PREMIUM));
|
this.scene.unshiftPhase(new GameOverModifierRewardPhase(this.scene, modifierTypes.VOUCHER_PREMIUM));
|
||||||
}
|
}
|
||||||
this.scene.reset();
|
this.scene.pushPhase(new PostGameOverPhase(this.scene));
|
||||||
this.scene.unshiftPhase(new TitlePhase(this.scene));
|
|
||||||
this.end();
|
this.end();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
};
|
||||||
|
if (this.victory) {
|
||||||
|
Utils.apiFetch(`savedata/newclear?slot=${this.scene.sessionSlotId}`, true)
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(newClear => doGameOver(newClear));
|
||||||
|
} else
|
||||||
|
doGameOver(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleUnlocks(): void {
|
handleUnlocks(): void {
|
||||||
|
@ -3653,19 +3649,36 @@ export class UnlockPhase extends Phase {
|
||||||
start(): void {
|
start(): void {
|
||||||
this.scene.time.delayedCall(2000, () => {
|
this.scene.time.delayedCall(2000, () => {
|
||||||
this.scene.gameData.unlocks[this.unlockable] = true;
|
this.scene.gameData.unlocks[this.unlockable] = true;
|
||||||
this.scene.gameData.saveSystem().then(success => {
|
this.scene.playSound('level_up_fanfare');
|
||||||
if (success) {
|
this.scene.ui.setMode(Mode.MESSAGE);
|
||||||
this.scene.playSound('level_up_fanfare');
|
this.scene.arenaBg.setVisible(false);
|
||||||
this.scene.ui.setMode(Mode.MESSAGE);
|
this.scene.ui.fadeIn(250).then(() => {
|
||||||
this.scene.arenaBg.setVisible(false);
|
this.scene.ui.showText(`${getUnlockableName(this.unlockable)}\nhas been unlocked.`, null, () => {
|
||||||
this.scene.ui.fadeIn(250).then(() => {
|
this.scene.time.delayedCall(1500, () => this.scene.arenaBg.setVisible(true));
|
||||||
this.scene.ui.showText(`${getUnlockableName(this.unlockable)}\nhas been unlocked.`, null, () => {
|
this.end();
|
||||||
this.scene.time.delayedCall(1500, () => this.scene.arenaBg.setVisible(true));
|
}, null, true, 1500);
|
||||||
this.end();
|
});
|
||||||
}, null, true, 1500);
|
});
|
||||||
});
|
}
|
||||||
} else
|
}
|
||||||
this.scene.reset(true);
|
|
||||||
|
export class PostGameOverPhase extends Phase {
|
||||||
|
constructor(scene: BattleScene) {
|
||||||
|
super(scene);
|
||||||
|
}
|
||||||
|
|
||||||
|
start() {
|
||||||
|
super.start();
|
||||||
|
|
||||||
|
this.scene.gameData.saveSystem().then(success => {
|
||||||
|
if (!success)
|
||||||
|
return this.scene.reset(true);
|
||||||
|
this.scene.gameData.tryClearSession(this.scene, this.scene.sessionSlotId).then((success: boolean | [boolean, boolean]) => {
|
||||||
|
if (!success[0])
|
||||||
|
return this.scene.reset(true);
|
||||||
|
this.scene.reset();
|
||||||
|
this.scene.unshiftPhase(new TitlePhase(this.scene));
|
||||||
|
this.end();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,11 +190,14 @@ const systemShortKeys = {
|
||||||
natureAttr: '$na',
|
natureAttr: '$na',
|
||||||
seenCount: '$s' ,
|
seenCount: '$s' ,
|
||||||
caughtCount: '$c',
|
caughtCount: '$c',
|
||||||
|
hatchedCount: '$hc',
|
||||||
ivs: '$i',
|
ivs: '$i',
|
||||||
moveset: '$m',
|
moveset: '$m',
|
||||||
eggMoves: '$em',
|
eggMoves: '$em',
|
||||||
candyCount: '$x',
|
candyCount: '$x',
|
||||||
passive: '$p',
|
friendship: '$f',
|
||||||
|
abilityAttr: '$a',
|
||||||
|
passiveAttr: '$pa',
|
||||||
valueReduction: '$vr',
|
valueReduction: '$vr',
|
||||||
classicWinCount: '$wc'
|
classicWinCount: '$wc'
|
||||||
};
|
};
|
||||||
|
@ -454,6 +457,10 @@ export class GameData {
|
||||||
}
|
}
|
||||||
|
|
||||||
private convertSystemDataStr(dataStr: string, shorten: boolean = false): string {
|
private convertSystemDataStr(dataStr: string, shorten: boolean = false): string {
|
||||||
|
if (!shorten) {
|
||||||
|
// Account for past key oversight
|
||||||
|
dataStr = dataStr.replace(/\$pAttr/g, '$pa');
|
||||||
|
}
|
||||||
const fromKeys = shorten ? Object.keys(systemShortKeys) : Object.values(systemShortKeys);
|
const fromKeys = shorten ? Object.keys(systemShortKeys) : Object.values(systemShortKeys);
|
||||||
const toKeys = shorten ? Object.values(systemShortKeys) : Object.keys(systemShortKeys);
|
const toKeys = shorten ? Object.values(systemShortKeys) : Object.keys(systemShortKeys);
|
||||||
for (let k in fromKeys)
|
for (let k in fromKeys)
|
||||||
|
|
Loading…
Reference in New Issue