mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-01-16 05:51:56 +00:00
bac6c22973
* eslint config + packages * updated eslint config * fix the issue eslint adding ;;;; at interfaces * first round with eslint --fix . * removed config for unused export * Revert "first round with eslint --fix ." This reverts commit 77a88e0895f7c3389cb223651b90d918af778fe9. * removed config for camelCase * for real this time, first round of eslint --fix . * halfway to manual eslint fix * eslint done * added "how to setup" the hook to eslint --fix each new file before commit (if wanted) * removed eslintrc config file duplicat * fix human error + ignore build folder + merge overrides * added curly brace style + eslint * applied double quote linter rule * added lefthook * test precommit * test precommit * test precommit * test precommit * test precommit * test precommit * test precommit * github action to run eslint * added node_modules to ignore eslint * different action for typescript * no need for different glob (default src) * node 20 * node 20 * removed no longer needed install file * remove hooks part from README * eslint fixes --------- Co-authored-by: Frederico Santos <frederico.f.santos@tecnico.ulisboa.pt>
114 lines
3.1 KiB
TypeScript
114 lines
3.1 KiB
TypeScript
import BattleScene from "../battle-scene";
|
|
import { Species } from "./enums/species";
|
|
import { getPokemonSpecies, speciesStarters } from "./pokemon-species";
|
|
import { EggTier } from "./enums/egg-type";
|
|
import i18next from "../plugins/i18n";
|
|
|
|
export const EGG_SEED = 1073741824;
|
|
|
|
export enum GachaType {
|
|
MOVE,
|
|
LEGENDARY,
|
|
SHINY
|
|
}
|
|
|
|
export class Egg {
|
|
public id: integer;
|
|
public tier: EggTier;
|
|
public gachaType: GachaType;
|
|
public hatchWaves: integer;
|
|
public timestamp: integer;
|
|
|
|
constructor(id: integer, gachaType: GachaType, hatchWaves: integer, timestamp: integer) {
|
|
this.id = id;
|
|
this.tier = Math.floor(id / EGG_SEED);
|
|
this.gachaType = gachaType;
|
|
this.hatchWaves = hatchWaves;
|
|
this.timestamp = timestamp;
|
|
}
|
|
|
|
isManaphyEgg(): boolean {
|
|
return this.tier === EggTier.COMMON && !(this.id % 255);
|
|
}
|
|
|
|
getKey(): string {
|
|
if (this.isManaphyEgg()) {
|
|
return "manaphy";
|
|
}
|
|
return this.tier.toString();
|
|
}
|
|
}
|
|
|
|
export function getEggTierDefaultHatchWaves(tier: EggTier): integer {
|
|
switch (tier) {
|
|
case EggTier.COMMON:
|
|
return 10;
|
|
case EggTier.GREAT:
|
|
return 25;
|
|
case EggTier.ULTRA:
|
|
return 50;
|
|
}
|
|
return 100;
|
|
}
|
|
|
|
export function getEggDescriptor(egg: Egg): string {
|
|
if (egg.isManaphyEgg()) {
|
|
return "Manaphy";
|
|
}
|
|
switch (egg.tier) {
|
|
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");
|
|
}
|
|
}
|
|
|
|
export function getEggHatchWavesMessage(hatchWaves: integer): string {
|
|
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");
|
|
}
|
|
|
|
export function getEggGachaTypeDescriptor(scene: BattleScene, egg: Egg): string {
|
|
switch (egg.gachaType) {
|
|
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");
|
|
}
|
|
}
|
|
|
|
export function getLegendaryGachaSpeciesForTimestamp(scene: BattleScene, timestamp: integer): Species {
|
|
const legendarySpecies = Object.entries(speciesStarters)
|
|
.filter(s => s[1] >= 8 && s[1] <= 9)
|
|
.map(s => parseInt(s[0]))
|
|
.filter(s => getPokemonSpecies(s).isObtainable());
|
|
|
|
let ret: Species;
|
|
|
|
// 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
|
|
const index = Math.floor(dayTimestamp / 86400000) % legendarySpecies.length; // Index within cycle
|
|
|
|
scene.executeWithSeedOffset(() => {
|
|
ret = Phaser.Math.RND.shuffle(legendarySpecies)[index];
|
|
}, offset, EGG_SEED.toString());
|
|
|
|
return ret;
|
|
}
|