pokerogue/src/system/voucher.ts

129 lines
3.7 KiB
TypeScript
Raw Normal View History

import BattleScene from "../battle-scene";
import i18next from "i18next";
2024-06-01 23:30:22 -03:00
import { Achv, AchvTier, achvs, getAchievementDescription } from "./achv";
import { PlayerGender } from "#enums/player-gender";
import { TrainerType } from "#enums/trainer-type";
export enum VoucherType {
REGULAR,
PLUS,
PREMIUM,
GOLDEN
}
export class Voucher {
public id: string;
public voucherType: VoucherType;
public description: string;
private conditionFunc: (scene: BattleScene, args: any[]) => boolean;
constructor(voucherType: VoucherType, description: string, conditionFunc?: (scene: BattleScene, args: any[]) => boolean) {
this.description = description;
this.voucherType = voucherType;
this.conditionFunc = conditionFunc;
}
validate(scene: BattleScene, args: any[]): boolean {
return !this.conditionFunc || this.conditionFunc(scene, args);
}
[Localization] Achievements are now based on Player Gender (because some languages differ based on that). (#1721) * Achivments(localization of name and description) now depend on the player gender * Fixed Name in ptBr config * Now the achivments are also shown with a gender specific title * Changed it so it checks if PlayerGender is undefined first * Update src/locales/de/config.ts Co-authored-by: flx-sta <50131232+flx-sta@users.noreply.github.com> * Update src/locales/en/config.ts Co-authored-by: flx-sta <50131232+flx-sta@users.noreply.github.com> * Update src/locales/es/config.ts Co-authored-by: flx-sta <50131232+flx-sta@users.noreply.github.com> * Update src/locales/fr/config.ts Co-authored-by: flx-sta <50131232+flx-sta@users.noreply.github.com> * Update src/locales/it/config.ts Co-authored-by: flx-sta <50131232+flx-sta@users.noreply.github.com> * Update src/locales/ko/config.ts Co-authored-by: flx-sta <50131232+flx-sta@users.noreply.github.com> * Update src/locales/pt_BR/config.ts Co-authored-by: flx-sta <50131232+flx-sta@users.noreply.github.com> * Update src/system/voucher.ts Co-authored-by: flx-sta <50131232+flx-sta@users.noreply.github.com> * Update src/locales/zh_CN/config.ts Co-authored-by: flx-sta <50131232+flx-sta@users.noreply.github.com> * Update src/locales/zh_TW/config.ts Co-authored-by: flx-sta <50131232+flx-sta@users.noreply.github.com> * Update src/ui/achv-bar.ts Co-authored-by: flx-sta <50131232+flx-sta@users.noreply.github.com> * Update src/ui/achv-bar.ts Co-authored-by: flx-sta <50131232+flx-sta@users.noreply.github.com> * Update src/ui/achv-bar.ts Co-authored-by: flx-sta <50131232+flx-sta@users.noreply.github.com> * Update src/ui/achv-bar.ts Co-authored-by: flx-sta <50131232+flx-sta@users.noreply.github.com> * Update src/system/achv.ts Co-authored-by: flx-sta <50131232+flx-sta@users.noreply.github.com> * Update src/system/achv.ts Co-authored-by: flx-sta <50131232+flx-sta@users.noreply.github.com> * Update src/system/achv.ts Co-authored-by: flx-sta <50131232+flx-sta@users.noreply.github.com> * Update src/ui/achvs-ui-handler.ts Co-authored-by: flx-sta <50131232+flx-sta@users.noreply.github.com> * Update src/ui/achvs-ui-handler.ts Co-authored-by: flx-sta <50131232+flx-sta@users.noreply.github.com> * Update src/ui/achvs-ui-handler.ts Co-authored-by: flx-sta <50131232+flx-sta@users.noreply.github.com> * instantiate player gender on in AchvBar constructor * Reverted the change made only for the tests. And adjusted the import to use the new enum file * Changed a import to make vite build it again correctly * Again some changes to the imports for the github docs that was complaining * The new challenges are also now localized and gender based * Readded getDescription --------- Co-authored-by: flx-sta <50131232+flx-sta@users.noreply.github.com> Co-authored-by: ImperialSympathizer <imperialsympathizer@gmail.com>
2024-06-09 18:40:23 +02:00
/**
* Get the name of the voucher
* @param playerGender - this is ignored here. It's only there to match the signature of the function in the Achv class
* @returns the name of the voucher
*/
getName(playerGender: PlayerGender): string {
return getVoucherTypeName(this.voucherType);
}
getIconImage(): string {
return getVoucherTypeIcon(this.voucherType);
}
getTier(): AchvTier {
switch (this.voucherType) {
case VoucherType.REGULAR:
return AchvTier.COMMON;
case VoucherType.PLUS:
return AchvTier.GREAT;
case VoucherType.PREMIUM:
return AchvTier.ULTRA;
case VoucherType.GOLDEN:
return AchvTier.ROGUE;
}
}
}
export function getVoucherTypeName(voucherType: VoucherType): string {
switch (voucherType) {
case VoucherType.REGULAR:
return i18next.t("voucher:eggVoucher");
case VoucherType.PLUS:
return i18next.t("voucher:eggVoucherPlus");
case VoucherType.PREMIUM:
return i18next.t("voucher:eggVoucherPremium");
case VoucherType.GOLDEN:
return i18next.t("voucher:eggVoucherGold");
}
}
export function getVoucherTypeIcon(voucherType: VoucherType): string {
switch (voucherType) {
case VoucherType.REGULAR:
return "coupon";
case VoucherType.PLUS:
return "pair_of_tickets";
case VoucherType.PREMIUM:
return "mystic_ticket";
case VoucherType.GOLDEN:
return "golden_mystic_ticket";
}
}
export interface Vouchers {
[key: string]: Voucher;
}
export const vouchers: Vouchers = {};
const voucherAchvs: Achv[] = [ achvs.CLASSIC_VICTORY ];
2024-06-07 23:50:07 -04:00
export function initVouchers() {
import("../data/trainer-config").then(tc => {
const trainerConfigs = tc.trainerConfigs;
for (const achv of voucherAchvs) {
const voucherType = achv.score >= 150
? VoucherType.GOLDEN
: achv.score >= 100
? VoucherType.PREMIUM
: achv.score >= 75
? VoucherType.PLUS
: VoucherType.REGULAR;
vouchers[achv.id] = new Voucher(voucherType, getAchievementDescription(achv.localizationKey));
}
const bossTrainerTypes = Object.keys(trainerConfigs)
.filter(tt => trainerConfigs[tt].isBoss && trainerConfigs[tt].getDerivedType() !== TrainerType.RIVAL);
for (const trainerType of bossTrainerTypes) {
const voucherType = trainerConfigs[trainerType].moneyMultiplier < 10
? VoucherType.PLUS
: VoucherType.PREMIUM;
const key = TrainerType[trainerType];
const trainerName = trainerConfigs[trainerType].name;
const trainer = trainerConfigs[trainerType];
const title = trainer.title ? ` (${trainer.title})` : "";
vouchers[key] = new Voucher(
voucherType,
`${i18next.t("voucher:defeatTrainer", { trainerName })} ${title}`,
);
}
const voucherKeys = Object.keys(vouchers);
for (const k of voucherKeys) {
vouchers[k].id = k;
}
});
}