mirror of
https://github.com/sp-tarkov/server.git
synced 2025-02-13 02:30:43 -05:00
Refactor InRaidHelper.deleteInventory()
This commit is contained in:
parent
a1e7f21a59
commit
d6bb12a3a2
@ -322,36 +322,52 @@ export class InRaidHelper
|
|||||||
*/
|
*/
|
||||||
public deleteInventory(pmcData: IPmcData, sessionID: string): void
|
public deleteInventory(pmcData: IPmcData, sessionID: string): void
|
||||||
{
|
{
|
||||||
const toDelete = [];
|
// Get inventory item ids to remove from players profile
|
||||||
for (const item of pmcData.Inventory.items)
|
const itemIdsToDeleteFromProfile = this.getInventoryItemsLostOnDeath(pmcData).map(x => x._id);
|
||||||
|
itemIdsToDeleteFromProfile.forEach(x =>
|
||||||
{
|
{
|
||||||
if (this.isItemKeptAfterDeath(pmcData, item))
|
this.inventoryHelper.removeItem(pmcData, x, sessionID);
|
||||||
{
|
});
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove normal items or quest raid items
|
|
||||||
if (item.parentId === pmcData.Inventory.equipment
|
|
||||||
|| item.parentId === pmcData.Inventory.questRaidItems)
|
|
||||||
{
|
|
||||||
toDelete.push(item._id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.slotId.startsWith("pocket"))
|
|
||||||
{
|
|
||||||
toDelete.push(item._id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete items flagged above
|
|
||||||
for (const item of toDelete)
|
|
||||||
{
|
|
||||||
this.inventoryHelper.removeItem(pmcData, item, sessionID);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Remove contents of fast panel
|
||||||
pmcData.Inventory.fastPanel = {};
|
pmcData.Inventory.fastPanel = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an array of items from a profile that will be lost on death
|
||||||
|
* @param pmcProfile Profile to get items from
|
||||||
|
* @returns Array of items lost on death
|
||||||
|
*/
|
||||||
|
protected getInventoryItemsLostOnDeath(pmcProfile: IPmcData): Item[]
|
||||||
|
{
|
||||||
|
const inventoryItems = pmcProfile.Inventory.items ?? [];
|
||||||
|
const equipment = pmcProfile?.Inventory?.equipment;
|
||||||
|
const questRaidItems = pmcProfile?.Inventory?.questRaidItems;
|
||||||
|
|
||||||
|
return inventoryItems.filter(x =>
|
||||||
|
{
|
||||||
|
// Keep items flagged as kept after death
|
||||||
|
if (this.isItemKeptAfterDeath(pmcProfile, x))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove normal items or quest raid items
|
||||||
|
if (x.parentId === equipment || x.parentId === questRaidItems)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pocket items are not lost on death
|
||||||
|
if (x.slotId.startsWith("pocket"))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get items in vest/pocket/backpack inventory containers (excluding children)
|
* Get items in vest/pocket/backpack inventory containers (excluding children)
|
||||||
* @param pmcData Player profile
|
* @param pmcData Player profile
|
||||||
|
Loading…
x
Reference in New Issue
Block a user