diff --git a/src/service/lootData.ts b/src/service/lootData.ts index acc2a152..7dcb2267 100644 --- a/src/service/lootData.ts +++ b/src/service/lootData.ts @@ -137,6 +137,9 @@ export const lootTemplateMap: Record = { [LootKind.DOENER]: { id: LootKind.DOENER, weight: 5, + timeBasedWeight: { + evening: 10, + }, displayName: "Döner", titleText: "Einen Döner", dropDescription: "Bewahre ihn gut als Geldanlage auf!", @@ -156,6 +159,9 @@ export const lootTemplateMap: Record = { [LootKind.KRANKSCHREIBUNG]: { id: LootKind.KRANKSCHREIBUNG, weight: 0.5, + timeBasedWeight: { + morning: 1, + }, displayName: "Arbeitsunfähigkeitsbescheinigung", titleText: "Einen gelben Urlaubsschein", dropDescription: "Benutze ihn weise!", @@ -222,6 +228,9 @@ export const lootTemplateMap: Record = { [LootKind.AYRAN]: { id: LootKind.AYRAN, weight: 1, + timeBasedWeight: { + evening: 2, + }, displayName: "Ayran", titleText: "Einen Ayran", dropDescription: "Der gute von Müller", @@ -242,6 +251,9 @@ export const lootTemplateMap: Record = { [LootKind.TRICHTER]: { id: LootKind.TRICHTER, weight: 1, + timeBasedWeight: { + evening: 2, + }, displayName: "Trichter", titleText: "Einen Trichter", dropDescription: "Für die ganz großen Schlücke", @@ -313,6 +325,9 @@ export const lootTemplateMap: Record = { [LootKind.OETTINGER]: { id: LootKind.OETTINGER, weight: 1, + timeBasedWeight: { + morning: 2, + }, displayName: "Oettinger", titleText: "Ein warmes Oettinger", dropDescription: "Ja dann Prost ne!", @@ -370,6 +385,9 @@ export const lootTemplateMap: Record = { [LootKind.SAHNE]: { id: LootKind.SAHNE, weight: 1, + timeBasedWeight: { + evening: 2, + }, displayName: "Sprühsahne", titleText: "Sprühsahne", dropDescription: "Fürs Frühstück oder so", @@ -414,6 +432,9 @@ export const lootTemplateMap: Record = { [LootKind.GAULOISES_BLAU]: { id: LootKind.GAULOISES_BLAU, weight: 1, + timeBasedWeight: { + evening: 2, + }, displayName: "Gauloises Blau", titleText: "Eine Schachtel Gauloises Blau", dropDescription: @@ -496,6 +517,9 @@ export const lootTemplateMap: Record = { [LootKind.KAFFEEMUEHLE]: { id: LootKind.KAFFEEMUEHLE, weight: 1, + timeBasedWeight: { + morning: 2, + }, displayName: "Kaffeemühle", titleText: "Eine Kaffeemühle für 400€", dropDescription: "Kann Kaffee mühlen. Und das gut. Mit Gold.", diff --git a/src/service/lootDrop.ts b/src/service/lootDrop.ts index cb194b4e..b070eba4 100644 --- a/src/service/lootDrop.ts +++ b/src/service/lootDrop.ts @@ -22,9 +22,10 @@ import * as sentry from "@sentry/node"; import type { BotContext } from "#context.ts"; import type { Loot, LootId } from "#storage/db/model.ts"; -import type { LootTemplate } from "#storage/loot.ts"; +import type { LootTemplate, TimeBasedWeightConfig } from "#storage/loot.ts"; import { randomBoolean, randomEntry, randomEntryWeighted } from "#service/random.ts"; import * as timeUtils from "#utils/time.ts"; +import { zonedNow } from "#utils/dateUtils.ts"; import * as lootService from "#service/loot.ts"; import { @@ -154,7 +155,12 @@ export async function postLootDrop( return; } - const defaultWeights = lootTemplates.map(t => t.weight); + const timeBasedWeightKey = getCurrentTimeBasedKey(); + + const defaultWeights = timeBasedWeightKey + ? lootTemplates.map(t => t.timeBasedWeight?.[timeBasedWeightKey] ?? t.weight) + : lootTemplates.map(t => t.weight); + const { messages, weights } = await getDropWeightAdjustments(interaction.user, defaultWeights); const template = randomEntryWeighted(lootTemplates, weights); @@ -358,6 +364,22 @@ export async function createDropTakenContent( }; } +function getCurrentTimeBasedKey(): keyof TimeBasedWeightConfig | undefined { + // Caution: using a ZonedDateTime and comparing the hour to the raw values breaks when daylight-saving-time happens (an hour can happen multiple times) + // We disregard these edge-cases, but keep it in mind + const hour = zonedNow().hour; + + // :shibakek: + switch (true) { + case 6 <= hour && hour <= 12: + return "morning"; + case 18 <= hour && hour <= 24: + return "evening"; + default: + return undefined; + } +} + type AdjustmentResult = { messages: string[]; weights: number[]; diff --git a/src/storage/loot.ts b/src/storage/loot.ts index 944ba889..e6c325d7 100644 --- a/src/storage/loot.ts +++ b/src/storage/loot.ts @@ -32,9 +32,15 @@ export type LootUseCommandInteraction = ChatInputCommandInteraction & { channel: GuildTextBasedChannel; }; +export interface TimeBasedWeightConfig { + morning?: number; + evening?: number; +} + export interface LootTemplate { id: LootKindId; weight: number; + timeBasedWeight?: TimeBasedWeightConfig; displayName: string; titleText: string; dropDescription: string;