From 0265418accadcc7953d8dface0db84b04dcc0a82 Mon Sep 17 00:00:00 2001 From: td76099 Date: Mon, 13 May 2024 16:03:33 -0400 Subject: [PATCH] Draft for Hidden Ability Gacha machine --- src/data/egg.ts | 3 ++- src/egg-hatch-phase.ts | 3 ++- src/field/pokemon.ts | 24 +++++++++++++----------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/data/egg.ts b/src/data/egg.ts index f0d6de26a..f57f7a8f2 100644 --- a/src/data/egg.ts +++ b/src/data/egg.ts @@ -10,7 +10,8 @@ export const EGG_SEED = 1073741824; export enum GachaType { MOVE, LEGENDARY, - SHINY + SHINY, + ABILITY } export class Egg { diff --git a/src/egg-hatch-phase.ts b/src/egg-hatch-phase.ts index 70f2d5f38..1e7d2ba53 100644 --- a/src/egg-hatch-phase.ts +++ b/src/egg-hatch-phase.ts @@ -12,6 +12,7 @@ import { achvs } from "./system/achv"; import { pokemonPrevolutions } from "./data/pokemon-evolutions"; import { EggTier } from "./data/enums/egg-type"; import PokemonInfoContainer from "./ui/pokemon-info-container"; +import { Abilities } from "./data/enums/abilities"; export class EggHatchPhase extends Phase { private egg: Egg; @@ -413,10 +414,10 @@ export class EggHatchPhase extends Phase { } const pokemonSpecies = getPokemonSpecies(species); - ret = this.scene.addPlayerPokemon(pokemonSpecies, 1, undefined, undefined, undefined, false); } + ret.abilityIndex = this.egg.gachaType == GachaType.ABILITY ? ret.abilityIndex : ret.calculateHiddenAbilityIndex(128); ret.trySetShiny(this.egg.gachaType === GachaType.SHINY ? 1024 : 512); ret.variant = ret.shiny ? ret.generateVariant() : 0; diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 807be3f8d..2a0e22652 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -111,20 +111,10 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { if (!species.isObtainable() && this.isPlayer()) throw `Cannot create a player Pokemon for species '${species.getName(formIndex)}'`; - - const hiddenAbilityChance = new Utils.IntegerHolder(256); - if (!this.hasTrainer()) - this.scene.applyModifiers(HiddenAbilityRateBoosterModifier, true, hiddenAbilityChance); - - const hasHiddenAbility = !Utils.randSeedInt(hiddenAbilityChance.value); - const randAbilityIndex = Utils.randSeedInt(2); - this.species = species; this.pokeball = dataSource?.pokeball || PokeballType.POKEBALL; this.level = level; - this.abilityIndex = abilityIndex !== undefined - ? abilityIndex - : (species.abilityHidden && hasHiddenAbility ? species.ability2 ? 2 : 1 : species.ability2 ? randAbilityIndex : 0); + this.abilityIndex = abilityIndex != undefined ? abilityIndex : this.calculateHiddenAbilityIndex(); if (formIndex !== undefined) this.formIndex = formIndex; if (gender !== undefined) @@ -350,6 +340,18 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { }); } + calculateHiddenAbilityIndex(chanceOverride: number=256): number { + const hiddenAbilityChance = new Utils.IntegerHolder(chanceOverride); + if (!this.hasTrainer()) + this.scene.applyModifiers(HiddenAbilityRateBoosterModifier, true, hiddenAbilityChance); + + const hasHiddenAbility = !Utils.randSeedInt(hiddenAbilityChance.value); + const randAbilityIndex = Utils.randSeedInt(2); + + const abilityIndex = this.species.abilityHidden && hasHiddenAbility ? this.species.ability2 ? 2 : 1 : this.species.ability2 ? randAbilityIndex : 0; + return abilityIndex; + } + getFormKey(): string { if (!this.species.forms.length || this.species.forms.length <= this.formIndex) return '';