Fix Disable implementation

pull/2/head
Flashfyre 2023-10-25 09:41:37 -04:00
parent 1fd5f6c01f
commit e0acb1e737
3 changed files with 22 additions and 23 deletions

View File

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

View File

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

View File

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