mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-01-26 02:40:59 +00:00
bac6c22973
* eslint config + packages * updated eslint config * fix the issue eslint adding ;;;; at interfaces * first round with eslint --fix . * removed config for unused export * Revert "first round with eslint --fix ." This reverts commit 77a88e0895f7c3389cb223651b90d918af778fe9. * removed config for camelCase * for real this time, first round of eslint --fix . * halfway to manual eslint fix * eslint done * added "how to setup" the hook to eslint --fix each new file before commit (if wanted) * removed eslintrc config file duplicat * fix human error + ignore build folder + merge overrides * added curly brace style + eslint * applied double quote linter rule * added lefthook * test precommit * test precommit * test precommit * test precommit * test precommit * test precommit * test precommit * github action to run eslint * added node_modules to ignore eslint * different action for typescript * no need for different glob (default src) * node 20 * node 20 * removed no longer needed install file * remove hooks part from README * eslint fixes --------- Co-authored-by: Frederico Santos <frederico.f.santos@tecnico.ulisboa.pt>
60 lines
2.1 KiB
TypeScript
60 lines
2.1 KiB
TypeScript
import BattleScene from "../battle-scene";
|
|
import { PersistentModifier } from "../modifier/modifier";
|
|
import { GeneratedPersistentModifierType, ModifierTypeGenerator, getModifierTypeFuncById } from "../modifier/modifier-type";
|
|
|
|
export default class ModifierData {
|
|
private player: boolean;
|
|
private typeId: string;
|
|
private typeGeneratorId: string;
|
|
private typePregenArgs: any[];
|
|
private args: any[];
|
|
private 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;
|
|
this.typeGeneratorId = sourceModifier ? sourceModifier.type.generatorId : source.typeGeneratorId;
|
|
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 {
|
|
const typeFunc = getModifierTypeFuncById(this.typeId);
|
|
if (!typeFunc) {
|
|
return null;
|
|
}
|
|
|
|
try {
|
|
let type = typeFunc();
|
|
type.id = this.typeId;
|
|
type.generatorId = this.typeGeneratorId;
|
|
|
|
if (type instanceof ModifierTypeGenerator) {
|
|
type = (type as ModifierTypeGenerator).generateType(this.player ? scene.getParty() : 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;
|
|
}
|
|
}
|
|
}
|