Add Pokeball modifier when modifier stack is full

pull/1/head
Flashfyre 2023-04-20 11:29:26 -04:00
parent 92e3a6f537
commit 6135243641
4 changed files with 40 additions and 15 deletions

View File

@ -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;

View File

@ -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<void> {
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) {

View File

@ -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;

View File

@ -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 {