Skip to content

Commit 543c208

Browse files
twobiersholzmaster
andauthored
Add default attributes to loot templates (#490)
* Add default attributes to loot templates * Format * Rename `defaultAttributes` to `initialAttributes` * Update src/storage/loot.ts --------- Co-authored-by: holzmaster <[email protected]>
1 parent 3a7cb08 commit 543c208

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

src/service/lootData.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export const lootTemplates: LootTemplate[] = [
8585
dropDescription: "Awww",
8686
emote: ":catsmile:",
8787
asset: "assets/loot/01-kadse.jpg",
88+
initialAttributes: [LootAttributeKindId.SWEET],
8889
attributeAsset: {
8990
[LootAttributeKindId.RADIOACTIVE]: "assets/loot/attributes/01-kadse-verstrahlt.jpg",
9091
},
@@ -484,6 +485,7 @@ export const lootTemplates: LootTemplate[] = [
484485
dropDescription: "Bóbr kurwa! Ja pierdolę! Jakie bydlę!",
485486
emote: ":beaver:",
486487
asset: "assets/loot/36-biber.jpg",
488+
initialAttributes: [LootAttributeKindId.SWEET],
487489
},
488490
] as const;
489491

src/service/lootDrop.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,6 @@ export async function postLootDrop(
182182
return;
183183
}
184184

185-
await awardPostDropLootAttributes(claimedLoot);
186-
187185
await reply.delete();
188186

189187
log.info(
@@ -284,13 +282,3 @@ async function getDropWeightAdjustments(
284282
weights: newWeights,
285283
};
286284
}
287-
288-
async function awardPostDropLootAttributes(loot: Loot) {
289-
switch (loot.lootKindId) {
290-
case LootKindId.KADSE:
291-
await lootService.addLootAttributeIfNotPresent(loot.id, LootAttributeKindId.SWEET);
292-
break;
293-
default:
294-
break;
295-
}
296-
}

src/storage/loot.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import type {
2020
} from "./db/model.js";
2121

2222
import db from "@db";
23-
import type { LootAttributeKindId } from "@/service/lootData.js";
23+
import { resolveLootAttributeTemplate, type LootAttributeKindId } from "@/service/lootData.js";
2424

2525
export type LootUseCommandInteraction = ChatInputCommandInteraction & {
2626
channel: GuildTextBasedChannel;
@@ -36,6 +36,7 @@ export interface LootTemplate {
3636
emote: string;
3737
excludeFromInventory?: boolean;
3838
effects?: string[];
39+
initialAttributes?: LootAttributeKindId[];
3940

4041
onDrop?: (
4142
context: BotContext,
@@ -110,6 +111,13 @@ export async function createLoot(
110111
.returningAll()
111112
.executeTakeFirstOrThrow();
112113

114+
for (const attributeId of template.initialAttributes ?? []) {
115+
const attribute = resolveLootAttributeTemplate(attributeId);
116+
if (!attribute) continue;
117+
118+
await addLootAttributeIfNotPresent(res.id, attribute, ctx);
119+
}
120+
113121
if (rarityAttribute) {
114122
await addLootAttributeIfNotPresent(res.id, rarityAttribute, ctx);
115123
}

0 commit comments

Comments
 (0)