From 80095a64fc3d5a2b5cd124898529dbcac405bc20 Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Thu, 18 Jan 2024 17:22:18 -0500 Subject: [PATCH] Add money items --- src/battle-phases.ts | 7 ++----- src/battle-scene.ts | 7 +++++++ src/modifier/modifier-type.ts | 27 ++++++++++++++++++++++++++- src/modifier/modifier.ts | 25 ++++++++++++++++++++++++- src/ui/modifier-select-ui-handler.ts | 2 +- src/ui/summary-ui-handler.ts | 2 +- 6 files changed, 61 insertions(+), 9 deletions(-) diff --git a/src/battle-phases.ts b/src/battle-phases.ts index 4c527fad1..515320e69 100644 --- a/src/battle-phases.ts +++ b/src/battle-phases.ts @@ -2733,11 +2733,8 @@ export class MoneyRewardPhase extends BattlePhase { } start() { - const waveIndex = this.scene.currentBattle.waveIndex; - const waveSetIndex = Math.ceil(waveIndex / 10) - 1; - const moneyValue = Math.pow((waveSetIndex + 1 + (0.75 + (((waveIndex - 1) % 10) + 1) / 10)) * 100, 1 + 0.005 * waveSetIndex) * this.moneyMultiplier; - const moneyAmount = new Utils.IntegerHolder(Math.floor(moneyValue / 10) * 10); - + const moneyAmount = new Utils.IntegerHolder(this.scene.getMoneyAmountForWave(this.moneyMultiplier)); + this.scene.applyModifiers(MoneyMultiplierModifier, true, moneyAmount); this.scene.money += moneyAmount.value; diff --git a/src/battle-scene.ts b/src/battle-scene.ts index 25e20b575..630828870 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -1437,6 +1437,13 @@ export default class BattleScene extends Phaser.Scene { this.phaseQueue.push(new TurnInitPhase(this)); } + getMoneyAmountForWave(moneyMultiplier: number): integer { + const waveIndex = this.currentBattle.waveIndex; + const waveSetIndex = Math.ceil(waveIndex / 10) - 1; + const moneyValue = Math.pow((waveSetIndex + 1 + (0.75 + (((waveIndex - 1) % 10) + 1) / 10)) * 100, 1 + 0.005 * waveSetIndex) * moneyMultiplier; + return Math.floor(moneyValue / 10) * 10; + } + addModifier(modifier: Modifier, ignoreUpdate?: boolean, playSound?: boolean, virtual?: boolean, instant?: boolean): Promise { return new Promise(resolve => { const soundName = modifier.type.soundName; diff --git a/src/modifier/modifier-type.ts b/src/modifier/modifier-type.ts index f9d585c1f..3eb971ab5 100644 --- a/src/modifier/modifier-type.ts +++ b/src/modifier/modifier-type.ts @@ -35,7 +35,7 @@ export class ModifierType { public id: string; public generatorId: string; public name: string; - public description: string; + protected description: string; public iconImage: string; public group: string; public soundName: string; @@ -51,6 +51,10 @@ export class ModifierType { this.newModifierFunc = newModifierFunc; } + getDescription(scene: BattleScene): string { + return this.description; + } + setTier(tier: ModifierTier): void { this.tier = tier; } @@ -403,6 +407,20 @@ class AllPokemonFullReviveModifierType extends AllPokemonFullHpRestoreModifierTy } } +export class MoneyRewardModifierType extends ModifierType { + private moneyMultiplier: number; + + constructor(name: string, moneyMultiplier: number, moneyMultiplierDescriptor: string, iconImage?: string) { + super(name, `Grants a ${moneyMultiplierDescriptor} amount of money (₽{AMOUNT})`, (_type, _args) => new Modifiers.MoneyRewardModifier(this, moneyMultiplier), iconImage, 'money', 'buy'); + + this.moneyMultiplier = moneyMultiplier; + } + + getDescription(scene: BattleScene): string { + return this.description.replace('{AMOUNT}', scene.getMoneyAmountForWave(this.moneyMultiplier).toLocaleString('en-US')); + } +} + export class ExpBoosterModifierType extends ModifierType { constructor(name: string, boostPercent: integer, iconImage?: string) { super(name, `Increases gain of EXP. Points by ${boostPercent}%`, () => new Modifiers.ExpBoosterModifier(this, boostPercent), iconImage); @@ -738,6 +756,10 @@ export const modifierTypes = { SOUL_DEW: () => new PokemonHeldItemModifierType('Soul Dew', 'Increases the influence of a Pokémon\'s nature on its stats by 5% (additive)', (type, args) => new Modifiers.PokemonNatureWeightModifier(type, (args[0] as Pokemon).id)), + NUGGET: () => new MoneyRewardModifierType('Nugget', 1, 'small'), + BIG_NUGGET: () => new MoneyRewardModifierType('Big Nugget', 2.5, 'moderate'), + RELIC_GOLD: () => new MoneyRewardModifierType('Relic Gold', 10, 'large'), + AMULET_COIN: () => new ModifierType('Amulet Coin', 'Increases money rewards by 20%', (type, _args) => new Modifiers.MoneyMultiplierModifier(type)), GOLDEN_PUNCH: () => new PokemonHeldItemModifierType('Golden Punch', 'Grants 20% of damage inflicted as money', (type, args) => new Modifiers.DamageMoneyRewardModifier(type, (args[0] as Pokemon).id)), COIN_CASE: () => new ModifierType('Coin Case', 'After every 10th battle, receive 10% of your money in interest', (type, _args) => new Modifiers.MoneyInterestModifier(type)), @@ -856,6 +878,8 @@ const modifierPool = { return thresholdPartyMemberCount; }), new WeightedModifierType(modifierTypes.SUPER_LURE, 4), + new WeightedModifierType(modifierTypes.NUGGET, 5), + new WeightedModifierType(modifierTypes.BIG_NUGGET, 1), new WeightedModifierType(modifierTypes.MAP, (party: Pokemon[]) => party[0].scene.gameMode === GameMode.CLASSIC ? 1 : 0), new WeightedModifierType(modifierTypes.TM_GREAT, 2), new WeightedModifierType(modifierTypes.EXP_SHARE, 1), @@ -868,6 +892,7 @@ const modifierPool = { [ModifierTier.ULTRA]: [ new WeightedModifierType(modifierTypes.ULTRA_BALL, 8), new WeightedModifierType(modifierTypes.MAX_LURE, 4), + new WeightedModifierType(modifierTypes.RELIC_GOLD, 3), new WeightedModifierType(modifierTypes.PP_UP, 6), new WeightedModifierType(modifierTypes.PP_MAX, 2), new WeightedModifierType(modifierTypes.ATTACK_TYPE_BOOSTER, 4), diff --git a/src/modifier/modifier.ts b/src/modifier/modifier.ts index c4836f956..7fbfd2962 100644 --- a/src/modifier/modifier.ts +++ b/src/modifier/modifier.ts @@ -57,7 +57,7 @@ export class ModifierBar extends Phaser.GameObjects.Container { this.setModifierIconPosition(icon, visibleIconModifiers.length); icon.setInteractive(new Phaser.Geom.Rectangle(0, 0, 32, 32), Phaser.Geom.Rectangle.Contains); icon.on('pointerover', () => { - (this.scene as BattleScene).ui.showTooltip(modifier.type.name, modifier.type.description); + (this.scene as BattleScene).ui.showTooltip(modifier.type.name, modifier.type.getDescription(this.scene as BattleScene)); if (this.modifierCache && this.modifierCache.length > iconOverflowIndex) thisArg.updateModifierOverflowVisibility(true); }); @@ -1312,6 +1312,29 @@ export class PokemonFormChangeItemModifier extends PokemonHeldItemModifier { } } +export class MoneyRewardModifier extends ConsumableModifier { + private moneyMultiplier: number; + + constructor(type: ModifierType, moneyMultiplier: number) { + super(type); + + this.moneyMultiplier = moneyMultiplier; + } + + apply(args: any[]): boolean { + const scene = args[0] as BattleScene; + const moneyAmount = new Utils.IntegerHolder(scene.getMoneyAmountForWave(this.moneyMultiplier)); + + scene.applyModifiers(MoneyMultiplierModifier, true, moneyAmount); + + scene.money += moneyAmount.value; + scene.updateMoneyText(); + scene.validateAchvs(MoneyAchv); + + return true; + } +} + export class MoneyMultiplierModifier extends PersistentModifier { constructor(type: ModifierType, stackCount?: integer) { super(type, stackCount); diff --git a/src/ui/modifier-select-ui-handler.ts b/src/ui/modifier-select-ui-handler.ts index bb49eff61..b84543f49 100644 --- a/src/ui/modifier-select-ui-handler.ts +++ b/src/ui/modifier-select-ui-handler.ts @@ -218,7 +218,7 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler { if (cursor < this.options.length) { const sliceWidth = (this.scene.game.canvas.width / 6) / (this.options.length + 2); this.cursorObj.setPosition(sliceWidth * (cursor + 1) + (sliceWidth * 0.5) - 20, -this.scene.game.canvas.height / 12 - 20); - ui.showText(this.options[this.cursor].modifierTypeOption.type.description); + ui.showText(this.options[this.cursor].modifierTypeOption.type.getDescription(this.scene)); } else if (cursor === this.options.length) { this.cursorObj.setPosition(6, -60); ui.showText('Spend money to reroll your item options'); diff --git a/src/ui/summary-ui-handler.ts b/src/ui/summary-ui-handler.ts index 1967408a4..a3ed8d510 100644 --- a/src/ui/summary-ui-handler.ts +++ b/src/ui/summary-ui-handler.ts @@ -578,7 +578,7 @@ export default class SummaryUiHandler extends UiHandler { statsContainer.add(icon); icon.setInteractive(new Phaser.Geom.Rectangle(0, 0, 32, 32), Phaser.Geom.Rectangle.Contains); - icon.on('pointerover', () => (this.scene as BattleScene).ui.showTooltip(item.type.name, item.type.description, true)); + icon.on('pointerover', () => (this.scene as BattleScene).ui.showTooltip(item.type.name, item.type.getDescription(this.scene), true)); icon.on('pointerout', () => (this.scene as BattleScene).ui.hideTooltip()); });