Skip to content

Commit

Permalink
Add default attributes to loot templates (#490)
Browse files Browse the repository at this point in the history
* Add default attributes to loot templates

* Format

* Rename `defaultAttributes` to `initialAttributes`

* Update src/storage/loot.ts

---------

Co-authored-by: holzmaster <[email protected]>
  • Loading branch information
twobiers and holzmaster authored Nov 26, 2024
1 parent 3a7cb08 commit 543c208
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/service/lootData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export const lootTemplates: LootTemplate[] = [
dropDescription: "Awww",
emote: ":catsmile:",
asset: "assets/loot/01-kadse.jpg",
initialAttributes: [LootAttributeKindId.SWEET],
attributeAsset: {
[LootAttributeKindId.RADIOACTIVE]: "assets/loot/attributes/01-kadse-verstrahlt.jpg",
},
Expand Down Expand Up @@ -484,6 +485,7 @@ export const lootTemplates: LootTemplate[] = [
dropDescription: "Bóbr kurwa! Ja pierdolę! Jakie bydlę!",
emote: ":beaver:",
asset: "assets/loot/36-biber.jpg",
initialAttributes: [LootAttributeKindId.SWEET],
},
] as const;

Expand Down
12 changes: 0 additions & 12 deletions src/service/lootDrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,6 @@ export async function postLootDrop(
return;
}

await awardPostDropLootAttributes(claimedLoot);

await reply.delete();

log.info(
Expand Down Expand Up @@ -284,13 +282,3 @@ async function getDropWeightAdjustments(
weights: newWeights,
};
}

async function awardPostDropLootAttributes(loot: Loot) {
switch (loot.lootKindId) {
case LootKindId.KADSE:
await lootService.addLootAttributeIfNotPresent(loot.id, LootAttributeKindId.SWEET);
break;
default:
break;
}
}
10 changes: 9 additions & 1 deletion src/storage/loot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type {
} from "./db/model.js";

import db from "@db";
import type { LootAttributeKindId } from "@/service/lootData.js";
import { resolveLootAttributeTemplate, type LootAttributeKindId } from "@/service/lootData.js";

export type LootUseCommandInteraction = ChatInputCommandInteraction & {
channel: GuildTextBasedChannel;
Expand All @@ -36,6 +36,7 @@ export interface LootTemplate {
emote: string;
excludeFromInventory?: boolean;
effects?: string[];
initialAttributes?: LootAttributeKindId[];

onDrop?: (
context: BotContext,
Expand Down Expand Up @@ -110,6 +111,13 @@ export async function createLoot(
.returningAll()
.executeTakeFirstOrThrow();

for (const attributeId of template.initialAttributes ?? []) {
const attribute = resolveLootAttributeTemplate(attributeId);
if (!attribute) continue;

await addLootAttributeIfNotPresent(res.id, attribute, ctx);
}

if (rarityAttribute) {
await addLootAttributeIfNotPresent(res.id, rarityAttribute, ctx);
}
Expand Down

0 comments on commit 543c208

Please sign in to comment.