mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-02-21 11:46:47 +00:00
[Ability] Ignore Held Items for Stat Calculation (#5254)
* added the ability to ignore held items at stat calculation * integer -> number in src/field/pokemon.ts * added tests from @SirzBenjie * Update test * Fix test filename * added turnorder to tests * added tera_blast changes and tests --------- Co-authored-by: damocleas <damocleas25@gmail.com> Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
This commit is contained in:
parent
8012a1b559
commit
e75ddfa975
@ -1752,7 +1752,7 @@ export class HighestStatBoostTag extends AbilityBattlerTag {
|
|||||||
super.onAdd(pokemon);
|
super.onAdd(pokemon);
|
||||||
|
|
||||||
let highestStat: EffectiveStat;
|
let highestStat: EffectiveStat;
|
||||||
EFFECTIVE_STATS.map(s => pokemon.getEffectiveStat(s)).reduce((highestValue: number, value: number, i: number) => {
|
EFFECTIVE_STATS.map(s => pokemon.getEffectiveStat(s, undefined, undefined, undefined, undefined, undefined, undefined, true)).reduce((highestValue: number, value: number, i: number) => {
|
||||||
if (value > highestValue) {
|
if (value > highestValue) {
|
||||||
highestStat = EFFECTIVE_STATS[i];
|
highestStat = EFFECTIVE_STATS[i];
|
||||||
return value;
|
return value;
|
||||||
@ -1763,15 +1763,7 @@ export class HighestStatBoostTag extends AbilityBattlerTag {
|
|||||||
highestStat = highestStat!; // tell TS compiler it's defined!
|
highestStat = highestStat!; // tell TS compiler it's defined!
|
||||||
this.stat = highestStat;
|
this.stat = highestStat;
|
||||||
|
|
||||||
switch (this.stat) {
|
this.multiplier = this.stat === Stat.SPD ? 1.5 : 1.3;
|
||||||
case Stat.SPD:
|
|
||||||
this.multiplier = 1.5;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
this.multiplier = 1.3;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
globalScene.queueMessage(i18next.t("battlerTags:highestStatBoostOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), statName: i18next.t(getStatKey(highestStat)) }), null, false, null, true);
|
globalScene.queueMessage(i18next.t("battlerTags:highestStatBoostOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), statName: i18next.t(getStatKey(highestStat)) }), null, false, null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4559,7 +4559,8 @@ export class TeraMoveCategoryAttr extends VariableMoveCategoryAttr {
|
|||||||
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
|
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
|
||||||
const category = (args[0] as Utils.NumberHolder);
|
const category = (args[0] as Utils.NumberHolder);
|
||||||
|
|
||||||
if (user.isTerastallized() && user.getEffectiveStat(Stat.ATK, target, move) > user.getEffectiveStat(Stat.SPATK, target, move)) {
|
if (user.isTerastallized() && user.getEffectiveStat(Stat.ATK, target, move, true, true, false, false, true) >
|
||||||
|
user.getEffectiveStat(Stat.SPATK, target, move, true, true, false, false, true)) {
|
||||||
category.value = MoveCategory.PHYSICAL;
|
category.value = MoveCategory.PHYSICAL;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -10905,8 +10906,7 @@ export function initMoves() {
|
|||||||
.attr(TeraMoveCategoryAttr)
|
.attr(TeraMoveCategoryAttr)
|
||||||
.attr(TeraBlastTypeAttr)
|
.attr(TeraBlastTypeAttr)
|
||||||
.attr(TeraBlastPowerAttr)
|
.attr(TeraBlastPowerAttr)
|
||||||
.attr(StatStageChangeAttr, [ Stat.ATK, Stat.SPATK ], -1, true, { condition: (user, target, move) => user.isTerastallized() && user.isOfType(Type.STELLAR) })
|
.attr(StatStageChangeAttr, [ Stat.ATK, Stat.SPATK ], -1, true, { condition: (user, target, move) => user.isTerastallized() && user.isOfType(Type.STELLAR) }),
|
||||||
.partial(), /** Does not ignore abilities that affect stats, relevant in determining the move's category {@see TeraMoveCategoryAttr} */
|
|
||||||
new SelfStatusMove(Moves.SILK_TRAP, Type.BUG, -1, 10, -1, 4, 9)
|
new SelfStatusMove(Moves.SILK_TRAP, Type.BUG, -1, 10, -1, 4, 9)
|
||||||
.attr(ProtectAttr, BattlerTagType.SILK_TRAP)
|
.attr(ProtectAttr, BattlerTagType.SILK_TRAP)
|
||||||
.condition(failIfLastCondition),
|
.condition(failIfLastCondition),
|
||||||
|
@ -947,11 +947,14 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
|
|||||||
* @param ignoreOppAbility during an attack, determines whether the opposing Pokemon's abilities should be ignored during the stat calculation.
|
* @param ignoreOppAbility during an attack, determines whether the opposing Pokemon's abilities should be ignored during the stat calculation.
|
||||||
* @param isCritical determines whether a critical hit has occurred or not (`false` by default)
|
* @param isCritical determines whether a critical hit has occurred or not (`false` by default)
|
||||||
* @param simulated if `true`, nullifies any effects that produce any changes to game state from triggering
|
* @param simulated if `true`, nullifies any effects that produce any changes to game state from triggering
|
||||||
|
* @param ignoreHeldItems determines whether this Pokemon's held items should be ignored during the stat calculation, default `false`
|
||||||
* @returns the final in-battle value of a stat
|
* @returns the final in-battle value of a stat
|
||||||
*/
|
*/
|
||||||
getEffectiveStat(stat: EffectiveStat, opponent?: Pokemon, move?: Move, ignoreAbility: boolean = false, ignoreOppAbility: boolean = false, isCritical: boolean = false, simulated: boolean = true): number {
|
getEffectiveStat(stat: EffectiveStat, opponent?: Pokemon, move?: Move, ignoreAbility: boolean = false, ignoreOppAbility: boolean = false, isCritical: boolean = false, simulated: boolean = true, ignoreHeldItems: boolean = false): number {
|
||||||
const statValue = new Utils.NumberHolder(this.getStat(stat, false));
|
const statValue = new Utils.NumberHolder(this.getStat(stat, false));
|
||||||
globalScene.applyModifiers(StatBoosterModifier, this.isPlayer(), this, stat, statValue);
|
if (!ignoreHeldItems) {
|
||||||
|
globalScene.applyModifiers(StatBoosterModifier, this.isPlayer(), this, stat, statValue);
|
||||||
|
}
|
||||||
|
|
||||||
// The Ruin abilities here are never ignored, but they reveal themselves on summon anyway
|
// The Ruin abilities here are never ignored, but they reveal themselves on summon anyway
|
||||||
const fieldApplied = new Utils.BooleanHolder(false);
|
const fieldApplied = new Utils.BooleanHolder(false);
|
||||||
@ -965,7 +968,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
|
|||||||
applyStatMultiplierAbAttrs(StatMultiplierAbAttr, this, stat, statValue, simulated);
|
applyStatMultiplierAbAttrs(StatMultiplierAbAttr, this, stat, statValue, simulated);
|
||||||
}
|
}
|
||||||
|
|
||||||
let ret = statValue.value * this.getStatStageMultiplier(stat, opponent, move, ignoreOppAbility, isCritical, simulated);
|
let ret = statValue.value * this.getStatStageMultiplier(stat, opponent, move, ignoreOppAbility, isCritical, simulated, ignoreHeldItems);
|
||||||
|
|
||||||
switch (stat) {
|
switch (stat) {
|
||||||
case Stat.ATK:
|
case Stat.ATK:
|
||||||
@ -2487,9 +2490,10 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
|
|||||||
* @param ignoreOppAbility determines whether the effects of the opponent's abilities (i.e. Unaware) should be ignored (`false` by default)
|
* @param ignoreOppAbility determines whether the effects of the opponent's abilities (i.e. Unaware) should be ignored (`false` by default)
|
||||||
* @param isCritical determines whether a critical hit has occurred or not (`false` by default)
|
* @param isCritical determines whether a critical hit has occurred or not (`false` by default)
|
||||||
* @param simulated determines whether effects are applied without altering game state (`true` by default)
|
* @param simulated determines whether effects are applied without altering game state (`true` by default)
|
||||||
|
* @param ignoreHeldItems determines whether this Pokemon's held items should be ignored during the stat calculation, default `false`
|
||||||
* @return the stat stage multiplier to be used for effective stat calculation
|
* @return the stat stage multiplier to be used for effective stat calculation
|
||||||
*/
|
*/
|
||||||
getStatStageMultiplier(stat: EffectiveStat, opponent?: Pokemon, move?: Move, ignoreOppAbility: boolean = false, isCritical: boolean = false, simulated: boolean = true): number {
|
getStatStageMultiplier(stat: EffectiveStat, opponent?: Pokemon, move?: Move, ignoreOppAbility: boolean = false, isCritical: boolean = false, simulated: boolean = true, ignoreHeldItems: boolean = false): number {
|
||||||
const statStage = new Utils.IntegerHolder(this.getStatStage(stat));
|
const statStage = new Utils.IntegerHolder(this.getStatStage(stat));
|
||||||
const ignoreStatStage = new Utils.BooleanHolder(false);
|
const ignoreStatStage = new Utils.BooleanHolder(false);
|
||||||
|
|
||||||
@ -2516,7 +2520,9 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
|
|||||||
|
|
||||||
if (!ignoreStatStage.value) {
|
if (!ignoreStatStage.value) {
|
||||||
const statStageMultiplier = new Utils.NumberHolder(Math.max(2, 2 + statStage.value) / Math.max(2, 2 - statStage.value));
|
const statStageMultiplier = new Utils.NumberHolder(Math.max(2, 2 + statStage.value) / Math.max(2, 2 - statStage.value));
|
||||||
globalScene.applyModifiers(TempStatStageBoosterModifier, this.isPlayer(), stat, statStageMultiplier);
|
if (!ignoreHeldItems) {
|
||||||
|
globalScene.applyModifiers(TempStatStageBoosterModifier, this.isPlayer(), stat, statStageMultiplier);
|
||||||
|
}
|
||||||
return Math.min(statStageMultiplier.value, 4);
|
return Math.min(statStageMultiplier.value, 4);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
66
src/test/abilities/protosynthesis.test.ts
Normal file
66
src/test/abilities/protosynthesis.test.ts
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
import { Abilities } from "#enums/abilities";
|
||||||
|
import { Moves } from "#enums/moves";
|
||||||
|
import { Nature } from "#enums/nature";
|
||||||
|
import { Species } from "#enums/species";
|
||||||
|
import { Stat } from "#enums/stat";
|
||||||
|
import GameManager from "#test/utils/gameManager";
|
||||||
|
import Phaser from "phaser";
|
||||||
|
import { BattlerIndex } from "#app/battle";
|
||||||
|
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
describe("Abilities - Protosynthesis", () => {
|
||||||
|
let phaserGame: Phaser.Game;
|
||||||
|
let game: GameManager;
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
phaserGame = new Phaser.Game({
|
||||||
|
type: Phaser.HEADLESS,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
game.phaseInterceptor.restoreOg();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
game = new GameManager(phaserGame);
|
||||||
|
game.override
|
||||||
|
.moveset([ Moves.SPLASH, Moves.TACKLE ])
|
||||||
|
.ability(Abilities.PROTOSYNTHESIS)
|
||||||
|
.battleType("single")
|
||||||
|
.disableCrits()
|
||||||
|
.enemySpecies(Species.MAGIKARP)
|
||||||
|
.enemyAbility(Abilities.BALL_FETCH)
|
||||||
|
.enemyMoveset(Moves.SPLASH);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not consider temporary items when determining which stat to boost", async() => {
|
||||||
|
// Mew has uniform base stats
|
||||||
|
game.override.startingModifier([{ name: "TEMP_STAT_STAGE_BOOSTER", type: Stat.DEF }])
|
||||||
|
.enemyMoveset(Moves.SUNNY_DAY)
|
||||||
|
.startingLevel(100)
|
||||||
|
.enemyLevel(100);
|
||||||
|
await game.classicMode.startBattle([ Species.MEW ]);
|
||||||
|
const mew = game.scene.getPlayerPokemon()!;
|
||||||
|
// Nature of starting mon is randomized. We need to fix it to a neutral nature for the automated test.
|
||||||
|
mew.setNature(Nature.HARDY);
|
||||||
|
const enemy = game.scene.getEnemyPokemon()!;
|
||||||
|
const def_before_boost = mew.getEffectiveStat(Stat.DEF, undefined, undefined, false, undefined, false, false, true);
|
||||||
|
const atk_before_boost = mew.getEffectiveStat(Stat.ATK, undefined, undefined, false, undefined, false, false, true);
|
||||||
|
const initialHp = enemy.hp;
|
||||||
|
game.move.select(Moves.TACKLE);
|
||||||
|
await game.setTurnOrder([ BattlerIndex.PLAYER, BattlerIndex.ENEMY ]);
|
||||||
|
await game.toNextTurn();
|
||||||
|
const unboosted_dmg = initialHp - enemy.hp;
|
||||||
|
enemy.hp = initialHp;
|
||||||
|
const def_after_boost = mew.getEffectiveStat(Stat.DEF, undefined, undefined, false, undefined, false, false, true);
|
||||||
|
const atk_after_boost = mew.getEffectiveStat(Stat.ATK, undefined, undefined, false, undefined, false, false, true);
|
||||||
|
game.move.select(Moves.TACKLE);
|
||||||
|
await game.setTurnOrder([ BattlerIndex.PLAYER, BattlerIndex.ENEMY ]);
|
||||||
|
await game.toNextTurn();
|
||||||
|
const boosted_dmg = initialHp - enemy.hp;
|
||||||
|
expect(boosted_dmg).toBeGreaterThan(unboosted_dmg);
|
||||||
|
expect(def_after_boost).toEqual(def_before_boost);
|
||||||
|
expect(atk_after_boost).toBeGreaterThan(atk_before_boost);
|
||||||
|
});
|
||||||
|
});
|
@ -1,6 +1,6 @@
|
|||||||
import { BattlerIndex } from "#app/battle";
|
import { BattlerIndex } from "#app/battle";
|
||||||
import { Stat } from "#enums/stat";
|
import { Stat } from "#enums/stat";
|
||||||
import { allMoves } from "#app/data/move";
|
import { allMoves, TeraMoveCategoryAttr } from "#app/data/move";
|
||||||
import { Type } from "#enums/type";
|
import { Type } from "#enums/type";
|
||||||
import { Abilities } from "#app/enums/abilities";
|
import { Abilities } from "#app/enums/abilities";
|
||||||
import { HitResult } from "#app/field/pokemon";
|
import { HitResult } from "#app/field/pokemon";
|
||||||
@ -14,6 +14,7 @@ describe("Moves - Tera Blast", () => {
|
|||||||
let phaserGame: Phaser.Game;
|
let phaserGame: Phaser.Game;
|
||||||
let game: GameManager;
|
let game: GameManager;
|
||||||
const moveToCheck = allMoves[Moves.TERA_BLAST];
|
const moveToCheck = allMoves[Moves.TERA_BLAST];
|
||||||
|
const teraBlastAttr = moveToCheck.getAttrs(TeraMoveCategoryAttr)[0];
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
phaserGame = new Phaser.Game({
|
phaserGame = new Phaser.Game({
|
||||||
@ -86,19 +87,86 @@ describe("Moves - Tera Blast", () => {
|
|||||||
expect(enemyPokemon.apply).toHaveReturnedWith(HitResult.SUPER_EFFECTIVE);
|
expect(enemyPokemon.apply).toHaveReturnedWith(HitResult.SUPER_EFFECTIVE);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Currently abilities are bugged and can't see when a move's category is changed
|
it("uses the higher ATK for damage calculation", async () => {
|
||||||
it.todo("uses the higher stat of the user's Atk and SpAtk for damage calculation", async () => {
|
|
||||||
game.override.enemyAbility(Abilities.TOXIC_DEBRIS);
|
|
||||||
await game.startBattle();
|
await game.startBattle();
|
||||||
|
|
||||||
const playerPokemon = game.scene.getPlayerPokemon()!;
|
const playerPokemon = game.scene.getPlayerPokemon()!;
|
||||||
playerPokemon.stats[Stat.ATK] = 100;
|
playerPokemon.stats[Stat.ATK] = 100;
|
||||||
playerPokemon.stats[Stat.SPATK] = 1;
|
playerPokemon.stats[Stat.SPATK] = 1;
|
||||||
|
|
||||||
|
vi.spyOn(teraBlastAttr, "apply");
|
||||||
|
|
||||||
game.move.select(Moves.TERA_BLAST);
|
game.move.select(Moves.TERA_BLAST);
|
||||||
await game.phaseInterceptor.to("TurnEndPhase");
|
await game.toNextTurn();
|
||||||
expect(game.scene.getEnemyPokemon()!.battleData.abilityRevealed).toBe(true);
|
expect(teraBlastAttr.apply).toHaveLastReturnedWith(true);
|
||||||
}, 20000);
|
});
|
||||||
|
|
||||||
|
it("uses the higher SPATK for damage calculation", async () => {
|
||||||
|
await game.startBattle();
|
||||||
|
|
||||||
|
const playerPokemon = game.scene.getPlayerPokemon()!;
|
||||||
|
playerPokemon.stats[Stat.ATK] = 1;
|
||||||
|
playerPokemon.stats[Stat.SPATK] = 100;
|
||||||
|
|
||||||
|
vi.spyOn(teraBlastAttr, "apply");
|
||||||
|
|
||||||
|
game.move.select(Moves.TERA_BLAST);
|
||||||
|
await game.toNextTurn();
|
||||||
|
expect(teraBlastAttr.apply).toHaveLastReturnedWith(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should stay as a special move if ATK turns lower than SPATK mid-turn", async () => {
|
||||||
|
game.override.enemyMoveset([ Moves.CHARM ]);
|
||||||
|
await game.startBattle();
|
||||||
|
|
||||||
|
const playerPokemon = game.scene.getPlayerPokemon()!;
|
||||||
|
playerPokemon.stats[Stat.ATK] = 51;
|
||||||
|
playerPokemon.stats[Stat.SPATK] = 50;
|
||||||
|
|
||||||
|
vi.spyOn(teraBlastAttr, "apply");
|
||||||
|
|
||||||
|
game.move.select(Moves.TERA_BLAST);
|
||||||
|
await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.PLAYER ]);
|
||||||
|
await game.toNextTurn();
|
||||||
|
expect(teraBlastAttr.apply).toHaveLastReturnedWith(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not change its move category from stat changes due to held items", async () => {
|
||||||
|
game.override
|
||||||
|
.startingHeldItems([{ name: "SPECIES_STAT_BOOSTER", type: "THICK_CLUB" }])
|
||||||
|
.starterSpecies(Species.CUBONE);
|
||||||
|
await game.startBattle();
|
||||||
|
|
||||||
|
const playerPokemon = game.scene.getPlayerPokemon()!;
|
||||||
|
|
||||||
|
playerPokemon.stats[Stat.ATK] = 50;
|
||||||
|
playerPokemon.stats[Stat.SPATK] = 51;
|
||||||
|
|
||||||
|
vi.spyOn(teraBlastAttr, "apply");
|
||||||
|
|
||||||
|
game.move.select(Moves.TERA_BLAST);
|
||||||
|
await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.PLAYER ]);
|
||||||
|
await game.toNextTurn();
|
||||||
|
|
||||||
|
expect(teraBlastAttr.apply).toHaveLastReturnedWith(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not change its move category from stat changes due to abilities", async () => {
|
||||||
|
game.override.ability(Abilities.HUGE_POWER);
|
||||||
|
await game.startBattle();
|
||||||
|
|
||||||
|
const playerPokemon = game.scene.getPlayerPokemon()!;
|
||||||
|
playerPokemon.stats[Stat.ATK] = 50;
|
||||||
|
playerPokemon.stats[Stat.SPATK] = 51;
|
||||||
|
|
||||||
|
vi.spyOn(teraBlastAttr, "apply");
|
||||||
|
|
||||||
|
game.move.select(Moves.TERA_BLAST);
|
||||||
|
await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.PLAYER ]);
|
||||||
|
await game.toNextTurn();
|
||||||
|
expect(teraBlastAttr.apply).toHaveLastReturnedWith(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
it("causes stat drops if user is Stellar tera type", async () => {
|
it("causes stat drops if user is Stellar tera type", async () => {
|
||||||
game.override.startingHeldItems([{ name: "TERA_SHARD", type: Type.STELLAR }]);
|
game.override.startingHeldItems([{ name: "TERA_SHARD", type: Type.STELLAR }]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user