diff --git a/src/battle-phases.ts b/src/battle-phases.ts index 4f189da55..323b0f81b 100644 --- a/src/battle-phases.ts +++ b/src/battle-phases.ts @@ -1,7 +1,7 @@ import BattleScene, { startingLevel, startingWave } from "./battle-scene"; import { default as Pokemon, PlayerPokemon, EnemyPokemon, PokemonMove, MoveResult, DamageResult } from "./pokemon"; import * as Utils from './utils'; -import { allMoves, applyMoveAttrs, BypassSleepAttr, ChargeAttr, HitsTagAttr, MissEffectAttr, MoveCategory, MoveEffectAttr, MoveFlags, MoveHitEffectAttr, Moves, MultiHitAttr, OverrideMoveEffectAttr, VariableAccuracyAttr } from "./data/move"; +import { allMoves, applyMoveAttrs, BypassSleepAttr, ChargeAttr, applyFilteredMoveAttrs, HitsTagAttr, MissEffectAttr, MoveAttr, MoveCategory, MoveEffectAttr, MoveFlags, MoveHitEffectAttr, Moves, MultiHitAttr, OverrideMoveEffectAttr, VariableAccuracyAttr } from "./data/move"; import { Mode } from './ui/ui'; import { Command } from "./ui/command-ui-handler"; import { Stat } from "./data/pokemon-stat"; @@ -588,7 +588,7 @@ export class CommandPhase extends FieldPhase { const moveQueue = playerPokemon.getMoveQueue(); while (moveQueue.length && moveQueue[0] - && moveQueue[0].move && (playerPokemon.moveset.find(m => m.moveId === moveQueue[0].move) + && moveQueue[0].move && (!playerPokemon.moveset.find(m => m.moveId === moveQueue[0].move) || !playerPokemon.moveset[playerPokemon.moveset.findIndex(m => m.moveId === moveQueue[0].move)].isUsable(moveQueue[0].ignorePP))) moveQueue.shift(); @@ -659,9 +659,10 @@ export class CommandPhase extends FieldPhase { break; case Command.BALL: if (this.scene.arena.biomeType === Biome.END) { + this.scene.ui.setMode(Mode.COMMAND); this.scene.ui.setMode(Mode.MESSAGE); - this.scene.ui.showText(`A strange force\nprevents using ${getPokeballName(PokeballType.POKEBALL)}s.`, null, () => { - this.scene.ui.clearText(); + this.scene.ui.showText(`A strange force\nprevents using POKé BALLS.`, null, () => { + this.scene.ui.showText(null, 0); this.scene.ui.setMode(Mode.COMMAND); }, null, true); } else if (cursor < 4) { @@ -1028,8 +1029,8 @@ abstract class MoveEffectPhase extends PokemonPhase { target.addTag(BattlerTagType.FLINCHED, undefined, this.move.moveId, user.id); } // Charge attribute with charge effect takes all effect attributes and applies them to charge stage, so ignore them if this is present - if (!isProtected && target.hp && !this.move.getMove().getAttrs(ChargeAttr).filter(ca => (ca as ChargeAttr).chargeEffect).length) - applyMoveAttrs(MoveHitEffectAttr, user, target, this.move.getMove()); + if (!isProtected && !this.move.getMove().getAttrs(ChargeAttr).filter(ca => (ca as ChargeAttr).chargeEffect).length) + applyFilteredMoveAttrs((attr: MoveAttr) => attr instanceof MoveHitEffectAttr && (!!target.hp || (attr as MoveHitEffectAttr).selfTarget), user, target, this.move.getMove()); } this.end(); }); diff --git a/src/data/move.ts b/src/data/move.ts index a71dbf3fd..2d15eaef2 100644 --- a/src/data/move.ts +++ b/src/data/move.ts @@ -749,6 +749,13 @@ export class MoveEffectAttr extends MoveAttr { } export class MoveHitEffectAttr extends MoveAttr { + public selfTarget: boolean; + + constructor(selfTarget?: boolean) { + super(); + + this.selfTarget = !!selfTarget; + } } export class HighCritAttr extends MoveAttr { @@ -905,7 +912,7 @@ export class HitHealAttr extends MoveHitEffectAttr { private healRatio: number; constructor(healRatio?: number) { - super(); + super(true); this.healRatio = healRatio || 0.5; } @@ -954,14 +961,12 @@ export class MultiHitAttr extends MoveAttr { export class StatusEffectAttr extends MoveHitEffectAttr { public effect: StatusEffect; - public selfTarget: boolean; public cureTurn: integer; constructor(effect: StatusEffect, selfTarget?: boolean, cureTurn?: integer) { - super(); + super(selfTarget); this.effect = effect; - this.selfTarget = !!selfTarget; this.cureTurn = cureTurn; } @@ -1789,10 +1794,12 @@ export class SketchAttr extends MoveEffectAttr { } } -export function applyMoveAttrs(attrType: { new(...args: any[]): MoveAttr }, user: Pokemon, target: Pokemon, move: Move, ...args: any[]): Promise { +export type MoveAttrFilter = (attr: MoveAttr) => boolean; + +function applyMoveAttrsInternal(attrFilter: MoveAttrFilter, user: Pokemon, target: Pokemon, move: Move, args: any[]): Promise { return new Promise(resolve => { const attrPromises: Promise[] = []; - const moveAttrs = move.attrs.filter(a => a instanceof attrType); + const moveAttrs = move.attrs.filter(a => attrFilter(a)); for (let attr of moveAttrs) { const result = attr.apply(user, target, move, args); if (result instanceof Promise) @@ -1802,6 +1809,14 @@ export function applyMoveAttrs(attrType: { new(...args: any[]): MoveAttr }, user }); } +export function applyMoveAttrs(attrType: { new(...args: any[]): MoveAttr }, user: Pokemon, target: Pokemon, move: Move, ...args: any[]): Promise { + return applyMoveAttrsInternal((attr: MoveAttr) => attr instanceof attrType, user, target, move, args); +} + +export function applyFilteredMoveAttrs(attrFilter: MoveAttrFilter, user: Pokemon, target: Pokemon, move: Move, ...args: any[]): Promise { + return applyMoveAttrsInternal(attrFilter, user, target, move, args); +} + export const allMoves = [ new StatusMove(Moves.NONE, "-", Type.NORMAL, MoveCategory.STATUS, -1, -1, "", -1, 0, 1), ]; diff --git a/src/modifier/modifier-type.ts b/src/modifier/modifier-type.ts index d963027bb..81001e3f2 100644 --- a/src/modifier/modifier-type.ts +++ b/src/modifier/modifier-type.ts @@ -804,7 +804,7 @@ function getNewModifierTypeOption(party: Pokemon[], player?: boolean, tier?: Mod player = true; if (tier === undefined) { const tierValue = Utils.randInt(256); - if (player) { + if (player && tierValue) { const partyShinyCount = party.filter(p => p.shiny).length; const upgradeOdds = Math.floor(32 / Math.max((partyShinyCount * 2), 1)); upgrade = !Utils.randInt(upgradeOdds); diff --git a/src/ui/ball-ui-handler.ts b/src/ui/ball-ui-handler.ts index fc50c2a6f..5ebf7553d 100644 --- a/src/ui/ball-ui-handler.ts +++ b/src/ui/ball-ui-handler.ts @@ -66,10 +66,11 @@ export default class BallUiHandler extends UiHandler { success = true; if (button === Button.ACTION && this.cursor < pokeballTypeCount) { if (this.scene.pokeballCounts[this.cursor]) { - (this.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.BALL, this.cursor); - this.scene.ui.setMode(Mode.COMMAND); - this.scene.ui.setMode(Mode.MESSAGE); - success = true; + if ((this.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.BALL, this.cursor)) { + this.scene.ui.setMode(Mode.COMMAND); + this.scene.ui.setMode(Mode.MESSAGE); + success = true; + } } else ui.playError(); } else { diff --git a/src/ui/command-ui-handler.ts b/src/ui/command-ui-handler.ts index 42e9c8299..5e85399bb 100644 --- a/src/ui/command-ui-handler.ts +++ b/src/ui/command-ui-handler.ts @@ -113,14 +113,14 @@ export default class CommandUiHandler extends UiHandler { return ret; } - clear() { + clear(): void { super.clear(); this.commandsContainer.setVisible(false); this.getUi().getMessageHandler().clearText(); this.eraseCursor(); } - eraseCursor() { + eraseCursor(): void { if (this.cursorObj) this.cursorObj.destroy(); this.cursorObj = null;