pokerogue/src/modifier.ts

687 lines
23 KiB
TypeScript
Raw Normal View History

2023-04-08 00:21:44 -04:00
import { LearnMovePhase, LevelUpPhase } from "./battle-phase";
2023-03-28 14:54:52 -04:00
import BattleScene from "./battle-scene";
2023-04-04 18:28:21 -04:00
import { getLevelTotalExp } from "./exp";
2023-04-08 00:21:44 -04:00
import { allMoves, Moves } from "./move";
2023-03-28 14:54:52 -04:00
import { getPokeballName, PokeballType } from "./pokeball";
import Pokemon, { PlayerPokemon } from "./pokemon";
import { Stat, getStatName } from "./pokemon-stat";
import { addTextObject, TextStyle } from "./text";
2023-04-08 00:21:44 -04:00
import { tmSpecies } from "./tms";
import { Type } from "./type";
2023-03-28 14:54:52 -04:00
import PartyUiHandler from "./ui/party-ui-handler";
import * as Utils from "./utils";
export class ModifierBar extends Phaser.GameObjects.Container {
constructor(scene: BattleScene) {
super(scene, 1, 2);
this.setScale(0.5);
}
addModifier(modifier: Modifier) {
const icon = modifier.getIcon(this.scene as BattleScene);
this.add(icon);
this.setModifierIconPosition(icon);
}
updateModifier(modifier: Modifier, modifiers: Modifier[]) {
const index = modifiers.indexOf(modifier);
if (index > -1) {
this.getAt(index).destroy();
const newIcon = modifier.getIcon(this.scene as BattleScene);
this.addAt(newIcon, index);
this.setModifierIconPosition(newIcon);
}
}
setModifierIconPosition(icon: Phaser.GameObjects.Container) {
const x = (this.getIndex(icon) % 12) * 26;
const y = Math.floor((this.getIndex(icon) * 6) / (this.scene.game.canvas.width / 6)) * 20;
icon.setPosition(x, y);
}
}
export abstract class Modifier {
public type: ModifierType;
public stackCount: integer;
constructor(type: ModifierType) {
this.type = type;
this.stackCount = 1;
}
add(modifierBar: ModifierBar, modifiers: Modifier[]): boolean {
modifiers.push(this);
modifierBar.addModifier(this);
return true;
}
shouldApply(_args: any[]): boolean {
return true;
}
abstract apply(args: any[]): boolean;
incrementStack(): void {
2023-03-30 23:02:35 -04:00
if (this.stackCount < this.getMaxStackCount())
this.stackCount++;
}
getMaxStackCount(): integer {
return 99;
2023-03-28 14:54:52 -04:00
}
getIcon(scene: BattleScene): Phaser.GameObjects.Container {
const container = scene.add.container(0, 0);
const item = scene.add.sprite(0, 12, 'items');
item.setFrame(this.type.iconImage);
item.setOrigin(0, 0.5);
container.add(item);
const stackText = this.getIconStackText(scene);
if (stackText)
container.add(stackText);
return container;
}
getIconStackText(scene: BattleScene): Phaser.GameObjects.Text {
if (this.stackCount <= 1)
return null;
2023-03-31 20:19:57 -04:00
const text = addTextObject(scene, 16, 12, this.stackCount.toString(), TextStyle.PARTY, { fontSize: '66px', color: this.stackCount < this.getMaxStackCount() ? '#f8f8f8' : '#e64a18' });
2023-03-28 14:54:52 -04:00
text.setStroke('#424242', 16)
text.setOrigin(1, 0);
return text;
}
}
export abstract class ConsumableModifier extends Modifier {
constructor(type: ModifierType) {
super(type);
}
add(_modifierBar: ModifierBar, _modifiers: Modifier[]): boolean {
return true;
}
shouldApply(args: any[]): boolean {
2023-03-30 23:02:35 -04:00
return super.shouldApply(args) && args.length === 1 && args[0] instanceof BattleScene;
2023-03-28 14:54:52 -04:00
}
}
class AddPokeballModifier extends ConsumableModifier {
private pokeballType: PokeballType;
private count: integer;
constructor(type: ModifierType, pokeballType: PokeballType, count: integer) {
super(type);
this.pokeballType = pokeballType;
this.count = count;
}
apply(args: any[]): boolean {
2023-04-01 22:59:07 -04:00
const pokeballCounts = (args[0] as BattleScene).pokeballCounts;
pokeballCounts[this.pokeballType] = Math.min(pokeballCounts[this.pokeballType] + this.count, 99);
2023-03-28 14:54:52 -04:00
return true;
}
}
export abstract class PokemonModifier extends Modifier {
public pokemonId: integer;
constructor(type: ModifierType, pokemonId: integer) {
super(type);
this.pokemonId = pokemonId;
}
shouldApply(args: any[]): boolean {
2023-04-08 00:21:44 -04:00
console.log(args[0]);
2023-03-30 23:02:35 -04:00
return super.shouldApply(args) && args.length && args[0] instanceof Pokemon && (this.pokemonId === -1 || (args[0] as Pokemon).id === this.pokemonId);
2023-03-28 14:54:52 -04:00
}
getIcon(scene: BattleScene): Phaser.GameObjects.Container {
const container = scene.add.container(0, 0);
const pokemon = this.getPokemon(scene);
const pokemonIcon = scene.add.sprite(0, 8, pokemon.getIconAtlasKey());
pokemonIcon.play(pokemon.getIconKey()).stop();
pokemonIcon.setOrigin(0, 0.5);
container.add(pokemonIcon);
return container;
}
getPokemon(scene: BattleScene) {
return scene.getParty().find(p => p.id === this.pokemonId);
}
}
export class PokemonBaseStatModifier extends PokemonModifier {
protected stat: Stat;
constructor(type: PokemonBaseStatBoosterModifierType, pokemonId: integer, stat: Stat) {
super(type, pokemonId);
this.stat = stat;
}
add(modifierBar: ModifierBar, modifiers: Modifier[]): boolean {
for (let modifier of modifiers) {
if (modifier instanceof PokemonBaseStatModifier) {
const pokemonStatModifier = modifier as PokemonBaseStatModifier;
if (pokemonStatModifier.pokemonId === this.pokemonId && pokemonStatModifier.stat === this.stat) {
pokemonStatModifier.incrementStack();
modifierBar.updateModifier(pokemonStatModifier, modifiers);
return true;
}
}
}
return super.add(modifierBar, modifiers);
}
shouldApply(args: any[]): boolean {
return super.shouldApply(args) && args.length === 2 && args[1] instanceof Array<integer>;
}
apply(args: any[]): boolean {
2023-03-30 23:02:35 -04:00
args[1][this.stat] = Math.min(Math.floor(args[1][this.stat] * (1 + this.stackCount * 0.2)), 999999);
2023-03-28 14:54:52 -04:00
return true;
}
getIcon(scene: BattleScene): Phaser.GameObjects.Container {
const container = super.getIcon(scene);
const item = scene.add.sprite(16, 16, 'items');
item.setScale(0.5);
item.setOrigin(0, 0.5);
item.setTexture('items', this.type.iconImage);
container.add(item);
const stackText = this.getIconStackText(scene);
if (stackText)
container.add(stackText);
return container;
}
}
export abstract class ConsumablePokemonModifier extends PokemonModifier {
constructor(type: ModifierType, pokemonId: integer) {
super(type, pokemonId);
}
add(_modifierBar: ModifierBar, _modifiers: Modifier[]): boolean {
return true;
}
}
export class PokemonHpRestoreModifier extends ConsumablePokemonModifier {
private restorePercent: integer;
private fainted: boolean;
2023-03-28 14:54:52 -04:00
constructor(type: ModifierType, pokemonId: integer, restorePercent: integer, fainted?: boolean) {
2023-03-28 14:54:52 -04:00
super(type, pokemonId);
this.restorePercent = restorePercent;
this.fainted = !!fainted;
2023-03-28 14:54:52 -04:00
}
apply(args: any[]): boolean {
const pokemon = args[0] as Pokemon;
if (!pokemon.hp === this.fainted)
pokemon.hp = Math.min(pokemon.hp + Math.max((this.restorePercent * 0.01) * pokemon.getMaxHp(), this.restorePercent), pokemon.getMaxHp());
2023-03-28 14:54:52 -04:00
return true;
}
}
2023-04-04 21:10:11 -04:00
export class PokemonPpRestoreModifier extends ConsumablePokemonModifier {
private restorePoints: integer;
constructor(type: ModifierType, pokemonId: integer, restorePoints: integer) {
super(type, pokemonId);
this.restorePoints = restorePoints;
}
shouldApply(args: any[]): boolean {
return super.shouldApply(args) && args.length > 1 && typeof(args[1]) === 'number';
}
apply(args: any[]): boolean {
const pokemon = args[0] as Pokemon;
const moveIndex = args[1] as integer;
const move = pokemon.moveset[moveIndex];
move.ppUsed = this.restorePoints >= 0 ? Math.max(move.ppUsed - this.restorePoints, 0) : 0;
return true;
}
}
2023-04-04 18:28:21 -04:00
export class PokemonLevelIncrementModifier extends ConsumablePokemonModifier {
constructor(type: ModifierType, pokemonId: integer) {
super(type, pokemonId);
}
apply(args: any[]): boolean {
const pokemon = args[0] as PlayerPokemon;
pokemon.level++;
pokemon.exp = getLevelTotalExp(pokemon.level, pokemon.species.growthRate);
pokemon.levelExp = 0;
const scene = pokemon.scene as BattleScene;
scene.unshiftPhase(new LevelUpPhase(scene, scene.getParty().indexOf(pokemon), pokemon.level));
return true;
}
}
2023-04-08 00:21:44 -04:00
export class TmModifier extends ConsumablePokemonModifier {
constructor(type: TmModifierType, pokemonId: integer) {
super(type, pokemonId);
}
apply(args: any[]): boolean {
const pokemon = args[0] as PlayerPokemon;
const scene = pokemon.scene as BattleScene;
scene.unshiftPhase(new LearnMovePhase(scene, scene.getParty().indexOf(pokemon), (this.type as TmModifierType).moveId));
return true;
}
}
2023-03-28 14:54:52 -04:00
export class ExpBoosterModifier extends Modifier {
private boostMultiplier: integer;
constructor(type: ModifierType, boostPercent: integer) {
2023-03-28 14:54:52 -04:00
super(type);
this.boostMultiplier = boostPercent * 0.01;
2023-03-28 14:54:52 -04:00
}
add(modifierBar: ModifierBar, modifiers: Modifier[]): boolean {
for (let modifier of modifiers) {
if (modifier instanceof ExpBoosterModifier) {
const expModifier = modifier as ExpBoosterModifier;
if (expModifier.boostMultiplier === this.boostMultiplier) {
expModifier.incrementStack();
modifierBar.updateModifier(expModifier, modifiers);
return true;
}
2023-03-28 14:54:52 -04:00
}
}
return super.add(modifierBar, modifiers);
}
apply(args: any[]): boolean {
2023-03-30 23:02:35 -04:00
(args[0] as Utils.NumberHolder).value = Math.floor((args[0] as Utils.NumberHolder).value * (1 + (this.stackCount * (this.boostMultiplier))));
return true;
}
}
export class ExpShareModifier extends Modifier {
constructor(type: ModifierType) {
super(type);
}
2023-03-28 14:54:52 -04:00
2023-03-30 23:02:35 -04:00
apply(_args: any[]): boolean {
2023-03-28 14:54:52 -04:00
return true;
}
2023-03-30 23:02:35 -04:00
getMaxStackCount(): integer {
return 5;
}
2023-03-28 14:54:52 -04:00
}
export class ShinyRateBoosterModifier extends Modifier {
constructor(type: ModifierType) {
super(type);
}
add(modifierBar: ModifierBar, modifiers: Modifier[]): boolean {
for (let modifier of modifiers) {
if (modifier instanceof ShinyRateBoosterModifier) {
const shinyRateModifier = modifier as ShinyRateBoosterModifier;
shinyRateModifier.incrementStack();
modifierBar.updateModifier(shinyRateModifier, modifiers);
return true;
}
}
return super.add(modifierBar, modifiers);
}
apply(args: any[]): boolean {
(args[0] as Utils.IntegerHolder).value = Math.pow((args[0] as Utils.IntegerHolder).value * 0.5, this.stackCount + 1);
return true;
}
2023-03-30 23:02:35 -04:00
getMaxStackCount(): integer {
return 5;
}
2023-03-28 14:54:52 -04:00
}
export class ExtraModifierModifier extends Modifier {
constructor(type: ModifierType) {
super(type);
}
apply(args: any[]): boolean {
(args[0] as Utils.IntegerHolder).value += this.stackCount;
return true;
}
}
2023-03-28 14:54:52 -04:00
export enum ModifierTier {
COMMON,
GREAT,
ULTRA,
MASTER,
LUXURY
2023-03-28 14:54:52 -04:00
};
export class ModifierType {
public name: string;
public description: string;
public iconImage: string;
public tier: ModifierTier;
private newModifierFunc: Function;
constructor(name: string, description: string, newModifierFunc: Function, iconImage?: string) {
this.name = name;
this.description = description;
2023-04-08 00:21:44 -04:00
this.iconImage = iconImage || name?.replace(/[ \-]/g, '_')?.toLowerCase();
2023-03-28 14:54:52 -04:00
this.newModifierFunc = newModifierFunc;
}
setTier(tier: ModifierTier) {
this.tier = tier;
}
newModifier(...args: any[]) {
return this.newModifierFunc(this, args);
}
}
class AddPokeballModifierType extends ModifierType {
constructor(pokeballType: PokeballType, count: integer, iconImage?: string) {
super(`${count}x ${getPokeballName(pokeballType)}`, `Receive ${getPokeballName(pokeballType)} x${count}`, (_type, _args) => new AddPokeballModifier(this, pokeballType, count), iconImage);
}
}
export abstract class PokemonModifierType extends ModifierType {
public selectFilter: Function;
constructor(name: string, description: string, newModifierFunc: Function, selectFilter?: Function, iconImage?: string) {
super(name, description, newModifierFunc, iconImage);
this.selectFilter = selectFilter;
}
}
2023-03-29 00:31:25 -04:00
export class PokemonHpRestoreModifierType extends PokemonModifierType {
2023-03-28 14:54:52 -04:00
protected restorePercent: integer;
2023-04-04 18:28:21 -04:00
constructor(name: string, restorePercent: integer, newModifierFunc?: Function, selectFilter?: Function, iconImage?: string) {
super(name, `Restore ${restorePercent} HP or ${restorePercent}% HP for one POKéMON, whichever is higher`,
2023-03-30 23:02:35 -04:00
newModifierFunc || ((_type, args) => new PokemonHpRestoreModifier(this, (args[0] as PlayerPokemon).id, this.restorePercent, false)),
2023-04-04 18:28:21 -04:00
selectFilter || ((pokemon: PlayerPokemon) => {
if (!pokemon.hp || pokemon.hp >= pokemon.getMaxHp())
2023-03-28 14:54:52 -04:00
return PartyUiHandler.NoEffectMessage;
return null;
2023-04-04 18:28:21 -04:00
}), iconImage);
2023-03-28 14:54:52 -04:00
this.restorePercent = restorePercent;
}
}
2023-03-29 00:31:25 -04:00
export class PokemonReviveModifierType extends PokemonHpRestoreModifierType {
2023-03-28 14:54:52 -04:00
constructor(name: string, restorePercent: integer, iconImage?: string) {
2023-04-04 18:28:21 -04:00
super(name, restorePercent, (_type, args) => new PokemonHpRestoreModifier(this, (args[0] as PlayerPokemon).id, this.restorePercent, true),
((pokemon: PlayerPokemon) => {
if (pokemon.hp)
return PartyUiHandler.NoEffectMessage;
return null;
}), iconImage);
2023-03-28 14:54:52 -04:00
this.description = `Revive one POKéMON and restore ${restorePercent}% HP`;
this.selectFilter = (pokemon: PlayerPokemon) => {
if (pokemon.hp)
return PartyUiHandler.NoEffectMessage;
return null;
};
}
}
2023-04-04 21:10:11 -04:00
export class PokemonLevelIncrementModifierType extends PokemonModifierType {
constructor(name: string, iconImage?: string) {
super(name, `Increase a POKéMON\'s level by 1`, (_type, args) => new PokemonLevelIncrementModifier(this, (args[0] as PlayerPokemon).id),
(_pokemon: PlayerPokemon) => null, iconImage);
}
}
export class PokemonPpRestoreModifierType extends PokemonModifierType {
protected restorePoints: integer;
constructor(name: string, restorePoints: integer, iconImage?: string) {
super(name, `Restore ${restorePoints} PP for one POKéMON's move`, (_type, args) => new PokemonPpRestoreModifier(this, (args[0] as PlayerPokemon).id, this.restorePoints),
(pokemon: PlayerPokemon) => {
return null;
}, iconImage);
this.restorePoints = this.restorePoints;
}
}
2023-03-29 00:31:25 -04:00
export class PokemonBaseStatBoosterModifierType extends PokemonModifierType {
2023-03-28 14:54:52 -04:00
private stat: Stat;
constructor(name: string, stat: Stat, _iconImage?: string) {
2023-03-30 23:02:35 -04:00
super(name, `Increases one POKéMON's base ${getStatName(stat)} by 20%` , (_type, args) => new PokemonBaseStatModifier(this, (args[0] as PlayerPokemon).id, this.stat));
2023-03-28 14:54:52 -04:00
this.stat = stat;
}
}
2023-03-29 12:23:52 -04:00
class AllPokemonFullHpRestoreModifierType extends ModifierType {
constructor(name: string, description?: string, newModifierFunc?: Function, iconImage?: string) {
super(name, description || `Restore 100% HP for all POKéMON`, newModifierFunc || ((_type, _args) => new PokemonHpRestoreModifier(this, -1, 100, false)), iconImage);
}
}
class AllPokemonFullReviveModifierType extends AllPokemonFullHpRestoreModifierType {
2023-03-29 12:23:52 -04:00
constructor(name: string, iconImage?: string) {
super(name, `Revives all fainted POKéMON, restoring 100% HP`, (_type, _args) => new PokemonHpRestoreModifier(this, -1, 100, true), iconImage);
2023-03-28 14:54:52 -04:00
}
}
2023-03-31 20:19:57 -04:00
export class ExpBoosterModifierType extends ModifierType {
constructor(name: string, boostPercent: integer, iconImage?: string) {
super(name, `Increases gain of EXP. Points by ${boostPercent}%`, () => new ExpBoosterModifier(this, boostPercent), iconImage);
}
}
2023-04-08 00:21:44 -04:00
export class TmModifierType extends PokemonModifierType {
public moveId: Moves;
constructor(moveId: Moves) {
super(`TM${Utils.padInt(Object.keys(tmSpecies).indexOf(moveId.toString()) + 1, 3)} - ${allMoves[moveId - 1].name}`, `Teach ${allMoves[moveId - 1].name} to a POKéMON`, (_type, args) => new TmModifier(this, (args[0] as PlayerPokemon).id),
(pokemon: PlayerPokemon) => {
if (pokemon.compatibleTms.indexOf(moveId) === -1 || pokemon.moveset.filter(m => m?.moveId === moveId).length)
return PartyUiHandler.NoEffectMessage;
return null;
}, `tm_${Type[allMoves[moveId - 1].type].toLowerCase()}`);
this.moveId = moveId;
}
}
class ModifierTypeGenerator extends ModifierType {
private genTypeFunc: Function;
constructor(genTypeFunc: Function) {
super(null, null, null, null);
this.genTypeFunc = genTypeFunc;
}
generateType(party: PlayerPokemon[]) {
const ret = this.genTypeFunc(party);
ret.setTier(this.tier);
return ret;
}
}
2023-03-28 14:54:52 -04:00
class WeightedModifierType {
public modifierType: ModifierType;
2023-03-29 12:23:52 -04:00
public weight: integer | Function;
2023-03-28 14:54:52 -04:00
2023-03-29 12:23:52 -04:00
constructor(modifierType: ModifierType, weight: integer | Function) {
2023-03-28 14:54:52 -04:00
this.modifierType = modifierType;
this.weight = weight;
}
setTier(tier: ModifierTier) {
this.modifierType.setTier(tier);
}
}
const modifierPool = {
[ModifierTier.COMMON]: [
new WeightedModifierType(new AddPokeballModifierType(PokeballType.POKEBALL, 5, 'pb'), 2),
2023-04-08 00:21:44 -04:00
new WeightedModifierType(new PokemonHpRestoreModifierType('POTION', 20), (party: PlayerPokemon[]) => {
2023-03-29 12:23:52 -04:00
const thresholdPartyMemberCount = party.filter(p => p.getHpRatio() <= 0.9).length;
return thresholdPartyMemberCount;
}),
2023-04-08 00:21:44 -04:00
new WeightedModifierType(new PokemonHpRestoreModifierType('SUPER POTION', 50), (party: PlayerPokemon[]) => {
2023-03-29 12:23:52 -04:00
const thresholdPartyMemberCount = party.filter(p => p.getHpRatio() <= 0.75).length;
return Math.ceil(thresholdPartyMemberCount / 3);
2023-04-08 00:21:44 -04:00
})
2023-03-28 14:54:52 -04:00
].map(m => { m.setTier(ModifierTier.COMMON); return m; }),
[ModifierTier.GREAT]: [
2023-03-30 23:02:35 -04:00
new WeightedModifierType(new AddPokeballModifierType(PokeballType.GREAT_BALL, 5, 'gb'), 3),
2023-04-08 00:21:44 -04:00
new WeightedModifierType(new PokemonReviveModifierType('REVIVE', 50), (party: PlayerPokemon[]) => {
2023-03-30 23:02:35 -04:00
const faintedPartyMemberCount = party.filter(p => !p.hp).length;
return faintedPartyMemberCount * 3;
}),
2023-04-08 00:21:44 -04:00
new WeightedModifierType(new PokemonReviveModifierType('MAX REVIVE', 100), (party: PlayerPokemon[]) => {
2023-03-29 12:23:52 -04:00
const faintedPartyMemberCount = party.filter(p => !p.hp).length;
return faintedPartyMemberCount;
}),
2023-04-08 00:21:44 -04:00
new WeightedModifierType(new PokemonHpRestoreModifierType('HYPER POTION', 80), (party: PlayerPokemon[]) => {
2023-03-29 12:23:52 -04:00
const thresholdPartyMemberCount = party.filter(p => p.getHpRatio() <= 0.6).length;
2023-03-30 23:02:35 -04:00
return thresholdPartyMemberCount;
}),
2023-04-08 00:21:44 -04:00
new WeightedModifierType(new ModifierTypeGenerator((party: PlayerPokemon[]) => {
const partyMemberCompatibleTms = party.map(p => p.compatibleTms);
const uniqueCompatibleTms = partyMemberCompatibleTms.flat().filter((tm, i, array) => array.indexOf(tm) === i);
const randTmIndex = Utils.randInt(uniqueCompatibleTms.length);
return new TmModifierType(uniqueCompatibleTms[randTmIndex]);
}), 2),
2023-04-04 18:28:21 -04:00
new PokemonLevelIncrementModifierType('RARE CANDY'),
2023-03-30 23:02:35 -04:00
new PokemonBaseStatBoosterModifierType('HP-UP', Stat.HP),
new PokemonBaseStatBoosterModifierType('PROTEIN', Stat.ATK),
new PokemonBaseStatBoosterModifierType('IRON', Stat.DEF),
new PokemonBaseStatBoosterModifierType('CALCIUM', Stat.SPATK),
new PokemonBaseStatBoosterModifierType('ZINC', Stat.SPDEF),
new PokemonBaseStatBoosterModifierType('CARBOS', Stat.SPD)
2023-03-28 14:54:52 -04:00
].map(m => { m.setTier(ModifierTier.GREAT); return m; }),
[ModifierTier.ULTRA]: [
new AddPokeballModifierType(PokeballType.ULTRA_BALL, 5, 'ub'),
2023-04-08 00:21:44 -04:00
new WeightedModifierType(new AllPokemonFullHpRestoreModifierType('MAX POTION'), (party: PlayerPokemon[]) => {
2023-03-29 12:23:52 -04:00
const thresholdPartyMemberCount = party.filter(p => p.getHpRatio() <= 0.5).length;
return Math.ceil(thresholdPartyMemberCount / 3);
}),
2023-04-08 00:21:44 -04:00
new WeightedModifierType(new AllPokemonFullReviveModifierType('SACRED ASH'), (party: PlayerPokemon[]) => {
return party.filter(p => !p.hp).length >= Math.ceil(party.length / 2) ? 1 : 0;
}),
2023-03-30 23:02:35 -04:00
new ExpBoosterModifierType('LUCKY EGG', 25),
new ModifierType('EXP. SHARE', 'All POKéMON in your party gain an additional 10% of a battle\'s EXP. Points', (type, _args) => new ExpShareModifier(type), 'exp_share')
].map(m => { m.setTier(ModifierTier.ULTRA); return m; }),
[ModifierTier.MASTER]: [
new AddPokeballModifierType(PokeballType.MASTER_BALL, 1, 'mb'),
new WeightedModifierType(new ModifierType('SHINY CHARM', 'Dramatically increases the chance of a wild POKéMON being shiny', (type, _args) => new ShinyRateBoosterModifier(type)), 2)
].map(m => { m.setTier(ModifierTier.MASTER); return m; }),
[ModifierTier.LUXURY]: [
new ExpBoosterModifierType('GOLDEN EGG', 100),
new ModifierType(`GOLDEN ${getPokeballName(PokeballType.POKEBALL)}`, 'Adds 1 extra ITEM option at the end of every battle', (type, _args) => new ExtraModifierModifier(type), 'pb_gold')
].map(m => { m.setTier(ModifierTier.LUXURY); return m; }),
2023-03-28 14:54:52 -04:00
};
2023-03-29 12:23:52 -04:00
let modifierPoolThresholds = {};
let ignoredPoolIndexes = {};
2023-04-08 00:21:44 -04:00
export function regenerateModifierPoolThresholds(party: PlayerPokemon[]) {
2023-03-29 12:23:52 -04:00
ignoredPoolIndexes = {};
modifierPoolThresholds = Object.fromEntries(new Map(Object.keys(modifierPool).map(t => {
ignoredPoolIndexes[t] = [];
const thresholds = new Map();
let i = 0;
modifierPool[t].reduce((total: integer, modifierType: ModifierType | WeightedModifierType) => {
if (modifierType instanceof WeightedModifierType) {
const weightedModifierType = modifierType as WeightedModifierType;
const weight = weightedModifierType.weight instanceof Function
? (weightedModifierType.weight as Function)(party)
: weightedModifierType.weight as integer;
if (weight)
total += weight;
else {
ignoredPoolIndexes[t].push(i++);
return total;
}
} else
total++;
thresholds.set(total, i++);
return total;
}, 0);
return [ t, Object.fromEntries(thresholds) ]
})));
console.log(modifierPoolThresholds)
}
2023-03-28 14:54:52 -04:00
2023-04-08 00:21:44 -04:00
export function getModifierTypesForWave(waveIndex: integer, count: integer, party: PlayerPokemon[]): Array<ModifierType> {
if (waveIndex % 10 === 0)
return modifierPool[ModifierTier.LUXURY];
const ret = [];
for (let m = 0; m < count; m++)
2023-04-08 00:21:44 -04:00
ret.push(getNewModifierType(party));
return ret;
}
2023-04-08 00:21:44 -04:00
function getNewModifierType(party: PlayerPokemon[]) {
2023-03-28 14:54:52 -04:00
const tierValue = Utils.randInt(256);
const tier = tierValue >= 52 ? ModifierTier.COMMON : tierValue >= 8 ? ModifierTier.GREAT : tierValue >= 1 ? ModifierTier.ULTRA : ModifierTier.MASTER;
const thresholds = Object.keys(modifierPoolThresholds[tier]);
const totalWeight = parseInt(thresholds[thresholds.length - 1]);
const value = Utils.randInt(totalWeight);
let index: integer;
for (let t of thresholds) {
let threshold = parseInt(t);
if (value < threshold) {
index = modifierPoolThresholds[tier][threshold];
break;
}
}
2023-03-29 12:23:52 -04:00
console.log(index, ignoredPoolIndexes[tier].filter(i => i <= index).length, ignoredPoolIndexes[tier])
2023-03-28 14:54:52 -04:00
let modifierType: ModifierType | WeightedModifierType = modifierPool[tier][index];
if (modifierType instanceof WeightedModifierType)
2023-04-08 00:21:44 -04:00
modifierType = (modifierType as WeightedModifierType).modifierType;
if (modifierType instanceof ModifierTypeGenerator)
modifierType = (modifierType as ModifierTypeGenerator).generateType(party);
2023-03-28 14:54:52 -04:00
return modifierType;
}