Rework insurance to not duplicate items + still return soft_inserts
Added missing groin_back to `itemRequiresSoftInserts()`
This commit is contained in:
parent
e5bc45c6d4
commit
a2668a9618
@ -137,17 +137,9 @@ export class ItemHelper
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if item has slots that match soft insert name ids
|
// Check if item has slots that match soft insert name ids
|
||||||
const softInsertSlotIds = [
|
if (
|
||||||
"groin",
|
itemDbDetails[1]._props.Slots.find((slot) => this.getSoftInsertSlotIds().includes(slot._name.toLowerCase()))
|
||||||
"soft_armor_back",
|
)
|
||||||
"soft_armor_front",
|
|
||||||
"soft_armor_left",
|
|
||||||
"soft_armor_right",
|
|
||||||
"shoulder_l",
|
|
||||||
"shoulder_r",
|
|
||||||
"collar",
|
|
||||||
];
|
|
||||||
if (itemDbDetails[1]._props.Slots.find((slot) => softInsertSlotIds.includes(slot._name.toLowerCase())))
|
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -162,6 +154,21 @@ export class ItemHelper
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getSoftInsertSlotIds(): string[]
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
"groin",
|
||||||
|
"groin_back",
|
||||||
|
"soft_armor_back",
|
||||||
|
"soft_armor_front",
|
||||||
|
"soft_armor_left",
|
||||||
|
"soft_armor_right",
|
||||||
|
"shoulder_l",
|
||||||
|
"shoulder_r",
|
||||||
|
"collar",
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the item price based on the handbook or as a fallback from the prices.json if the item is not
|
* Returns the item price based on the handbook or as a fallback from the prices.json if the item is not
|
||||||
* found in the handbook. If the price can't be found at all return 0
|
* found in the handbook. If the price can't be found at all return 0
|
||||||
|
@ -247,30 +247,50 @@ export class InsuranceService
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Item iterated on could have already been processed previously (as a child of another item)
|
|
||||||
if (equipmentToSendToPlayer.some((item) => item.itemsToReturnToPlayer._id === insuredItem.itemId))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if item missing in post-raid gear OR player died
|
// Check if item missing in post-raid gear OR player died
|
||||||
// Catches both events: player died with item on + player survived but dropped item in raid
|
// Catches both events: player died with item on + player survived but dropped item in raid
|
||||||
if (!offRaidGearHash[insuredItem.itemId] || playerDied)
|
if (!offRaidGearHash[insuredItem.itemId] || playerDied)
|
||||||
{
|
{
|
||||||
equipmentToSendToPlayer.push({
|
equipmentToSendToPlayer.push({
|
||||||
pmcData: pmcData,
|
pmcData: pmcData,
|
||||||
itemsToReturnToPlayer: this.getInsuredItemDetails(
|
itemToReturnToPlayer: this.getInsuredItemDetails(
|
||||||
pmcData,
|
pmcData,
|
||||||
this.itemHelper.findAndReturnChildrenAsItems(
|
preRaidItem,
|
||||||
Object.values(preRaidGearHash),
|
offraidData.insurance?.find((insuranceItem) => insuranceItem.id === insuredItem.itemId),
|
||||||
preRaidItem._id,
|
|
||||||
true,
|
|
||||||
),
|
|
||||||
offraidData.insurance,
|
|
||||||
),
|
),
|
||||||
traderId: insuredItem.tid,
|
traderId: insuredItem.tid,
|
||||||
sessionID: sessionID,
|
sessionID: sessionID,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Armor item with slots, we need to include soft_inserts as they can never be removed from armor items
|
||||||
|
if (this.itemHelper.armorItemCanHoldMods(preRaidItem._tpl))
|
||||||
|
{
|
||||||
|
if (this.itemHelper.itemHasSlots(preRaidItem._tpl))
|
||||||
|
{
|
||||||
|
// Get IDs of all soft insert child items on armor from pre raid gear data
|
||||||
|
const softInsertChildIds = preRaidGear.filter((item) =>
|
||||||
|
item.parentId === preRaidItem._id
|
||||||
|
&& this.itemHelper.getSoftInsertSlotIds().includes(item.slotId.toLowerCase())
|
||||||
|
).map((x) => x._id);
|
||||||
|
|
||||||
|
// Add all items found above to return data
|
||||||
|
for (const softInsertChildModId of softInsertChildIds)
|
||||||
|
{
|
||||||
|
equipmentToSendToPlayer.push({
|
||||||
|
pmcData: pmcData,
|
||||||
|
itemToReturnToPlayer: this.getInsuredItemDetails(
|
||||||
|
pmcData,
|
||||||
|
preRaidGear.find((item) => item._id === softInsertChildModId),
|
||||||
|
offraidData.insurance?.find((insuranceItem) =>
|
||||||
|
insuranceItem.id === softInsertChildModId
|
||||||
|
),
|
||||||
|
),
|
||||||
|
traderId: insuredItem.tid,
|
||||||
|
sessionID: sessionID,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,26 +320,11 @@ export class InsuranceService
|
|||||||
*/
|
*/
|
||||||
protected getInsuredItemDetails(
|
protected getInsuredItemDetails(
|
||||||
pmcData: IPmcData,
|
pmcData: IPmcData,
|
||||||
preRaidItemWithChildren: Item[],
|
preRaidItem: Item,
|
||||||
allItemsFromClient: IInsuredItemsData[],
|
insuredItemFromClient: IInsuredItemsData,
|
||||||
): Item[]
|
): Item
|
||||||
{
|
{
|
||||||
const itemsToReturn: Item[] = [];
|
// Get baseline item to return, clone pre raid item
|
||||||
for (const preRaidItem of preRaidItemWithChildren)
|
|
||||||
{
|
|
||||||
const isInsured = pmcData.InsuredItems.some((item) => item.itemId === preRaidItem._id);
|
|
||||||
const itemClientInsuranceData = allItemsFromClient?.find((x) => x.id === preRaidItem._id);
|
|
||||||
const itemIsSoftInsert = this.itemHelper.isOfBaseclass(preRaidItem._tpl, BaseClasses.BUILT_IN_INSERTS);
|
|
||||||
|
|
||||||
if (isInsured || itemIsSoftInsert)
|
|
||||||
{
|
|
||||||
// Check if item should always be lost
|
|
||||||
if (this.insuranceConfig.slotIdsToAlwaysRemove.includes(preRaidItem.slotId.toLowerCase()))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get baseline item to return, clone pre-raid item
|
|
||||||
const itemToReturn: Item = this.jsonUtil.clone(preRaidItem);
|
const itemToReturn: Item = this.jsonUtil.clone(preRaidItem);
|
||||||
|
|
||||||
// Add upd if it doesnt exist
|
// Add upd if it doesnt exist
|
||||||
@ -328,7 +333,7 @@ export class InsuranceService
|
|||||||
itemToReturn.upd = {};
|
itemToReturn.upd = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for slotId values that need to be updated and adjust
|
// Check for slotid values that need to be updated and adjust
|
||||||
this.updateSlotIdValue(pmcData.Inventory.equipment, itemToReturn);
|
this.updateSlotIdValue(pmcData.Inventory.equipment, itemToReturn);
|
||||||
|
|
||||||
// Remove location property
|
// Remove location property
|
||||||
@ -344,42 +349,38 @@ export class InsuranceService
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Client item has durability values, Ensure values persist into server data
|
// Client item has durability values, Ensure values persist into server data
|
||||||
if (itemClientInsuranceData?.durability)
|
if (insuredItemFromClient?.durability)
|
||||||
{
|
{
|
||||||
// Item didnt have Repairable object pre-raid, add it
|
// Item didnt have Repairable object pre-raid, add it
|
||||||
if (!itemToReturn.upd.Repairable)
|
if (!itemToReturn.upd.Repairable)
|
||||||
{
|
{
|
||||||
itemToReturn.upd.Repairable = {
|
itemToReturn.upd.Repairable = {
|
||||||
Durability: itemClientInsuranceData.durability,
|
Durability: insuredItemFromClient.durability,
|
||||||
MaxDurability: itemClientInsuranceData.maxDurability,
|
MaxDurability: insuredItemFromClient.maxDurability,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
itemToReturn.upd.Repairable.Durability = itemClientInsuranceData.durability;
|
itemToReturn.upd.Repairable.Durability = insuredItemFromClient.durability;
|
||||||
itemToReturn.upd.Repairable.MaxDurability = itemClientInsuranceData.maxDurability;
|
itemToReturn.upd.Repairable.MaxDurability = insuredItemFromClient.maxDurability;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Client item has FaceShield values, Ensure values persist into server data
|
// Client item has FaceShield values, Ensure values persist into server data
|
||||||
if (itemClientInsuranceData?.hits)
|
if (insuredItemFromClient?.hits)
|
||||||
{
|
{
|
||||||
// Item didnt have faceshield object pre-raid, add it
|
// Item didnt have faceshield object pre-raid, add it
|
||||||
if (!itemToReturn.upd.FaceShield)
|
if (!itemToReturn.upd.FaceShield)
|
||||||
{
|
{
|
||||||
itemToReturn.upd.FaceShield = { Hits: itemClientInsuranceData.hits };
|
itemToReturn.upd.FaceShield = { Hits: insuredItemFromClient.hits };
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
itemToReturn.upd.FaceShield.Hits = itemClientInsuranceData.hits;
|
itemToReturn.upd.FaceShield.Hits = insuredItemFromClient.hits;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
itemsToReturn.push(itemToReturn);
|
return itemToReturn;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return itemsToReturn;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -428,12 +429,12 @@ export class InsuranceService
|
|||||||
* @param traderId Id of trader item was insured with
|
* @param traderId Id of trader item was insured with
|
||||||
*/
|
*/
|
||||||
protected addGearToSend(
|
protected addGearToSend(
|
||||||
gear: { sessionID: string; pmcData: IPmcData; itemsToReturnToPlayer: Item[]; traderId: string; },
|
gear: { sessionID: string; pmcData: IPmcData; itemToReturnToPlayer: Item; traderId: string; },
|
||||||
): void
|
): void
|
||||||
{
|
{
|
||||||
const sessionId = gear.sessionID;
|
const sessionId = gear.sessionID;
|
||||||
const pmcData = gear.pmcData;
|
const pmcData = gear.pmcData;
|
||||||
const itemsToReturnToPlayer = gear.itemsToReturnToPlayer;
|
const itemToReturnToPlayer = gear.itemToReturnToPlayer;
|
||||||
const traderId = gear.traderId;
|
const traderId = gear.traderId;
|
||||||
|
|
||||||
// Ensure insurance array is init
|
// Ensure insurance array is init
|
||||||
@ -448,11 +449,13 @@ export class InsuranceService
|
|||||||
this.resetInsuranceTraderArray(sessionId, traderId);
|
this.resetInsuranceTraderArray(sessionId, traderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.addInsuranceItemToArray(sessionId, traderId, itemsToReturnToPlayer);
|
this.addInsuranceItemToArray(sessionId, traderId, itemToReturnToPlayer);
|
||||||
|
|
||||||
// Remove item from insured items array as its been processed
|
// Remove item from insured items array as its been processed
|
||||||
const returnedItemIds = itemsToReturnToPlayer.map((item) => item._id);
|
pmcData.InsuredItems = pmcData.InsuredItems.filter((item) =>
|
||||||
pmcData.InsuredItems = pmcData.InsuredItems.filter((item) => !returnedItemIds.includes(item.itemId));
|
{
|
||||||
|
return item.itemId !== itemToReturnToPlayer._id;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -480,11 +483,11 @@ export class InsuranceService
|
|||||||
* Store insured item
|
* Store insured item
|
||||||
* @param sessionId Player id (session id)
|
* @param sessionId Player id (session id)
|
||||||
* @param traderId Trader item insured with
|
* @param traderId Trader item insured with
|
||||||
* @param itemsToAdd Insured item (with children)
|
* @param itemToAdd Insured item (with children)
|
||||||
*/
|
*/
|
||||||
public addInsuranceItemToArray(sessionId: string, traderId: string, itemsToAdd: Item[]): void
|
public addInsuranceItemToArray(sessionId: string, traderId: string, itemToAdd: Item): void
|
||||||
{
|
{
|
||||||
this.insured[sessionId][traderId].push(...itemsToAdd);
|
this.insured[sessionId][traderId].push(itemToAdd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user