From 6af54ce2c7a26fdfd835064734c5d31ac11f68b0 Mon Sep 17 00:00:00 2001 From: Korwai Date: Wed, 24 Apr 2024 10:43:26 -0700 Subject: [PATCH] start implemetation of post damage phase conditions --- src/battle-scene.ts | 6 +++--- src/data/ability.ts | 43 ++++++++++++++++++++++++++++++++++++++++--- src/field/pokemon.ts | 16 ++++++++++++++-- 3 files changed, 57 insertions(+), 8 deletions(-) diff --git a/src/battle-scene.ts b/src/battle-scene.ts index 7cb92c451a9..d946e702bd2 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -63,10 +63,10 @@ import { Localizable } from './plugins/i18n'; export const bypassLogin = import.meta.env.VITE_BYPASS_LOGIN === "1"; export const SEED_OVERRIDE = ''; -export const STARTER_SPECIES_OVERRIDE = 0; +export const STARTER_SPECIES_OVERRIDE = Species.GOLISOPOD; export const STARTER_FORM_OVERRIDE = 0; -export const STARTING_LEVEL_OVERRIDE = 0; -export const STARTING_WAVE_OVERRIDE = 0; +export const STARTING_LEVEL_OVERRIDE = 5; +export const STARTING_WAVE_OVERRIDE = 12; export const STARTING_BIOME_OVERRIDE = Biome.TOWN; export const STARTING_MONEY_OVERRIDE = 0; diff --git a/src/data/ability.ts b/src/data/ability.ts index e0bd24b4e62..a10b9de1c14 100644 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -1,8 +1,8 @@ -import Pokemon, { HitResult, PokemonMove } from "../field/pokemon"; +import Pokemon, { HitResult, PlayerPokemon, PokemonMove } from "../field/pokemon"; import { Type } from "./type"; import * as Utils from "../utils"; import { BattleStat, getBattleStatName } from "./battle-stat"; -import { PokemonHealPhase, ShowAbilityPhase, StatChangePhase } from "../phases"; +import { CheckSwitchPhase, PokemonHealPhase, ReturnPhase, ShowAbilityPhase, StatChangePhase, SwitchPhase, SwitchSummonPhase } from "../phases"; import { getPokemonMessage } from "../messages"; import { Weather, WeatherType } from "./weather"; import { BattlerTag } from "./battler-tags"; @@ -415,12 +415,43 @@ export class NonSuperEffectiveImmunityAbAttr extends TypeImmunityAbAttr { } } +export class PostDamageAbAttr extends AbAttr { + applyPostDamage(pokemon: Pokemon, initialPokemonHpRatio: number, passive: boolean): boolean | Promise { + return false; + } +} + export class PostDefendAbAttr extends AbAttr { applyPostDefend(pokemon: Pokemon, passive: boolean, attacker: Pokemon, move: PokemonMove, hitResult: HitResult, args: any[]): boolean | Promise { return false; } } +type HpThresholdCondition = (postMovePokemon: Pokemon, initialPokemonHpRatio: integer) => boolean; + +export class PostDamageForcedSwitchAbAttr extends PostDamageAbAttr { + private condition: HpThresholdCondition; + + constructor(condition?: HpThresholdCondition) { + super(); + + this.condition = condition; + } + + applyPostDamage(pokemon: Pokemon, initialPokemonHpRatio: number, passive: boolean): Promise { + return new Promise(resolve => { + console.log("Value of this.condition:", this.condition); + + if (this.condition(pokemon, initialPokemonHpRatio)) { + applyPreSwitchOutAbAttrs(PreSwitchOutAbAttr, pokemon); + (pokemon as PlayerPokemon).switchOut(false, true).then(() => resolve(true)); + } else { + resolve(false); + } + }); + } +} + export class PostDefendDisguiseAbAttr extends PostDefendAbAttr { applyPostDefend(pokemon: Pokemon, passive: boolean, attacker: Pokemon, move: PokemonMove, hitResult: HitResult, args: any[]): boolean { @@ -2303,6 +2334,11 @@ export function applyPostDefendAbAttrs(attrType: { new(...args: any[]): PostDefe return applyAbAttrsInternal(attrType, pokemon, (attr, passive) => attr.applyPostDefend(pokemon, passive, attacker, move, hitResult, args), args); } +export function applyPostDamageAbAttrs(attrType: { new(...args: any[]): PostDamageAbAttr }, + pokemon: Pokemon, initialPokemonHpRatio: integer, ...args: any[]): Promise { + return applyAbAttrsInternal(attrType, pokemon, (attr, passive) => attr.applyPostDamage(pokemon, initialPokemonHpRatio, passive), args); +} + export function applyBattleStatMultiplierAbAttrs(attrType: { new(...args: any[]): BattleStatMultiplierAbAttr }, pokemon: Pokemon, battleStat: BattleStat, statValue: Utils.NumberHolder, ...args: any[]): Promise { return applyAbAttrsInternal(attrType, pokemon, (attr, passive) => attr.applyBattleStat(pokemon, passive, battleStat, statValue, args), args); @@ -2906,7 +2942,8 @@ export function initAbilities() { new Ability(Abilities.STAMINA, "Stamina", "Boosts the Defense stat when hit by an attack.", 7) .attr(PostDefendStatChangeAbAttr, (target, user, move) => move.category !== MoveCategory.STATUS, BattleStat.DEF, 1), new Ability(Abilities.WIMP_OUT, "Wimp Out (N)", "The Pokémon cowardly switches out when its HP becomes half or less.", 7), - new Ability(Abilities.EMERGENCY_EXIT, "Emergency Exit (N)", "The Pokémon, sensing danger, switches out when its HP becomes half or less.", 7), + new Ability(Abilities.EMERGENCY_EXIT, "Emergency Exit", "The Pokémon, sensing danger, switches out when its HP becomes half or less.", 7) + .attr(PostDamageForcedSwitchAbAttr, (postMovePokemon, initialPokemonHpRatio) => initialPokemonHpRatio > 0.5 && postMovePokemon.getHpRatio() <= 0.5), new Ability(Abilities.WATER_COMPACTION, "Water Compaction", "Boosts the Pokémon's Defense stat sharply when hit by a Water-type move.", 7) .attr(PostDefendStatChangeAbAttr, (target, user, move) => move.type === Type.WATER, BattleStat.DEF, 2), new Ability(Abilities.MERCILESS, "Merciless (N)", "The Pokémon's attacks become critical hits if the target is poisoned.", 7), diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 97b228a24ca..42b92e4ac33 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -27,7 +27,7 @@ import { TempBattleStat } from '../data/temp-battle-stat'; import { ArenaTagSide, WeakenMoveScreenTag, WeakenMoveTypeTag } from '../data/arena-tag'; import { ArenaTagType } from "../data/enums/arena-tag-type"; import { Biome } from "../data/enums/biome"; -import { Ability, AbAttr, BattleStatMultiplierAbAttr, BlockCritAbAttr, BonusCritAbAttr, BypassBurnDamageReductionAbAttr, FieldPriorityMoveImmunityAbAttr, FieldVariableMovePowerAbAttr, IgnoreOpponentStatChangesAbAttr, MoveImmunityAbAttr, MoveTypeChangeAttr, NonSuperEffectiveImmunityAbAttr, PreApplyBattlerTagAbAttr, PreDefendFullHpEndureAbAttr, ReceivedMoveDamageMultiplierAbAttr, ReduceStatusEffectDurationAbAttr, StabBoostAbAttr, StatusEffectImmunityAbAttr, TypeImmunityAbAttr, VariableMovePowerAbAttr, VariableMoveTypeAbAttr, WeightMultiplierAbAttr, allAbilities, applyAbAttrs, applyBattleStatMultiplierAbAttrs, applyPostDefendAbAttrs, applyPreApplyBattlerTagAbAttrs, applyPreAttackAbAttrs, applyPreDefendAbAttrs, applyPreSetStatusAbAttrs, UnsuppressableAbilityAbAttr, SuppressFieldAbilitiesAbAttr, NoFusionAbilityAbAttr } from '../data/ability'; +import { Ability, AbAttr, BattleStatMultiplierAbAttr, BlockCritAbAttr, BonusCritAbAttr, BypassBurnDamageReductionAbAttr, FieldPriorityMoveImmunityAbAttr, FieldVariableMovePowerAbAttr, IgnoreOpponentStatChangesAbAttr, MoveImmunityAbAttr, MoveTypeChangeAttr, NonSuperEffectiveImmunityAbAttr, PostDamageForcedSwitchAbAttr, PreApplyBattlerTagAbAttr, PreDefendFullHpEndureAbAttr, ReceivedMoveDamageMultiplierAbAttr, ReduceStatusEffectDurationAbAttr, StabBoostAbAttr, StatusEffectImmunityAbAttr, TypeImmunityAbAttr, VariableMovePowerAbAttr, VariableMoveTypeAbAttr, WeightMultiplierAbAttr, allAbilities, applyAbAttrs, applyBattleStatMultiplierAbAttrs, applyPostDamageAbAttrs, applyPostDefendAbAttrs, applyPreApplyBattlerTagAbAttrs, applyPreAttackAbAttrs, applyPreDefendAbAttrs, applyPreSetStatusAbAttrs, UnsuppressableAbilityAbAttr, SuppressFieldAbilitiesAbAttr, NoFusionAbilityAbAttr } from '../data/ability'; import { Abilities } from "#app/data/enums/abilities"; import PokemonData from '../system/pokemon-data'; import Battle, { BattlerIndex } from '../battle'; @@ -1204,7 +1204,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { const move = battlerMove.getMove(); let damage = new Utils.NumberHolder(0); const defendingSidePlayField = this.isPlayer() ? this.scene.getPlayerField() : this.scene.getEnemyField(); - + const initialPokemonHpRatio: integer = source.getHpRatio(); + const variableCategory = new Utils.IntegerHolder(move.category); applyMoveAttrs(VariableMoveCategoryAttr, source, this, move, variableCategory); const moveCategory = variableCategory.value as MoveCategory; @@ -1391,6 +1392,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { damage.value = this.damageAndUpdate(damage.value, result as DamageResult, isCritical, oneHitKo, oneHitKo); if (isCritical) this.scene.queueMessage('A critical hit!'); + this.scene.setPhaseQueueSplice(); if (source.isPlayer()) { this.scene.validateAchvs(DamageAchv, damage); @@ -1421,6 +1423,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { break; } } + + applyPostDamageAbAttrs(PostDamageForcedSwitchAbAttr, this, initialPokemonHpRatio); if (damage) this.scene.clearPhaseQueueSplice(); @@ -2313,6 +2317,12 @@ export class PlayerPokemon extends Pokemon { return true; } + retreat() { + return new Promise(resolve => { + + }) + } + switchOut(batonPass: boolean, removeFromField: boolean = false): Promise { return new Promise(resolve => { this.resetTurnData(); @@ -2322,8 +2332,10 @@ export class PlayerPokemon extends Pokemon { this.scene.ui.setMode(Mode.PARTY, PartyUiMode.FAINT_SWITCH, this.getFieldIndex(), (slotIndex: integer, option: PartyOption) => { if (slotIndex >= this.scene.currentBattle.getBattlerCount() && slotIndex < 6) + console.log('this shit works ' + slotIndex) this.scene.unshiftPhase(new SwitchSummonPhase(this.scene, this.getFieldIndex(), slotIndex, false, batonPass)); if (removeFromField) { + console.log('this shit got removed!') this.setVisible(false); this.scene.field.remove(this); this.scene.triggerPokemonFormChange(this, SpeciesFormChangeActiveTrigger, true);