egg list icons for gacha or same species eggs

This commit is contained in:
James Diefenbach 2024-09-07 18:06:11 +10:00
parent d0cb5a65d4
commit da6d6be92e
2 changed files with 100 additions and 16 deletions

View File

@ -25,6 +25,10 @@ const DEFAULT_RARE_EGGMOVE_RATE = 6;
const SAME_SPECIES_EGG_RARE_EGGMOVE_RATE = 3; const SAME_SPECIES_EGG_RARE_EGGMOVE_RATE = 3;
const GACHA_MOVE_UP_RARE_EGGMOVE_RATE = 3; const GACHA_MOVE_UP_RARE_EGGMOVE_RATE = 3;
export const wavesHatchingSoon = 5;
const wavesHatchingClose = 15;
const wavesHatchingNotClose = 50;
/** Egg options to override egg properties */ /** Egg options to override egg properties */
export interface IEggOptions { export interface IEggOptions {
/** Id. Used to check if egg type will be manaphy (id % 204 === 0) */ /** Id. Used to check if egg type will be manaphy (id % 204 === 0) */
@ -277,18 +281,62 @@ export class Egg {
} }
public getEggHatchWavesMessage(): string { public getEggHatchWavesMessage(): string {
if (this.hatchWaves <= 5) { if (this.hatchWaves <= wavesHatchingSoon) {
return i18next.t("egg:hatchWavesMessageSoon"); return i18next.t("egg:hatchWavesMessageSoon");
} }
if (this.hatchWaves <= 15) { if (this.hatchWaves <= wavesHatchingClose) {
return i18next.t("egg:hatchWavesMessageClose"); return i18next.t("egg:hatchWavesMessageClose");
} }
if (this.hatchWaves <= 50) { if (this.hatchWaves <= wavesHatchingNotClose) {
return i18next.t("egg:hatchWavesMessageNotClose"); return i18next.t("egg:hatchWavesMessageNotClose");
} }
return i18next.t("egg:hatchWavesMessageLongTime"); return i18next.t("egg:hatchWavesMessageLongTime");
} }
public hasSourceIcon() {
if (this.sourceType === EggSourceType.EVENT) {
return false;
} else if (this.isManaphyEgg() && this.sourceType === EggSourceType.GACHA_LEGENDARY) {
// gacha legendary is useless so don't show
return false;
} else {
return true;
}
}
public getSourceIcon(scene: BattleScene): string {
switch (this.sourceType) {
case EggSourceType.GACHA_MOVE:
return "icon_egg_move";
case EggSourceType.GACHA_SHINY:
return "shiny_star_small";
case EggSourceType.GACHA_LEGENDARY:
const species = getPokemonSpecies(getLegendaryGachaSpeciesForTimestamp(scene, this.timestamp));
return species.getIconAtlasKey(0, false, 0);
case EggSourceType.SAME_SPECIES_EGG:
return getPokemonSpecies(this._species).getIconAtlasKey(1, false, 0);
case EggSourceType.EVENT:
return "icon_owned"; // what to use here?
default:
return "icon_owned";
}
}
public getSourcePokemonFrame(scene: BattleScene): string {
let species;
if (this.sourceType === EggSourceType.SAME_SPECIES_EGG) {
species = getPokemonSpecies(this._species);
} else if (this.sourceType === EggSourceType.GACHA_LEGENDARY) {
species = getPokemonSpecies(getLegendaryGachaSpeciesForTimestamp(scene, this.timestamp));
} else {
return "";
}
console.log(species.getName());
console.log(species.getIconAtlasKey(1, false, 0));
return species.getIconId(false, 0, false, 0);
}
public getEggTypeDescriptor(scene: BattleScene): string { public getEggTypeDescriptor(scene: BattleScene): string {
switch (this.sourceType) { switch (this.sourceType) {
case EggSourceType.SAME_SPECIES_EGG: case EggSourceType.SAME_SPECIES_EGG:

View File

@ -3,14 +3,19 @@ import { Mode } from "./ui";
import PokemonIconAnimHandler, { PokemonIconAnimMode } from "./pokemon-icon-anim-handler"; import PokemonIconAnimHandler, { PokemonIconAnimMode } from "./pokemon-icon-anim-handler";
import { TextStyle, addTextObject } from "./text"; import { TextStyle, addTextObject } from "./text";
import MessageUiHandler from "./message-ui-handler"; import MessageUiHandler from "./message-ui-handler";
import { Egg } from "../data/egg"; import { Egg, wavesHatchingSoon } from "../data/egg";
import { addWindow } from "./ui-theme"; import { addWindow } from "./ui-theme";
import {Button} from "#enums/buttons"; import {Button} from "#enums/buttons";
import i18next from "i18next"; import i18next from "i18next";
import { EggSourceType } from "#app/enums/egg-source-types.js";
const iconSize = 18;
const numCols = 11;
export default class EggListUiHandler extends MessageUiHandler { export default class EggListUiHandler extends MessageUiHandler {
private eggListContainer: Phaser.GameObjects.Container; private eggListContainer: Phaser.GameObjects.Container;
private eggListIconContainer: Phaser.GameObjects.Container; private eggListIconContainer: Phaser.GameObjects.Container;
private eggSourceIconContainer: Phaser.GameObjects.Container;
private eggSprite: Phaser.GameObjects.Sprite; private eggSprite: Phaser.GameObjects.Sprite;
private eggNameText: Phaser.GameObjects.Text; private eggNameText: Phaser.GameObjects.Text;
private eggDateText: Phaser.GameObjects.Text; private eggDateText: Phaser.GameObjects.Text;
@ -33,6 +38,8 @@ export default class EggListUiHandler extends MessageUiHandler {
this.eggListContainer.setVisible(false); this.eggListContainer.setVisible(false);
ui.add(this.eggListContainer); ui.add(this.eggListContainer);
const bgColor = this.scene.add.rectangle(0, 0, this.scene.game.canvas.width / 6, this.scene.game.canvas.height / 6, 0x006860); const bgColor = this.scene.add.rectangle(0, 0, this.scene.game.canvas.width / 6, this.scene.game.canvas.height / 6, 0x006860);
bgColor.setOrigin(0, 0); bgColor.setOrigin(0, 0);
this.eggListContainer.add(bgColor); this.eggListContainer.add(bgColor);
@ -66,6 +73,8 @@ export default class EggListUiHandler extends MessageUiHandler {
this.eggListIconContainer = this.scene.add.container(115, 9); this.eggListIconContainer = this.scene.add.container(115, 9);
this.eggListContainer.add(this.eggListIconContainer); this.eggListContainer.add(this.eggListIconContainer);
this.eggSourceIconContainer = this.scene.add.container(115, 9);
this.eggListContainer.add(this.eggSourceIconContainer);
this.cursorObj = this.scene.add.image(0, 0, "select_cursor"); this.cursorObj = this.scene.add.image(0, 0, "select_cursor");
this.cursorObj.setOrigin(0, 0); this.cursorObj.setOrigin(0, 0);
@ -99,14 +108,40 @@ export default class EggListUiHandler extends MessageUiHandler {
let e = 0; let e = 0;
for (const egg of this.scene.gameData.eggs) { for (const egg of this.scene.gameData.eggs) {
const x = (e % 11) * 18; const x = (e % numCols) * iconSize;
const y = Math.floor(e / 11) * 18; const y = Math.floor(e / numCols) * iconSize;
const icon = this.scene.add.sprite(x - 2, y + 2, "egg_icons"); const icon = this.scene.add.sprite(x - 2, y + 2, "egg_icons");
icon.setScale(0.5); icon.setScale(0.5);
icon.setOrigin(0, 0); icon.setOrigin(0, 0);
icon.setFrame(egg.getKey()); icon.setFrame(egg.getKey());
this.eggListIconContainer.add(icon); this.eggListIconContainer.add(icon);
this.iconAnimHandler.addOrUpdate(icon, PokemonIconAnimMode.NONE); if (egg.hatchWaves <= wavesHatchingSoon) {
this.iconAnimHandler.addOrUpdate(icon, PokemonIconAnimMode.ACTIVE);
} else {
this.iconAnimHandler.addOrUpdate(icon, PokemonIconAnimMode.NONE);
}
if (!egg.hasSourceIcon()) {
e++;
continue;
}
const source = this.scene.add.sprite(x + iconSize - 8, y + 2, egg.getSourceIcon(this.scene));
source.setOrigin(0, 0);
source.setScale(0.5);
if (egg.sourceType === EggSourceType.GACHA_LEGENDARY || egg.sourceType === EggSourceType.SAME_SPECIES_EGG) {
source.setFrame(egg.getSourcePokemonFrame(this.scene));
source.setScale(0.4);
source.setPosition(x + 5, y + 1);
}
if (egg.sourceType === EggSourceType.SAME_SPECIES_EGG) {
// add background to differentiate same species from legendary gacha
const bg = this.scene.add.image(x+8, y+3, "passive_bg");
bg.setOrigin(0, 0);
bg.setScale(0.65);
bg.setVisible(true);
this.eggSourceIconContainer.add(bg);
}
this.eggSourceIconContainer.add(source);
e++; e++;
} }
@ -125,27 +160,27 @@ export default class EggListUiHandler extends MessageUiHandler {
ui.revertMode(); ui.revertMode();
success = true; success = true;
} else { } else {
const eggCount = this.eggListIconContainer.getAll().length; const eggCount = this.scene.gameData.eggs.length;
const rows = Math.ceil(eggCount / 11); const rows = Math.ceil(eggCount / numCols);
const row = Math.floor(this.cursor / 11); const row = Math.floor(this.cursor / numCols);
switch (button) { switch (button) {
case Button.UP: case Button.UP:
if (row) { if (row) {
success = this.setCursor(this.cursor - 11); success = this.setCursor(this.cursor - numCols);
} }
break; break;
case Button.DOWN: case Button.DOWN:
if (row < rows - 2 || (row < rows - 1 && this.cursor % 11 <= (eggCount - 1) % 11)) { if (row < rows - 2 || (row < rows - 1 && this.cursor % numCols <= (eggCount - 1) % numCols)) {
success = this.setCursor(this.cursor + 11); success = this.setCursor(this.cursor + numCols);
} }
break; break;
case Button.LEFT: case Button.LEFT:
if (this.cursor % 11) { if (this.cursor % numCols) {
success = this.setCursor(this.cursor - 1); success = this.setCursor(this.cursor - 1);
} }
break; break;
case Button.RIGHT: case Button.RIGHT:
if (this.cursor % 11 < (row < rows - 1 ? 10 : (eggCount - 1) % 11)) { if (this.cursor % numCols < (row < rows - 1 ? 10 : (eggCount - 1) % numCols)) {
success = this.setCursor(this.cursor + 1); success = this.setCursor(this.cursor + 1);
} }
break; break;
@ -184,7 +219,7 @@ export default class EggListUiHandler extends MessageUiHandler {
changed = super.setCursor(cursor); changed = super.setCursor(cursor);
if (changed) { if (changed) {
this.cursorObj.setPosition(114 + 18 * (cursor % 11), 10 + 18 * Math.floor(cursor / 11)); this.cursorObj.setPosition(114 + 18 * (cursor % numCols), 10 + 18 * Math.floor(cursor / numCols));
if (lastCursor > -1) { if (lastCursor > -1) {
this.iconAnimHandler.addOrUpdate(this.eggListIconContainer.getAt(lastCursor) as Phaser.GameObjects.Sprite, PokemonIconAnimMode.NONE); this.iconAnimHandler.addOrUpdate(this.eggListIconContainer.getAt(lastCursor) as Phaser.GameObjects.Sprite, PokemonIconAnimMode.NONE);
@ -203,5 +238,6 @@ export default class EggListUiHandler extends MessageUiHandler {
this.eggListContainer.setVisible(false); this.eggListContainer.setVisible(false);
this.iconAnimHandler.removeAll(); this.iconAnimHandler.removeAll();
this.eggListIconContainer.removeAll(true); this.eggListIconContainer.removeAll(true);
this.eggSourceIconContainer.removeAll(true);
} }
} }