diff --git a/src/data/ability.ts b/src/data/ability.ts index 5ef07c39f7b..22867ee131f 100644 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -1407,6 +1407,23 @@ export class PostSummonMessageAbAttr extends PostSummonAbAttr { } } +export class PostSummonUnnamedMessageAbAttr extends PostSummonAbAttr { + //Attr doesn't force pokemon name on the message + private message: string; + + constructor(message: string) { + super(true); + + this.message = message; + } + + applyPostSummon(pokemon: Pokemon, passive: boolean, args: any[]): boolean { + pokemon.scene.queueMessage(this.message); + + return true; + } +} + export class PostSummonAddBattlerTagAbAttr extends PostSummonAbAttr { private tagType: BattlerTagType; private turnCount: integer; @@ -3061,7 +3078,8 @@ export function initAbilities() { .attr(BlockCritAbAttr) .ignorable(), new Ability(Abilities.AIR_LOCK, 3) - .attr(SuppressWeatherEffectAbAttr, true), + .attr(SuppressWeatherEffectAbAttr, true) + .attr(PostSummonUnnamedMessageAbAttr, "The effects of the weather disappeared."), new Ability(Abilities.TANGLED_FEET, 4) .conditionalAttr(pokemon => !!pokemon.getTag(BattlerTagType.CONFUSED), BattleStatMultiplierAbAttr, BattleStat.EVA, 2) .ignorable(), diff --git a/src/locales/fr/ability-trigger.ts b/src/locales/fr/ability-trigger.ts index 88900741218..f668ee5e8ab 100644 --- a/src/locales/fr/ability-trigger.ts +++ b/src/locales/fr/ability-trigger.ts @@ -1,5 +1,5 @@ import { SimpleTranslationEntries } from "#app/plugins/i18n"; export const abilityTriggers: SimpleTranslationEntries = { - 'blockRecoilDamage' : `{{pokemonName}}'s {{abilityName}}\nprotected it from recoil!`, -} as const; \ No newline at end of file + 'blockRecoilDamage' : `{{abilityName}}\nde {{pokemonName}} le protège du contrecoup !`, +} as const; diff --git a/src/phases.ts b/src/phases.ts index 6cc6af93ef9..271e5350c82 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -775,7 +775,7 @@ export class EncounterPhase extends BattlePhase { this.scene.ui.setMode(Mode.MESSAGE).then(() => { if (!this.loaded) { - this.scene.gameData.saveAll(this.scene, true, battle.waveIndex % 5 === 1).then(success => { + this.scene.gameData.saveAll(this.scene, true).then(success => { this.scene.disableMenu = false; if (!success) return this.scene.reset(true); diff --git a/src/system/game-data.ts b/src/system/game-data.ts index d0e296cc4c0..7f6e1475b4a 100644 --- a/src/system/game-data.ts +++ b/src/system/game-data.ts @@ -277,7 +277,7 @@ export class GameData { const maxIntAttrValue = Math.pow(2, 31); const systemData = JSON.stringify(data, (k: any, v: any) => typeof v === 'bigint' ? v <= maxIntAttrValue ? Number(v) : v.toString() : v); - if (!bypassLogin && !localStorage.getItem('data')) { + if (!bypassLogin) { Utils.apiPost(`savedata/update?datatype=${GameDataType.SYSTEM}`, systemData, undefined, true) .then(response => response.text()) .then(error => { @@ -293,15 +293,12 @@ export class GameData { console.error(error); return resolve(false); } - localStorage.removeItem('data'); resolve(true); }); } else { - const encFunc = bypassLogin - ? (data: string) => btoa(data) - : (data: string) => AES.encrypt(data, saveKey); + localStorage.setItem('data_bak', localStorage.getItem('data')); - localStorage.setItem('data', encFunc(systemData)); + localStorage.setItem('data', btoa(systemData)); this.scene.ui.savingIcon.hide(); @@ -312,7 +309,7 @@ export class GameData { public loadSystem(): Promise { return new Promise(resolve => { - if (bypassLogin && !localStorage.getItem('data')) + if (bypassLogin && !localStorage.hasOwnProperty('data')) return resolve(false); const handleSystemData = (systemDataStr: string) => { @@ -424,7 +421,7 @@ export class GameData { } } - if (!bypassLogin && !localStorage.getItem('data')) { + if (!bypassLogin) { Utils.apiFetch(`savedata/get?datatype=${GameDataType.SYSTEM}`, true) .then(response => response.text()) .then(response => { @@ -442,12 +439,8 @@ export class GameData { handleSystemData(response); }); - } else { - const decFunc = bypassLogin - ? (data: string) => atob(data) - : (data: string) => AES.decrypt(data, saveKey).toString(enc.Utf8); - handleSystemData(decFunc(localStorage.getItem('data'))); - } + } else + handleSystemData(atob(localStorage.getItem('data'))); }); } @@ -564,6 +557,40 @@ export class GameData { } as SessionSaveData; } + saveSession(scene: BattleScene, skipVerification?: boolean): Promise { + return new Promise(resolve => { + Utils.executeIf(!skipVerification, updateUserInfo).then(success => { + if (success !== null && !success) + return resolve(false); + + const sessionData = this.getSessionSaveData(scene); + + if (!bypassLogin) { + Utils.apiPost(`savedata/update?datatype=${GameDataType.SESSION}&slot=${scene.sessionSlotId}&trainerId=${this.trainerId}&secretId=${this.secretId}`, JSON.stringify(sessionData), undefined, true) + .then(response => response.text()) + .then(error => { + if (error) { + if (error.startsWith('session out of date')) { + this.scene.clearPhaseQueue(); + this.scene.unshiftPhase(new ReloadSessionPhase(this.scene)); + } + console.error(error); + return resolve(false); + } + console.debug('Session data saved'); + resolve(true); + }); + } else { + localStorage.setItem(`sessionData${scene.sessionSlotId ? scene.sessionSlotId : ''}`, btoa(JSON.stringify(sessionData))); + + console.debug('Session data saved'); + + resolve(true); + } + }); + }); + } + getSession(slotId: integer): Promise { return new Promise(async (resolve, reject) => { if (slotId < 0) @@ -578,7 +605,7 @@ export class GameData { } }; - if (!bypassLogin && !localStorage.getItem(`sessionData${slotId ? slotId : ''}`)) { + if (!bypassLogin) { Utils.apiFetch(`savedata/get?datatype=${GameDataType.SESSION}&slot=${slotId}`, true) .then(response => response.text()) .then(async response => { @@ -591,12 +618,9 @@ export class GameData { }); } else { const sessionData = localStorage.getItem(`sessionData${slotId ? slotId : ''}`); - if (sessionData) { - const decFunc = bypassLogin - ? (data: string) => atob(data) - : (data: string) => AES.decrypt(data, saveKey).toString(enc.Utf8); - await handleSessionData(decFunc(sessionData)); - } else + if (sessionData) + await handleSessionData(atob(sessionData)); + else return resolve(null); } }); @@ -707,7 +731,7 @@ export class GameData { deleteSession(slotId: integer): Promise { return new Promise(resolve => { if (bypassLogin) { - localStorage.removeItem(`sessionData${this.scene.sessionSlotId ? this.scene.sessionSlotId : ''}`); + localStorage.removeItem('sessionData'); return resolve(true); } @@ -717,7 +741,6 @@ export class GameData { Utils.apiFetch(`savedata/delete?datatype=${GameDataType.SESSION}&slot=${slotId}`, true).then(response => { if (response.ok) { loggedInUser.lastSessionSlot = -1; - localStorage.removeItem(`sessionData${this.scene.sessionSlotId ? this.scene.sessionSlotId : ''}`); resolve(true); } return response.text(); @@ -748,10 +771,8 @@ export class GameData { return resolve([false, false]); const sessionData = this.getSessionSaveData(scene); Utils.apiPost(`savedata/clear?slot=${slotId}&trainerId=${this.trainerId}&secretId=${this.secretId}`, JSON.stringify(sessionData), undefined, true).then(response => { - if (response.ok) { + if (response.ok) loggedInUser.lastSessionSlot = -1; - localStorage.removeItem(`sessionData${this.scene.sessionSlotId ? this.scene.sessionSlotId : ''}`); - } return response.json(); }).then(jsonResponse => { if (!jsonResponse.error) @@ -804,13 +825,13 @@ export class GameData { }) as SessionSaveData; } - saveAll(scene: BattleScene, skipVerification: boolean = false, sync: boolean = false): Promise { + saveAll(scene: BattleScene, skipVerification?: boolean): Promise { return new Promise(resolve => { Utils.executeIf(!skipVerification, updateUserInfo).then(success => { if (success !== null && !success) return resolve(false); - if (sync) - this.scene.ui.savingIcon.show(); + this.scene.ui.savingIcon.show(); + const data = this.getSystemSaveData(); const sessionData = this.getSessionSaveData(scene); const maxIntAttrValue = Math.pow(2, 31); @@ -822,12 +843,11 @@ export class GameData { sessionSlotId: scene.sessionSlotId }; - if (!bypassLogin && sync) { + if (!bypassLogin) { Utils.apiPost('savedata/updateall', JSON.stringify(request, (k: any, v: any) => typeof v === 'bigint' ? v <= maxIntAttrValue ? Number(v) : v.toString() : v), undefined, true) .then(response => response.text()) .then(error => { - if (sync) - this.scene.ui.savingIcon.hide(); + this.scene.ui.savingIcon.hide(); if (error) { if (error.startsWith('client version out of date')) { this.scene.clearPhaseQueue(); @@ -839,18 +859,14 @@ export class GameData { console.error(error); return resolve(false); } - localStorage.removeItem('data'); - localStorage.removeItem(`sessionData${scene.sessionSlotId ? scene.sessionSlotId : ''}`); resolve(true); }); } else { - const encFunc = bypassLogin - ? (data: string) => btoa(data) - : (data: string) => AES.encrypt(data, saveKey); + localStorage.setItem('data_bak', localStorage.getItem('data')); - localStorage.setItem('data', encFunc(JSON.stringify(systemData, (k: any, v: any) => typeof v === 'bigint' ? v <= maxIntAttrValue ? Number(v) : v.toString() : v))); + localStorage.setItem('data', btoa(JSON.stringify(systemData, (k: any, v: any) => typeof v === 'bigint' ? v <= maxIntAttrValue ? Number(v) : v.toString() : v))); - localStorage.setItem(`sessionData${scene.sessionSlotId ? scene.sessionSlotId : ''}`, encFunc(JSON.stringify(sessionData))); + localStorage.setItem(`sessionData${scene.sessionSlotId ? scene.sessionSlotId : ''}`, btoa(JSON.stringify(sessionData))); console.debug('Session data saved'); @@ -894,12 +910,8 @@ export class GameData { }); } else { const data = localStorage.getItem(dataKey); - if (data) { - const decFunc = bypassLogin - ? (data: string) => atob(data) - : (data: string) => AES.decrypt(data, saveKey).toString(enc.Utf8); - handleData(decFunc(data)); - } + if (data) + handleData(atob(data)); resolve(!!data); } }); @@ -967,7 +979,7 @@ export class GameData { return this.scene.ui.showText(`Your ${dataName} data could not be loaded. It may be corrupted.`, null, () => this.scene.ui.showText(null, 0), Utils.fixedInt(1500)); this.scene.ui.showText(`Your ${dataName} data will be overridden and the page will reload. Proceed?`, null, () => { this.scene.ui.setOverlayMode(Mode.CONFIRM, () => { - if (!bypassLogin && dataType < GameDataType.SETTINGS && localStorage.getItem(dataKey)) { + if (!bypassLogin && dataType < GameDataType.SETTINGS) { updateUserInfo().then(success => { if (!success) return displayError(`Could not contact the server. Your ${dataName} data could not be imported.`); @@ -978,15 +990,11 @@ export class GameData { console.error(error); return displayError(`An error occurred while updating ${dataName} data. Please contact the administrator.`); } - localStorage.removeItem(dataKey); window.location = window.location; }); }); } else { - const encFunc = bypassLogin || dataType === GameDataType.SETTINGS - ? (data: string) => btoa(data) - : (data: string) => AES.encrypt(data, saveKey); - localStorage.setItem(dataKey, encFunc(dataStr)); + localStorage.setItem(dataKey, btoa(dataStr)); window.location = window.location; } }, () => {