Merge branch 'pagefaultgames:main' into main
commit
1791921653
|
@ -7,18 +7,20 @@ export interface UserInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
export let loggedInUser: UserInfo = null;
|
export let loggedInUser: UserInfo = null;
|
||||||
|
export const clientSessionId = Utils.randomString(32);
|
||||||
|
|
||||||
export function updateUserInfo(): Promise<[boolean, integer]> {
|
export function updateUserInfo(): Promise<[boolean, integer]> {
|
||||||
return new Promise<[boolean, integer]>(resolve => {
|
return new Promise<[boolean, integer]>(resolve => {
|
||||||
if (bypassLogin) {
|
if (bypassLogin) {
|
||||||
|
loggedInUser = { username: 'Guest', lastSessionSlot: -1 };
|
||||||
let lastSessionSlot = -1;
|
let lastSessionSlot = -1;
|
||||||
for (let s = 0; s < 2; s++) {
|
for (let s = 0; s < 2; s++) {
|
||||||
if (localStorage.getItem(`sessionData${s ? s : ''}`)) {
|
if (localStorage.getItem(`sessionData${s ? s : ''}_${loggedInUser.username}`)) {
|
||||||
lastSessionSlot = s;
|
lastSessionSlot = s;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
loggedInUser = { username: 'Guest', lastSessionSlot: lastSessionSlot };
|
loggedInUser.lastSessionSlot = lastSessionSlot;
|
||||||
return resolve([ true, 200 ]);
|
return resolve([ true, 200 ]);
|
||||||
}
|
}
|
||||||
Utils.apiFetch('account/info', true).then(response => {
|
Utils.apiFetch('account/info', true).then(response => {
|
||||||
|
|
|
@ -88,6 +88,7 @@ export default class BattleScene extends SceneBase {
|
||||||
public uiInputs: UiInputs;
|
public uiInputs: UiInputs;
|
||||||
|
|
||||||
public sessionPlayTime: integer = null;
|
public sessionPlayTime: integer = null;
|
||||||
|
public lastSavePlayTime: integer = null;
|
||||||
public masterVolume: number = 0.5;
|
public masterVolume: number = 0.5;
|
||||||
public bgmVolume: number = 1;
|
public bgmVolume: number = 1;
|
||||||
public seVolume: number = 1;
|
public seVolume: number = 1;
|
||||||
|
@ -452,6 +453,8 @@ export default class BattleScene extends SceneBase {
|
||||||
initSession(): void {
|
initSession(): void {
|
||||||
if (this.sessionPlayTime === null)
|
if (this.sessionPlayTime === null)
|
||||||
this.sessionPlayTime = 0;
|
this.sessionPlayTime = 0;
|
||||||
|
if (this.lastSavePlayTime === null)
|
||||||
|
this.lastSavePlayTime = 0;
|
||||||
|
|
||||||
if (this.playTimeTimer)
|
if (this.playTimeTimer)
|
||||||
this.playTimeTimer.destroy();
|
this.playTimeTimer.destroy();
|
||||||
|
@ -464,6 +467,8 @@ export default class BattleScene extends SceneBase {
|
||||||
this.gameData.gameStats.playTime++;
|
this.gameData.gameStats.playTime++;
|
||||||
if (this.sessionPlayTime !== null)
|
if (this.sessionPlayTime !== null)
|
||||||
this.sessionPlayTime++;
|
this.sessionPlayTime++;
|
||||||
|
if (this.lastSavePlayTime !== null)
|
||||||
|
this.lastSavePlayTime++;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1007,6 +1012,7 @@ export default class BattleScene extends SceneBase {
|
||||||
case Species.FLORGES:
|
case Species.FLORGES:
|
||||||
case Species.FURFROU:
|
case Species.FURFROU:
|
||||||
case Species.ORICORIO:
|
case Species.ORICORIO:
|
||||||
|
case Species.MAGEARNA:
|
||||||
case Species.SQUAWKABILLY:
|
case Species.SQUAWKABILLY:
|
||||||
case Species.TATSUGIRI:
|
case Species.TATSUGIRI:
|
||||||
case Species.PALDEA_TAUROS:
|
case Species.PALDEA_TAUROS:
|
||||||
|
|
|
@ -544,6 +544,33 @@ export class AquaRingTag extends BattlerTag {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Tag used to allow moves that interact with {@link Moves.MINIMIZE} to function */
|
||||||
|
export class MinimizeTag extends BattlerTag {
|
||||||
|
constructor() {
|
||||||
|
super(BattlerTagType.MINIMIZED, BattlerTagLapseType.TURN_END, 1, Moves.MINIMIZE, undefined);
|
||||||
|
}
|
||||||
|
|
||||||
|
canAdd(pokemon: Pokemon): boolean {
|
||||||
|
return !pokemon.isMax();
|
||||||
|
}
|
||||||
|
|
||||||
|
onAdd(pokemon: Pokemon): void {
|
||||||
|
super.onAdd(pokemon);
|
||||||
|
}
|
||||||
|
|
||||||
|
lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean {
|
||||||
|
//If a pokemon dynamaxes they lose minimized status
|
||||||
|
if(pokemon.isMax()){
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return lapseType !== BattlerTagLapseType.CUSTOM || super.lapse(pokemon, lapseType);
|
||||||
|
}
|
||||||
|
|
||||||
|
onRemove(pokemon: Pokemon): void {
|
||||||
|
super.onRemove(pokemon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export class DrowsyTag extends BattlerTag {
|
export class DrowsyTag extends BattlerTag {
|
||||||
constructor() {
|
constructor() {
|
||||||
super(BattlerTagType.DROWSY, BattlerTagLapseType.TURN_END, 2, Moves.YAWN);
|
super(BattlerTagType.DROWSY, BattlerTagLapseType.TURN_END, 2, Moves.YAWN);
|
||||||
|
@ -1358,6 +1385,8 @@ export function getBattlerTag(tagType: BattlerTagType, turnCount: integer, sourc
|
||||||
return new TypeBoostTag(tagType, sourceMove, Type.ELECTRIC, 2, true);
|
return new TypeBoostTag(tagType, sourceMove, Type.ELECTRIC, 2, true);
|
||||||
case BattlerTagType.MAGNET_RISEN:
|
case BattlerTagType.MAGNET_RISEN:
|
||||||
return new MagnetRisenTag(tagType, sourceMove);
|
return new MagnetRisenTag(tagType, sourceMove);
|
||||||
|
case BattlerTagType.MINIMIZED:
|
||||||
|
return new MinimizeTag();
|
||||||
case BattlerTagType.NONE:
|
case BattlerTagType.NONE:
|
||||||
default:
|
default:
|
||||||
return new BattlerTag(tagType, BattlerTagLapseType.CUSTOM, turnCount, sourceMove, sourceId);
|
return new BattlerTag(tagType, BattlerTagLapseType.CUSTOM, turnCount, sourceMove, sourceId);
|
||||||
|
|
|
@ -48,7 +48,7 @@ export const biomeLinks: BiomeLinks = {
|
||||||
[Biome.SEABED]: [ Biome.CAVE, [ Biome.VOLCANO, 4 ] ],
|
[Biome.SEABED]: [ Biome.CAVE, [ Biome.VOLCANO, 4 ] ],
|
||||||
[Biome.MOUNTAIN]: [ Biome.VOLCANO, [ Biome.WASTELAND, 3 ] ],
|
[Biome.MOUNTAIN]: [ Biome.VOLCANO, [ Biome.WASTELAND, 3 ] ],
|
||||||
[Biome.BADLANDS]: [ Biome.DESERT, Biome.MOUNTAIN ],
|
[Biome.BADLANDS]: [ Biome.DESERT, Biome.MOUNTAIN ],
|
||||||
[Biome.CAVE]: [ Biome.BADLANDS, Biome.BEACH ],
|
[Biome.CAVE]: [ Biome.BADLANDS, Biome.LAKE ],
|
||||||
[Biome.DESERT]: Biome.RUINS,
|
[Biome.DESERT]: Biome.RUINS,
|
||||||
[Biome.ICE_CAVE]: Biome.SNOWY_FOREST,
|
[Biome.ICE_CAVE]: Biome.SNOWY_FOREST,
|
||||||
[Biome.MEADOW]: [ Biome.PLAINS, [ Biome.FAIRY_CAVE, 2 ] ],
|
[Biome.MEADOW]: [ Biome.PLAINS, [ Biome.FAIRY_CAVE, 2 ] ],
|
||||||
|
|
|
@ -55,5 +55,6 @@ export enum BattlerTagType {
|
||||||
CURSED = "CURSED",
|
CURSED = "CURSED",
|
||||||
CHARGED = "CHARGED",
|
CHARGED = "CHARGED",
|
||||||
GROUNDED = "GROUNDED",
|
GROUNDED = "GROUNDED",
|
||||||
MAGNET_RISEN = "MAGNET_RISEN"
|
MAGNET_RISEN = "MAGNET_RISEN",
|
||||||
|
MINIMIZED = "MINIMIZED"
|
||||||
}
|
}
|
||||||
|
|
268
src/data/move.ts
268
src/data/move.ts
|
@ -434,29 +434,66 @@ export class SelfStatusMove extends Move {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base class defining all {@link Move} Attributes
|
||||||
|
* @abstract
|
||||||
|
*/
|
||||||
export abstract class MoveAttr {
|
export abstract class MoveAttr {
|
||||||
|
/** Should this {@link Move} target the user? */
|
||||||
public selfTarget: boolean;
|
public selfTarget: boolean;
|
||||||
|
|
||||||
constructor(selfTarget: boolean = false) {
|
constructor(selfTarget: boolean = false) {
|
||||||
this.selfTarget = selfTarget;
|
this.selfTarget = selfTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies move attributes
|
||||||
|
* @see {@link applyMoveAttrsInternal}
|
||||||
|
* @virtual
|
||||||
|
* @param user The {@link Pokemon} using the move
|
||||||
|
* @param target The target {@link Pokemon} of the move
|
||||||
|
* @param move The {@link Move} being used
|
||||||
|
* @param args Set of unique arguments needed by this attribute
|
||||||
|
* @returns true if the application succeeds
|
||||||
|
*/
|
||||||
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean | Promise<boolean> {
|
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean | Promise<boolean> {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @virtual
|
||||||
|
* @returns the {@link MoveCondition} or {@link MoveConditionFunc} for this {@link Move}
|
||||||
|
*/
|
||||||
getCondition(): MoveCondition | MoveConditionFunc {
|
getCondition(): MoveCondition | MoveConditionFunc {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @virtual
|
||||||
|
* @param user The {@link Pokemon} using the move
|
||||||
|
* @param target The target {@link Pokemon} of the move
|
||||||
|
* @param move The {@link Move} being used
|
||||||
|
* @param cancelled A {@link Utils.BooleanHolder} which stores if the move should fail
|
||||||
|
* @returns the string representing failure of this {@link Move}
|
||||||
|
*/
|
||||||
getFailedText(user: Pokemon, target: Pokemon, move: Move, cancelled: Utils.BooleanHolder): string | null {
|
getFailedText(user: Pokemon, target: Pokemon, move: Move, cancelled: Utils.BooleanHolder): string | null {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used by the Enemy AI to rank an attack based on a given user
|
||||||
|
* @see {@link EnemyPokemon.getNextMove}
|
||||||
|
* @virtual
|
||||||
|
*/
|
||||||
getUserBenefitScore(user: Pokemon, target: Pokemon, move: Move): integer {
|
getUserBenefitScore(user: Pokemon, target: Pokemon, move: Move): integer {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used by the Enemy AI to rank an attack based on a given target
|
||||||
|
* @see {@link EnemyPokemon.getNextMove}
|
||||||
|
* @virtual
|
||||||
|
*/
|
||||||
getTargetBenefitScore(user: Pokemon, target: Pokemon, move: Move): integer {
|
getTargetBenefitScore(user: Pokemon, target: Pokemon, move: Move): integer {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -470,6 +507,9 @@ export enum MoveEffectTrigger {
|
||||||
POST_TARGET,
|
POST_TARGET,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Base class defining all Move Effect Attributes
|
||||||
|
* @extends MoveAttr
|
||||||
|
*/
|
||||||
export class MoveEffectAttr extends MoveAttr {
|
export class MoveEffectAttr extends MoveAttr {
|
||||||
public trigger: MoveEffectTrigger;
|
public trigger: MoveEffectTrigger;
|
||||||
public firstHitOnly: boolean;
|
public firstHitOnly: boolean;
|
||||||
|
@ -480,11 +520,21 @@ export class MoveEffectAttr extends MoveAttr {
|
||||||
this.firstHitOnly = firstHitOnly;
|
this.firstHitOnly = firstHitOnly;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether the {@link Move}'s effects are valid to {@link apply}
|
||||||
|
* @virtual
|
||||||
|
* @param user The {@link Pokemon} using the move
|
||||||
|
* @param target The target {@link Pokemon} of the move
|
||||||
|
* @param move The {@link Move} being used
|
||||||
|
* @param args Set of unique arguments needed by this attribute
|
||||||
|
* @returns true if the application succeeds
|
||||||
|
*/
|
||||||
canApply(user: Pokemon, target: Pokemon, move: Move, args: any[]) {
|
canApply(user: Pokemon, target: Pokemon, move: Move, args: any[]) {
|
||||||
return !!(this.selfTarget ? user.hp && !user.getTag(BattlerTagType.FRENZY) : target.hp)
|
return !!(this.selfTarget ? user.hp && !user.getTag(BattlerTagType.FRENZY) : target.hp)
|
||||||
&& (this.selfTarget || !target.getTag(BattlerTagType.PROTECTED) || move.hasFlag(MoveFlags.IGNORE_PROTECT));
|
&& (this.selfTarget || !target.getTag(BattlerTagType.PROTECTED) || move.hasFlag(MoveFlags.IGNORE_PROTECT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Applies move effects so long as they are able based on {@link canApply} */
|
||||||
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean | Promise<boolean> {
|
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean | Promise<boolean> {
|
||||||
return this.canApply(user, target, move, args);
|
return this.canApply(user, target, move, args);
|
||||||
}
|
}
|
||||||
|
@ -738,12 +788,60 @@ export class RecoilAttr extends MoveEffectAttr {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attribute used for moves which self KO the user regardless if the move hits a target
|
||||||
|
* @extends MoveEffectAttr
|
||||||
|
* @see {@link apply}
|
||||||
|
**/
|
||||||
export class SacrificialAttr extends MoveEffectAttr {
|
export class SacrificialAttr extends MoveEffectAttr {
|
||||||
constructor() {
|
constructor() {
|
||||||
super(true, MoveEffectTrigger.PRE_APPLY);
|
super(true, MoveEffectTrigger.POST_TARGET);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deals damage to the user equal to their current hp
|
||||||
|
* @param user Pokemon that used the move
|
||||||
|
* @param target The target of the move
|
||||||
|
* @param move Move with this attribute
|
||||||
|
* @param args N/A
|
||||||
|
* @returns true if the function succeeds
|
||||||
|
**/
|
||||||
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
|
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
|
||||||
|
user.damageAndUpdate(user.hp, HitResult.OTHER, false, true, true);
|
||||||
|
user.turnData.damageTaken += user.hp;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
getUserBenefitScore(user: Pokemon, target: Pokemon, move: Move): integer {
|
||||||
|
if (user.isBoss())
|
||||||
|
return -20;
|
||||||
|
return Math.ceil(((1 - user.getHpRatio()) * 10 - 10) * (target.getAttackTypeEffectiveness(move.type, user) - 0.5));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attribute used for moves which self KO the user but only if the move hits a target
|
||||||
|
* @extends MoveEffectAttr
|
||||||
|
* @see {@link apply}
|
||||||
|
**/
|
||||||
|
export class SacrificialAttrOnHit extends MoveEffectAttr {
|
||||||
|
constructor() {
|
||||||
|
super(true, MoveEffectTrigger.POST_TARGET);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deals damage to the user equal to their current hp if the move lands
|
||||||
|
* @param user Pokemon that used the move
|
||||||
|
* @param target The target of the move
|
||||||
|
* @param move Move with this attribute
|
||||||
|
* @param args N/A
|
||||||
|
* @returns true if the function succeeds
|
||||||
|
**/
|
||||||
|
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
|
||||||
|
|
||||||
|
// If the move fails to hit a target, then the user does not faint and the function returns false
|
||||||
if (!super.apply(user, target, move, args))
|
if (!super.apply(user, target, move, args))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -806,8 +904,15 @@ export enum MultiHitType {
|
||||||
_1_TO_10,
|
_1_TO_10,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Heals the user or target by {@link healRatio} depending on the value of {@link selfTarget}
|
||||||
|
* @extends MoveEffectAttr
|
||||||
|
* @see {@link apply}
|
||||||
|
*/
|
||||||
export class HealAttr extends MoveEffectAttr {
|
export class HealAttr extends MoveEffectAttr {
|
||||||
|
/** The percentage of {@link Stat.HP} to heal */
|
||||||
private healRatio: number;
|
private healRatio: number;
|
||||||
|
/** Should an animation be shown? */
|
||||||
private showAnim: boolean;
|
private showAnim: boolean;
|
||||||
|
|
||||||
constructor(healRatio?: number, showAnim?: boolean, selfTarget?: boolean) {
|
constructor(healRatio?: number, showAnim?: boolean, selfTarget?: boolean) {
|
||||||
|
@ -822,6 +927,10 @@ export class HealAttr extends MoveEffectAttr {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link PokemonHealPhase}.
|
||||||
|
* This heals the target and shows the appropriate message.
|
||||||
|
*/
|
||||||
addHealPhase(target: Pokemon, healRatio: number) {
|
addHealPhase(target: Pokemon, healRatio: number) {
|
||||||
target.scene.unshiftPhase(new PokemonHealPhase(target.scene, target.getBattlerIndex(),
|
target.scene.unshiftPhase(new PokemonHealPhase(target.scene, target.getBattlerIndex(),
|
||||||
Math.max(Math.floor(target.getMaxHp() * healRatio), 1), getPokemonMessage(target, ' \nhad its HP restored.'), true, !this.showAnim));
|
Math.max(Math.floor(target.getMaxHp() * healRatio), 1), getPokemonMessage(target, ' \nhad its HP restored.'), true, !this.showAnim));
|
||||||
|
@ -903,7 +1012,7 @@ export class IgnoreWeatherTypeDebuffAttr extends MoveAttr {
|
||||||
* @param user Pokemon that used the move
|
* @param user Pokemon that used the move
|
||||||
* @param target N/A
|
* @param target N/A
|
||||||
* @param move Move with this attribute
|
* @param move Move with this attribute
|
||||||
* @param args Utils.NumberHolder for arenaAttackTypeMultiplier
|
* @param args [0] Utils.NumberHolder for arenaAttackTypeMultiplier
|
||||||
* @returns true if the function succeeds
|
* @returns true if the function succeeds
|
||||||
*/
|
*/
|
||||||
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
|
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
|
||||||
|
@ -963,27 +1072,19 @@ export class SandHealAttr extends WeatherHealAttr {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Heals the target by either {@link normalHealRatio} or {@link boostedHealRatio}
|
* Heals the target or the user by either {@link normalHealRatio} or {@link boostedHealRatio}
|
||||||
* depending on the evaluation of {@link condition}
|
* depending on the evaluation of {@link condition}
|
||||||
|
* @extends HealAttr
|
||||||
* @see {@link apply}
|
* @see {@link apply}
|
||||||
* @param user The Pokemon using this move
|
|
||||||
* @param target The target Pokemon of this move
|
|
||||||
* @param move This move
|
|
||||||
* @param args N/A
|
|
||||||
* @returns if the move was successful
|
|
||||||
*/
|
*/
|
||||||
export class BoostHealAttr extends HealAttr {
|
export class BoostHealAttr extends HealAttr {
|
||||||
|
/** Healing received when {@link condition} is false */
|
||||||
private normalHealRatio?: number;
|
private normalHealRatio?: number;
|
||||||
|
/** Healing received when {@link condition} is true */
|
||||||
private boostedHealRatio?: number;
|
private boostedHealRatio?: number;
|
||||||
|
/** The lambda expression to check against when boosting the healing value */
|
||||||
private condition?: MoveConditionFunc;
|
private condition?: MoveConditionFunc;
|
||||||
|
|
||||||
/**
|
|
||||||
* @param normalHealRatio Healing received when {@link condition} is false
|
|
||||||
* @param boostedHealRatio Healing received when {@link condition} is true
|
|
||||||
* @param showAnim Should a healing animation be showed?
|
|
||||||
* @param selfTarget Should the move target the user?
|
|
||||||
* @param condition The condition to check against when boosting the healing value
|
|
||||||
*/
|
|
||||||
constructor(normalHealRatio?: number, boostedHealRatio?: number, showAnim?: boolean, selfTarget?: boolean, condition?: MoveConditionFunc) {
|
constructor(normalHealRatio?: number, boostedHealRatio?: number, showAnim?: boolean, selfTarget?: boolean, condition?: MoveConditionFunc) {
|
||||||
super(normalHealRatio, showAnim, selfTarget);
|
super(normalHealRatio, showAnim, selfTarget);
|
||||||
this.normalHealRatio = normalHealRatio;
|
this.normalHealRatio = normalHealRatio;
|
||||||
|
@ -991,6 +1092,13 @@ export class BoostHealAttr extends HealAttr {
|
||||||
this.condition = condition;
|
this.condition = condition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param user The Pokemon using this move
|
||||||
|
* @param target The target Pokemon of this move
|
||||||
|
* @param move This move
|
||||||
|
* @param args N/A
|
||||||
|
* @returns true if the move was successful
|
||||||
|
*/
|
||||||
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
|
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
|
||||||
const healRatio = this.condition(user, target, move) ? this.boostedHealRatio : this.normalHealRatio;
|
const healRatio = this.condition(user, target, move) ? this.boostedHealRatio : this.normalHealRatio;
|
||||||
this.addHealPhase(target, healRatio);
|
this.addHealPhase(target, healRatio);
|
||||||
|
@ -1897,6 +2005,86 @@ export class HpSplitAttr extends MoveEffectAttr {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attribute used for moves which split the user and the target's offensive raw stats.
|
||||||
|
* @extends MoveEffectAttr
|
||||||
|
* @see {@link apply}
|
||||||
|
*/
|
||||||
|
export class PowerSplitAttr extends MoveEffectAttr {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applying Power Split to the user and the target.
|
||||||
|
* @param user The pokemon using the move. {@link Pokemon}
|
||||||
|
* @param target The targeted pokemon of the move. {@link Pokemon}
|
||||||
|
* @param move The move used. {@link Move}
|
||||||
|
* @param args N/A
|
||||||
|
* @returns True if power split is applied successfully.
|
||||||
|
*/
|
||||||
|
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]) : Promise<boolean> {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
|
||||||
|
if (!super.apply(user, target, move, args))
|
||||||
|
return resolve(false);
|
||||||
|
|
||||||
|
const infoUpdates = [];
|
||||||
|
|
||||||
|
const attackValue = Math.floor((target.getStat(Stat.ATK) + user.getStat(Stat.ATK)) / 2);
|
||||||
|
user.changeSummonStat(Stat.ATK, attackValue);
|
||||||
|
infoUpdates.push(user.updateInfo());
|
||||||
|
target.changeSummonStat(Stat.ATK, attackValue);
|
||||||
|
infoUpdates.push(target.updateInfo());
|
||||||
|
|
||||||
|
const specialAttackValue = Math.floor((target.getStat(Stat.SPATK) + user.getStat(Stat.SPATK)) / 2);
|
||||||
|
user.changeSummonStat(Stat.SPATK, specialAttackValue);
|
||||||
|
infoUpdates.push(user.updateInfo());
|
||||||
|
target.changeSummonStat(Stat.SPATK, specialAttackValue);
|
||||||
|
infoUpdates.push(target.updateInfo());
|
||||||
|
|
||||||
|
return Promise.all(infoUpdates).then(() => resolve(true));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attribute used for moves which split the user and the target's defensive raw stats.
|
||||||
|
* @extends MoveEffectAttr
|
||||||
|
* @see {@link apply}
|
||||||
|
*/
|
||||||
|
export class GuardSplitAttr extends MoveEffectAttr {
|
||||||
|
/**
|
||||||
|
* Applying Guard Split to the user and the target.
|
||||||
|
* @param user The pokemon using the move. {@link Pokemon}
|
||||||
|
* @param target The targeted pokemon of the move. {@link Pokemon}
|
||||||
|
* @param move The move used. {@link Move}
|
||||||
|
* @param args N/A
|
||||||
|
* @returns True if power split is applied successfully.
|
||||||
|
*/
|
||||||
|
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): Promise<boolean> {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
if (!super.apply(user, target, move, args))
|
||||||
|
return resolve(false);
|
||||||
|
|
||||||
|
const infoUpdates = [];
|
||||||
|
|
||||||
|
const defenseValue = Math.floor((target.getStat(Stat.DEF) + user.getStat(Stat.DEF)) / 2);
|
||||||
|
user.changeSummonStat(Stat.DEF, defenseValue);
|
||||||
|
infoUpdates.push(user.updateInfo());
|
||||||
|
target.changeSummonStat(Stat.DEF, defenseValue);
|
||||||
|
infoUpdates.push(target.updateInfo());
|
||||||
|
|
||||||
|
const specialDefenseValue = Math.floor((target.getStat(Stat.SPDEF) + user.getStat(Stat.SPDEF)) / 2);
|
||||||
|
user.changeSummonStat(Stat.SPDEF, specialDefenseValue);
|
||||||
|
infoUpdates.push(user.updateInfo());
|
||||||
|
target.changeSummonStat(Stat.SPDEF, specialDefenseValue);
|
||||||
|
infoUpdates.push(target.updateInfo());
|
||||||
|
|
||||||
|
|
||||||
|
return Promise.all(infoUpdates).then(() => resolve(true));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
export class VariablePowerAttr extends MoveAttr {
|
export class VariablePowerAttr extends MoveAttr {
|
||||||
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
|
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
|
||||||
//const power = args[0] as Utils.NumberHolder;
|
//const power = args[0] as Utils.NumberHolder;
|
||||||
|
@ -2372,6 +2560,30 @@ export class ThunderAccuracyAttr extends VariableAccuracyAttr {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attribute used for moves which never miss
|
||||||
|
* against Pokemon with the {@link BattlerTagType.MINIMIZED}
|
||||||
|
* @see {@link apply}
|
||||||
|
* @param user N/A
|
||||||
|
* @param target Target of the move
|
||||||
|
* @param move N/A
|
||||||
|
* @param args [0] Accuracy of the move to be modified
|
||||||
|
* @returns true if the function succeeds
|
||||||
|
*/
|
||||||
|
export class MinimizeAccuracyAttr extends VariableAccuracyAttr{
|
||||||
|
|
||||||
|
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
|
||||||
|
if (target.getTag(BattlerTagType.MINIMIZED)){
|
||||||
|
const accuracy = args[0] as Utils.NumberHolder
|
||||||
|
accuracy.value = -1;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export class ToxicAccuracyAttr extends VariableAccuracyAttr {
|
export class ToxicAccuracyAttr extends VariableAccuracyAttr {
|
||||||
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
|
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
|
||||||
if (user.isOfType(Type.POISON)) {
|
if (user.isOfType(Type.POISON)) {
|
||||||
|
@ -3127,8 +3339,11 @@ export class FaintCountdownAttr extends AddBattlerTagAttr {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Attribute used when a move hits a {@link BattlerTagType} for double damage */
|
||||||
export class HitsTagAttr extends MoveAttr {
|
export class HitsTagAttr extends MoveAttr {
|
||||||
|
/** The {@link BattlerTagType} this move hits */
|
||||||
public tagType: BattlerTagType;
|
public tagType: BattlerTagType;
|
||||||
|
/** Should this move deal double damage against {@link HitsTagAttr.tagType}? */
|
||||||
public doubleDamage: boolean;
|
public doubleDamage: boolean;
|
||||||
|
|
||||||
constructor(tagType: BattlerTagType, doubleDamage?: boolean) {
|
constructor(tagType: BattlerTagType, doubleDamage?: boolean) {
|
||||||
|
@ -4295,6 +4510,8 @@ export function initMoves() {
|
||||||
new AttackMove(Moves.SLAM, Type.NORMAL, MoveCategory.PHYSICAL, 80, 75, 20, -1, 0, 1),
|
new AttackMove(Moves.SLAM, Type.NORMAL, MoveCategory.PHYSICAL, 80, 75, 20, -1, 0, 1),
|
||||||
new AttackMove(Moves.VINE_WHIP, Type.GRASS, MoveCategory.PHYSICAL, 45, 100, 25, -1, 0, 1),
|
new AttackMove(Moves.VINE_WHIP, Type.GRASS, MoveCategory.PHYSICAL, 45, 100, 25, -1, 0, 1),
|
||||||
new AttackMove(Moves.STOMP, Type.NORMAL, MoveCategory.PHYSICAL, 65, 100, 20, 30, 0, 1)
|
new AttackMove(Moves.STOMP, Type.NORMAL, MoveCategory.PHYSICAL, 65, 100, 20, 30, 0, 1)
|
||||||
|
.attr(MinimizeAccuracyAttr)
|
||||||
|
.attr(HitsTagAttr, BattlerTagType.MINIMIZED, true)
|
||||||
.attr(FlinchAttr),
|
.attr(FlinchAttr),
|
||||||
new AttackMove(Moves.DOUBLE_KICK, Type.FIGHTING, MoveCategory.PHYSICAL, 30, 100, 30, -1, 0, 1)
|
new AttackMove(Moves.DOUBLE_KICK, Type.FIGHTING, MoveCategory.PHYSICAL, 30, 100, 30, -1, 0, 1)
|
||||||
.attr(MultiHitAttr, MultiHitType._2),
|
.attr(MultiHitAttr, MultiHitType._2),
|
||||||
|
@ -4318,6 +4535,8 @@ export function initMoves() {
|
||||||
.attr(OneHitKOAccuracyAttr),
|
.attr(OneHitKOAccuracyAttr),
|
||||||
new AttackMove(Moves.TACKLE, Type.NORMAL, MoveCategory.PHYSICAL, 40, 100, 35, -1, 0, 1),
|
new AttackMove(Moves.TACKLE, Type.NORMAL, MoveCategory.PHYSICAL, 40, 100, 35, -1, 0, 1),
|
||||||
new AttackMove(Moves.BODY_SLAM, Type.NORMAL, MoveCategory.PHYSICAL, 85, 100, 15, 30, 0, 1)
|
new AttackMove(Moves.BODY_SLAM, Type.NORMAL, MoveCategory.PHYSICAL, 85, 100, 15, 30, 0, 1)
|
||||||
|
.attr(MinimizeAccuracyAttr)
|
||||||
|
.attr(HitsTagAttr, BattlerTagType.MINIMIZED, true)
|
||||||
.attr(StatusEffectAttr, StatusEffect.PARALYSIS),
|
.attr(StatusEffectAttr, StatusEffect.PARALYSIS),
|
||||||
new AttackMove(Moves.WRAP, Type.NORMAL, MoveCategory.PHYSICAL, 15, 90, 20, 100, 0, 1)
|
new AttackMove(Moves.WRAP, Type.NORMAL, MoveCategory.PHYSICAL, 15, 90, 20, 100, 0, 1)
|
||||||
.attr(TrapAttr, BattlerTagType.WRAP),
|
.attr(TrapAttr, BattlerTagType.WRAP),
|
||||||
|
@ -4515,6 +4734,7 @@ export function initMoves() {
|
||||||
new SelfStatusMove(Moves.HARDEN, Type.NORMAL, -1, 30, -1, 0, 1)
|
new SelfStatusMove(Moves.HARDEN, Type.NORMAL, -1, 30, -1, 0, 1)
|
||||||
.attr(StatChangeAttr, BattleStat.DEF, 1, true),
|
.attr(StatChangeAttr, BattleStat.DEF, 1, true),
|
||||||
new SelfStatusMove(Moves.MINIMIZE, Type.NORMAL, -1, 10, -1, 0, 1)
|
new SelfStatusMove(Moves.MINIMIZE, Type.NORMAL, -1, 10, -1, 0, 1)
|
||||||
|
.attr(AddBattlerTagAttr, BattlerTagType.MINIMIZED, true, false)
|
||||||
.attr(StatChangeAttr, BattleStat.EVA, 2, true),
|
.attr(StatChangeAttr, BattleStat.EVA, 2, true),
|
||||||
new StatusMove(Moves.SMOKESCREEN, Type.NORMAL, 100, 20, -1, 0, 1)
|
new StatusMove(Moves.SMOKESCREEN, Type.NORMAL, 100, 20, -1, 0, 1)
|
||||||
.attr(StatChangeAttr, BattleStat.ACC, -1),
|
.attr(StatChangeAttr, BattleStat.ACC, -1),
|
||||||
|
@ -4960,7 +5180,7 @@ export function initMoves() {
|
||||||
new StatusMove(Moves.WILL_O_WISP, Type.FIRE, 85, 15, -1, 0, 3)
|
new StatusMove(Moves.WILL_O_WISP, Type.FIRE, 85, 15, -1, 0, 3)
|
||||||
.attr(StatusEffectAttr, StatusEffect.BURN),
|
.attr(StatusEffectAttr, StatusEffect.BURN),
|
||||||
new StatusMove(Moves.MEMENTO, Type.DARK, 100, 10, -1, 0, 3)
|
new StatusMove(Moves.MEMENTO, Type.DARK, 100, 10, -1, 0, 3)
|
||||||
.attr(SacrificialAttr)
|
.attr(SacrificialAttrOnHit)
|
||||||
.attr(StatChangeAttr, [ BattleStat.ATK, BattleStat.SPATK ], -2),
|
.attr(StatChangeAttr, [ BattleStat.ATK, BattleStat.SPATK ], -2),
|
||||||
new AttackMove(Moves.FACADE, Type.NORMAL, MoveCategory.PHYSICAL, 70, 100, 20, -1, 0, 3)
|
new AttackMove(Moves.FACADE, Type.NORMAL, MoveCategory.PHYSICAL, 70, 100, 20, -1, 0, 3)
|
||||||
.attr(MovePowerMultiplierAttr, (user, target, move) => user.status
|
.attr(MovePowerMultiplierAttr, (user, target, move) => user.status
|
||||||
|
@ -5354,6 +5574,8 @@ export function initMoves() {
|
||||||
new AttackMove(Moves.DRAGON_PULSE, Type.DRAGON, MoveCategory.SPECIAL, 85, 100, 10, -1, 0, 4)
|
new AttackMove(Moves.DRAGON_PULSE, Type.DRAGON, MoveCategory.SPECIAL, 85, 100, 10, -1, 0, 4)
|
||||||
.pulseMove(),
|
.pulseMove(),
|
||||||
new AttackMove(Moves.DRAGON_RUSH, Type.DRAGON, MoveCategory.PHYSICAL, 100, 75, 10, 20, 0, 4)
|
new AttackMove(Moves.DRAGON_RUSH, Type.DRAGON, MoveCategory.PHYSICAL, 100, 75, 10, 20, 0, 4)
|
||||||
|
.attr(MinimizeAccuracyAttr)
|
||||||
|
.attr(HitsTagAttr, BattlerTagType.MINIMIZED, true)
|
||||||
.attr(FlinchAttr),
|
.attr(FlinchAttr),
|
||||||
new AttackMove(Moves.POWER_GEM, Type.ROCK, MoveCategory.SPECIAL, 80, 100, 20, -1, 0, 4),
|
new AttackMove(Moves.POWER_GEM, Type.ROCK, MoveCategory.SPECIAL, 80, 100, 20, -1, 0, 4),
|
||||||
new AttackMove(Moves.DRAIN_PUNCH, Type.FIGHTING, MoveCategory.PHYSICAL, 75, 100, 10, -1, 0, 4)
|
new AttackMove(Moves.DRAIN_PUNCH, Type.FIGHTING, MoveCategory.PHYSICAL, 75, 100, 10, -1, 0, 4)
|
||||||
|
@ -5496,7 +5718,7 @@ export function initMoves() {
|
||||||
new AttackMove(Moves.SPACIAL_REND, Type.DRAGON, MoveCategory.SPECIAL, 100, 95, 5, -1, 0, 4)
|
new AttackMove(Moves.SPACIAL_REND, Type.DRAGON, MoveCategory.SPECIAL, 100, 95, 5, -1, 0, 4)
|
||||||
.attr(HighCritAttr),
|
.attr(HighCritAttr),
|
||||||
new SelfStatusMove(Moves.LUNAR_DANCE, Type.PSYCHIC, -1, 10, -1, 0, 4)
|
new SelfStatusMove(Moves.LUNAR_DANCE, Type.PSYCHIC, -1, 10, -1, 0, 4)
|
||||||
.attr(SacrificialAttr)
|
.attr(SacrificialAttrOnHit)
|
||||||
.danceMove()
|
.danceMove()
|
||||||
.triageMove()
|
.triageMove()
|
||||||
.unimplemented(),
|
.unimplemented(),
|
||||||
|
@ -5522,9 +5744,9 @@ export function initMoves() {
|
||||||
.target(MoveTarget.USER_SIDE)
|
.target(MoveTarget.USER_SIDE)
|
||||||
.unimplemented(),
|
.unimplemented(),
|
||||||
new StatusMove(Moves.GUARD_SPLIT, Type.PSYCHIC, -1, 10, -1, 0, 5)
|
new StatusMove(Moves.GUARD_SPLIT, Type.PSYCHIC, -1, 10, -1, 0, 5)
|
||||||
.unimplemented(),
|
.attr(GuardSplitAttr),
|
||||||
new StatusMove(Moves.POWER_SPLIT, Type.PSYCHIC, -1, 10, -1, 0, 5)
|
new StatusMove(Moves.POWER_SPLIT, Type.PSYCHIC, -1, 10, -1, 0, 5)
|
||||||
.unimplemented(),
|
.attr(PowerSplitAttr),
|
||||||
new StatusMove(Moves.WONDER_ROOM, Type.PSYCHIC, -1, 10, -1, 0, 5)
|
new StatusMove(Moves.WONDER_ROOM, Type.PSYCHIC, -1, 10, -1, 0, 5)
|
||||||
.ignoresProtect()
|
.ignoresProtect()
|
||||||
.target(MoveTarget.BOTH_SIDES)
|
.target(MoveTarget.BOTH_SIDES)
|
||||||
|
@ -5563,7 +5785,9 @@ export function initMoves() {
|
||||||
.attr(StatChangeAttr, [ BattleStat.SPATK, BattleStat.SPDEF, BattleStat.SPD ], 1, true)
|
.attr(StatChangeAttr, [ BattleStat.SPATK, BattleStat.SPDEF, BattleStat.SPD ], 1, true)
|
||||||
.danceMove(),
|
.danceMove(),
|
||||||
new AttackMove(Moves.HEAVY_SLAM, Type.STEEL, MoveCategory.PHYSICAL, -1, 100, 10, -1, 0, 5)
|
new AttackMove(Moves.HEAVY_SLAM, Type.STEEL, MoveCategory.PHYSICAL, -1, 100, 10, -1, 0, 5)
|
||||||
|
.attr(MinimizeAccuracyAttr)
|
||||||
.attr(CompareWeightPowerAttr)
|
.attr(CompareWeightPowerAttr)
|
||||||
|
.attr(HitsTagAttr, BattlerTagType.MINIMIZED, true)
|
||||||
.condition(failOnMaxCondition),
|
.condition(failOnMaxCondition),
|
||||||
new AttackMove(Moves.SYNCHRONOISE, Type.PSYCHIC, MoveCategory.SPECIAL, 120, 100, 10, -1, 0, 5)
|
new AttackMove(Moves.SYNCHRONOISE, Type.PSYCHIC, MoveCategory.SPECIAL, 120, 100, 10, -1, 0, 5)
|
||||||
.target(MoveTarget.ALL_NEAR_OTHERS)
|
.target(MoveTarget.ALL_NEAR_OTHERS)
|
||||||
|
@ -5645,7 +5869,7 @@ export function initMoves() {
|
||||||
.partial(),
|
.partial(),
|
||||||
new AttackMove(Moves.FINAL_GAMBIT, Type.FIGHTING, MoveCategory.SPECIAL, -1, 100, 5, -1, 0, 5)
|
new AttackMove(Moves.FINAL_GAMBIT, Type.FIGHTING, MoveCategory.SPECIAL, -1, 100, 5, -1, 0, 5)
|
||||||
.attr(UserHpDamageAttr)
|
.attr(UserHpDamageAttr)
|
||||||
.attr(SacrificialAttr),
|
.attr(SacrificialAttrOnHit),
|
||||||
new StatusMove(Moves.BESTOW, Type.NORMAL, -1, 15, -1, 0, 5)
|
new StatusMove(Moves.BESTOW, Type.NORMAL, -1, 15, -1, 0, 5)
|
||||||
.ignoresProtect()
|
.ignoresProtect()
|
||||||
.unimplemented(),
|
.unimplemented(),
|
||||||
|
@ -5694,7 +5918,9 @@ export function initMoves() {
|
||||||
.attr(StatChangeAttr, BattleStat.DEF, -1)
|
.attr(StatChangeAttr, BattleStat.DEF, -1)
|
||||||
.slicingMove(),
|
.slicingMove(),
|
||||||
new AttackMove(Moves.HEAT_CRASH, Type.FIRE, MoveCategory.PHYSICAL, -1, 100, 10, -1, 0, 5)
|
new AttackMove(Moves.HEAT_CRASH, Type.FIRE, MoveCategory.PHYSICAL, -1, 100, 10, -1, 0, 5)
|
||||||
|
.attr(MinimizeAccuracyAttr)
|
||||||
.attr(CompareWeightPowerAttr)
|
.attr(CompareWeightPowerAttr)
|
||||||
|
.attr(HitsTagAttr, BattlerTagType.MINIMIZED, true)
|
||||||
.condition(failOnMaxCondition),
|
.condition(failOnMaxCondition),
|
||||||
new AttackMove(Moves.LEAF_TORNADO, Type.GRASS, MoveCategory.SPECIAL, 65, 90, 10, 50, 0, 5)
|
new AttackMove(Moves.LEAF_TORNADO, Type.GRASS, MoveCategory.SPECIAL, 65, 90, 10, 50, 0, 5)
|
||||||
.attr(StatChangeAttr, BattleStat.ACC, -1),
|
.attr(StatChangeAttr, BattleStat.ACC, -1),
|
||||||
|
@ -5765,7 +5991,9 @@ export function initMoves() {
|
||||||
.makesContact(false)
|
.makesContact(false)
|
||||||
.partial(),
|
.partial(),
|
||||||
new AttackMove(Moves.FLYING_PRESS, Type.FIGHTING, MoveCategory.PHYSICAL, 100, 95, 10, -1, 0, 6)
|
new AttackMove(Moves.FLYING_PRESS, Type.FIGHTING, MoveCategory.PHYSICAL, 100, 95, 10, -1, 0, 6)
|
||||||
|
.attr(MinimizeAccuracyAttr)
|
||||||
.attr(FlyingTypeMultiplierAttr)
|
.attr(FlyingTypeMultiplierAttr)
|
||||||
|
.attr(HitsTagAttr, BattlerTagType.MINIMIZED, true)
|
||||||
.condition(failOnGravityCondition),
|
.condition(failOnGravityCondition),
|
||||||
new StatusMove(Moves.MAT_BLOCK, Type.FIGHTING, -1, 10, -1, 0, 6)
|
new StatusMove(Moves.MAT_BLOCK, Type.FIGHTING, -1, 10, -1, 0, 6)
|
||||||
.unimplemented(),
|
.unimplemented(),
|
||||||
|
|
|
@ -544,10 +544,19 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value of the specified stat.
|
||||||
|
* @param stat Stat to get the value of. {@link Stat}
|
||||||
|
* @returns The value of the stat. If the pokemon is already summoned, it uses those values, otherwise uses the base stats.
|
||||||
|
*/
|
||||||
getStat(stat: Stat): integer {
|
getStat(stat: Stat): integer {
|
||||||
|
if (!this.summonData) {
|
||||||
return this.stats[stat];
|
return this.stats[stat];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return this.summonData.stats[stat];
|
||||||
|
}
|
||||||
|
|
||||||
getBattleStat(stat: Stat, opponent?: Pokemon, move?: Move, isCritical: boolean = false): integer {
|
getBattleStat(stat: Stat, opponent?: Pokemon, move?: Move, isCritical: boolean = false): integer {
|
||||||
if (stat === Stat.HP)
|
if (stat === Stat.HP)
|
||||||
return this.getStat(Stat.HP);
|
return this.getStat(Stat.HP);
|
||||||
|
@ -1544,6 +1553,12 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
|
||||||
|
|
||||||
applyPreAttackAbAttrs(DamageBoostAbAttr, source, this, battlerMove, damage);
|
applyPreAttackAbAttrs(DamageBoostAbAttr, source, this, battlerMove, damage);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For each {@link HitsTagAttr} the move has, doubles the damage of the move if:
|
||||||
|
* The target has a {@link BattlerTagType} that this move interacts with
|
||||||
|
* AND
|
||||||
|
* The move doubles damage when used against that tag
|
||||||
|
* */
|
||||||
move.getAttrs(HitsTagAttr).map(hta => hta as HitsTagAttr).filter(hta => hta.doubleDamage).forEach(hta => {
|
move.getAttrs(HitsTagAttr).map(hta => hta as HitsTagAttr).filter(hta => hta.doubleDamage).forEach(hta => {
|
||||||
if (this.getTag(hta.tagType))
|
if (this.getTag(hta.tagType))
|
||||||
damage.value *= 2;
|
damage.value *= 2;
|
||||||
|
@ -1702,6 +1717,16 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
|
||||||
return healAmount;
|
return healAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a specific stat to a specific value.
|
||||||
|
* Used for summon data, while the pokemon is out until the next time it is retrieved.
|
||||||
|
* @param stat Stat to change. {@link Stat}
|
||||||
|
* @param value Amount to set the stat to.
|
||||||
|
*/
|
||||||
|
changeSummonStat(stat: Stat, value: integer) : void {
|
||||||
|
this.summonData.stats[stat] = value;
|
||||||
|
}
|
||||||
|
|
||||||
isBossImmune(): boolean {
|
isBossImmune(): boolean {
|
||||||
return this.isBoss();
|
return this.isBoss();
|
||||||
}
|
}
|
||||||
|
@ -2160,6 +2185,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
|
||||||
if (!this.battleData)
|
if (!this.battleData)
|
||||||
this.resetBattleData();
|
this.resetBattleData();
|
||||||
this.resetBattleSummonData();
|
this.resetBattleSummonData();
|
||||||
|
this.summonData.stats = this.stats;
|
||||||
if (this.summonDataPrimer) {
|
if (this.summonDataPrimer) {
|
||||||
for (let k of Object.keys(this.summonData)) {
|
for (let k of Object.keys(this.summonData)) {
|
||||||
if (this.summonDataPrimer[k])
|
if (this.summonDataPrimer[k])
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { SimpleTranslationEntries } from "#app/plugins/i18n";
|
import { SimpleTranslationEntries } from "#app/plugins/i18n";
|
||||||
|
|
||||||
export const abilityTriggers: SimpleTranslationEntries = {
|
export const abilityTriggers: SimpleTranslationEntries = {
|
||||||
'blockRecoilDamage' : `{{pokemonName}}'s {{abilityName}}\nprotected it from recoil!`,
|
'blockRecoilDamage' : `{{pokemonName}} wurde durch {{abilityName}}\nvor Rückstoß geschützt!`,
|
||||||
} as const;
|
} as const;
|
|
@ -2,7 +2,7 @@ import BattleScene, { AnySound, bypassLogin, startingWave } from "./battle-scene
|
||||||
import { default as Pokemon, PlayerPokemon, EnemyPokemon, PokemonMove, MoveResult, DamageResult, FieldPosition, HitResult, TurnMove } from "./field/pokemon";
|
import { default as Pokemon, PlayerPokemon, EnemyPokemon, PokemonMove, MoveResult, DamageResult, FieldPosition, HitResult, TurnMove } from "./field/pokemon";
|
||||||
import * as Utils from './utils';
|
import * as Utils from './utils';
|
||||||
import { Moves } from "./data/enums/moves";
|
import { Moves } from "./data/enums/moves";
|
||||||
import { allMoves, applyMoveAttrs, BypassSleepAttr, ChargeAttr, applyFilteredMoveAttrs, HitsTagAttr, MissEffectAttr, MoveAttr, MoveEffectAttr, MoveFlags, MultiHitAttr, OverrideMoveEffectAttr, VariableAccuracyAttr, MoveTarget, OneHitKOAttr, getMoveTargets, MoveTargetSet, MoveEffectTrigger, CopyMoveAttr, AttackMove, SelfStatusMove, DelayedAttackAttr, RechargeAttr, PreMoveMessageAttr, HealStatusEffectAttr, IgnoreOpponentStatChangesAttr, NoEffectAttr, BypassRedirectAttr, FixedDamageAttr, PostVictoryStatChangeAttr, OneHitKOAccuracyAttr, ForceSwitchOutAttr, VariableTargetAttr } from "./data/move";
|
import { allMoves, applyMoveAttrs, BypassSleepAttr, ChargeAttr, applyFilteredMoveAttrs, HitsTagAttr, MissEffectAttr, MoveAttr, MoveEffectAttr, MoveFlags, MultiHitAttr, OverrideMoveEffectAttr, VariableAccuracyAttr, MoveTarget, OneHitKOAttr, getMoveTargets, MoveTargetSet, MoveEffectTrigger, CopyMoveAttr, AttackMove, SelfStatusMove, DelayedAttackAttr, RechargeAttr, PreMoveMessageAttr, HealStatusEffectAttr, IgnoreOpponentStatChangesAttr, NoEffectAttr, BypassRedirectAttr, FixedDamageAttr, PostVictoryStatChangeAttr, OneHitKOAccuracyAttr, ForceSwitchOutAttr, VariableTargetAttr, SacrificialAttr } from "./data/move";
|
||||||
import { Mode } from './ui/ui';
|
import { Mode } from './ui/ui';
|
||||||
import { Command } from "./ui/command-ui-handler";
|
import { Command } from "./ui/command-ui-handler";
|
||||||
import { Stat } from "./data/pokemon-stat";
|
import { Stat } from "./data/pokemon-stat";
|
||||||
|
@ -330,6 +330,7 @@ export class TitlePhase extends Phase {
|
||||||
this.scene.newBattle();
|
this.scene.newBattle();
|
||||||
this.scene.arena.init();
|
this.scene.arena.init();
|
||||||
this.scene.sessionPlayTime = 0;
|
this.scene.sessionPlayTime = 0;
|
||||||
|
this.scene.lastSavePlayTime = 0;
|
||||||
this.end();
|
this.end();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -393,8 +394,12 @@ export class UnavailablePhase extends Phase {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ReloadSessionPhase extends Phase {
|
export class ReloadSessionPhase extends Phase {
|
||||||
constructor(scene: BattleScene) {
|
private systemDataStr: string;
|
||||||
|
|
||||||
|
constructor(scene: BattleScene, systemDataStr?: string) {
|
||||||
super(scene);
|
super(scene);
|
||||||
|
|
||||||
|
this.systemDataStr = systemDataStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
start(): void {
|
start(): void {
|
||||||
|
@ -410,7 +415,9 @@ export class ReloadSessionPhase extends Phase {
|
||||||
delayElapsed = true;
|
delayElapsed = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
this.scene.gameData.loadSystem().then(() => {
|
this.scene.gameData.clearLocalData();
|
||||||
|
|
||||||
|
(this.systemDataStr ? this.scene.gameData.initSystem(this.systemDataStr) : this.scene.gameData.loadSystem()).then(() => {
|
||||||
if (delayElapsed)
|
if (delayElapsed)
|
||||||
this.end();
|
this.end();
|
||||||
else
|
else
|
||||||
|
@ -531,6 +538,7 @@ export class SelectStarterPhase extends Phase {
|
||||||
this.scene.newBattle();
|
this.scene.newBattle();
|
||||||
this.scene.arena.init();
|
this.scene.arena.init();
|
||||||
this.scene.sessionPlayTime = 0;
|
this.scene.sessionPlayTime = 0;
|
||||||
|
this.scene.lastSavePlayTime = 0;
|
||||||
this.end();
|
this.end();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -784,7 +792,7 @@ export class EncounterPhase extends BattlePhase {
|
||||||
|
|
||||||
this.scene.ui.setMode(Mode.MESSAGE).then(() => {
|
this.scene.ui.setMode(Mode.MESSAGE).then(() => {
|
||||||
if (!this.loaded) {
|
if (!this.loaded) {
|
||||||
this.scene.gameData.saveAll(this.scene, true).then(success => {
|
this.scene.gameData.saveAll(this.scene, true, battle.waveIndex % 10 === 1 || this.scene.lastSavePlayTime >= 300).then(success => {
|
||||||
this.scene.disableMenu = false;
|
this.scene.disableMenu = false;
|
||||||
if (!success)
|
if (!success)
|
||||||
return this.scene.reset(true);
|
return this.scene.reset(true);
|
||||||
|
@ -2297,7 +2305,7 @@ export class MovePhase extends BattlePhase {
|
||||||
if (this.move.moveId)
|
if (this.move.moveId)
|
||||||
this.showMoveText();
|
this.showMoveText();
|
||||||
|
|
||||||
if ((moveQueue.length && moveQueue[0].move === Moves.NONE) || !targets.length) {
|
if ((moveQueue.length && moveQueue[0].move === Moves.NONE) || (!targets.length && !this.move.getMove().getAttrs(SacrificialAttr).length)) {
|
||||||
moveQueue.shift();
|
moveQueue.shift();
|
||||||
this.cancel();
|
this.cancel();
|
||||||
this.pokemon.pushMoveHistory({ move: Moves.NONE, result: MoveResult.FAIL });
|
this.pokemon.pushMoveHistory({ move: Moves.NONE, result: MoveResult.FAIL });
|
||||||
|
@ -2529,8 +2537,14 @@ export class MoveEffectPhase extends PokemonPhase {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
// Trigger effect which should only apply one time after all targeted effects have already applied
|
// Trigger effect which should only apply one time after all targeted effects have already applied
|
||||||
applyFilteredMoveAttrs((attr: MoveAttr) => attr instanceof MoveEffectAttr && (attr as MoveEffectAttr).trigger === MoveEffectTrigger.POST_TARGET,
|
const postTarget = applyFilteredMoveAttrs((attr: MoveAttr) => attr instanceof MoveEffectAttr && (attr as MoveEffectAttr).trigger === MoveEffectTrigger.POST_TARGET,
|
||||||
user, null, this.move.getMove())
|
user, null, this.move.getMove());
|
||||||
|
|
||||||
|
if (applyAttrs.length) // If there is a pending asynchronous move effect, do this after
|
||||||
|
applyAttrs[applyAttrs.length - 1]?.then(() => postTarget);
|
||||||
|
else // Otherwise, push a new asynchronous move effect
|
||||||
|
applyAttrs.push(postTarget);
|
||||||
|
|
||||||
Promise.allSettled(applyAttrs).then(() => this.end());
|
Promise.allSettled(applyAttrs).then(() => this.end());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -3692,7 +3706,7 @@ export class PostGameOverPhase extends Phase {
|
||||||
start() {
|
start() {
|
||||||
super.start();
|
super.start();
|
||||||
|
|
||||||
this.scene.gameData.saveSystem().then(success => {
|
this.scene.gameData.saveAll(this.scene, true, true, true).then(success => {
|
||||||
if (!success)
|
if (!success)
|
||||||
return this.scene.reset(true);
|
return this.scene.reset(true);
|
||||||
this.scene.gameData.tryClearSession(this.scene, this.scene.sessionSlotId).then((success: boolean | [boolean, boolean]) => {
|
this.scene.gameData.tryClearSession(this.scene, this.scene.sessionSlotId).then((success: boolean | [boolean, boolean]) => {
|
||||||
|
|
|
@ -20,7 +20,7 @@ import { Egg } from "../data/egg";
|
||||||
import { VoucherType, vouchers } from "./voucher";
|
import { VoucherType, vouchers } from "./voucher";
|
||||||
import { AES, enc } from "crypto-js";
|
import { AES, enc } from "crypto-js";
|
||||||
import { Mode } from "../ui/ui";
|
import { Mode } from "../ui/ui";
|
||||||
import { loggedInUser, updateUserInfo } from "../account";
|
import { clientSessionId, loggedInUser, updateUserInfo } from "../account";
|
||||||
import { Nature } from "../data/nature";
|
import { Nature } from "../data/nature";
|
||||||
import { GameStats } from "./game-stats";
|
import { GameStats } from "./game-stats";
|
||||||
import { Tutorial } from "../tutorial";
|
import { Tutorial } from "../tutorial";
|
||||||
|
@ -67,6 +67,18 @@ export function getDataTypeKey(dataType: GameDataType, slotId: integer = 0): str
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function encrypt(data: string, bypassLogin: boolean): string {
|
||||||
|
return (bypassLogin
|
||||||
|
? (data: string) => btoa(data)
|
||||||
|
: (data: string) => AES.encrypt(data, saveKey))(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
function decrypt(data: string, bypassLogin: boolean): string {
|
||||||
|
return (bypassLogin
|
||||||
|
? (data: string) => atob(data)
|
||||||
|
: (data: string) => AES.decrypt(data, saveKey).toString(enc.Utf8))(data);
|
||||||
|
}
|
||||||
|
|
||||||
interface SystemSaveData {
|
interface SystemSaveData {
|
||||||
trainerId: integer;
|
trainerId: integer;
|
||||||
secretId: integer;
|
secretId: integer;
|
||||||
|
@ -277,8 +289,10 @@ export class GameData {
|
||||||
const maxIntAttrValue = Math.pow(2, 31);
|
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);
|
const systemData = JSON.stringify(data, (k: any, v: any) => typeof v === 'bigint' ? v <= maxIntAttrValue ? Number(v) : v.toString() : v);
|
||||||
|
|
||||||
|
localStorage.setItem(`data_${loggedInUser.username}`, encrypt(systemData, bypassLogin));
|
||||||
|
|
||||||
if (!bypassLogin) {
|
if (!bypassLogin) {
|
||||||
Utils.apiPost(`savedata/update?datatype=${GameDataType.SYSTEM}`, systemData, undefined, true)
|
Utils.apiPost(`savedata/update?datatype=${GameDataType.SYSTEM}&clientSessionId=${clientSessionId}`, systemData, undefined, true)
|
||||||
.then(response => response.text())
|
.then(response => response.text())
|
||||||
.then(error => {
|
.then(error => {
|
||||||
this.scene.ui.savingIcon.hide();
|
this.scene.ui.savingIcon.hide();
|
||||||
|
@ -296,10 +310,6 @@ export class GameData {
|
||||||
resolve(true);
|
resolve(true);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
localStorage.setItem('data_bak', localStorage.getItem('data'));
|
|
||||||
|
|
||||||
localStorage.setItem('data', btoa(systemData));
|
|
||||||
|
|
||||||
this.scene.ui.savingIcon.hide();
|
this.scene.ui.savingIcon.hide();
|
||||||
|
|
||||||
resolve(true);
|
resolve(true);
|
||||||
|
@ -309,12 +319,49 @@ export class GameData {
|
||||||
|
|
||||||
public loadSystem(): Promise<boolean> {
|
public loadSystem(): Promise<boolean> {
|
||||||
return new Promise<boolean>(resolve => {
|
return new Promise<boolean>(resolve => {
|
||||||
if (bypassLogin && !localStorage.hasOwnProperty('data'))
|
console.log('Client Session:', clientSessionId);
|
||||||
|
|
||||||
|
if (bypassLogin && !localStorage.getItem(`data_${loggedInUser.username}`))
|
||||||
return resolve(false);
|
return resolve(false);
|
||||||
|
|
||||||
const handleSystemData = (systemDataStr: string) => {
|
if (!bypassLogin) {
|
||||||
|
Utils.apiFetch(`savedata/system?clientSessionId=${clientSessionId}`, true)
|
||||||
|
.then(response => response.text())
|
||||||
|
.then(response => {
|
||||||
|
if (!response.length || response[0] !== '{') {
|
||||||
|
if (response.startsWith('sql: no rows in result set')) {
|
||||||
|
this.scene.queueMessage('Save data could not be found. If this is a new account, you can safely ignore this message.', null, true);
|
||||||
|
return resolve(true);
|
||||||
|
} else if (response.indexOf('Too many connections') > -1) {
|
||||||
|
this.scene.queueMessage('Too many people are trying to connect and the server is overloaded. Please try again later.', null, true);
|
||||||
|
return resolve(false);
|
||||||
|
}
|
||||||
|
console.error(response);
|
||||||
|
return resolve(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
const cachedSystem = localStorage.getItem(`data_${loggedInUser.username}`);
|
||||||
|
this.initSystem(response, cachedSystem ? AES.decrypt(cachedSystem, saveKey).toString(enc.Utf8) : null).then(resolve);
|
||||||
|
});
|
||||||
|
} else
|
||||||
|
this.initSystem(decrypt(localStorage.getItem(`data_${loggedInUser.username}`), bypassLogin)).then(resolve);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public initSystem(systemDataStr: string, cachedSystemDataStr?: string): Promise<boolean> {
|
||||||
|
return new Promise<boolean>(resolve => {
|
||||||
try {
|
try {
|
||||||
const systemData = this.parseSystemData(systemDataStr);
|
let systemData = this.parseSystemData(systemDataStr);
|
||||||
|
|
||||||
|
if (cachedSystemDataStr) {
|
||||||
|
let cachedSystemData = this.parseSystemData(cachedSystemDataStr);
|
||||||
|
console.log(cachedSystemData.timestamp, systemData.timestamp)
|
||||||
|
if (cachedSystemData.timestamp > systemData.timestamp) {
|
||||||
|
console.debug('Use cached system');
|
||||||
|
systemData = cachedSystemData;
|
||||||
|
} else
|
||||||
|
this.clearLocalData();
|
||||||
|
}
|
||||||
|
|
||||||
console.debug(systemData);
|
console.debug(systemData);
|
||||||
|
|
||||||
|
@ -419,28 +466,6 @@ export class GameData {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
resolve(false);
|
resolve(false);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!bypassLogin) {
|
|
||||||
Utils.apiFetch(`savedata/get?datatype=${GameDataType.SYSTEM}`, true)
|
|
||||||
.then(response => response.text())
|
|
||||||
.then(response => {
|
|
||||||
if (!response.length || response[0] !== '{') {
|
|
||||||
if (response.startsWith('sql: no rows in result set')) {
|
|
||||||
this.scene.queueMessage('Save data could not be found. If this is a new account, you can safely ignore this message.', null, true);
|
|
||||||
return resolve(true);
|
|
||||||
} else if (response.indexOf('Too many connections') > -1) {
|
|
||||||
this.scene.queueMessage('Too many people are trying to connect and the server is overloaded. Please try again later.', null, true);
|
|
||||||
return resolve(false);
|
|
||||||
}
|
|
||||||
console.error(response);
|
|
||||||
return resolve(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
handleSystemData(response);
|
|
||||||
});
|
|
||||||
} else
|
|
||||||
handleSystemData(atob(localStorage.getItem('data')));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -474,6 +499,31 @@ export class GameData {
|
||||||
return dataStr;
|
return dataStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async verify(): Promise<boolean> {
|
||||||
|
if (bypassLogin)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
const response = await Utils.apiPost(`savedata/system/verify`, JSON.stringify({ clientSessionId: clientSessionId }), undefined, true)
|
||||||
|
.then(response => response.json());
|
||||||
|
|
||||||
|
if (!response.valid) {
|
||||||
|
this.scene.clearPhaseQueue();
|
||||||
|
this.scene.unshiftPhase(new ReloadSessionPhase(this.scene, JSON.stringify(response.systemData)));
|
||||||
|
this.clearLocalData();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public clearLocalData(): void {
|
||||||
|
if (bypassLogin)
|
||||||
|
return;
|
||||||
|
localStorage.removeItem(`data_${loggedInUser.username}`);
|
||||||
|
for (let s = 0; s < 5; s++)
|
||||||
|
localStorage.removeItem(`sessionData${s ? s : ''}_${loggedInUser.username}`);
|
||||||
|
}
|
||||||
|
|
||||||
public saveSetting(setting: Setting, valueIndex: integer): boolean {
|
public saveSetting(setting: Setting, valueIndex: integer): boolean {
|
||||||
let settings: object = {};
|
let settings: object = {};
|
||||||
if (localStorage.hasOwnProperty('settings'))
|
if (localStorage.hasOwnProperty('settings'))
|
||||||
|
@ -557,40 +607,6 @@ export class GameData {
|
||||||
} as SessionSaveData;
|
} as SessionSaveData;
|
||||||
}
|
}
|
||||||
|
|
||||||
saveSession(scene: BattleScene, skipVerification?: boolean): Promise<boolean> {
|
|
||||||
return new Promise<boolean>(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<SessionSaveData> {
|
getSession(slotId: integer): Promise<SessionSaveData> {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
if (slotId < 0)
|
if (slotId < 0)
|
||||||
|
@ -605,8 +621,8 @@ export class GameData {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!bypassLogin) {
|
if (!bypassLogin && !localStorage.getItem(`sessionData${slotId ? slotId : ''}_${loggedInUser.username}`)) {
|
||||||
Utils.apiFetch(`savedata/get?datatype=${GameDataType.SESSION}&slot=${slotId}`, true)
|
Utils.apiFetch(`savedata/session?slot=${slotId}&clientSessionId=${clientSessionId}`, true)
|
||||||
.then(response => response.text())
|
.then(response => response.text())
|
||||||
.then(async response => {
|
.then(async response => {
|
||||||
if (!response.length || response[0] !== '{') {
|
if (!response.length || response[0] !== '{') {
|
||||||
|
@ -614,12 +630,14 @@ export class GameData {
|
||||||
return resolve(null);
|
return resolve(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
localStorage.setItem(`sessionData${slotId ? slotId : ''}_${loggedInUser.username}`, encrypt(response, bypassLogin));
|
||||||
|
|
||||||
await handleSessionData(response);
|
await handleSessionData(response);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const sessionData = localStorage.getItem(`sessionData${slotId ? slotId : ''}`);
|
const sessionData = localStorage.getItem(`sessionData${slotId ? slotId : ''}_${loggedInUser.username}`);
|
||||||
if (sessionData)
|
if (sessionData)
|
||||||
await handleSessionData(atob(sessionData));
|
await handleSessionData(decrypt(sessionData, bypassLogin));
|
||||||
else
|
else
|
||||||
return resolve(null);
|
return resolve(null);
|
||||||
}
|
}
|
||||||
|
@ -640,6 +658,7 @@ export class GameData {
|
||||||
console.log('Seed:', scene.seed);
|
console.log('Seed:', scene.seed);
|
||||||
|
|
||||||
scene.sessionPlayTime = sessionData.playTime || 0;
|
scene.sessionPlayTime = sessionData.playTime || 0;
|
||||||
|
scene.lastSavePlayTime = 0;
|
||||||
|
|
||||||
const loadPokemonAssets: Promise<void>[] = [];
|
const loadPokemonAssets: Promise<void>[] = [];
|
||||||
|
|
||||||
|
@ -731,16 +750,17 @@ export class GameData {
|
||||||
deleteSession(slotId: integer): Promise<boolean> {
|
deleteSession(slotId: integer): Promise<boolean> {
|
||||||
return new Promise<boolean>(resolve => {
|
return new Promise<boolean>(resolve => {
|
||||||
if (bypassLogin) {
|
if (bypassLogin) {
|
||||||
localStorage.removeItem('sessionData');
|
localStorage.removeItem(`sessionData${this.scene.sessionSlotId ? this.scene.sessionSlotId : ''}_${loggedInUser.username}`);
|
||||||
return resolve(true);
|
return resolve(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateUserInfo().then(success => {
|
updateUserInfo().then(success => {
|
||||||
if (success !== null && !success)
|
if (success !== null && !success)
|
||||||
return resolve(false);
|
return resolve(false);
|
||||||
Utils.apiFetch(`savedata/delete?datatype=${GameDataType.SESSION}&slot=${slotId}`, true).then(response => {
|
Utils.apiFetch(`savedata/delete?datatype=${GameDataType.SESSION}&slot=${slotId}&clientSessionId=${clientSessionId}`, true).then(response => {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
loggedInUser.lastSessionSlot = -1;
|
loggedInUser.lastSessionSlot = -1;
|
||||||
|
localStorage.removeItem(`sessionData${this.scene.sessionSlotId ? this.scene.sessionSlotId : ''}_${loggedInUser.username}`);
|
||||||
resolve(true);
|
resolve(true);
|
||||||
}
|
}
|
||||||
return response.text();
|
return response.text();
|
||||||
|
@ -792,7 +812,7 @@ export class GameData {
|
||||||
tryClearSession(scene: BattleScene, slotId: integer): Promise<[success: boolean, newClear: boolean]> {
|
tryClearSession(scene: BattleScene, slotId: integer): Promise<[success: boolean, newClear: boolean]> {
|
||||||
return new Promise<[boolean, boolean]>(resolve => {
|
return new Promise<[boolean, boolean]>(resolve => {
|
||||||
if (bypassLogin) {
|
if (bypassLogin) {
|
||||||
localStorage.removeItem(`sessionData${slotId ? slotId : ''}`);
|
localStorage.removeItem(`sessionData${slotId ? slotId : ''}_${loggedInUser.username}`);
|
||||||
return resolve([true, true]);
|
return resolve([true, true]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -800,9 +820,11 @@ export class GameData {
|
||||||
if (success !== null && !success)
|
if (success !== null && !success)
|
||||||
return resolve([false, false]);
|
return resolve([false, false]);
|
||||||
const sessionData = this.getSessionSaveData(scene);
|
const sessionData = this.getSessionSaveData(scene);
|
||||||
Utils.apiPost(`savedata/clear?slot=${slotId}&trainerId=${this.trainerId}&secretId=${this.secretId}`, JSON.stringify(sessionData), undefined, true).then(response => {
|
Utils.apiPost(`savedata/clear?slot=${slotId}&trainerId=${this.trainerId}&secretId=${this.secretId}&clientSessionId=${clientSessionId}`, JSON.stringify(sessionData), undefined, true).then(response => {
|
||||||
if (response.ok)
|
if (response.ok) {
|
||||||
loggedInUser.lastSessionSlot = -1;
|
loggedInUser.lastSessionSlot = -1;
|
||||||
|
localStorage.removeItem(`sessionData${this.scene.sessionSlotId ? this.scene.sessionSlotId : ''}_${loggedInUser.username}`);
|
||||||
|
}
|
||||||
return response.json();
|
return response.json();
|
||||||
}).then(jsonResponse => {
|
}).then(jsonResponse => {
|
||||||
if (!jsonResponse.error)
|
if (!jsonResponse.error)
|
||||||
|
@ -855,14 +877,14 @@ export class GameData {
|
||||||
}) as SessionSaveData;
|
}) as SessionSaveData;
|
||||||
}
|
}
|
||||||
|
|
||||||
saveAll(scene: BattleScene, skipVerification?: boolean): Promise<boolean> {
|
saveAll(scene: BattleScene, skipVerification: boolean = false, sync: boolean = false, useCachedSession: boolean = false): Promise<boolean> {
|
||||||
return new Promise<boolean>(resolve => {
|
return new Promise<boolean>(resolve => {
|
||||||
Utils.executeIf(!skipVerification, updateUserInfo).then(success => {
|
Utils.executeIf(!skipVerification, updateUserInfo).then(success => {
|
||||||
if (success !== null && !success)
|
if (success !== null && !success)
|
||||||
return resolve(false);
|
return resolve(false);
|
||||||
|
if (sync)
|
||||||
this.scene.ui.savingIcon.show();
|
this.scene.ui.savingIcon.show();
|
||||||
const data = this.getSystemSaveData();
|
const sessionData = useCachedSession ? this.parseSessionData(decrypt(localStorage.getItem(`sessionData${scene.sessionSlotId ? scene.sessionSlotId : ''}_${loggedInUser.username}`), bypassLogin)) : this.getSessionSaveData(scene);
|
||||||
const sessionData = this.getSessionSaveData(scene);
|
|
||||||
|
|
||||||
const maxIntAttrValue = Math.pow(2, 31);
|
const maxIntAttrValue = Math.pow(2, 31);
|
||||||
const systemData = this.getSystemSaveData();
|
const systemData = this.getSystemSaveData();
|
||||||
|
@ -870,14 +892,24 @@ export class GameData {
|
||||||
const request = {
|
const request = {
|
||||||
system: systemData,
|
system: systemData,
|
||||||
session: sessionData,
|
session: sessionData,
|
||||||
sessionSlotId: scene.sessionSlotId
|
sessionSlotId: scene.sessionSlotId,
|
||||||
|
clientSessionId: clientSessionId
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!bypassLogin) {
|
localStorage.setItem(`data_${loggedInUser.username}`, encrypt(JSON.stringify(systemData, (k: any, v: any) => typeof v === 'bigint' ? v <= maxIntAttrValue ? Number(v) : v.toString() : v), bypassLogin));
|
||||||
|
|
||||||
|
localStorage.setItem(`sessionData${scene.sessionSlotId ? scene.sessionSlotId : ''}_${loggedInUser.username}`, encrypt(JSON.stringify(sessionData), bypassLogin));
|
||||||
|
|
||||||
|
console.debug('Session data saved');
|
||||||
|
|
||||||
|
if (!bypassLogin && sync) {
|
||||||
Utils.apiPost('savedata/updateall', JSON.stringify(request, (k: any, v: any) => typeof v === 'bigint' ? v <= maxIntAttrValue ? Number(v) : v.toString() : v), undefined, true)
|
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(response => response.text())
|
||||||
.then(error => {
|
.then(error => {
|
||||||
|
if (sync) {
|
||||||
|
this.scene.lastSavePlayTime = 0;
|
||||||
this.scene.ui.savingIcon.hide();
|
this.scene.ui.savingIcon.hide();
|
||||||
|
}
|
||||||
if (error) {
|
if (error) {
|
||||||
if (error.startsWith('client version out of date')) {
|
if (error.startsWith('client version out of date')) {
|
||||||
this.scene.clearPhaseQueue();
|
this.scene.clearPhaseQueue();
|
||||||
|
@ -892,17 +924,10 @@ export class GameData {
|
||||||
resolve(true);
|
resolve(true);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
localStorage.setItem('data_bak', localStorage.getItem('data'));
|
this.verify().then(success => {
|
||||||
|
|
||||||
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 : ''}`, btoa(JSON.stringify(sessionData)));
|
|
||||||
|
|
||||||
console.debug('Session data saved');
|
|
||||||
|
|
||||||
this.scene.ui.savingIcon.hide();
|
this.scene.ui.savingIcon.hide();
|
||||||
|
resolve(success);
|
||||||
resolve(true);
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -910,7 +935,7 @@ export class GameData {
|
||||||
|
|
||||||
public tryExportData(dataType: GameDataType, slotId: integer = 0): Promise<boolean> {
|
public tryExportData(dataType: GameDataType, slotId: integer = 0): Promise<boolean> {
|
||||||
return new Promise<boolean>(resolve => {
|
return new Promise<boolean>(resolve => {
|
||||||
const dataKey: string = getDataTypeKey(dataType, slotId);
|
const dataKey: string = `${getDataTypeKey(dataType, slotId)}_${loggedInUser.username}`;
|
||||||
const handleData = (dataStr: string) => {
|
const handleData = (dataStr: string) => {
|
||||||
switch (dataType) {
|
switch (dataType) {
|
||||||
case GameDataType.SYSTEM:
|
case GameDataType.SYSTEM:
|
||||||
|
@ -926,7 +951,7 @@ export class GameData {
|
||||||
link.remove();
|
link.remove();
|
||||||
};
|
};
|
||||||
if (!bypassLogin && dataType < GameDataType.SETTINGS) {
|
if (!bypassLogin && dataType < GameDataType.SETTINGS) {
|
||||||
Utils.apiFetch(`savedata/get?datatype=${dataType}${dataType === GameDataType.SESSION ? `&slot=${slotId}` : ''}`, true)
|
Utils.apiFetch(`savedata/${dataType === GameDataType.SYSTEM ? 'system' : 'session'}?clientSessionId=${clientSessionId}${dataType === GameDataType.SESSION ? `&slot=${slotId}` : ''}`, true)
|
||||||
.then(response => response.text())
|
.then(response => response.text())
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (!response.length || response[0] !== '{') {
|
if (!response.length || response[0] !== '{') {
|
||||||
|
@ -941,14 +966,14 @@ export class GameData {
|
||||||
} else {
|
} else {
|
||||||
const data = localStorage.getItem(dataKey);
|
const data = localStorage.getItem(dataKey);
|
||||||
if (data)
|
if (data)
|
||||||
handleData(atob(data));
|
handleData(decrypt(data, bypassLogin));
|
||||||
resolve(!!data);
|
resolve(!!data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public importData(dataType: GameDataType, slotId: integer = 0): void {
|
public importData(dataType: GameDataType, slotId: integer = 0): void {
|
||||||
const dataKey = getDataTypeKey(dataType, slotId);
|
const dataKey = `${getDataTypeKey(dataType, slotId)}_${loggedInUser.username}`;
|
||||||
|
|
||||||
let saveFile: any = document.getElementById('saveFile');
|
let saveFile: any = document.getElementById('saveFile');
|
||||||
if (saveFile)
|
if (saveFile)
|
||||||
|
@ -1009,11 +1034,13 @@ 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));
|
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.showText(`Your ${dataName} data will be overridden and the page will reload. Proceed?`, null, () => {
|
||||||
this.scene.ui.setOverlayMode(Mode.CONFIRM, () => {
|
this.scene.ui.setOverlayMode(Mode.CONFIRM, () => {
|
||||||
|
localStorage.setItem(dataKey, encrypt(dataStr, bypassLogin));
|
||||||
|
|
||||||
if (!bypassLogin && dataType < GameDataType.SETTINGS) {
|
if (!bypassLogin && dataType < GameDataType.SETTINGS) {
|
||||||
updateUserInfo().then(success => {
|
updateUserInfo().then(success => {
|
||||||
if (!success)
|
if (!success)
|
||||||
return displayError(`Could not contact the server. Your ${dataName} data could not be imported.`);
|
return displayError(`Could not contact the server. Your ${dataName} data could not be imported.`);
|
||||||
Utils.apiPost(`savedata/update?datatype=${dataType}${dataType === GameDataType.SESSION ? `&slot=${slotId}` : ''}&trainerId=${this.trainerId}&secretId=${this.secretId}`, dataStr, undefined, true)
|
Utils.apiPost(`savedata/update?datatype=${dataType}${dataType === GameDataType.SESSION ? `&slot=${slotId}` : ''}&trainerId=${this.trainerId}&secretId=${this.secretId}&clientSessionId=${clientSessionId}`, dataStr, undefined, true)
|
||||||
.then(response => response.text())
|
.then(response => response.text())
|
||||||
.then(error => {
|
.then(error => {
|
||||||
if (error) {
|
if (error) {
|
||||||
|
@ -1023,10 +1050,8 @@ export class GameData {
|
||||||
window.location = window.location;
|
window.location = window.location;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else
|
||||||
localStorage.setItem(dataKey, btoa(dataStr));
|
|
||||||
window.location = window.location;
|
window.location = window.location;
|
||||||
}
|
|
||||||
}, () => {
|
}, () => {
|
||||||
this.scene.ui.revertMode();
|
this.scene.ui.revertMode();
|
||||||
this.scene.ui.showText(null, 0);
|
this.scene.ui.showText(null, 0);
|
||||||
|
|
|
@ -112,6 +112,7 @@ export default class PokemonData {
|
||||||
this.summonData = new PokemonSummonData();
|
this.summonData = new PokemonSummonData();
|
||||||
if (!forHistory && source.summonData) {
|
if (!forHistory && source.summonData) {
|
||||||
this.summonData.battleStats = source.summonData.battleStats;
|
this.summonData.battleStats = source.summonData.battleStats;
|
||||||
|
this.summonData.stats = source.summonData.stats;
|
||||||
this.summonData.moveQueue = source.summonData.moveQueue;
|
this.summonData.moveQueue = source.summonData.moveQueue;
|
||||||
this.summonData.disabledMove = source.summonData.disabledMove;
|
this.summonData.disabledMove = source.summonData.disabledMove;
|
||||||
this.summonData.disabledTurns = source.summonData.disabledTurns;
|
this.summonData.disabledTurns = source.summonData.disabledTurns;
|
||||||
|
|
|
@ -372,7 +372,7 @@ export default class EggGachaUiHandler extends MessageUiHandler {
|
||||||
this.scene.gameData.gameStats.eggsPulled++;
|
this.scene.gameData.gameStats.eggsPulled++;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.scene.gameData.saveSystem().then(success => {
|
(this.scene.currentBattle ? this.scene.gameData.saveAll(this.scene, true, true, true) : this.scene.gameData.saveSystem()).then(success => {
|
||||||
if (!success)
|
if (!success)
|
||||||
return this.scene.reset(true);
|
return this.scene.reset(true);
|
||||||
doPull();
|
doPull();
|
||||||
|
|
Loading…
Reference in New Issue