Draft for Hidden Ability Gacha machine

pull/825/head
td76099 2024-05-13 16:03:33 -04:00
parent 09287c22ba
commit 0265418acc
3 changed files with 17 additions and 13 deletions

View File

@ -10,7 +10,8 @@ export const EGG_SEED = 1073741824;
export enum GachaType {
MOVE,
LEGENDARY,
SHINY
SHINY,
ABILITY
}
export class Egg {

View File

@ -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;

View File

@ -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 '';