feat: galleon of ghouls #2280
@ -21,13 +21,14 @@ import mongoose from "mongoose";
 | 
			
		||||
import { JSONStringify } from "json-with-bigint";
 | 
			
		||||
import { startWebServer } from "./services/webService";
 | 
			
		||||
 | 
			
		||||
import { validateConfig } from "@/src/services/configWatcherService";
 | 
			
		||||
import { syncConfigWithDatabase, validateConfig } from "@/src/services/configWatcherService";
 | 
			
		||||
import { updateWorldStateCollections } from "./services/worldStateService";
 | 
			
		||||
 | 
			
		||||
// Patch JSON.stringify to work flawlessly with Bigints.
 | 
			
		||||
JSON.stringify = JSONStringify;
 | 
			
		||||
 | 
			
		||||
validateConfig();
 | 
			
		||||
syncConfigWithDatabase();
 | 
			
		||||
 | 
			
		||||
mongoose
 | 
			
		||||
    .connect(config.mongodbUrl)
 | 
			
		||||
 | 
			
		||||
@ -27,11 +27,12 @@ export interface IMessage {
 | 
			
		||||
    icon?: string;
 | 
			
		||||
    highPriority?: boolean;
 | 
			
		||||
    lowPrioNewPlayers?: boolean;
 | 
			
		||||
    startDate?: Date;
 | 
			
		||||
    endDate?: Date;
 | 
			
		||||
    transmission?: string;
 | 
			
		||||
    att?: string[];
 | 
			
		||||
    countedAtt?: ITypeCount[];
 | 
			
		||||
    transmission?: string;
 | 
			
		||||
    startDate?: Date;
 | 
			
		||||
    endDate?: Date;
 | 
			
		||||
    goalTag?: string;
 | 
			
		||||
    CrossPlatform?: boolean;
 | 
			
		||||
    arg?: Arg[];
 | 
			
		||||
    gifts?: IGift[];
 | 
			
		||||
@ -107,6 +108,7 @@ const messageSchema = new Schema<IMessageDatabase>(
 | 
			
		||||
        lowPrioNewPlayers: Boolean,
 | 
			
		||||
        startDate: Date,
 | 
			
		||||
        endDate: Date,
 | 
			
		||||
        goalTag: String,
 | 
			
		||||
        date: { type: Date, required: true },
 | 
			
		||||
        r: Boolean,
 | 
			
		||||
        CrossPlatform: Boolean,
 | 
			
		||||
 | 
			
		||||
@ -3,6 +3,7 @@ import fsPromises from "fs/promises";
 | 
			
		||||
import { logger } from "../utils/logger";
 | 
			
		||||
import { config, configPath, loadConfig } from "./configService";
 | 
			
		||||
import { getWebPorts, sendWsBroadcast, startWebServer, stopWebServer } from "./webService";
 | 
			
		||||
import { Inbox } from "../models/inboxModel";
 | 
			
		||||
 | 
			
		||||
let amnesia = false;
 | 
			
		||||
fs.watchFile(configPath, (now, then) => {
 | 
			
		||||
@ -22,6 +23,7 @@ fs.watchFile(configPath, (now, then) => {
 | 
			
		||||
            process.exit(1);
 | 
			
		||||
        }
 | 
			
		||||
        validateConfig();
 | 
			
		||||
        syncConfigWithDatabase();
 | 
			
		||||
 | 
			
		||||
        const webPorts = getWebPorts();
 | 
			
		||||
        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) {
 | 
			
		||||
        logger.info(`Updating config file to fix some issues with it.`);
 | 
			
		||||
        void saveConfig();
 | 
			
		||||
@ -61,3 +72,10 @@ export const saveConfig = async (): Promise<void> => {
 | 
			
		||||
    amnesia = true;
 | 
			
		||||
    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" });
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -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) {
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user