From ae1026df67eaa728e4a00ef73c39d3df32a5b1d7 Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Sun, 6 Jul 2025 07:17:39 +0200 Subject: [PATCH 1/2] fix: ensure nightwave weekly challenges are unique --- src/services/worldStateService.ts | 68 +++++++++++++++++++------------ 1 file changed, 41 insertions(+), 27 deletions(-) diff --git a/src/services/worldStateService.ts b/src/services/worldStateService.ts index cd4139ac..dac84c0f 100644 --- a/src/services/worldStateService.ts +++ b/src/services/worldStateService.ts @@ -395,34 +395,48 @@ const getSeasonDailyChallenge = (pools: IRotatingSeasonChallengePools, day: numb }; }; -const getSeasonWeeklyChallenge = (pools: IRotatingSeasonChallengePools, week: number, id: number): ISeasonChallenge => { - const weekStart = EPOCH + week * 604800000; - const weekEnd = weekStart + 604800000; - const challengeId = week * 7 + id; - const rng = new SRng(new SRng(challengeId).randomInt(0, 100_000)); - return { - _id: { $oid: "67e1bb2d9d00cb47" + challengeId.toString().padStart(8, "0") }, - Activation: { $date: { $numberLong: weekStart.toString() } }, - Expiry: { $date: { $numberLong: weekEnd.toString() } }, - Challenge: rng.randomElement(pools.weekly)! - }; -}; - -const getSeasonWeeklyHardChallenge = ( +const pushSeasonWeeklyChallenge = ( + activeChallenges: ISeasonChallenge[], pools: IRotatingSeasonChallengePools, week: number, id: number -): ISeasonChallenge => { +): void => { const weekStart = EPOCH + week * 604800000; const weekEnd = weekStart + 604800000; const challengeId = week * 7 + id; const rng = new SRng(new SRng(challengeId).randomInt(0, 100_000)); - return { + let challenge: string; + do { + challenge = rng.randomElement(pools.weekly)!; + } while (activeChallenges.some(x => x.Challenge == challenge)); + activeChallenges.push({ _id: { $oid: "67e1bb2d9d00cb47" + challengeId.toString().padStart(8, "0") }, Activation: { $date: { $numberLong: weekStart.toString() } }, Expiry: { $date: { $numberLong: weekEnd.toString() } }, - Challenge: rng.randomElement(pools.hardWeekly)! - }; + Challenge: challenge + }); +}; + +const pushSeasonWeeklyHardChallenge = ( + activeChallenges: ISeasonChallenge[], + pools: IRotatingSeasonChallengePools, + week: number, + id: number +): void => { + const weekStart = EPOCH + week * 604800000; + const weekEnd = weekStart + 604800000; + const challengeId = week * 7 + id; + const rng = new SRng(new SRng(challengeId).randomInt(0, 100_000)); + let challenge: string; + do { + challenge = rng.randomElement(pools.hardWeekly)!; + } while (activeChallenges.some(x => x.Challenge == challenge)); + activeChallenges.push({ + _id: { $oid: "67e1bb2d9d00cb47" + challengeId.toString().padStart(8, "0") }, + Activation: { $date: { $numberLong: weekStart.toString() } }, + Expiry: { $date: { $numberLong: weekEnd.toString() } }, + Challenge: challenge + }); }; const pushWeeklyActs = ( @@ -433,8 +447,8 @@ const pushWeeklyActs = ( const weekStart = EPOCH + week * 604800000; const weekEnd = weekStart + 604800000; - activeChallenges.push(getSeasonWeeklyChallenge(pools, week, 0)); - activeChallenges.push(getSeasonWeeklyChallenge(pools, week, 1)); + pushSeasonWeeklyChallenge(activeChallenges, pools, week, 0); + pushSeasonWeeklyChallenge(activeChallenges, pools, week, 1); if (pools.hasWeeklyPermanent) { activeChallenges.push({ _id: { $oid: "67e1b96e9d00cb47" + (week * 7 + 0).toString().padStart(8, "0") }, @@ -454,14 +468,14 @@ const pushWeeklyActs = ( Expiry: { $date: { $numberLong: weekEnd.toString() } }, Challenge: "/Lotus/Types/Challenges/Seasons/Weekly/SeasonWeeklyPermanentKillEnemies" }); - activeChallenges.push(getSeasonWeeklyHardChallenge(pools, week, 2)); - activeChallenges.push(getSeasonWeeklyHardChallenge(pools, week, 3)); + pushSeasonWeeklyHardChallenge(activeChallenges, pools, week, 2); + pushSeasonWeeklyHardChallenge(activeChallenges, pools, week, 3); } else { - activeChallenges.push(getSeasonWeeklyChallenge(pools, week, 2)); - activeChallenges.push(getSeasonWeeklyChallenge(pools, week, 3)); - activeChallenges.push(getSeasonWeeklyChallenge(pools, week, 4)); - activeChallenges.push(getSeasonWeeklyHardChallenge(pools, week, 5)); - activeChallenges.push(getSeasonWeeklyHardChallenge(pools, week, 6)); + pushSeasonWeeklyChallenge(activeChallenges, pools, week, 2); + pushSeasonWeeklyChallenge(activeChallenges, pools, week, 3); + pushSeasonWeeklyChallenge(activeChallenges, pools, week, 4); + pushSeasonWeeklyHardChallenge(activeChallenges, pools, week, 5); + pushSeasonWeeklyHardChallenge(activeChallenges, pools, week, 6); } }; -- 2.47.2 From 5b325c48002744736a582d63637e5f8a9b71e985 Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Sun, 6 Jul 2025 07:19:32 +0200 Subject: [PATCH 2/2] fix code duplication --- src/services/worldStateService.ts | 44 ++++++++----------------------- 1 file changed, 11 insertions(+), 33 deletions(-) diff --git a/src/services/worldStateService.ts b/src/services/worldStateService.ts index dac84c0f..8eb141d9 100644 --- a/src/services/worldStateService.ts +++ b/src/services/worldStateService.ts @@ -397,7 +397,7 @@ const getSeasonDailyChallenge = (pools: IRotatingSeasonChallengePools, day: numb const pushSeasonWeeklyChallenge = ( activeChallenges: ISeasonChallenge[], - pools: IRotatingSeasonChallengePools, + pool: string[], week: number, id: number ): void => { @@ -407,29 +407,7 @@ const pushSeasonWeeklyChallenge = ( const rng = new SRng(new SRng(challengeId).randomInt(0, 100_000)); let challenge: string; do { - challenge = rng.randomElement(pools.weekly)!; - } while (activeChallenges.some(x => x.Challenge == challenge)); - activeChallenges.push({ - _id: { $oid: "67e1bb2d9d00cb47" + challengeId.toString().padStart(8, "0") }, - Activation: { $date: { $numberLong: weekStart.toString() } }, - Expiry: { $date: { $numberLong: weekEnd.toString() } }, - Challenge: challenge - }); -}; - -const pushSeasonWeeklyHardChallenge = ( - activeChallenges: ISeasonChallenge[], - pools: IRotatingSeasonChallengePools, - week: number, - id: number -): void => { - const weekStart = EPOCH + week * 604800000; - const weekEnd = weekStart + 604800000; - const challengeId = week * 7 + id; - const rng = new SRng(new SRng(challengeId).randomInt(0, 100_000)); - let challenge: string; - do { - challenge = rng.randomElement(pools.hardWeekly)!; + challenge = rng.randomElement(pool)!; } while (activeChallenges.some(x => x.Challenge == challenge)); activeChallenges.push({ _id: { $oid: "67e1bb2d9d00cb47" + challengeId.toString().padStart(8, "0") }, @@ -447,8 +425,8 @@ const pushWeeklyActs = ( const weekStart = EPOCH + week * 604800000; const weekEnd = weekStart + 604800000; - pushSeasonWeeklyChallenge(activeChallenges, pools, week, 0); - pushSeasonWeeklyChallenge(activeChallenges, pools, week, 1); + pushSeasonWeeklyChallenge(activeChallenges, pools.weekly, week, 0); + pushSeasonWeeklyChallenge(activeChallenges, pools.weekly, week, 1); if (pools.hasWeeklyPermanent) { activeChallenges.push({ _id: { $oid: "67e1b96e9d00cb47" + (week * 7 + 0).toString().padStart(8, "0") }, @@ -468,14 +446,14 @@ const pushWeeklyActs = ( Expiry: { $date: { $numberLong: weekEnd.toString() } }, Challenge: "/Lotus/Types/Challenges/Seasons/Weekly/SeasonWeeklyPermanentKillEnemies" }); - pushSeasonWeeklyHardChallenge(activeChallenges, pools, week, 2); - pushSeasonWeeklyHardChallenge(activeChallenges, pools, week, 3); + pushSeasonWeeklyChallenge(activeChallenges, pools.hardWeekly, week, 2); + pushSeasonWeeklyChallenge(activeChallenges, pools.hardWeekly, week, 3); } else { - pushSeasonWeeklyChallenge(activeChallenges, pools, week, 2); - pushSeasonWeeklyChallenge(activeChallenges, pools, week, 3); - pushSeasonWeeklyChallenge(activeChallenges, pools, week, 4); - pushSeasonWeeklyHardChallenge(activeChallenges, pools, week, 5); - pushSeasonWeeklyHardChallenge(activeChallenges, pools, week, 6); + pushSeasonWeeklyChallenge(activeChallenges, pools.weekly, week, 2); + pushSeasonWeeklyChallenge(activeChallenges, pools.weekly, week, 3); + pushSeasonWeeklyChallenge(activeChallenges, pools.weekly, week, 4); + pushSeasonWeeklyChallenge(activeChallenges, pools.hardWeekly, week, 5); + pushSeasonWeeklyChallenge(activeChallenges, pools.hardWeekly, week, 6); } }; -- 2.47.2