Add session save data
This commit is contained in:
1 parent
fcd711673d
commit
a2ecb4089d
12 files changed
+541
-105
No files matched your search
@@ -24,6 +24,7 @@ export enum ModifierTier {
|
||||
type NewModifierFunc = (type: ModifierType, args: any[]) => Modifier;
|
||||
|
||||
export class ModifierType {
|
||||
public id: string;
|
||||
public name: string;
|
||||
public description: string;
|
||||
public iconImage: string;
|
||||
@@ -50,6 +51,30 @@ export class ModifierType {
|
||||
}
|
||||
}
|
||||
|
||||
type ModifierTypeGeneratorFunc = (party: Pokemon[], pregenArgs?: any[]) => ModifierType;
|
||||
|
||||
export class ModifierTypeGenerator extends ModifierType {
|
||||
private genTypeFunc: ModifierTypeGeneratorFunc;
|
||||
|
||||
constructor(genTypeFunc: ModifierTypeGeneratorFunc) {
|
||||
super(null, null, null, null);
|
||||
this.genTypeFunc = genTypeFunc;
|
||||
}
|
||||
|
||||
generateType(party: Pokemon[], pregenArgs?: any[]) {
|
||||
const ret = this.genTypeFunc(party, pregenArgs);
|
||||
if (ret) {
|
||||
ret.id = this.id;
|
||||
ret.setTier(this.tier);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
export interface GeneratedPersistentModifierType {
|
||||
getPregenArgs(): any[];
|
||||
}
|
||||
|
||||
class AddPokeballModifierType extends ModifierType {
|
||||
constructor(pokeballType: PokeballType, count: integer, iconImage?: string) {
|
||||
super(`${count}x ${getPokeballName(pokeballType)}`, `Receive ${getPokeballName(pokeballType)} x${count}`,
|
||||
@@ -168,7 +193,7 @@ export class PokemonAllMovePpRestoreModifierType extends PokemonModifierType {
|
||||
}
|
||||
}
|
||||
|
||||
export class TempBattleStatBoosterModifierType extends ModifierType {
|
||||
export class TempBattleStatBoosterModifierType extends ModifierType implements GeneratedPersistentModifierType {
|
||||
public tempBattleStat: TempBattleStat;
|
||||
|
||||
constructor(tempBattleStat: TempBattleStat) {
|
||||
@@ -179,6 +204,26 @@ export class TempBattleStatBoosterModifierType extends ModifierType {
|
||||
|
||||
this.tempBattleStat = tempBattleStat;
|
||||
}
|
||||
|
||||
getPregenArgs(): any[] {
|
||||
return [ this.tempBattleStat ];
|
||||
}
|
||||
}
|
||||
|
||||
export class BerryModifierType extends PokemonHeldItemModifierType implements GeneratedPersistentModifierType {
|
||||
private berryType: BerryType;
|
||||
|
||||
constructor(berryType: BerryType) {
|
||||
super(getBerryName(berryType), getBerryEffectDescription(berryType),
|
||||
(type, args) => new Modifiers.BerryModifier(type, (args[0] as Pokemon).id, berryType),
|
||||
null, 'berry');
|
||||
|
||||
this.berryType = berryType;
|
||||
}
|
||||
|
||||
getPregenArgs(): any[] {
|
||||
return [ this.berryType ];
|
||||
}
|
||||
}
|
||||
|
||||
function getAttackTypeBoosterItemName(type: Type) {
|
||||
@@ -222,7 +267,7 @@ function getAttackTypeBoosterItemName(type: Type) {
|
||||
}
|
||||
}
|
||||
|
||||
export class AttackTypeBoosterModifierType extends PokemonHeldItemModifierType {
|
||||
export class AttackTypeBoosterModifierType extends PokemonHeldItemModifierType implements GeneratedPersistentModifierType {
|
||||
public moveType: Type;
|
||||
public boostPercent: integer;
|
||||
|
||||
@@ -234,6 +279,10 @@ export class AttackTypeBoosterModifierType extends PokemonHeldItemModifierType {
|
||||
this.moveType = moveType;
|
||||
this.boostPercent = boostPercent;
|
||||
}
|
||||
|
||||
getPregenArgs(): any[] {
|
||||
return [ this.moveType ];
|
||||
}
|
||||
}
|
||||
|
||||
export class PokemonLevelIncrementModifierType extends PokemonModifierType {
|
||||
@@ -266,7 +315,7 @@ function getBaseStatBoosterItemName(stat: Stat) {
|
||||
}
|
||||
}
|
||||
|
||||
export class PokemonBaseStatBoosterModifierType extends PokemonHeldItemModifierType {
|
||||
export class PokemonBaseStatBoosterModifierType extends PokemonHeldItemModifierType implements GeneratedPersistentModifierType {
|
||||
private stat: Stat;
|
||||
|
||||
constructor(name: string, stat: Stat, _iconImage?: string) {
|
||||
@@ -274,6 +323,10 @@ export class PokemonBaseStatBoosterModifierType extends PokemonHeldItemModifierT
|
||||
|
||||
this.stat = stat;
|
||||
}
|
||||
|
||||
getPregenArgs(): any[] {
|
||||
return [ this.stat ];
|
||||
}
|
||||
}
|
||||
|
||||
class AllPokemonFullHpRestoreModifierType extends ModifierType {
|
||||
@@ -343,7 +396,7 @@ function getEvolutionItemName(evolutionItem: EvolutionItem) {
|
||||
}
|
||||
}
|
||||
|
||||
export class EvolutionItemModifierType extends PokemonModifierType {
|
||||
export class EvolutionItemModifierType extends PokemonModifierType implements GeneratedPersistentModifierType {
|
||||
public evolutionItem: EvolutionItem;
|
||||
|
||||
constructor(evolutionItem: EvolutionItem) {
|
||||
@@ -358,27 +411,18 @@ export class EvolutionItemModifierType extends PokemonModifierType {
|
||||
|
||||
this.evolutionItem = evolutionItem;
|
||||
}
|
||||
}
|
||||
|
||||
class ModifierTypeGenerator extends ModifierType {
|
||||
private genTypeFunc: Function;
|
||||
|
||||
constructor(genTypeFunc: Function) {
|
||||
super(null, null, null, null);
|
||||
this.genTypeFunc = genTypeFunc;
|
||||
}
|
||||
|
||||
generateType(party: Pokemon[]) {
|
||||
const ret = this.genTypeFunc(party);
|
||||
if (ret)
|
||||
ret.setTier(this.tier);
|
||||
return ret;
|
||||
getPregenArgs(): any[] {
|
||||
return [ this.evolutionItem ];
|
||||
}
|
||||
}
|
||||
|
||||
class AttackTypeBoosterModifierTypeGenerator extends ModifierTypeGenerator {
|
||||
constructor() {
|
||||
super((party: Pokemon[]) => {
|
||||
super((party: Pokemon[], pregenArgs?: any[]) => {
|
||||
if (pregenArgs)
|
||||
return new AttackTypeBoosterModifierType(pregenArgs[0] as Type, 20);
|
||||
|
||||
const attackMoveTypes = party.map(p => p.moveset.map(m => m.getMove()).filter(m => m instanceof AttackMove).map(m => m.type)).flat();
|
||||
const attackMoveTypeWeights = new Map<Type, integer>();
|
||||
let totalWeight = 0;
|
||||
@@ -417,7 +461,10 @@ class AttackTypeBoosterModifierTypeGenerator extends ModifierTypeGenerator {
|
||||
|
||||
class EvolutionItemModifierTypeGenerator extends ModifierTypeGenerator {
|
||||
constructor() {
|
||||
super((party: Pokemon[]) => {
|
||||
super((party: Pokemon[], pregenArgs?: any[]) => {
|
||||
if (pregenArgs)
|
||||
return new EvolutionItemModifierType(pregenArgs[0] as EvolutionItem);
|
||||
|
||||
const evolutionItemPool = party.filter(p => pokemonEvolutions.hasOwnProperty(p.species.speciesId)).map(p => {
|
||||
const evolutions = pokemonEvolutions[p.species.speciesId]
|
||||
return evolutions.filter(e => e.item !== EvolutionItem.NONE && (!e.condition || e.condition.predicate(p)));
|
||||
@@ -446,6 +493,7 @@ class WeightedModifierType {
|
||||
|
||||
constructor(modifierTypeFunc: ModifierTypeFunc, weight: integer | WeightedModifierTypeWeightFunc) {
|
||||
this.modifierType = modifierTypeFunc();
|
||||
this.modifierType.id = Object.keys(modifierTypes).find(k => modifierTypes[k] === modifierTypeFunc);
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
@@ -485,21 +533,29 @@ const modifierTypes = {
|
||||
ELIXIR: () => new PokemonAllMovePpRestoreModifierType('ELIXIR', 10),
|
||||
MAX_ELIXIR: () => new PokemonAllMovePpRestoreModifierType('MAX ELIXIR', -1),
|
||||
|
||||
TEMP_STAT_BOOSTER: () => new ModifierTypeGenerator((party: Pokemon[]) => {
|
||||
TEMP_STAT_BOOSTER: () => new ModifierTypeGenerator((party: Pokemon[], pregenArgs?: any[]) => {
|
||||
if (pregenArgs)
|
||||
return new TempBattleStatBoosterModifierType(pregenArgs[0] as TempBattleStat);
|
||||
const randTempBattleStat = Utils.randInt(7) as TempBattleStat;
|
||||
return new TempBattleStatBoosterModifierType(randTempBattleStat);
|
||||
}),
|
||||
|
||||
BASE_STAT_BOOSTER: () => new ModifierTypeGenerator((party: Pokemon[]) => {
|
||||
BASE_STAT_BOOSTER: () => new ModifierTypeGenerator((party: Pokemon[], pregenArgs?: any[]) => {
|
||||
if (pregenArgs) {
|
||||
const stat = pregenArgs[0] as Stat;
|
||||
return new PokemonBaseStatBoosterModifierType(getBaseStatBoosterItemName(stat), stat);
|
||||
}
|
||||
const randStat = Utils.randInt(6) as Stat;
|
||||
return new PokemonBaseStatBoosterModifierType(getBaseStatBoosterItemName(randStat), randStat);
|
||||
}),
|
||||
|
||||
ATTACK_TYPE_BOOSTER: () => new AttackTypeBoosterModifierTypeGenerator(),
|
||||
|
||||
BERRY: () => new ModifierTypeGenerator((party: Pokemon[]) => {
|
||||
BERRY: () => new ModifierTypeGenerator((party: Pokemon[], pregenArgs?: any[]) => {
|
||||
if (pregenArgs)
|
||||
return new BerryModifierType(pregenArgs[0] as BerryType);
|
||||
const berryTypes = Utils.getEnumValues(BerryType);
|
||||
let randBerryType;
|
||||
let randBerryType: BerryType;
|
||||
let rand = Utils.randInt(10);
|
||||
if (rand < 2)
|
||||
randBerryType = BerryType.SITRUS;
|
||||
@@ -507,9 +563,7 @@ const modifierTypes = {
|
||||
randBerryType = BerryType.LUM;
|
||||
else
|
||||
randBerryType = berryTypes[Utils.randInt(berryTypes.length - 2) + 2];
|
||||
return new PokemonHeldItemModifierType(getBerryName(randBerryType), getBerryEffectDescription(randBerryType),
|
||||
(type, args) => new Modifiers.BerryModifier(type, (args[0] as Pokemon).id, randBerryType),
|
||||
null, 'berry');
|
||||
return new BerryModifierType(randBerryType);
|
||||
}),
|
||||
|
||||
TM: () => new ModifierTypeGenerator((party: Pokemon[]) => {
|
||||
@@ -575,11 +629,11 @@ const modifierPool = {
|
||||
return thresholdPartyMemberCount;
|
||||
}),
|
||||
new WeightedModifierType(modifierTypes.ETHER, (party: Pokemon[]) => {
|
||||
const thresholdPartyMemberCount = Math.min(party.filter(p => p.hp && p.moveset.filter(m => m.getPpRatio() <= 0.2).length).length, 3);
|
||||
const thresholdPartyMemberCount = Math.min(party.filter(p => p.hp && p.moveset.filter(m => (m.getMove().pp - m.ppUsed) <= 5).length).length, 3);
|
||||
return thresholdPartyMemberCount * 3;
|
||||
}),
|
||||
new WeightedModifierType(modifierTypes.MAX_ETHER, (party: Pokemon[]) => {
|
||||
const thresholdPartyMemberCount = Math.min(party.filter(p => p.hp && p.moveset.filter(m => m.getPpRatio() <= 0.2).length).length, 3);
|
||||
const thresholdPartyMemberCount = Math.min(party.filter(p => p.hp && p.moveset.filter(m => (m.getMove().pp - m.ppUsed) <= 5).length).length, 3);
|
||||
return thresholdPartyMemberCount;
|
||||
}),
|
||||
new WeightedModifierType(modifierTypes.TEMP_STAT_BOOSTER, 4),
|
||||
@@ -611,11 +665,11 @@ const modifierPool = {
|
||||
return thresholdPartyMemberCount;
|
||||
}),
|
||||
new WeightedModifierType(modifierTypes.ELIXIR, (party: Pokemon[]) => {
|
||||
const thresholdPartyMemberCount = Math.min(party.filter(p => p.hp && p.moveset.filter(m => m.getPpRatio() <= 0.2).length).length, 3);
|
||||
const thresholdPartyMemberCount = Math.min(party.filter(p => p.hp && p.moveset.filter(m => (m.getMove().pp - m.ppUsed) <= 5).length).length, 3);
|
||||
return thresholdPartyMemberCount * 3;
|
||||
}),
|
||||
new WeightedModifierType(modifierTypes.MAX_ELIXIR, (party: Pokemon[]) => {
|
||||
const thresholdPartyMemberCount = Math.min(party.filter(p => p.hp && p.moveset.filter(m => m.getPpRatio() <= 0.2).length).length, 3);
|
||||
const thresholdPartyMemberCount = Math.min(party.filter(p => p.hp && p.moveset.filter(m => (m.getMove().pp - m.ppUsed) <= 5).length).length, 3);
|
||||
return thresholdPartyMemberCount;
|
||||
}),
|
||||
new WeightedModifierType(modifierTypes.MAP, (party: Pokemon[]) => {
|
||||
@@ -714,6 +768,10 @@ export function regenerateModifierPoolThresholds(party: Pokemon[], player?: bool
|
||||
}
|
||||
}
|
||||
|
||||
export function getModifierTypeFuncById(id: string): ModifierTypeFunc {
|
||||
return modifierTypes[id];
|
||||
}
|
||||
|
||||
export function getPlayerModifierTypeOptionsForWave(waveIndex: integer, count: integer, party: PlayerPokemon[]): ModifierTypeOption[] {
|
||||
if (waveIndex % 10 === 0)
|
||||
return modifierPool[ModifierTier.LUXURY].filter(m => !(m.weight instanceof Function) || m.weight(party)).map(m => new ModifierTypeOption(m.modifierType, false));
|
||||
|
||||
@@ -92,6 +92,10 @@ export abstract class PersistentModifier extends Modifier {
|
||||
|
||||
abstract clone(): PersistentModifier;
|
||||
|
||||
getArgs(): any[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
incrementStack(amount: integer, virtual: boolean): boolean {
|
||||
if (this.getStackCount() + amount <= this.getMaxStackCount()) {
|
||||
if (!virtual)
|
||||
@@ -194,17 +198,21 @@ export class TempBattleStatBoosterModifier extends PersistentModifier {
|
||||
private tempBattleStat: TempBattleStat;
|
||||
private battlesLeft: integer;
|
||||
|
||||
constructor(type: ModifierTypes.TempBattleStatBoosterModifierType, tempBattleStat: TempBattleStat, stackCount?: integer) {
|
||||
constructor(type: ModifierTypes.TempBattleStatBoosterModifierType, tempBattleStat: TempBattleStat, battlesLeft?: integer, stackCount?: integer) {
|
||||
super(type, stackCount);
|
||||
|
||||
this.tempBattleStat = tempBattleStat;
|
||||
this.battlesLeft = 5;
|
||||
this.battlesLeft = battlesLeft || 5;
|
||||
}
|
||||
|
||||
clone(): TempBattleStatBoosterModifier {
|
||||
return new TempBattleStatBoosterModifier(this.type as ModifierTypes.TempBattleStatBoosterModifierType, this.tempBattleStat, this.stackCount);
|
||||
}
|
||||
|
||||
getArgs(): any[] {
|
||||
return [ this.tempBattleStat, this.battlesLeft ];
|
||||
}
|
||||
|
||||
apply(args: any[]): boolean {
|
||||
const tempBattleStat = args[0] as TempBattleStat;
|
||||
|
||||
@@ -267,6 +275,10 @@ export abstract class PokemonHeldItemModifier extends PersistentModifier {
|
||||
return this.matchType(modifier) && (modifier as PokemonHeldItemModifier).pokemonId === this.pokemonId;
|
||||
}
|
||||
|
||||
getArgs(): any[] {
|
||||
return [ this.pokemonId ];
|
||||
}
|
||||
|
||||
shouldApply(args: any[]): boolean {
|
||||
return super.shouldApply(args) && args.length && args[0] instanceof Pokemon && (this.pokemonId === -1 || (args[0] as Pokemon).id === this.pokemonId);
|
||||
}
|
||||
@@ -332,6 +344,10 @@ export class PokemonBaseStatModifier extends PokemonHeldItemModifier {
|
||||
return new PokemonBaseStatModifier(this.type as ModifierTypes.PokemonBaseStatBoosterModifierType, this.pokemonId, this.stat, this.stackCount);
|
||||
}
|
||||
|
||||
getArgs(): any[] {
|
||||
return super.getArgs().concat(this.stat);
|
||||
}
|
||||
|
||||
shouldApply(args: any[]): boolean {
|
||||
return super.shouldApply(args) && args.length === 2 && args[1] instanceof Array<integer>;
|
||||
}
|
||||
@@ -365,6 +381,10 @@ export class AttackTypeBoosterModifier extends PokemonHeldItemModifier {
|
||||
return new AttackTypeBoosterModifier(this.type, this.pokemonId, this.moveType, this.boostMultiplier * 100, this.stackCount);
|
||||
}
|
||||
|
||||
getArgs(): any[] {
|
||||
return super.getArgs().concat([ this.moveType, this.boostMultiplier * 100 ]);
|
||||
}
|
||||
|
||||
shouldApply(args: any[]): boolean {
|
||||
return super.shouldApply(args) && args.length === 2 && args[1] instanceof Utils.NumberHolder;
|
||||
}
|
||||
@@ -543,6 +563,10 @@ export class BerryModifier extends PokemonHeldItemModifier {
|
||||
return new BerryModifier(this.type, this.pokemonId, this.berryType, this.stackCount);
|
||||
}
|
||||
|
||||
getArgs(): any[] {
|
||||
return super.getArgs().concat(this.berryType);
|
||||
}
|
||||
|
||||
shouldApply(args: any[]): boolean {
|
||||
return !this.consumed && super.shouldApply(args) && getBerryPredicate(this.berryType)(args[0] as Pokemon);
|
||||
}
|
||||
@@ -818,6 +842,10 @@ export class HealingBoosterModifier extends PersistentModifier {
|
||||
return new HealingBoosterModifier(this.type, this.multiplier, this.stackCount);
|
||||
}
|
||||
|
||||
getArgs(): any[] {
|
||||
return [ this.multiplier ];
|
||||
}
|
||||
|
||||
apply(args: any[]): boolean {
|
||||
const healingMultiplier = args[0] as Utils.IntegerHolder;
|
||||
for (let s = 0; s < this.getStackCount(); s++)
|
||||
@@ -853,6 +881,10 @@ export class ExpBoosterModifier extends PersistentModifier {
|
||||
return new ExpBoosterModifier(this.type, this.boostMultiplier * 100, this.stackCount);
|
||||
}
|
||||
|
||||
getArgs(): any[] {
|
||||
return [ this.boostMultiplier * 100 ];
|
||||
}
|
||||
|
||||
apply(args: any[]): boolean {
|
||||
(args[0] as Utils.NumberHolder).value = Math.floor((args[0] as Utils.NumberHolder).value * (1 + (this.getStackCount() * this.boostMultiplier)));
|
||||
|
||||
@@ -880,6 +912,10 @@ export class PokemonExpBoosterModifier extends PokemonHeldItemModifier {
|
||||
return new PokemonExpBoosterModifier(this.type as ModifierTypes.PokemonExpBoosterModifierType, this.pokemonId, this.boostMultiplier * 100, this.stackCount);
|
||||
}
|
||||
|
||||
getArgs(): any[] {
|
||||
return super.getArgs().concat(this.boostMultiplier * 100);
|
||||
}
|
||||
|
||||
shouldApply(args: any[]): boolean {
|
||||
return super.shouldApply(args) && args.length === 2 && args[1] instanceof Utils.NumberHolder;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user