Fix give command not working on armor presets and not marking presets as FiR (!250)

- Commando `give` command now handles all presets in the same way, so if BSG adds new types of presets in the future they should be supported without changes
- Commando `give` command now marks all given items as FiR for consistency

Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com>
Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/250
Co-authored-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
Co-committed-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
This commit is contained in:
DrakiaXYZ 2024-03-07 08:43:15 +00:00 committed by chomp
parent c0ae34052b
commit 246f0d5030
2 changed files with 23 additions and 12 deletions

View File

@ -88,19 +88,9 @@ export class GiveSptCommand implements ISptCommand
} }
const itemsToSend: Item[] = []; const itemsToSend: Item[] = [];
if (this.itemHelper.isOfBaseclass(checkedItem[1]._id, BaseClasses.WEAPON)) const preset = this.presetHelper.getDefaultPreset(checkedItem[1]._id);
if (preset)
{ {
const preset = this.presetHelper.getDefaultPreset(checkedItem[1]._id);
if (!preset)
{
this.mailSendService.sendUserMessageToPlayer(
sessionId,
commandHandler,
"Invalid weapon template ID requested. There are no default presets for this weapon.",
);
return request.dialogId;
}
for (let i = 0; i < +quantity; i++) for (let i = 0; i < +quantity; i++)
{ {
// Make sure IDs are unique before adding to array - prevent collisions // Make sure IDs are unique before adding to array - prevent collisions
@ -128,6 +118,9 @@ export class GiveSptCommand implements ISptCommand
itemsToSend.push(...this.itemHelper.splitStack(item)); itemsToSend.push(...this.itemHelper.splitStack(item));
} }
// Flag the items as FiR
this.itemHelper.setFoundInRaid(itemsToSend);
this.mailSendService.sendSystemMessageToPlayer(sessionId, "Give command!", itemsToSend); this.mailSendService.sendSystemMessageToPlayer(sessionId, "Give command!", itemsToSend);
return request.dialogId; return request.dialogId;
} }

View File

@ -809,6 +809,24 @@ export class ItemHelper
return items; return items;
} }
/**
* Mark the passed in array of items as found in raid.
* Modifies passed in items
* @param items The list of items to mark as FiR
*/
public setFoundInRaid(items: Item[]): void
{
for (const item of items)
{
if (!item.upd)
{
item.upd = {};
}
item.upd.SpawnedInSession = true;
}
}
/** /**
* WARNING, SLOW. Recursively loop down through an items hierarchy to see if any of the ids match the supplied list, return true if any do * WARNING, SLOW. Recursively loop down through an items hierarchy to see if any of the ids match the supplied list, return true if any do
* @param {string} tpl Items tpl to check parents of * @param {string} tpl Items tpl to check parents of