XFEstudio/SpaceNinjaServer
fix: handle kahl weekly reset while completed kahl mission (#4462)
Two weeks ago (week 649), I tested the impact of the Kahl mission on inventory on the official server and discovered two differences. Firstly, when running the Kahl mission for the first time each week, ResetChallenges = true. Secondly, Kahl reset does not occur at login, but at mission completed. Therefore, this week (week 651), I specifically skipped a week to conduct testing, and also tested whether mission failure affects challengesreset and Kahl reset. It was confirmed that regardless of whether the mission is successful or not, challengesreset will always be set to true, and Kahl reset only occurs after the mission is successful. The original addkahlprocess and kahl weekly reset would cause the client to return ResetChallenges = true and CompletedMission=true whenever the first mission was started, even if you immediately exited. This would trigger the kahl weekly reset when logging in the following week. Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/4462 Reviewed-by: Sainan <63328889+sainan@users.noreply.github.com> Co-authored-by: yhhkevin <235+yhhkevin@noreply.localhost> Co-committed-by: yhhkevin <235+yhhkevin@noreply.localhost>
cb02b999
代码差异
@@ -62,7 +62,7 @@ import {
version_compare
} from "../../helpers/inventoryHelpers.ts";
import { Inbox } from "../../models/inboxModel.ts";
import { KAHL_EPOCH, unixTimesInMs } from "../../constants/timeConstants.ts";
import { unixTimesInMs } from "../../constants/timeConstants.ts";
import { DailyDeal } from "../../models/worldStateModel.ts";
import { eEquipmentFeatures } from "../../types/equipmentTypes.ts";
import { generateRewardSeed } from "../../services/rngService.ts";
@@ -160,31 +160,6 @@ export const inventoryController: RequestHandler = async (request, response) =>
suit.ExtraRemaining = undefined;
}
}
// Handle weekly reset
const lastLoginWeek = Math.trunc(
(inventory.NextRefill.getTime() - (86400000 + KAHL_EPOCH)) / unixTimesInMs.week
);
const currentWeek = Math.trunc((Date.now() - KAHL_EPOCH) / unixTimesInMs.week);
if (lastLoginWeek != currentWeek) {
const kahl = inventory.Affiliations.find(x => x.Tag == "KahlSyndicate");
if (kahl && kahl.WeeklyMissions) {
const mission = kahl.WeeklyMissions[kahl.WeeklyMissions.length - 1];
if (mission.CompletedMission) {
if (kahl.WeeklyMissions.length == 2) {
kahl.WeeklyMissions.splice(0, 1);
}
mission.ChallengesReset = true;
kahl.WeeklyMissions.push({
MissionIndex: mission.MissionIndex + 1,
CompletedMission: false,
JobManifest: "/Lotus/Syndicates/Kahl/KahlJobManifestVersionThree",
Challenges: [],
WeekCount: currentWeek
});
}
}
}
}
// TODO: Setup CalendarProgress as part of 1999 mission completion?
@@ -2873,6 +2873,31 @@ export const addCalendarProgress = (inventory: TInventoryDatabaseDocument, value
checkCalendarAutoAdvance(inventory, currentSeason);
};
export const resetKahlWeeklyMission = (
inventory: Pick<TInventoryDatabaseDocument, "Affiliations">,
value: string
): void => {
const currentWeek = Math.trunc((Date.now() - KAHL_EPOCH) / unixTimesInMs.week);
const kahl = inventory.Affiliations.find(x => x.Tag == "KahlSyndicate");
if (kahl && kahl.WeeklyMissions) {
const index = kahl.WeeklyMissions.findIndex(i => i.WeekCount == Number(value.slice("KahlSyndicate_".length)));
if (index !== -1) {
logger.debug(`kahl weekly mission completed, handling weekly reset`);
kahl.WeeklyMissions[index].CompletedMission = true;
if (kahl.WeeklyMissions.findIndex(i => i.WeekCount == currentWeek + 1) == -1) {
kahl.WeeklyMissions.splice(0, kahl.WeeklyMissions.length, kahl.WeeklyMissions[index]);
kahl.WeeklyMissions.push({
MissionIndex: kahl.WeeklyMissions[kahl.WeeklyMissions.length - 1].MissionIndex + 1,
CompletedMission: false,
JobManifest: "/Lotus/Syndicates/Kahl/KahlJobManifestVersionThree",
Challenges: [],
WeekCount: currentWeek + 1
});
}
}
}
};
export const addKahlProgress = (
inventory: Pick<TInventoryDatabaseDocument, "Affiliations" | "MiscItems">,
value: IWeeklyMissionChallengeInfo[],
@@ -2881,9 +2906,9 @@ export const addKahlProgress = (
for (const info of value) {
let stockEarned = 0;
const kahl = inventory.Affiliations.find(x => x.Tag == info.Syndicate)!;
const mission = kahl.WeeklyMissions![kahl.WeeklyMissions!.length - 1];
const mission = kahl.WeeklyMissions!.find(i => i.WeekCount == info.WeekCount)!;
if (info.ResetChallenges) {
mission.CompletedMission = true;
mission.ChallengesReset = true;
}
for (const challenge of info.CompletedChallenges) {
if (mission.Challenges.indexOf(challenge) == -1) {
@@ -59,6 +59,7 @@ import {
giveThousandYearFishDeco,
isEligibleForThousandYearFishDeco,
processGoalProgressUpdates,
resetKahlWeeklyMission,
updateCurrency,
updateEntratiVault,
updateIncentiveStates,
@@ -675,6 +676,9 @@ export const addMissionInventoryUpdates = async (
if (!inventory.syndicateMissionsRepeatable && !inventory.CompletedSyndicates.includes(value)) {
inventory.CompletedSyndicates.push(value);
}
if (value.includes("KahlSyndicate")) {
resetKahlWeeklyMission(inventory, value);
}
break;
}
case "SortieId": {