2023-04-28 20:03:42 +01:00
|
|
|
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;
|
2023-05-09 20:01:27 +01:00
|
|
|
private typeGeneratorId: string;
|
2023-04-28 20:03:42 +01:00
|
|
|
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;
|
2023-05-09 20:01:27 +01:00
|
|
|
this.typeGeneratorId = sourceModifier ? sourceModifier.type.generatorId : source.typeGeneratorId;
|
2023-04-28 20:03:42 +01:00
|
|
|
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;
|
|
|
|
|
|
|
|
let type = typeFunc();
|
|
|
|
type.id = this.typeId;
|
2023-05-09 20:01:27 +01:00
|
|
|
type.generatorId = this.typeGeneratorId;
|
2023-04-28 20:03:42 +01:00
|
|
|
|
|
|
|
if (type instanceof ModifierTypeGenerator)
|
2023-05-18 16:11:06 +01:00
|
|
|
type = (type as ModifierTypeGenerator).generateType(this.player ? scene.getParty() : scene.getEnemyField(), this.typePregenArgs);
|
2023-04-28 20:03:42 +01:00
|
|
|
|
2023-10-28 23:55:07 +01:00
|
|
|
const ret = Reflect.construct(constructor, ([ type ] as any[]).concat(this.args).concat(this.stackCount)) as PersistentModifier;
|
|
|
|
|
2023-12-09 05:33:29 +00:00
|
|
|
if (ret.stackCount > ret.getMaxStackCount(scene))
|
|
|
|
ret.stackCount = ret.getMaxStackCount(scene);
|
2023-04-28 20:03:42 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|