-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathtimed-event-manager.ts
451 lines (412 loc) · 14.3 KB
/
timed-event-manager.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
import { globalScene } from "#app/global-scene";
import { TextStyle, addTextObject } from "#app/ui/text";
import type { nil } from "#app/utils";
import { isNullOrUndefined } from "#app/utils";
import i18next from "i18next";
import { Species } from "#enums/species";
import type { WeatherPoolEntry } from "#app/data/weather";
import { WeatherType } from "#enums/weather-type";
import { CLASSIC_CANDY_FRIENDSHIP_MULTIPLIER } from "./data/balance/starters";
import { MysteryEncounterType } from "./enums/mystery-encounter-type";
import { MysteryEncounterTier } from "./enums/mystery-encounter-tier";
export enum EventType {
SHINY,
NO_TIMER_DISPLAY,
LUCK
}
interface EventBanner {
bannerKey?: string;
xOffset?: number;
yOffset?: number;
scale?: number;
availableLangs?: string[];
}
interface EventEncounter {
species: Species;
blockEvolution?: boolean;
formIndex?: number;
}
interface EventMysteryEncounterTier {
mysteryEncounter: MysteryEncounterType;
tier?: MysteryEncounterTier;
disable?: boolean;
}
interface TimedEvent extends EventBanner {
name: string;
eventType: EventType;
shinyMultiplier?: number;
classicFriendshipMultiplier?: number;
luckBoost?: number;
upgradeUnlockedVouchers?: boolean;
startDate: Date;
endDate: Date;
eventEncounters?: EventEncounter[];
delibirdyBuff?: string[];
weather?: WeatherPoolEntry[];
mysteryEncounterTierChanges?: EventMysteryEncounterTier[];
luckBoostedSpecies?: Species[];
boostFusions?: boolean; //MODIFIER REWORK PLEASE
}
const timedEvents: TimedEvent[] = [
{
name: "Winter Holiday Update",
eventType: EventType.SHINY,
shinyMultiplier: 2,
upgradeUnlockedVouchers: true,
startDate: new Date(Date.UTC(2024, 11, 21, 0)),
endDate: new Date(Date.UTC(2025, 0, 4, 0)),
bannerKey: "winter_holidays2024-event-",
scale: 0.21,
availableLangs: [ "en", "de", "it", "fr", "ja", "ko", "es-ES", "pt-BR", "zh-CN" ],
eventEncounters: [
{ species: Species.GIMMIGHOUL, blockEvolution: true },
{ species: Species.DELIBIRD },
{ species: Species.STANTLER },
{ species: Species.CYNDAQUIL },
{ species: Species.PIPLUP },
{ species: Species.CHESPIN },
{ species: Species.BALTOY },
{ species: Species.SNOVER },
{ species: Species.CHINGLING },
{ species: Species.LITWICK },
{ species: Species.CUBCHOO },
{ species: Species.SWIRLIX },
{ species: Species.AMAURA },
{ species: Species.MUDBRAY },
{ species: Species.ROLYCOLY },
{ species: Species.MILCERY },
{ species: Species.SMOLIV },
{ species: Species.ALOLA_VULPIX },
{ species: Species.GALAR_DARUMAKA },
{ species: Species.IRON_BUNDLE }
],
delibirdyBuff: [ "CATCHING_CHARM", "SHINY_CHARM", "ABILITY_CHARM", "EXP_CHARM", "SUPER_EXP_CHARM", "HEALING_CHARM" ],
weather: [{ weatherType: WeatherType.SNOW, weight: 1 }],
mysteryEncounterTierChanges: [
{ mysteryEncounter: MysteryEncounterType.DELIBIRDY, tier: MysteryEncounterTier.COMMON },
{ mysteryEncounter: MysteryEncounterType.PART_TIMER, disable: true },
{ mysteryEncounter: MysteryEncounterType.AN_OFFER_YOU_CANT_REFUSE, disable: true },
{ mysteryEncounter: MysteryEncounterType.FIELD_TRIP, disable: true },
{ mysteryEncounter: MysteryEncounterType.DEPARTMENT_STORE_SALE, disable: true }
]
},
{
name: "Year of the Snake",
eventType: EventType.LUCK,
luckBoost: 1,
startDate: new Date(Date.UTC(2025, 0, 29, 0)),
endDate: new Date(Date.UTC(2025, 1, 3, 0)),
bannerKey: "yearofthesnakeevent-",
scale: 0.21,
availableLangs: [ "en", "de", "it", "fr", "ja", "ko", "es-ES", "pt-BR", "zh-CN" ],
eventEncounters: [
{ species: Species.EKANS },
{ species: Species.ONIX },
{ species: Species.DRATINI },
{ species: Species.CLEFFA },
{ species: Species.UMBREON },
{ species: Species.DUNSPARCE },
{ species: Species.TEDDIURSA },
{ species: Species.SEVIPER },
{ species: Species.LUNATONE },
{ species: Species.CHINGLING },
{ species: Species.SNIVY },
{ species: Species.DARUMAKA },
{ species: Species.DRAMPA },
{ species: Species.SILICOBRA },
{ species: Species.BLOODMOON_URSALUNA }
],
luckBoostedSpecies: [
Species.EKANS, Species.ARBOK,
Species.ONIX, Species.STEELIX,
Species.DRATINI, Species.DRAGONAIR, Species.DRAGONITE,
Species.CLEFFA, Species.CLEFAIRY, Species.CLEFABLE,
Species.UMBREON,
Species.DUNSPARCE, Species.DUDUNSPARCE,
Species.TEDDIURSA, Species.URSARING, Species.URSALUNA,
Species.SEVIPER,
Species.LUNATONE,
Species.RAYQUAZA,
Species.CHINGLING, Species.CHIMECHO,
Species.CRESSELIA,
Species.DARKRAI,
Species.SNIVY, Species.SERVINE, Species.SERPERIOR,
Species.DARUMAKA, Species.DARMANITAN,
Species.ZYGARDE,
Species.DRAMPA,
Species.LUNALA,
Species.BLACEPHALON,
Species.SILICOBRA, Species.SANDACONDA,
Species.ROARING_MOON,
Species.BLOODMOON_URSALUNA
]
},
{
name: "Valentine",
eventType: EventType.SHINY,
startDate: new Date(Date.UTC(2025, 1, 10)),
endDate: new Date(Date.UTC(2025, 1, 21)),
boostFusions: true,
shinyMultiplier: 2,
bannerKey: "valentines2025event-",
scale: 0.21,
availableLangs: [ "en", "de", "it", "fr", "ja", "ko", "es-ES", "pt-BR", "zh-CN" ],
eventEncounters: [
{ species: Species.NIDORAN_F },
{ species: Species.NIDORAN_M },
{ species: Species.IGGLYBUFF },
{ species: Species.SMOOCHUM },
{ species: Species.VOLBEAT },
{ species: Species.ILLUMISE },
{ species: Species.ROSELIA },
{ species: Species.LUVDISC },
{ species: Species.WOOBAT },
{ species: Species.FRILLISH },
{ species: Species.ALOMOMOLA },
{ species: Species.FURFROU, formIndex: 1 }, // Heart trim
{ species: Species.ESPURR },
{ species: Species.SPRITZEE },
{ species: Species.SWIRLIX },
{ species: Species.APPLIN },
{ species: Species.MILCERY },
{ species: Species.INDEEDEE },
{ species: Species.TANDEMAUS },
{ species: Species.ENAMORUS }
],
luckBoostedSpecies: [ Species.LUVDISC ]
}
];
export class TimedEventManager {
constructor() {}
isActive(event: TimedEvent) {
return (
event.startDate < new Date() &&
new Date() < event.endDate
);
}
activeEvent(): TimedEvent | undefined {
return timedEvents.find((te: TimedEvent) => this.isActive(te));
}
isEventActive(): boolean {
return timedEvents.some((te: TimedEvent) => this.isActive(te));
}
activeEventHasBanner(): boolean {
const activeEvents = timedEvents.filter((te) => this.isActive(te) && te.hasOwnProperty("bannerFilename"));
return activeEvents.length > 0;
}
getShinyMultiplier(): number {
let multiplier = 1;
const shinyEvents = timedEvents.filter((te) => te.eventType === EventType.SHINY && this.isActive(te));
shinyEvents.forEach((se) => {
multiplier *= se.shinyMultiplier ?? 1;
});
return multiplier;
}
getEventBannerFilename(): string {
return timedEvents.find((te: TimedEvent) => this.isActive(te))?.bannerKey ?? "";
}
getEventEncounters(): EventEncounter[] {
const ret: EventEncounter[] = [];
timedEvents.filter((te) => this.isActive(te)).map((te) => {
if (!isNullOrUndefined(te.eventEncounters)) {
ret.push(...te.eventEncounters);
}
});
return ret;
}
/**
* For events that change the classic candy friendship multiplier
* @returns The highest classic friendship multiplier among the active events, or the default CLASSIC_CANDY_FRIENDSHIP_MULTIPLIER
*/
getClassicFriendshipMultiplier(): number {
let multiplier = CLASSIC_CANDY_FRIENDSHIP_MULTIPLIER;
const classicFriendshipEvents = timedEvents.filter((te) => this.isActive(te));
classicFriendshipEvents.forEach((fe) => {
if (!isNullOrUndefined(fe.classicFriendshipMultiplier) && fe.classicFriendshipMultiplier > multiplier) {
multiplier = fe.classicFriendshipMultiplier;
}
});
return multiplier;
}
/**
* For events where defeated bosses (Gym Leaders, E4 etc) give out Voucher Plus even if they were defeated before
* @returns Whether vouchers should be upgraded
*/
getUpgradeUnlockedVouchers(): boolean {
return timedEvents.some((te) => this.isActive(te) && (te.upgradeUnlockedVouchers ?? false));
}
/**
* For events where Delibirdy gives extra items
* @returns list of ids of {@linkcode ModifierType}s that Delibirdy hands out as a bonus
*/
getDelibirdyBuff(): string[] {
const ret: string[] = [];
timedEvents.filter((te) => this.isActive(te)).map((te) => {
if (!isNullOrUndefined(te.delibirdyBuff)) {
ret.push(...te.delibirdyBuff);
}
});
return ret;
}
/**
* For events where there's a set weather for town biome (other biomes are hard)
* @returns Event weathers for town
*/
getWeather(): WeatherPoolEntry[] {
const ret: WeatherPoolEntry[] = [];
timedEvents.filter((te) => this.isActive(te)).map((te) => {
if (!isNullOrUndefined(te.weather)) {
ret.push(...te.weather);
}
});
return ret;
}
getAllMysteryEncounterChanges(): EventMysteryEncounterTier[] {
const ret: EventMysteryEncounterTier[] = [];
timedEvents.filter((te) => this.isActive(te)).map((te) => {
if (!isNullOrUndefined(te.mysteryEncounterTierChanges)) {
ret.push(...te.mysteryEncounterTierChanges);
}
});
return ret;
}
getEventMysteryEncountersDisabled(): MysteryEncounterType[] {
const ret: MysteryEncounterType[] = [];
timedEvents.filter((te) => this.isActive(te) && !isNullOrUndefined(te.mysteryEncounterTierChanges)).map((te) => {
te.mysteryEncounterTierChanges?.map((metc) => {
if (metc.disable) {
ret.push(metc.mysteryEncounter);
}
});
});
return ret;
}
getMysteryEncounterTierForEvent(encounterType: MysteryEncounterType, normal: MysteryEncounterTier): MysteryEncounterTier {
let ret = normal;
timedEvents.filter((te) => this.isActive(te) && !isNullOrUndefined(te.mysteryEncounterTierChanges)).map((te) => {
te.mysteryEncounterTierChanges?.map((metc) => {
if (metc.mysteryEncounter === encounterType) {
ret = metc.tier ?? normal;
}
});
});
return ret;
}
getEventLuckBoost(): number {
let ret = 0;
const luckEvents = timedEvents.filter((te) => this.isActive(te) && !isNullOrUndefined(te.luckBoost));
luckEvents.forEach((le) => {
ret += le.luckBoost!;
});
return ret;
}
getEventLuckBoostedSpecies(): Species[] {
const ret: Species[] = [];
timedEvents.filter((te) => this.isActive(te)).map((te) => {
if (!isNullOrUndefined(te.luckBoostedSpecies)) {
ret.push(...te.luckBoostedSpecies.filter(s => !ret.includes(s)));
}
});
return ret;
}
areFusionsBoosted(): boolean {
return timedEvents.some((te) => this.isActive(te) && te.boostFusions);
}
}
export class TimedEventDisplay extends Phaser.GameObjects.Container {
private event: TimedEvent | nil;
private eventTimerText: Phaser.GameObjects.Text;
private banner: Phaser.GameObjects.Image;
private availableWidth: number;
private eventTimer: NodeJS.Timeout | null;
constructor(x: number, y: number, event?: TimedEvent) {
super(globalScene, x, y);
this.availableWidth = globalScene.scaledCanvas.width;
this.event = event;
this.setVisible(false);
}
/**
* Set the width that can be used to display the event timer and banner. By default
* these elements get centered horizontally in that space, in the bottom left of the screen
*/
setWidth(width: number) {
if (width !== this.availableWidth) {
this.availableWidth = width;
const xPosition = this.availableWidth / 2 + (this.event?.xOffset ?? 0);
if (this.banner) {
this.banner.x = xPosition;
}
if (this.eventTimerText) {
this.eventTimerText.x = xPosition;
}
}
}
setup() {
const lang = i18next.resolvedLanguage;
if (this.event && this.event.bannerKey) {
let key = this.event.bannerKey;
if (lang && this.event.availableLangs && this.event.availableLangs.length > 0) {
if (this.event.availableLangs.includes(lang)) {
key += lang;
} else {
key += "en";
}
}
console.log(this.event.bannerKey);
const padding = 5;
const showTimer = this.event.eventType !== EventType.NO_TIMER_DISPLAY;
const yPosition = globalScene.game.canvas.height / 6 - padding - (showTimer ? 10 : 0) - (this.event.yOffset ?? 0);
this.banner = new Phaser.GameObjects.Image(globalScene, this.availableWidth / 2, yPosition - padding, key);
this.banner.setName("img-event-banner");
this.banner.setOrigin(0.5, 1);
this.banner.setScale(this.event.scale ?? 0.18);
if (showTimer) {
this.eventTimerText = addTextObject(
this.banner.x,
this.banner.y + 2,
this.timeToGo(this.event.endDate),
TextStyle.WINDOW
);
this.eventTimerText.setName("text-event-timer");
this.eventTimerText.setScale(0.15);
this.eventTimerText.setOrigin(0.5, 0);
this.add(this.eventTimerText);
}
this.add(this.banner);
}
}
show() {
this.setVisible(true);
this.updateCountdown();
this.eventTimer = setInterval(() => {
this.updateCountdown();
}, 1000);
}
clear() {
this.setVisible(false);
this.eventTimer && clearInterval(this.eventTimer);
this.eventTimer = null;
}
private timeToGo(date: Date) {
// Utility to add leading zero
function z(n) {
return (n < 10 ? "0" : "") + n;
}
const now = new Date();
let diff = Math.abs(date.getTime() - now.getTime());
// Allow for previous times
diff = Math.abs(diff);
// Get time components
const days = diff / 8.64e7 | 0;
const hours = diff % 8.64e7 / 3.6e6 | 0;
const mins = diff % 3.6e6 / 6e4 | 0;
const secs = Math.round(diff % 6e4 / 1e3);
// Return formatted string
return i18next.t("menu:eventTimer", { days: z(days), hours: z(hours), mins: z(mins), secs: z(secs) });
}
updateCountdown() {
if (this.event && this.event.eventType !== EventType.NO_TIMER_DISPLAY) {
this.eventTimerText.setText(this.timeToGo(this.event.endDate));
}
}
}