Skip to content

Commit

Permalink
Fixed processItemsBeforeAddingToMail compile error
Browse files Browse the repository at this point in the history
  • Loading branch information
Chomp committed Jan 16, 2025
1 parent 91f1271 commit 7a9a06e
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions project/src/services/MailSendService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class MailSendService {
@inject("LocalisationService") protected localisationService: LocalisationService,
@inject("ItemHelper") protected itemHelper: ItemHelper,
@inject("TraderHelper") protected traderHelper: TraderHelper,
) { }
) {}

/**
* Send a message from an NPC (e.g. prapor) to the player with or without items using direct message text, do not look up any locale
Expand Down Expand Up @@ -451,13 +451,14 @@ export class MailSendService {
parentItem.parentId = this.hashUtil.generate();
}

// Prep return object
itemsToSendToPlayer = { stash: parentItem.parentId, data: [] };

// Ensure Ids are unique and cont collide with items in player inventory later
messageDetails.items = this.itemHelper.replaceIDs(messageDetails.items);

// Ensure item exits in items db
for (const reward of messageDetails.items) {
// Ensure item exists in items db
const itemTemplate = items[reward._tpl];
if (!itemTemplate) {
// Can happen when modded items are insured + mod is removed
Expand All @@ -481,15 +482,19 @@ export class MailSendService {
// Ammo boxes should contain sub-items
if (this.itemHelper.isOfBaseclass(itemTemplate._id, BaseClasses.AMMO_BOX)) {
const childItems = itemsToSendToPlayer.data?.filter((x) => x.parentId === reward._id);
if (childItems.length > 0) {
// Ammo box reward already has ammo, don't add
itemsToSendToPlayer.data.push(reward);
} else {
if (childItems?.length === 0) {
// No cartridges found, generate and add to rewards
const boxAndCartridges: IItem[] = [reward];
this.itemHelper.addCartridgesToAmmoBox(boxAndCartridges, itemTemplate);

// Push box + cartridge children into array
itemsToSendToPlayer.data.push(...boxAndCartridges);

continue;
}
// Push box + cartridge children into array
itemsToSendToPlayer.data.push(...boxAndCartridges);

// Ammo box reward already has ammo, don't do anything extra
itemsToSendToPlayer.data.push(reward);
} else {
if ("StackSlots" in itemTemplate._props) {
this.logger.error(
Expand Down

0 comments on commit 7a9a06e

Please sign in to comment.