feat: galleon of ghouls #2280

Merged
OrdisPrime merged 4 commits from galleon-robberies into main 2025-06-25 08:04:04 -07:00
4 changed files with 41 additions and 4 deletions
Showing only changes of commit 84c116f9bf - Show all commits

View File

@ -21,13 +21,14 @@ import mongoose from "mongoose";
import { JSONStringify } from "json-with-bigint"; import { JSONStringify } from "json-with-bigint";
import { startWebServer } from "./services/webService"; import { startWebServer } from "./services/webService";
import { validateConfig } from "@/src/services/configWatcherService"; import { syncConfigWithDatabase, validateConfig } from "@/src/services/configWatcherService";
import { updateWorldStateCollections } from "./services/worldStateService"; import { updateWorldStateCollections } from "./services/worldStateService";
// Patch JSON.stringify to work flawlessly with Bigints. // Patch JSON.stringify to work flawlessly with Bigints.
JSON.stringify = JSONStringify; JSON.stringify = JSONStringify;
validateConfig(); validateConfig();
syncConfigWithDatabase();
mongoose mongoose
.connect(config.mongodbUrl) .connect(config.mongodbUrl)

View File

@ -27,11 +27,12 @@ export interface IMessage {
icon?: string; icon?: string;
highPriority?: boolean; highPriority?: boolean;
lowPrioNewPlayers?: boolean; lowPrioNewPlayers?: boolean;
startDate?: Date; transmission?: string;
endDate?: Date;
att?: string[]; att?: string[];
countedAtt?: ITypeCount[]; countedAtt?: ITypeCount[];
transmission?: string; startDate?: Date;
endDate?: Date;
goalTag?: string;
CrossPlatform?: boolean; CrossPlatform?: boolean;
arg?: Arg[]; arg?: Arg[];
gifts?: IGift[]; gifts?: IGift[];
@ -107,6 +108,7 @@ const messageSchema = new Schema<IMessageDatabase>(
lowPrioNewPlayers: Boolean, lowPrioNewPlayers: Boolean,
startDate: Date, startDate: Date,
endDate: Date, endDate: Date,
goalTag: String,
date: { type: Date, required: true }, date: { type: Date, required: true },
r: Boolean, r: Boolean,
CrossPlatform: Boolean, CrossPlatform: Boolean,

View File

@ -3,6 +3,7 @@ import fsPromises from "fs/promises";
import { logger } from "../utils/logger"; import { logger } from "../utils/logger";
import { config, configPath, loadConfig } from "./configService"; import { config, configPath, loadConfig } from "./configService";
import { getWebPorts, sendWsBroadcast, startWebServer, stopWebServer } from "./webService"; import { getWebPorts, sendWsBroadcast, startWebServer, stopWebServer } from "./webService";
import { Inbox } from "../models/inboxModel";
let amnesia = false; let amnesia = false;
fs.watchFile(configPath, (now, then) => { fs.watchFile(configPath, (now, then) => {
@ -22,6 +23,7 @@ fs.watchFile(configPath, (now, then) => {
process.exit(1); process.exit(1);
} }
validateConfig(); validateConfig();
syncConfigWithDatabase();
const webPorts = getWebPorts(); const webPorts = getWebPorts();
if (config.httpPort != webPorts.http || config.httpsPort != webPorts.https) { if (config.httpPort != webPorts.http || config.httpsPort != webPorts.https) {
@ -51,6 +53,15 @@ export const validateConfig = (): void => {
} }
} }
} }
if (
config.worldState?.galleonOfGhouls &&
config.worldState.galleonOfGhouls != 1 &&
config.worldState.galleonOfGhouls != 2 &&
config.worldState.galleonOfGhouls != 3
) {
config.worldState.galleonOfGhouls = 0;
modified = true;
}
if (modified) { if (modified) {
logger.info(`Updating config file to fix some issues with it.`); logger.info(`Updating config file to fix some issues with it.`);
void saveConfig(); void saveConfig();
@ -61,3 +72,10 @@ export const saveConfig = async (): Promise<void> => {
amnesia = true; amnesia = true;
await fsPromises.writeFile(configPath, JSON.stringify(config, null, 2)); await fsPromises.writeFile(configPath, JSON.stringify(config, null, 2));
}; };
export const syncConfigWithDatabase = (): void => {
// Event messages are deleted after endDate. Since we don't use beginDate/endDate and instead have config toggles, we need to delete the messages once those bools are false.
if (!config.worldState?.galleonOfGhouls) {
void Inbox.deleteMany({ goalTag: "GalleonRobbery" });
}
};

View File

@ -54,6 +54,22 @@ export const createNewEventMessages = async (req: Request): Promise<void> => {
}); });
} }
// BUG: Deleting the inbox message manually means it'll just be automatically re-created. This is because we don't use startDate/endDate for these config-toggled events.
if (config.worldState?.galleonOfGhouls) {
if (!(await Inbox.exists({ ownerId: account._id, goalTag: "GalleonRobbery" }))) {
newEventMessages.push({
sndr: "/Lotus/Language/Bosses/BossCouncilorVayHek",
sub: "/Lotus/Language/Events/GalleonRobberyIntroMsgTitle",
msg: "/Lotus/Language/Events/GalleonRobberyIntroMsgDesc",
icon: "/Lotus/Interface/Icons/Npcs/VayHekPortrait.png",
transmission: "/Lotus/Sounds/Dialog/GalleonOfGhouls/DGhoulsWeekOneInbox0010VayHek",
att: ["/Lotus/Upgrades/Skins/Events/OgrisOldSchool"],
startDate: new Date(),
goalTag: "GalleonRobbery"
});
}
}
if (newEventMessages.length === 0) { if (newEventMessages.length === 0) {
return; return;
} }