Skip to content

Commit

Permalink
Implement penalty for radioactive waste
Browse files Browse the repository at this point in the history
  • Loading branch information
holzmaster committed Sep 6, 2024
1 parent a211ac4 commit f3d1f62
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/service/loot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ async function postLootDrop(context: BotContext, channel: GuildBasedChannel & Te

const defaultWeights = lootTemplates.map(t => t.weight);

const weights = await getDropWeightAdjustments(interaction.user, defaultWeights);
const { messages, weights } = await getDropWeightAdjustments(interaction.user, defaultWeights);

const template = randomEntryWeighted(lootTemplates, weights);
const l = await loot.createLoot(template, validUntil, message);
Expand Down Expand Up @@ -557,7 +557,7 @@ async function postLootDrop(context: BotContext, channel: GuildBasedChannel & Te
}
: undefined,
footer: {
text: `🎉 ${winner.displayName} hat das Geschenk geöffnet`,
text: `🎉 ${winner.displayName} hat das Geschenk geöffnet\n${messages.join("\n")}`.trim(),
},
},
],
Expand Down Expand Up @@ -632,6 +632,29 @@ export function transferLootToUser(lootId: number, user: User) {
return loot.transferLootToUser(lootId, user.id);
}

async function getDropWeightAdjustments(user: User, weights: readonly number[]): Promise<number[]> {
return [...weights]; // TODO: User penalties
type AdjustmentResult = {
messages: string[];
weights: number[];
};

async function getDropWeightAdjustments(
user: User,
weights: readonly number[],
): Promise<AdjustmentResult> {
const waste = await getUserLootsById(user, LootTypeId.RADIOACTIVE_WASTE);
const messages = [];

let wasteFactor = 1;
if (waste.length > 0) {
const wasteDropPenalty = 1.05;
wasteFactor = Math.min(2, waste.length ** wasteDropPenalty);
messages.push(
"Du hast schon radioaktiven Müll, deshalb ist die Chance auf ein Geschenk geringer.",
);
}

return {
messages,
weights: [Math.ceil(weights[0] * wasteFactor) | 0, ...weights.slice(1)],
};
}

0 comments on commit f3d1f62

Please sign in to comment.