From 3a892acaaf6fb329990f78c93a763e57bb5e1112 Mon Sep 17 00:00:00 2001 From: NxKarim Date: Tue, 30 Apr 2024 01:33:18 -0600 Subject: [PATCH] Some Fixes - HP ratio related checks (`getHpRatio`): Added rounding to 2 decimals for non-precise option. - Hustle (`BattleStatMultiplierAbAttr`): added optional condition; Hustle now works only for physical attacks. - Imposter (`PostSummonTransformAbAttr`): Switch in a double battle after both foes have been defeated no longer crashes the game. - Sleep Talk (`RandomMovesetMoveAttr`): Single target moves no longer target allies. --- src/data/ability.ts | 26 ++++++++++++++++++-------- src/data/move.ts | 22 +++++++++++++++++----- src/field/pokemon.ts | 2 +- src/phases.ts | 2 +- 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/data/ability.ts b/src/data/ability.ts index 281a37cfd0c..9faf0a5ce14 100644 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -976,16 +976,19 @@ export class FieldMoveTypePowerBoostAbAttr extends FieldMovePowerBoostAbAttr { export class BattleStatMultiplierAbAttr extends AbAttr { private battleStat: BattleStat; private multiplier: number; + private condition: PokemonAttackCondition; - constructor(battleStat: BattleStat, multiplier: number) { + constructor(battleStat: BattleStat, multiplier: number, condition?: PokemonAttackCondition) { super(false); this.battleStat = battleStat; this.multiplier = multiplier; + this.condition = condition; } applyBattleStat(pokemon: Pokemon, passive: boolean, battleStat: BattleStat, statValue: Utils.NumberHolder, args: any[]): boolean | Promise { - if (battleStat === this.battleStat) { + const move = (args[0] as Move); + if (battleStat === this.battleStat && (!this.condition || this.condition(pokemon, null, move))){ statValue.value *= this.multiplier; return true; } @@ -1428,10 +1431,17 @@ export class PostSummonTransformAbAttr extends PostSummonAbAttr { applyPostSummon(pokemon: Pokemon, passive: boolean, args: any[]): boolean { const targets = pokemon.getOpponents(); let target: Pokemon; - if (targets.length > 1) - pokemon.scene.executeWithSeedOffset(() => target = Utils.randSeedItem(targets), pokemon.scene.currentBattle.waveIndex); - else - target = targets[0]; + + if(targets.length < 1){ + return false; + } + + if (targets.length > 1){ + pokemon.scene.executeWithSeedOffset(() => target = Utils.randSeedItem(targets), pokemon.scene.currentBattle.waveIndex); + } + else{ + target = targets[0]; + } pokemon.summonData.speciesForm = target.getSpeciesForm(); pokemon.summonData.fusionSpeciesForm = target.getFusionSpeciesForm(); @@ -2642,8 +2652,8 @@ export function initAbilities() { new Ability(Abilities.TRUANT, 3) .attr(PostSummonAddBattlerTagAbAttr, BattlerTagType.TRUANT, 1, false), new Ability(Abilities.HUSTLE, 3) - .attr(BattleStatMultiplierAbAttr, BattleStat.ATK, 1.5) - .attr(BattleStatMultiplierAbAttr, BattleStat.ACC, 0.8), + .attr(BattleStatMultiplierAbAttr, BattleStat.ATK, 1.5, (user, target, move) => move.category == MoveCategory.PHYSICAL) + .attr(BattleStatMultiplierAbAttr, BattleStat.ACC, 0.8, (user, target, move) => move.category == MoveCategory.PHYSICAL), new Ability(Abilities.CUTE_CHARM, 3) .attr(PostDefendContactApplyTagChanceAbAttr, 30, BattlerTagType.INFATUATED), new Ability(Abilities.PLUS, 3) diff --git a/src/data/move.ts b/src/data/move.ts index 30c97a1ac8d..42bffbf6bd2 100644 --- a/src/data/move.ts +++ b/src/data/move.ts @@ -3099,11 +3099,23 @@ export class RandomMovesetMoveAttr extends OverrideMoveEffectAttr { const moveTargets = getMoveTargets(user, move.moveId); if (!moveTargets.targets.length) return false; - const targets = moveTargets.multiple || moveTargets.targets.length === 1 - ? moveTargets.targets - : moveTargets.targets.indexOf(target.getBattlerIndex()) > -1 - ? [ target.getBattlerIndex() ] - : [ moveTargets.targets[user.randSeedInt(moveTargets.targets.length)] ]; + let selectTargets; + switch(true){ + case (moveTargets.multiple || moveTargets.targets.length === 1): { + selectTargets = moveTargets.targets; + break; + } + case (moveTargets.targets.indexOf(target.getBattlerIndex()) > -1): { + selectTargets = [ target.getBattlerIndex() ]; + break; + } + default: { + moveTargets.targets.splice(moveTargets.targets.indexOf(user.getAlly().getBattlerIndex())) + selectTargets = [ moveTargets.targets[user.randSeedInt(moveTargets.targets.length)] ]; + break; + } + } + const targets = selectTargets; user.getMoveQueue().push({ move: move.moveId, targets: targets, ignorePP: true }); user.scene.unshiftPhase(new MovePhase(user.scene, user, targets, moveset[moveIndex], true)); return true; diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 4e20bad407b..4c449495937 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -657,7 +657,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { getHpRatio(precise: boolean = false): number { return precise ? this.hp / this.getMaxHp() - : ((this.hp / this.getMaxHp()) * 100) / 100; + : Math.round((this.hp / this.getMaxHp()) * 100) / 100; } generateGender(): void { diff --git a/src/phases.ts b/src/phases.ts index 1393355e3f5..9395ada0415 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -2547,7 +2547,7 @@ export class MoveEffectPhase extends PokemonPhase { : 3 / (3 + Math.min(targetEvasionLevel.value - userAccuracyLevel.value, 6)); } - applyBattleStatMultiplierAbAttrs(BattleStatMultiplierAbAttr, user, BattleStat.ACC, accuracyMultiplier); + applyBattleStatMultiplierAbAttrs(BattleStatMultiplierAbAttr, user, BattleStat.ACC, accuracyMultiplier, this.move.getMove()); const evasionMultiplier = new Utils.NumberHolder(1); applyBattleStatMultiplierAbAttrs(BattleStatMultiplierAbAttr, this.getTarget(), BattleStat.EVA, evasionMultiplier);