pokerogue/src/system/modifier-data.ts
Samuel H b9f7ba173d
Implement Double Battles (#1)
* Add WiP logic for double battles

* Minor changes for double battles

* More fixes for double battles

* Show battle info for both in double battles

* Improvements to double battles

* Add double battle version of party UI

* Fix some issues with double battles

* Updates to double battles

* More work on double battles for stability

* Fix issues with ability bar and evolution screen

* Add chance for double battles
2023-05-18 11:11:06 -04:00

46 lines
1.9 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;
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
return ret;
}
}