2023-12-19 23:51:48 -05:00
|
|
|
import BattleScene from "../battle-scene";
|
2024-01-13 12:24:24 -05:00
|
|
|
import { TrainerType } from "../data/enums/trainer-type";
|
2024-05-23 17:03:10 +02:00
|
|
|
import i18next from "../plugins/i18n";
|
2024-06-01 23:30:22 -03:00
|
|
|
import { Achv, AchvTier, achvs, getAchievementDescription } from "./achv";
|
2023-12-19 23:51:48 -05:00
|
|
|
|
|
|
|
export enum VoucherType {
|
|
|
|
REGULAR,
|
|
|
|
PLUS,
|
2023-12-20 17:22:50 -05:00
|
|
|
PREMIUM,
|
|
|
|
GOLDEN
|
2023-12-19 23:51:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
getName(): string {
|
|
|
|
return getVoucherTypeName(this.voucherType);
|
|
|
|
}
|
|
|
|
|
|
|
|
getIconImage(): string {
|
|
|
|
return getVoucherTypeIcon(this.voucherType);
|
|
|
|
}
|
|
|
|
|
2024-02-28 23:13:05 -05:00
|
|
|
getTier(): AchvTier {
|
2023-12-19 23:51:48 -05:00
|
|
|
switch (this.voucherType) {
|
2024-05-23 17:03:10 +02:00
|
|
|
case VoucherType.REGULAR:
|
|
|
|
return AchvTier.COMMON;
|
|
|
|
case VoucherType.PLUS:
|
|
|
|
return AchvTier.GREAT;
|
|
|
|
case VoucherType.PREMIUM:
|
|
|
|
return AchvTier.ULTRA;
|
|
|
|
case VoucherType.GOLDEN:
|
|
|
|
return AchvTier.ROGUE;
|
2023-12-19 23:51:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getVoucherTypeName(voucherType: VoucherType): string {
|
|
|
|
switch (voucherType) {
|
2024-05-23 17:03:10 +02:00
|
|
|
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");
|
2023-12-19 23:51:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getVoucherTypeIcon(voucherType: VoucherType): string {
|
|
|
|
switch (voucherType) {
|
2024-05-23 17:03:10 +02:00
|
|
|
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";
|
2023-12-19 23:51:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface Vouchers {
|
2024-05-20 00:25:52 +02:00
|
|
|
[key: string]: Voucher;
|
2023-12-19 23:51:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
});
|
2024-05-20 00:25:52 +02:00
|
|
|
}
|