Add achievement system and UI
Add achievement system and UI; fix counting invalid inputs in UI handlers for input delay
This commit is contained in:
1 parent
ff93e6233f
commit
cbbb8e972b
49 files changed
+4920
-3764
No files matched your search
@@ -0,0 +1,126 @@
|
||||
import BattleScene from "../battle-scene";
|
||||
import * as Utils from "../utils";
|
||||
|
||||
export enum AchvTier {
|
||||
COMMON,
|
||||
GREAT,
|
||||
ULTRA,
|
||||
MASTER
|
||||
}
|
||||
|
||||
export class Achv {
|
||||
public id: string;
|
||||
public name: string;
|
||||
public description: string;
|
||||
public iconImage: string;
|
||||
public score: integer;
|
||||
|
||||
public secret: boolean;
|
||||
public hasParent: boolean;
|
||||
public parentId: string;
|
||||
|
||||
private conditionFunc: (scene: BattleScene, args: any[]) => boolean;
|
||||
|
||||
constructor(name: string, description: string, iconImage: string, score: integer, conditionFunc?: (scene: BattleScene, args: any[]) => boolean) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.iconImage = iconImage;
|
||||
this.score = score;
|
||||
this.conditionFunc = conditionFunc;
|
||||
}
|
||||
|
||||
setSecret(hasParent?: boolean): this {
|
||||
this.secret = true;
|
||||
this.hasParent = !!hasParent;
|
||||
return this;
|
||||
}
|
||||
|
||||
validate(scene: BattleScene, args: any[]): boolean {
|
||||
return !this.conditionFunc || this.conditionFunc(scene, args);
|
||||
}
|
||||
|
||||
getTier(): AchvTier {
|
||||
if (this.score >= 250)
|
||||
return AchvTier.MASTER;
|
||||
if (this.score >= 100)
|
||||
return AchvTier.ULTRA;
|
||||
if (this.score >= 25)
|
||||
return AchvTier.GREAT;
|
||||
return AchvTier.COMMON;
|
||||
}
|
||||
}
|
||||
|
||||
export class MoneyAchv extends Achv {
|
||||
private moneyAmount: integer;
|
||||
|
||||
constructor(name: string, moneyAmount: integer, iconImage: string, score: integer) {
|
||||
super(name, `Accumulate a total of ₽${moneyAmount.toLocaleString('en-US')}`, iconImage, score, (scene: BattleScene, _args: any[]) => scene.money >= this.moneyAmount);
|
||||
|
||||
this.moneyAmount = moneyAmount;
|
||||
}
|
||||
}
|
||||
|
||||
export class DamageAchv extends Achv {
|
||||
private damageAmount: integer;
|
||||
|
||||
constructor(name: string, damageAmount: integer, iconImage: string, score: integer) {
|
||||
super(name, `Inflict ${damageAmount.toLocaleString('en-US')} damage in one hit`, iconImage, score, (_scene: BattleScene, args: any[]) => (args[0] as Utils.NumberHolder).value >= this.damageAmount);
|
||||
|
||||
this.damageAmount = damageAmount;
|
||||
}
|
||||
}
|
||||
|
||||
export class HealAchv extends Achv {
|
||||
private healAmount: integer;
|
||||
|
||||
constructor(name: string, healAmount: integer, iconImage: string, score: integer) {
|
||||
super(name, `Heal ${healAmount.toLocaleString('en-US')} HP at once with a move, ability, or held item`, iconImage, score, (_scene: BattleScene, args: any[]) => (args[0] as Utils.NumberHolder).value >= this.healAmount);
|
||||
|
||||
this.healAmount = healAmount;
|
||||
}
|
||||
}
|
||||
|
||||
export class LevelAchv extends Achv {
|
||||
private level: integer;
|
||||
|
||||
constructor(name: string, level: integer, iconImage: string, score: integer) {
|
||||
super(name, `Level up a Pokémon to Lv${level}`, iconImage, score, (scene: BattleScene, args: any[]) => (args[0] as Utils.IntegerHolder).value >= this.level);
|
||||
|
||||
this.level = level;
|
||||
}
|
||||
}
|
||||
|
||||
export const achvs = {
|
||||
_10K_MONEY: new MoneyAchv('Money Haver', 10000, 'nugget', 10),
|
||||
_100K_MONEY: new MoneyAchv('Rich', 100000, 'big_nugget', 25).setSecret(true),
|
||||
_1M_MONEY: new MoneyAchv('Millionaire', 1000000, 'relic_gold', 100).setSecret(true),
|
||||
_10M_MONEY: new MoneyAchv('One Percenter', 10000000, 'coin_case', 250).setSecret(true),
|
||||
_250_DMG: new DamageAchv('Hard Hitter', 1000, 'lucky_punch', 10),
|
||||
_1000_DMG: new DamageAchv('Harder Hitter', 1000, 'lucky_punch_great', 25).setSecret(true),
|
||||
_2500_DMG: new DamageAchv('That\'s a Lotta Damage!', 2500, 'lucky_punch_ultra', 100).setSecret(true),
|
||||
_10000_DMG: new DamageAchv('One Punch Man', 10000, 'lucky_punch_master', 250).setSecret(true),
|
||||
_250_HEAL: new HealAchv('Novice Healer', 250, 'potion', 10),
|
||||
_1000_HEAL: new HealAchv('Big Healer', 1000, 'super_potion', 25).setSecret(true),
|
||||
_2500_HEAL: new HealAchv('Cleric', 2500, 'hyper_potion', 100).setSecret(true),
|
||||
_10000_HEAL: new HealAchv('Recovery Master', 10000, 'max_potion', 250).setSecret(true),
|
||||
LV_100: new LevelAchv('But Wait, There\'s More!', 50, 'rare_candy', 50).setSecret(),
|
||||
LV_250: new LevelAchv('Elite', 250, 'rarer_candy', 150).setSecret(true),
|
||||
LV_1000: new LevelAchv('To Go Even Further Beyond', 250, 'candy_jar', 400).setSecret(true),
|
||||
TRANSFER_MAX_BATTLE_STAT: new Achv('Teamwork', 'Baton pass to another party member with at least one stat maxed out', 'stick', 25),
|
||||
CATCH_LEGENDARY: new Achv('Legendary', 'Catch a legendary Pokémon', 'mb', 100).setSecret(),
|
||||
CATCH_MYTHICAL: new Achv('Mythical', 'Catch a mythical Pokémon', 'strange_ball', 100).setSecret(),
|
||||
SEE_SHINY: new Achv('Shiny', 'Find a shiny Pokémon in the wild', 'pb_gold', 150).setSecret(),
|
||||
HIDDEN_ABILITY: new Achv('Hidden Potential', 'Catch a Pokémon with a hidden ability', 'ability_charm', 150).setSecret(),
|
||||
CLASSIC_VICTORY: new Achv('Undefeated', 'Beat the game in classic mode', 'relic_crown', 250)
|
||||
};
|
||||
|
||||
{
|
||||
(function() {
|
||||
const achvKeys = Object.keys(achvs);
|
||||
achvKeys.forEach((a: string, i: integer) => {
|
||||
achvs[a].id = a;
|
||||
if (achvs[a].hasParent)
|
||||
achvs[a].parentId = achvKeys[i - 1];
|
||||
});
|
||||
})();
|
||||
}
|
||||
+19
-1
@@ -7,7 +7,6 @@ import { Species } from "../data/species";
|
||||
import * as Utils from "../utils";
|
||||
import PokemonData from "./pokemon-data";
|
||||
import PersistentModifierData from "./modifier-data";
|
||||
import { PokemonHeldItemModifier } from "../modifier/modifier";
|
||||
import ArenaData from "./arena-data";
|
||||
import { Unlockables } from "./unlockables";
|
||||
import { GameMode } from "../game-mode";
|
||||
@@ -15,12 +14,14 @@ import { BattleType } from "../battle";
|
||||
import TrainerData from "./trainer-data";
|
||||
import { trainerConfigs } from "../data/trainer-type";
|
||||
import { Setting, setSetting, settingDefaults } from "./settings";
|
||||
import { achvs } from "./achv";
|
||||
|
||||
interface SystemSaveData {
|
||||
trainerId: integer;
|
||||
secretId: integer;
|
||||
dexData: DexData;
|
||||
unlocks: Unlocks;
|
||||
achvUnlocks: AchvUnlocks;
|
||||
timestamp: integer;
|
||||
}
|
||||
|
||||
@@ -45,6 +46,10 @@ interface Unlocks {
|
||||
[key: integer]: boolean;
|
||||
}
|
||||
|
||||
interface AchvUnlocks {
|
||||
[key: string]: integer
|
||||
}
|
||||
|
||||
export interface DexData {
|
||||
[key: integer]: DexData | DexEntry
|
||||
}
|
||||
@@ -81,6 +86,8 @@ export class GameData {
|
||||
|
||||
public unlocks: Unlocks;
|
||||
|
||||
public achvUnlocks: AchvUnlocks;
|
||||
|
||||
constructor(scene: BattleScene) {
|
||||
this.scene = scene;
|
||||
this.loadSettings();
|
||||
@@ -91,6 +98,7 @@ export class GameData {
|
||||
[Unlockables.MINI_BLACK_HOLE]: false,
|
||||
[Unlockables.SPLICED_ENDLESS_MODE]: false
|
||||
};
|
||||
this.achvUnlocks = {};
|
||||
this.initDexData();
|
||||
this.loadSystem();
|
||||
}
|
||||
@@ -98,12 +106,15 @@ export class GameData {
|
||||
public saveSystem(): boolean {
|
||||
if (this.scene.quickStart)
|
||||
return false;
|
||||
|
||||
console.log(this.achvUnlocks, "wah")
|
||||
|
||||
const data: SystemSaveData = {
|
||||
trainerId: this.trainerId,
|
||||
secretId: this.secretId,
|
||||
dexData: this.dexData,
|
||||
unlocks: this.unlocks,
|
||||
achvUnlocks: this.achvUnlocks,
|
||||
timestamp: new Date().getTime()
|
||||
};
|
||||
|
||||
@@ -129,6 +140,13 @@ export class GameData {
|
||||
}
|
||||
}
|
||||
|
||||
if (data.achvUnlocks) {
|
||||
for (let a of Object.keys(data.achvUnlocks)) {
|
||||
if (achvs.hasOwnProperty(a))
|
||||
this.achvUnlocks[a] = data.achvUnlocks[a];
|
||||
}
|
||||
}
|
||||
|
||||
if (data.timestamp === undefined)
|
||||
this.convertDexData(data.dexData);
|
||||
|
||||
|
||||
Reference in new issue
Block a user