From 7dbf3f62da9f8bc0f914da0402d93aaf6e85fd18 Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Sat, 21 Oct 2023 20:23:43 -0400 Subject: [PATCH] Add money (currently unused) and fix issue with reward modifiers not persisting --- src/battle-phases.ts | 1 + src/battle-scene.ts | 23 +++++++++++++++++++++-- src/data/biome.ts | 2 +- src/data/trainer-type.ts | 9 +++++---- src/modifier/modifier-type.ts | 2 +- src/ui/text.ts | 6 ++++-- 6 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/battle-phases.ts b/src/battle-phases.ts index 1e2ac8091..6d943d8b2 100644 --- a/src/battle-phases.ts +++ b/src/battle-phases.ts @@ -231,6 +231,7 @@ export class EncounterPhase extends BattlePhase { super.start(); this.scene.updateWaveCountText(); + this.scene.updateMoneyText(); const loadEnemyAssets = []; diff --git a/src/battle-scene.ts b/src/battle-scene.ts index 9442966fa..cd575faab 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -35,6 +35,7 @@ const quickStart = false; export const startingLevel = 5; export const startingWave = 1; export const startingBiome = Biome.TOWN; +export const startingMoney = 1000; export enum Button { UP, @@ -88,8 +89,10 @@ export default class BattleScene extends Phaser.Scene { public lastEnemyTrainer: Trainer; public currentBattle: Battle; public pokeballCounts: PokeballCounts; + public money: integer; private party: PlayerPokemon[]; private waveCountText: Phaser.GameObjects.Text; + private moneyText: Phaser.GameObjects.Text; private modifierBar: ModifierBar; private enemyModifierBar: ModifierBar; private modifiers: PersistentModifier[]; @@ -384,9 +387,14 @@ export default class BattleScene extends Phaser.Scene { this.waveCountText = addTextObject(this, (this.game.canvas.width / 6) - 2, 0, startingWave.toString(), TextStyle.BATTLE_INFO); this.waveCountText.setOrigin(1, 0); - this.updateUIPositions(); this.fieldUI.add(this.waveCountText); + this.moneyText = addTextObject(this, (this.game.canvas.width / 6) - 2, 0, startingWave.toString(), TextStyle.MONEY); + this.moneyText.setOrigin(1, 0); + this.fieldUI.add(this.moneyText); + + this.updateUIPositions(); + this.party = []; let loadPokemonAssets = []; @@ -538,6 +546,8 @@ export default class BattleScene extends Phaser.Scene { this.seed = Utils.randomString(16); console.log('Seed:', this.seed); + this.money = startingMoney; + this.pokeballCounts = Object.fromEntries(Utils.getEnumValues(PokeballType).filter(p => p <= PokeballType.MASTER_BALL).map(t => [ t, 0 ])); this.pokeballCounts[PokeballType.POKEBALL] += 5; @@ -556,6 +566,9 @@ export default class BattleScene extends Phaser.Scene { this.waveCountText.setText(startingWave.toString()); this.waveCountText.setVisible(false); + this.updateMoneyText(); + this.moneyText.setVisible(false); + this.newArena(startingBiome, true); this.arenaBgTransition.setPosition(0, 0); @@ -722,9 +735,15 @@ export default class BattleScene extends Phaser.Scene { this.waveCountText.setVisible(true); } + updateMoneyText(): void { + this.moneyText.setText(`₽${this.money.toLocaleString('en-US')}`); + this.moneyText.setVisible(true); + } + updateUIPositions(): void { this.waveCountText.setY(-(this.game.canvas.height / 6) + (this.enemyModifiers.length ? 15 : 0)); - this.partyExpBar.setY(this.waveCountText.y + 15); + this.moneyText.setY(this.waveCountText.y + 10); + this.partyExpBar.setY(this.moneyText.y + 15); } getMaxExpLevel(): integer { diff --git a/src/data/biome.ts b/src/data/biome.ts index 61a95a5b7..3f6e352c8 100644 --- a/src/data/biome.ts +++ b/src/data/biome.ts @@ -4702,7 +4702,7 @@ export const biomeTrainerPools: BiomeTrainerPools = { console.log(beautify(trainerOutput, null, 2, 120).replace(/( | (?:\{ "\d+": \[ )?| "(?:.*?)": \[ |, (?:(?:\{ )?"\d+": \[ )?)"(.*?)"/g, '$1TrainerType.$2').replace(/"(\d+)": /g, '$1: ').replace(/( )"(.*?)"/g, '$1[BiomePoolTier.$2]').replace(/( )"(.*?)"/g, '$1[Biome.$2]')); } - outputPools(); + //outputPools(); /*for (let pokemon of allSpecies) { if (pokemon.speciesId >= Species.XERNEAS) diff --git a/src/data/trainer-type.ts b/src/data/trainer-type.ts index 53c106347..45d0f6254 100644 --- a/src/data/trainer-type.ts +++ b/src/data/trainer-type.ts @@ -1,5 +1,5 @@ import BattleScene from "../battle-scene"; -import { ModifierType, modifierTypes } from "../modifier/modifier-type"; +import { ModifierType, ModifierTypeFunc, modifierTypes } from "../modifier/modifier-type"; import { EnemyPokemon } from "../pokemon"; import * as Utils from "../utils"; import { Moves } from "./move"; @@ -413,8 +413,9 @@ export class TrainerConfig { return this; } - setModifierRewardFuncs(...modifierTypeFuncs: (() => ModifierType)[]): TrainerConfig { - this.modifierRewardFuncs = modifierTypeFuncs.map(modifierTypeFunc => () => { + setModifierRewardFuncs(...modifierTypeFuncs: (() => ModifierTypeFunc)[]): TrainerConfig { + this.modifierRewardFuncs = modifierTypeFuncs.map(func => () => { + const modifierTypeFunc = func(); const modifierType = modifierTypeFunc(); modifierType.id = Object.keys(modifierTypes).find(k => modifierTypes[k] === modifierTypeFunc); return modifierType; @@ -682,7 +683,7 @@ export const trainerConfigs: TrainerConfigs = { $Just kidding! I lost fair and square, and now I know you'll do fine out there. $By the way, the professor wanted me to give you some items. Hopefully they're helpful! $Do your best like always! I believe in you!` - ]).setModifierRewardFuncs(() => modifierTypes.EXP_CHARM(), () => modifierTypes.EXP_SHARE()).setPartyMemberFunc(0, getRandomPartyMemberFunc([ Species.BULBASAUR, Species.CHARMANDER, Species.SQUIRTLE, Species.CHIKORITA, Species.CYNDAQUIL, Species.TOTODILE, Species.TREECKO, Species.TORCHIC, Species.MUDKIP, Species.TURTWIG, Species.CHIMCHAR, Species.PIPLUP, Species.SNIVY, Species.TEPIG, Species.OSHAWOTT ])) + ]).setModifierRewardFuncs(() => modifierTypes.EXP_CHARM, () => modifierTypes.EXP_SHARE).setPartyMemberFunc(0, getRandomPartyMemberFunc([ Species.BULBASAUR, Species.CHARMANDER, Species.SQUIRTLE, Species.CHIKORITA, Species.CYNDAQUIL, Species.TOTODILE, Species.TREECKO, Species.TORCHIC, Species.MUDKIP, Species.TURTWIG, Species.CHIMCHAR, Species.PIPLUP, Species.SNIVY, Species.TEPIG, Species.OSHAWOTT ])) .setPartyMemberFunc(1, getRandomPartyMemberFunc([ Species.PIDGEY, Species.HOOTHOOT, Species.TAILLOW, Species.STARLY, Species.PIDOVE ])), [TrainerType.RIVAL_2]: new TrainerConfig(++t).setStaticParty().setEncounterBgm(TrainerType.RIVAL).setBattleBgm('battle_rival').setPartyTemplates(trainerPartyTemplates.RIVAL_2).setEncounterMessages([ `Oh, fancy meeting you here. Looks like you're still undefeated. Right on! diff --git a/src/modifier/modifier-type.ts b/src/modifier/modifier-type.ts index 54cdf21bc..f5ea8c3f6 100644 --- a/src/modifier/modifier-type.ts +++ b/src/modifier/modifier-type.ts @@ -518,7 +518,7 @@ export class TurnHeldItemTransferModifierType extends PokemonHeldItemModifierTyp } } -type ModifierTypeFunc = () => ModifierType; +export type ModifierTypeFunc = () => ModifierType; type WeightedModifierTypeWeightFunc = (party: Pokemon[]) => integer; class WeightedModifierType { diff --git a/src/ui/text.ts b/src/ui/text.ts index e2d88d758..54f87ed9a 100644 --- a/src/ui/text.ts +++ b/src/ui/text.ts @@ -6,7 +6,8 @@ export enum TextStyle { PARTY_RED, SUMMARY, SUMMARY_RED, - SUMMARY_GOLD + SUMMARY_GOLD, + MONEY }; export function addTextObject(scene: Phaser.Scene, x: number, y: number, content: string, style: TextStyle, extraStyleOptions?: Phaser.Types.GameObjects.Text.TextStyle) { @@ -31,8 +32,8 @@ export function addTextObject(scene: Phaser.Scene, x: number, y: number, content styleOptions.fontSize = '96px'; break; case TextStyle.BATTLE_INFO: + case TextStyle.MONEY: styleOptions.fontSize = '72px'; - styleOptions.padding = undefined; shadowSize = 4; break; case TextStyle.PARTY: @@ -77,6 +78,7 @@ export function getTextColor(textStyle: TextStyle, shadow?: boolean) { case TextStyle.SUMMARY_RED: return !shadow ? '#f89890' : '#984038'; case TextStyle.SUMMARY_GOLD: + case TextStyle.MONEY: return !shadow ? '#e8e8a8' : '#a0a060' } } \ No newline at end of file