2023-12-19 23:51:48 -05:00
|
|
|
import BattleScene from "../battle-scene";
|
2024-06-09 10:45:21 -06:00
|
|
|
import PokemonSpecies, { getPokemonSpecies, speciesStarters } from "./pokemon-species";
|
2024-06-17 17:05:33 -04:00
|
|
|
import i18next from "i18next";
|
2024-06-13 18:44:23 -04:00
|
|
|
import { EggTier } from "#enums/egg-type";
|
|
|
|
import { Species } from "#enums/species";
|
2023-12-15 23:07:32 -05:00
|
|
|
|
|
|
|
export const EGG_SEED = 1073741824;
|
|
|
|
|
|
|
|
export enum GachaType {
|
2024-03-03 21:30:11 -05:00
|
|
|
MOVE,
|
2024-02-19 10:42:17 -05:00
|
|
|
LEGENDARY,
|
2023-12-15 23:07:32 -05:00
|
|
|
SHINY
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Egg {
|
|
|
|
public id: integer;
|
2024-02-28 23:13:05 -05:00
|
|
|
public tier: EggTier;
|
2023-12-15 23:07:32 -05:00
|
|
|
public gachaType: GachaType;
|
2023-12-19 23:51:48 -05:00
|
|
|
public hatchWaves: integer;
|
2023-12-15 23:07:32 -05:00
|
|
|
public timestamp: integer;
|
|
|
|
|
2023-12-19 23:51:48 -05:00
|
|
|
constructor(id: integer, gachaType: GachaType, hatchWaves: integer, timestamp: integer) {
|
2023-12-15 23:07:32 -05:00
|
|
|
this.id = id;
|
|
|
|
this.tier = Math.floor(id / EGG_SEED);
|
|
|
|
this.gachaType = gachaType;
|
2023-12-19 23:51:48 -05:00
|
|
|
this.hatchWaves = hatchWaves;
|
2023-12-15 23:07:32 -05:00
|
|
|
this.timestamp = timestamp;
|
|
|
|
}
|
2023-12-19 23:51:48 -05:00
|
|
|
|
|
|
|
isManaphyEgg(): boolean {
|
2024-06-14 00:06:29 +02:00
|
|
|
return this.tier === EggTier.COMMON && !(this.id % 204);
|
2023-12-19 23:51:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
getKey(): string {
|
2024-05-23 17:03:10 +02:00
|
|
|
if (this.isManaphyEgg()) {
|
|
|
|
return "manaphy";
|
|
|
|
}
|
2023-12-19 23:51:48 -05:00
|
|
|
return this.tier.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-28 23:13:05 -05:00
|
|
|
export function getEggTierDefaultHatchWaves(tier: EggTier): integer {
|
2023-12-19 23:51:48 -05:00
|
|
|
switch (tier) {
|
2024-05-23 17:03:10 +02:00
|
|
|
case EggTier.COMMON:
|
|
|
|
return 10;
|
|
|
|
case EggTier.GREAT:
|
|
|
|
return 25;
|
|
|
|
case EggTier.ULTRA:
|
|
|
|
return 50;
|
2023-12-19 23:51:48 -05:00
|
|
|
}
|
|
|
|
return 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getEggDescriptor(egg: Egg): string {
|
2024-05-23 17:03:10 +02:00
|
|
|
if (egg.isManaphyEgg()) {
|
|
|
|
return "Manaphy";
|
|
|
|
}
|
2023-12-19 23:51:48 -05:00
|
|
|
switch (egg.tier) {
|
2024-05-23 17:03:10 +02:00
|
|
|
case EggTier.GREAT:
|
|
|
|
return i18next.t("egg:greatTier");
|
|
|
|
case EggTier.ULTRA:
|
|
|
|
return i18next.t("egg:ultraTier");
|
|
|
|
case EggTier.MASTER:
|
|
|
|
return i18next.t("egg:masterTier");
|
|
|
|
default:
|
|
|
|
return i18next.t("egg:defaultTier");
|
2023-12-19 23:51:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getEggHatchWavesMessage(hatchWaves: integer): string {
|
2024-05-23 17:03:10 +02:00
|
|
|
if (hatchWaves <= 5) {
|
|
|
|
return i18next.t("egg:hatchWavesMessageSoon");
|
|
|
|
}
|
|
|
|
if (hatchWaves <= 15) {
|
|
|
|
return i18next.t("egg:hatchWavesMessageClose");
|
|
|
|
}
|
|
|
|
if (hatchWaves <= 50) {
|
|
|
|
return i18next.t("egg:hatchWavesMessageNotClose");
|
|
|
|
}
|
|
|
|
return i18next.t("egg:hatchWavesMessageLongTime");
|
2023-12-19 23:51:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getEggGachaTypeDescriptor(scene: BattleScene, egg: Egg): string {
|
|
|
|
switch (egg.gachaType) {
|
2024-05-23 17:03:10 +02:00
|
|
|
case GachaType.LEGENDARY:
|
|
|
|
return `${i18next.t("egg:gachaTypeLegendary")} (${getPokemonSpecies(getLegendaryGachaSpeciesForTimestamp(scene, egg.timestamp)).getName()})`;
|
|
|
|
case GachaType.MOVE:
|
|
|
|
return i18next.t("egg:gachaTypeMove");
|
|
|
|
case GachaType.SHINY:
|
|
|
|
return i18next.t("egg:gachaTypeShiny");
|
2023-12-19 23:51:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getLegendaryGachaSpeciesForTimestamp(scene: BattleScene, timestamp: integer): Species {
|
|
|
|
const legendarySpecies = Object.entries(speciesStarters)
|
|
|
|
.filter(s => s[1] >= 8 && s[1] <= 9)
|
2023-12-30 15:58:41 -05:00
|
|
|
.map(s => parseInt(s[0]))
|
|
|
|
.filter(s => getPokemonSpecies(s).isObtainable());
|
2023-12-19 23:51:48 -05:00
|
|
|
|
|
|
|
let ret: Species;
|
|
|
|
|
2024-05-15 01:34:40 +10:00
|
|
|
// 86400000 is the number of miliseconds in one day
|
|
|
|
const timeDate = new Date(timestamp);
|
|
|
|
const dayTimestamp = timeDate.getTime(); // Timestamp of current week
|
|
|
|
const offset = Math.floor(Math.floor(dayTimestamp / 86400000) / legendarySpecies.length); // Cycle number
|
2024-05-23 17:03:10 +02:00
|
|
|
const index = Math.floor(dayTimestamp / 86400000) % legendarySpecies.length; // Index within cycle
|
2024-05-15 01:34:40 +10:00
|
|
|
|
2023-12-19 23:51:48 -05:00
|
|
|
scene.executeWithSeedOffset(() => {
|
2024-05-15 01:34:40 +10:00
|
|
|
ret = Phaser.Math.RND.shuffle(legendarySpecies)[index];
|
|
|
|
}, offset, EGG_SEED.toString());
|
2023-12-19 23:51:48 -05:00
|
|
|
|
|
|
|
return ret;
|
2024-05-23 17:03:10 +02:00
|
|
|
}
|
2024-06-09 10:45:21 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check for a given species EggTier Value
|
|
|
|
* @param species - Species for wich we will check the egg tier it belongs to
|
|
|
|
* @returns The egg tier of a given pokemon species
|
|
|
|
*/
|
|
|
|
export function getEggTierForSpecies(pokemonSpecies :PokemonSpecies): EggTier {
|
|
|
|
const speciesBaseValue = speciesStarters[pokemonSpecies.getRootSpeciesId()];
|
|
|
|
if (speciesBaseValue <= 3) {
|
|
|
|
return EggTier.COMMON;
|
|
|
|
} else if (speciesBaseValue <= 5) {
|
|
|
|
return EggTier.GREAT;
|
|
|
|
} else if (speciesBaseValue <= 7) {
|
|
|
|
return EggTier.ULTRA;
|
|
|
|
}
|
|
|
|
return EggTier.MASTER;
|
|
|
|
}
|