2024-06-22 01:19:56 +01:00
|
|
|
import { EggTier } from "#enums/egg-type";
|
|
|
|
import { Species } from "#enums/species";
|
|
|
|
import { VariantTier } from "#enums/variant-tiers";
|
|
|
|
import { EGG_SEED, Egg } from "../data/egg";
|
|
|
|
import { EggSourceType } from "#app/enums/egg-source-types.js";
|
2023-12-16 04:07:32 +00:00
|
|
|
|
|
|
|
export default class EggData {
|
|
|
|
public id: integer;
|
2024-06-22 01:19:56 +01:00
|
|
|
public tier: EggTier;
|
|
|
|
public sourceType: EggSourceType;
|
2023-12-20 04:51:48 +00:00
|
|
|
public hatchWaves: integer;
|
2023-12-16 04:07:32 +00:00
|
|
|
public timestamp: integer;
|
2024-06-22 01:19:56 +01:00
|
|
|
public variantTier: VariantTier;
|
|
|
|
public isShiny: boolean;
|
|
|
|
public species: Species;
|
|
|
|
public eggMoveIndex: number;
|
|
|
|
public overrideHiddenAbility: boolean;
|
2023-12-16 04:07:32 +00:00
|
|
|
|
|
|
|
constructor(source: Egg | any) {
|
|
|
|
const sourceEgg = source instanceof Egg ? source as Egg : null;
|
|
|
|
this.id = sourceEgg ? sourceEgg.id : source.id;
|
2024-06-22 01:19:56 +01:00
|
|
|
this.tier = sourceEgg ? sourceEgg.tier : (source.tier ?? Math.floor(this.id / EGG_SEED));
|
2024-06-22 04:11:17 +01:00
|
|
|
// legacy egg
|
|
|
|
if (source.species === 0) {
|
|
|
|
// check if it has a gachaType (deprecated)
|
|
|
|
this.sourceType = source.gachaType ?? source.sourceType;
|
|
|
|
} else {
|
|
|
|
this.sourceType = sourceEgg ? sourceEgg.sourceType : source.sourceType;
|
|
|
|
}
|
2023-12-20 04:51:48 +00:00
|
|
|
this.hatchWaves = sourceEgg ? sourceEgg.hatchWaves : source.hatchWaves;
|
2023-12-16 04:07:32 +00:00
|
|
|
this.timestamp = sourceEgg ? sourceEgg.timestamp : source.timestamp;
|
2024-06-22 01:19:56 +01:00
|
|
|
this.variantTier = sourceEgg ? sourceEgg.variantTier : source.variantTier;
|
|
|
|
this.isShiny = sourceEgg ? sourceEgg.isShiny : source.isShiny;
|
|
|
|
this.species = sourceEgg ? sourceEgg.species : source.species;
|
|
|
|
this.eggMoveIndex = sourceEgg ? sourceEgg.eggMoveIndex : source.eggMoveIndex;
|
|
|
|
this.overrideHiddenAbility = sourceEgg ? sourceEgg.overrideHiddenAbility : source.overrideHiddenAbility;
|
2023-12-16 04:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
toEgg(): Egg {
|
2024-06-22 01:19:56 +01:00
|
|
|
// Species will be 0 if an old legacy is loaded from DB
|
|
|
|
if (!this.species) {
|
|
|
|
return new Egg({ id: this.id, hatchWaves: this.hatchWaves, sourceType: this.sourceType, timestamp: this.timestamp, tier: Math.floor(this.id / EGG_SEED) });
|
|
|
|
} else {
|
|
|
|
return new Egg({id: this.id, tier: this.tier, sourceType: this.sourceType, hatchWaves: this.hatchWaves,
|
|
|
|
timestamp: this.timestamp, variantTier: this.variantTier, isShiny: this.isShiny, species: this.species,
|
|
|
|
eggMoveIndex: this.eggMoveIndex, overrideHiddenAbility: this.overrideHiddenAbility });
|
|
|
|
}
|
2023-12-16 04:07:32 +00:00
|
|
|
}
|
2024-05-23 16:03:10 +01:00
|
|
|
}
|