pokerogue/src/system/modifier-data.ts
NightKev af473ba4ff
[Refactor] Clean up various methods in battle-scene.ts and pokemon.ts (#4412)
* Update `battle-scene.ts` and `data/field/pokemon.ts`

`battle-scene.ts` changes:
- `getParty()` renamed to `getPlayerParty()` for clarity
- `getNonSwitchedXPokemon()` consolidated into `getXPokemon()`
- Some tsdocs were added/updated for
`getXParty()`, `getXField()` and `getXPokemon()`;
and those functions were explicitly marked as `public`
- Helper function `getPokemonAllowedInBattle()` added

`pokemon.ts` changes:
- `isAllowed()` renamed to `isAllowedInChallenge()` for clarity
- A redundant check for an active scene is removed in `isActive()`
- Some tsdocs were added/updated for `isFainted()`,
`isAllowedInChallenge()`, `isAllowedInBattle()` and `isActive()`;
and those functions were explicitly marked as `public`
- `isFainted()` now checks for `hp <= 0` instead of `!hp`

Co-authored-by: flx-sta <50131232+flx-sta@users.noreply.github.com>

* Backport eslint change to reduce merge conflicts

* Fix merge issues

---------

Co-authored-by: flx-sta <50131232+flx-sta@users.noreply.github.com>
Co-authored-by: Tempoanon <163687446+Tempo-anon@users.noreply.github.com>
2024-11-03 21:53:52 -05:00

57 lines
2.0 KiB
TypeScript

import BattleScene from "../battle-scene";
import { PersistentModifier } from "../modifier/modifier";
import { GeneratedPersistentModifierType, ModifierType, ModifierTypeGenerator, getModifierTypeFuncById } from "../modifier/modifier-type";
export default class ModifierData {
public player: boolean;
public typeId: string;
public typePregenArgs: any[];
public args: any[];
public stackCount: integer;
public className: string;
constructor(source: PersistentModifier | any, player: boolean) {
const sourceModifier = source instanceof PersistentModifier ? source as PersistentModifier : null;
this.player = player;
this.typeId = sourceModifier ? sourceModifier.type.id : source.typeId;
if (sourceModifier) {
if ("getPregenArgs" in source.type) {
this.typePregenArgs = (source.type as GeneratedPersistentModifierType).getPregenArgs();
}
} else if (source.typePregenArgs) {
this.typePregenArgs = source.typePregenArgs;
}
this.args = sourceModifier ? sourceModifier.getArgs() : source.args || [];
this.stackCount = source.stackCount;
this.className = sourceModifier ? sourceModifier.constructor.name : source.className;
}
toModifier(scene: BattleScene, constructor: any): PersistentModifier | null {
const typeFunc = getModifierTypeFuncById(this.typeId);
if (!typeFunc) {
return null;
}
try {
let type: ModifierType | null = typeFunc();
type.id = this.typeId;
if (type instanceof ModifierTypeGenerator) {
type = (type as ModifierTypeGenerator).generateType(this.player ? scene.getPlayerParty() : scene.getEnemyField(), this.typePregenArgs);
}
const ret = Reflect.construct(constructor, ([ type ] as any[]).concat(this.args).concat(this.stackCount)) as PersistentModifier;
if (ret.stackCount > ret.getMaxStackCount(scene)) {
ret.stackCount = ret.getMaxStackCount(scene);
}
return ret;
} catch (err) {
console.error(err);
return null;
}
}
}