From 61352436419f94d20fd364319a5e423e4697efce Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Thu, 20 Apr 2023 11:29:26 -0400 Subject: [PATCH] Add Pokeball modifier when modifier stack is full --- src/battle-phases.ts | 5 +++++ src/battle-scene.ts | 19 ++++++++++++++----- src/modifier-type.ts | 20 +++++++++++++++----- src/modifier.ts | 11 ++++++----- 4 files changed, 40 insertions(+), 15 deletions(-) diff --git a/src/battle-phases.ts b/src/battle-phases.ts index b880ee134..10c7bb5c9 100644 --- a/src/battle-phases.ts +++ b/src/battle-phases.ts @@ -405,6 +405,11 @@ export class CheckSwitchPhase extends BattlePhase { return; } + if (!this.scene.getParty().slice(1).filter(p => p.hp).length) { + super.end(); + return; + } + if (this.scene.getPlayerPokemon().getTag(BattleTagType.FRENZY)) { super.end(); return; diff --git a/src/battle-scene.ts b/src/battle-scene.ts index a465ea3ca..ec5fb73aa 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -1,7 +1,7 @@ import Phaser from 'phaser'; import { Biome } from './biome'; import UI from './ui/ui'; -import { EncounterPhase, SummonPhase, CommandPhase, NextEncounterPhase, NewBiomeEncounterPhase, SelectBiomePhase, SelectStarterPhase } from './battle-phases'; +import { EncounterPhase, SummonPhase, CommandPhase, NextEncounterPhase, NewBiomeEncounterPhase, SelectBiomePhase, SelectStarterPhase, MessagePhase } from './battle-phases'; import { PlayerPokemon, EnemyPokemon } from './pokemon'; import PokemonSpecies, { allSpecies, getPokemonSpecies } from './pokemon-species'; import * as Utils from './utils'; @@ -18,6 +18,7 @@ import { GameData } from './game-data'; import StarterSelectUiHandler from './ui/starter-select-ui-handler'; import { TextStyle, addTextObject } from './text'; import { Moves } from './move'; +import { getDefaultModifierTypeForTier } from './modifier-type'; const enableAuto = true; export const startingLevel = 5; @@ -592,15 +593,23 @@ export default class BattleScene extends Phaser.Scene { addModifier(modifier: Modifier, virtual?: boolean): Promise { return new Promise(resolve => { + const soundName = modifier.type.soundName; if (modifier instanceof PersistentModifier) { - if ((modifier as PersistentModifier).add(this.modifiers, !!virtual) && !virtual && !this.sound.get('restore')) - this.sound.play('restore'); + if ((modifier as PersistentModifier).add(this.modifiers, !!virtual)) { + if (!virtual && !this.sound.get(soundName)) + this.sound.play(soundName); + } if (!virtual) { + const defaultModifierType = getDefaultModifierTypeForTier(modifier.type.tier); + this.addModifier(defaultModifierType.newModifier()).then(() => resolve()); + this.unshiftPhase(new MessagePhase(this, `The stack for this item is full.\n You will receive ${defaultModifierType.name} instead.`, null, true)); + return; + } if (!virtual) this.updateModifiers().then(() => resolve()); } else if (modifier instanceof ConsumableModifier) { - if (!this.sound.get('restore')) - this.sound.play('restore'); + if (!this.sound.get(soundName)) + this.sound.play(soundName); if (modifier instanceof ConsumablePokemonModifier) { for (let p in this.party) { diff --git a/src/modifier-type.ts b/src/modifier-type.ts index 0520c1748..f94dce062 100644 --- a/src/modifier-type.ts +++ b/src/modifier-type.ts @@ -27,14 +27,16 @@ export class ModifierType { public description: string; public iconImage: string; public group: string; + public soundName: string; public tier: ModifierTier; private newModifierFunc: NewModifierFunc; - constructor(name: string, description: string, newModifierFunc: NewModifierFunc, iconImage?: string, group?: string,) { + constructor(name: string, description: string, newModifierFunc: NewModifierFunc, iconImage?: string, group?: string, soundName?: string) { this.name = name; this.description = description; this.iconImage = iconImage || name?.replace(/[ \-]/g, '_')?.toLowerCase(); this.group = group || ''; + this.soundName = soundName || 'restore'; this.newModifierFunc = newModifierFunc; } @@ -49,7 +51,8 @@ export class ModifierType { class AddPokeballModifierType extends ModifierType { constructor(pokeballType: PokeballType, count: integer, iconImage?: string) { - super(`${count}x ${getPokeballName(pokeballType)}`, `Receive ${getPokeballName(pokeballType)} x${count}`, (_type, _args) => new Modifiers.AddPokeballModifier(this, pokeballType, count), iconImage, 'pb'); + super(`${count}x ${getPokeballName(pokeballType)}`, `Receive ${getPokeballName(pokeballType)} x${count}`, + (_type, _args) => new Modifiers.AddPokeballModifier(this, pokeballType, count), iconImage, 'pb', 'pb_bounce_1'); } } @@ -547,8 +550,8 @@ const modifierPool = { new WeightedModifierType(new ModifierType('SHINY CHARM', 'Dramatically increases the chance of a wild POKéMON being shiny', (type, _args) => new Modifiers.ShinyRateBoosterModifier(type)), 2) ].map(m => { m.setTier(ModifierTier.MASTER); return m; }), [ModifierTier.LUXURY]: [ - new ExpBoosterModifierType('GOLDEN EXP CHARM', 100), - new ModifierType(`GOLDEN ${getPokeballName(PokeballType.POKEBALL)}`, 'Adds 1 extra item option at the end of every battle', (type, _args) => new Modifiers.ExtraModifierModifier(type), 'pb_gold') + new ModifierType(`GOLDEN ${getPokeballName(PokeballType.POKEBALL)}`, 'Adds 1 extra item option at the end of every battle', (type, _args) => new Modifiers.ExtraModifierModifier(type), 'pb_gold', null, 'pb_bounce_1'), + new ExpBoosterModifierType('GOLDEN EXP CHARM', 100) ].map(m => { m.setTier(ModifierTier.LUXURY); return m; }), }; @@ -582,7 +585,7 @@ export function regenerateModifierPoolThresholds(party: PlayerPokemon[]) { }))); } -export function getModifierTypeOptionsForWave(waveIndex: integer, count: integer, party: PlayerPokemon[], maxedTypes: ModifierType[]): ModifierTypeOption[] { +export function getModifierTypeOptionsForWave(waveIndex: integer, count: integer, party: PlayerPokemon[]): ModifierTypeOption[] { if (waveIndex % 10 === 0) return modifierPool[ModifierTier.LUXURY].map(m => new ModifierTypeOption(m, false)); const options: ModifierTypeOption[] = []; @@ -631,6 +634,13 @@ function getNewModifierTypeOption(party: PlayerPokemon[], tier?: ModifierTier, u return new ModifierTypeOption(modifierType as ModifierType, upgrade); } +export function getDefaultModifierTypeForTier(tier: ModifierTier): ModifierType { + let modifierType: ModifierType | WeightedModifierType = modifierPool[tier][0]; + if (modifierType instanceof WeightedModifierType) + modifierType = (modifierType as WeightedModifierType).modifierType; + return modifierType; +} + export class ModifierTypeOption { public type: ModifierType; public upgraded: boolean; diff --git a/src/modifier.ts b/src/modifier.ts index 9bcffd29d..f12023c63 100644 --- a/src/modifier.ts +++ b/src/modifier.ts @@ -72,10 +72,8 @@ export abstract class PersistentModifier extends Modifier { add(modifiers: PersistentModifier[], virtual: boolean): boolean { for (let modifier of modifiers) { - if (this.match(modifier)) { - modifier.incrementStack(virtual); - return true; - } + if (this.match(modifier)) + return modifier.incrementStack(virtual); } if (virtual) { @@ -88,13 +86,16 @@ export abstract class PersistentModifier extends Modifier { abstract clone(): PersistentModifier; - incrementStack(virtual: boolean): void { + incrementStack(virtual: boolean): boolean { if (this.getStackCount() < this.getMaxStackCount()) { if (!virtual) this.stackCount++; else this.virtualStackCount++; + return true; } + + return false; } getStackCount(): integer {