From bfa95a372e3530a59042ad98463a92e7f20a11ee Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Thu, 20 Apr 2023 20:15:16 -0400 Subject: [PATCH] Add leftovers item --- src/battle-phases.ts | 4 +++- src/modifier/modifier-type.ts | 3 +++ src/modifier/modifier.ts | 36 ++++++++++++++++++++++++++++++++--- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/battle-phases.ts b/src/battle-phases.ts index 04598e65a..56e33c876 100644 --- a/src/battle-phases.ts +++ b/src/battle-phases.ts @@ -5,7 +5,7 @@ import { allMoves, applyMoveAttrs, BypassSleepAttr, ChargeAttr, ConditionalMoveA import { Mode } from './ui/ui'; import { Command } from "./ui/command-ui-handler"; import { Stat } from "./data/pokemon-stat"; -import { BerryModifier, ExpBalanceModifier, ExpBoosterModifier, ExpShareModifier, ExtraModifierModifier, HealingBoosterModifier, HitHealModifier, PokemonExpBoosterModifier, PokemonHeldItemModifier, TempBattleStatBoosterModifier } from "./modifier/modifier"; +import { BerryModifier, ExpBalanceModifier, ExpBoosterModifier, ExpShareModifier, ExtraModifierModifier, HealingBoosterModifier, HitHealModifier, PokemonExpBoosterModifier, PokemonHeldItemModifier, TempBattleStatBoosterModifier, TurnHealModifier } from "./modifier/modifier"; import PartyUiHandler, { PartyOption, PartyUiMode } from "./ui/party-ui-handler"; import { doPokeballBounceAnim, getPokeballAtlasKey, getPokeballCatchMultiplier, getPokeballTintColor, PokeballType } from "./data/pokeball"; import { CommonAnim, CommonBattleAnim, MoveAnim, initMoveAnim, loadMoveAnimAssets } from "./data/battle-anims"; @@ -601,6 +601,8 @@ export class TurnEndPhase extends BattlePhase { if (hasUsableBerry) this.scene.pushPhase(new BerryPhase(this.scene, pokemon.isPlayer())); + this.scene.applyModifiers(TurnHealModifier, pokemon.isPlayer(), pokemon); + pokemon.battleSummonData.turnCount++; }; diff --git a/src/modifier/modifier-type.ts b/src/modifier/modifier-type.ts index de94ed49c..3e9276d9d 100644 --- a/src/modifier/modifier-type.ts +++ b/src/modifier/modifier-type.ts @@ -515,6 +515,8 @@ const modifierTypes = { BERRY_POUCH: new ModifierType('BERRY POUCH', 'Adds a 25% chance that a used berry will not be consumed', (type, _args) => new Modifiers.PreserveBerryModifier(type)), + LEFTOVERS: new PokemonHeldItemModifierType('LEFTOVERS', 'Heals 1/16 of a POKéMON\'s maximum HP every turn', + (type, args) => new Modifiers.TurnHealModifier(type, (args[0] as Pokemon).id)), SHELL_BELL: new PokemonHeldItemModifierType('SHELL BELL', 'Heals 1/8 of a POKéMON\'s dealt damage', (type, args) => new Modifiers.HitHealModifier(type, (args[0] as Pokemon).id)), @@ -590,6 +592,7 @@ const modifierPool = { new WeightedModifierType(modifierTypes.ATTACK_TYPE_BOOSTER, 5), modifierTypes.OVAL_CHARM, modifierTypes.HEALING_CHARM, + new WeightedModifierType(modifierTypes.LEFTOVERS, 2), new WeightedModifierType(modifierTypes.SHELL_BELL, 2), new WeightedModifierType(modifierTypes.EXP_CHARM, 4), new WeightedModifierType(modifierTypes.LUCKY_EGG, 3), diff --git a/src/modifier/modifier.ts b/src/modifier/modifier.ts index a12a5814f..7cff27b20 100644 --- a/src/modifier/modifier.ts +++ b/src/modifier/modifier.ts @@ -340,6 +340,35 @@ export class AttackTypeBoosterModifier extends PokemonHeldItemModifier { } } +export class TurnHealModifier extends PokemonHeldItemModifier { + constructor(type: ModifierType, pokemonId: integer) { + super(type, pokemonId); + } + + match(modifier: Modifier) { + return modifier instanceof TurnHealModifier; + } + + clone() { + return new TurnHealModifier(this.type, this.pokemonId); + } + + apply(args: any[]): boolean { + const pokemon = args[0] as Pokemon; + + if (pokemon.getHpRatio() < 1) { + const scene = pokemon.scene; + scene.unshiftPhase(new PokemonHealPhase(scene, true, Math.max(Math.floor(pokemon.getMaxHp() / 16) * this.stackCount, 1), getPokemonMessage(pokemon, `'s ${this.type.name}\nrestored its HP a little!`), true)); + } + + return true; + } + + getMaxStackCount(): number { + return 16; + } +} + export class HitHealModifier extends PokemonHeldItemModifier { constructor(type: ModifierType, pokemonId: integer) { super(type, pokemonId); @@ -358,12 +387,15 @@ export class HitHealModifier extends PokemonHeldItemModifier { if (pokemon.turnData.damageDealt && pokemon.getHpRatio() < 1) { const scene = pokemon.scene; - scene.unshiftPhase(new PokemonHealPhase(scene, true, Math.max(Math.floor(pokemon.turnData.damageDealt / 8) * this.stackCount, 1), getPokemonMessage(pokemon, `'s ${this.type.name}\nrestored its HP a little!`), true)); } return true; } + + getMaxStackCount(): number { + return 16; + } } export class BerryModifier extends PokemonHeldItemModifier { @@ -395,8 +427,6 @@ export class BerryModifier extends PokemonHeldItemModifier { const preserve = new Utils.BooleanHolder(false); pokemon.scene.applyModifiers(PreserveBerryModifier, pokemon.isPlayer(), preserve); - console.log(pokemon.isPlayer()); - getBerryEffectFunc(this.berryType)(pokemon); if (!preserve.value) this.consumed = true;