From e0acb1e737a93c1f525d0a0e41f11528523fa88e Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Wed, 25 Oct 2023 09:41:37 -0400 Subject: [PATCH] Fix Disable implementation --- src/battle-phases.ts | 17 ++++++++--------- src/data/move.ts | 8 ++++++-- src/pokemon.ts | 20 ++++++++------------ 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/battle-phases.ts b/src/battle-phases.ts index 29cef5d4c..26cdeac5e 100644 --- a/src/battle-phases.ts +++ b/src/battle-phases.ts @@ -940,7 +940,7 @@ export class CommandPhase extends FieldPhase { while (moveQueue.length && moveQueue[0] && moveQueue[0].move && (!playerPokemon.getMoveset().find(m => m.moveId === moveQueue[0].move) - || !playerPokemon.getMoveset()[playerPokemon.getMoveset().findIndex(m => m.moveId === moveQueue[0].move)].isUsable(moveQueue[0].ignorePP))) + || !playerPokemon.getMoveset()[playerPokemon.getMoveset().findIndex(m => m.moveId === moveQueue[0].move)].isUsable(playerPokemon, moveQueue[0].ignorePP))) moveQueue.shift(); if (moveQueue.length) { @@ -949,7 +949,7 @@ export class CommandPhase extends FieldPhase { this.handleCommand(Command.FIGHT, -1, false); else { const moveIndex = playerPokemon.getMoveset().findIndex(m => m.moveId === queuedMove.move); - if (moveIndex > -1 && playerPokemon.getMoveset()[moveIndex].isUsable(queuedMove.ignorePP)) { + if (moveIndex > -1 && playerPokemon.getMoveset()[moveIndex].isUsable(playerPokemon, queuedMove.ignorePP)) { this.handleCommand(Command.FIGHT, moveIndex, queuedMove.ignorePP, { targets: queuedMove.targets, multiple: queuedMove.targets.length > 1 }); } else this.scene.ui.setMode(Mode.COMMAND, this.fieldIndex); @@ -978,7 +978,7 @@ export class CommandPhase extends FieldPhase { success = true; } else if (cursor < playerPokemon.getMoveset().length) { const move = playerPokemon.getMoveset()[cursor]; - if (move.isDisabled()) { + if (playerPokemon.summonData.disabledMove === move.moveId) { this.scene.ui.setMode(Mode.MESSAGE); this.scene.ui.showText(`${move.getName()} is disabled!`, null, () => { this.scene.ui.clearText(); @@ -1222,10 +1222,9 @@ export class TurnEndPhase extends FieldPhase { const handlePokemon = (pokemon: Pokemon) => { pokemon.lapseTags(BattlerTagLapseType.TURN_END); - const disabledMoves = pokemon.getMoveset().filter(m => m.isDisabled()); - for (let dm of disabledMoves) { - if (!--dm.disableTurns) - this.scene.pushPhase(new MessagePhase(this.scene, `${dm.getName()} is disabled\nno more!`)); + if (pokemon.summonData.disabledMove && !--pokemon.summonData.disabledTurns) { + pokemon.summonData.disabledMove = Moves.NONE; + this.scene.pushPhase(new MessagePhase(this.scene, `${allMoves[pokemon.summonData.disabledMove].name} is disabled\nno more!`)); } const hasUsableBerry = !!this.scene.findModifier(m => m instanceof BerryModifier && m.shouldApply([ pokemon ]), pokemon.isPlayer()); @@ -1321,7 +1320,7 @@ export class MovePhase extends BattlePhase { } canMove(): boolean { - return this.pokemon.isActive(true) && this.move.isUsable(this.ignorePp) && !!this.targets.length; + return this.pokemon.isActive(true) && this.move.isUsable(this.pokemon, this.ignorePp) && !!this.targets.length; } cancel(): void { @@ -1334,7 +1333,7 @@ export class MovePhase extends BattlePhase { console.log(Moves[this.move.moveId]); if (!this.canMove()) { - if (this.move.isDisabled()) + if (this.pokemon.summonData.disabledMove === this.move.moveId) this.scene.queueMessage(`${this.move.getName()} is disabled!`); this.end(); return; diff --git a/src/data/move.ts b/src/data/move.ts index 990c51698..8d39554ee 100644 --- a/src/data/move.ts +++ b/src/data/move.ts @@ -1671,7 +1671,8 @@ export class DisableMoveAttr extends MoveEffectAttr { return false; const disabledMove = target.getMoveset()[moveIndex]; - disabledMove.disableTurns = 4; + target.summonData.disabledMove = disabledMove.moveId; + target.summonData.disabledTurns = 4; user.scene.queueMessage(getPokemonMessage(target, `'s ${disabledMove.getName()}\nwas disabled!`)); @@ -1683,6 +1684,9 @@ export class DisableMoveAttr extends MoveEffectAttr { getCondition(): MoveCondition { return (user: Pokemon, target: Pokemon, move: Move) => { + if (target.summonData.disabledMove) + return false; + const moveQueue = target.getLastXMoves(); let turnMove: TurnMove; while (moveQueue.length) { @@ -1694,7 +1698,7 @@ export class DisableMoveAttr extends MoveEffectAttr { if (!move) continue; - return !move.isDisabled(); + return true; } }; } diff --git a/src/pokemon.ts b/src/pokemon.ts index 5aa0cb441..8e4a1bb4e 100644 --- a/src/pokemon.ts +++ b/src/pokemon.ts @@ -25,7 +25,7 @@ import { ArenaTagType, WeakenMoveTypeTag } from './data/arena-tag'; import { Biome } from './data/biome'; import { Abilities, Ability, BattleStatMultiplierAbAttr, BlockCritAbAttr, NonSuperEffectiveImmunityAbAttr, PreApplyBattlerTagAbAttr, StatusEffectImmunityAbAttr, TypeImmunityAbAttr, VariableMovePowerAbAttr, abilities, applyBattleStatMultiplierAbAttrs, applyPreApplyBattlerTagAbAttrs, applyPreAttackAbAttrs, applyPreDefendAbAttrs, applyPreSetStatusAbAttrs } from './data/ability'; import PokemonData from './system/pokemon-data'; -import { BattleType, BattlerIndex } from './battle'; +import { BattlerIndex } from './battle'; export enum FieldPosition { CENTER, @@ -548,7 +548,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { const move = this.getMoveset().length > moveIndex ? this.getMoveset()[moveIndex] : null; - return move?.isUsable(ignorePp); + return move?.isUsable(this, ignorePp); } showInfo() { @@ -1207,7 +1207,7 @@ export class EnemyPokemon extends Pokemon { ? this.getMoveset().find(m => m.moveId === this.getMoveQueue()[0].move) : null; if (queuedMove) { - if (queuedMove.isUsable(this.getMoveQueue()[0].ignorePP)) + if (queuedMove.isUsable(this, this.getMoveQueue()[0].ignorePP)) return { move: queuedMove.moveId, targets: this.getMoveQueue()[0].targets, ignorePP: this.getMoveQueue()[0].ignorePP }; else { this.getMoveQueue().shift(); @@ -1215,7 +1215,7 @@ export class EnemyPokemon extends Pokemon { } } - const movePool = this.getMoveset().filter(m => m.isUsable()); + const movePool = this.getMoveset().filter(m => m.isUsable(this)); if (movePool.length) { if (movePool.length === 1) return { move: movePool[0].moveId, targets: this.getNextTargets(movePool[0].moveId) }; @@ -1370,6 +1370,8 @@ export interface AttackMoveResult { export class PokemonSummonData { public battleStats: integer[] = [ 0, 0, 0, 0, 0, 0, 0 ]; public moveQueue: QueuedMove[] = []; + public disabledMove: Moves = Moves.NONE; + public disabledTurns: integer = 0; public tags: BattlerTag[] = []; public moveset: PokemonMove[]; public types: Type[]; @@ -1420,26 +1422,20 @@ export class PokemonMove { public ppUsed: integer; public ppUp: integer; public virtual: boolean; - public disableTurns: integer; constructor(moveId: Moves, ppUsed?: integer, ppUp?: integer, virtual?: boolean) { this.moveId = moveId; this.ppUsed = ppUsed || 0; this.ppUp = ppUp || 0; this.virtual = !!virtual; - this.disableTurns = 0; } - isUsable(ignorePp?: boolean): boolean { - if (this.isDisabled()) + isUsable(pokemon: Pokemon, ignorePp?: boolean): boolean { + if (pokemon.summonData?.disabledMove === this.moveId) return false; return ignorePp || this.ppUsed < this.getMove().pp + this.ppUp || this.getMove().pp === -1; } - isDisabled(): boolean { - return !!this.disableTurns; - } - getMove(): Move { return allMoves[this.moveId]; }