Implemented insurance returns

This commit is contained in:
Dev 2024-07-07 20:57:41 +01:00
parent bda69a5563
commit ac4c8ff0b3
2 changed files with 123 additions and 16 deletions

View File

@ -466,6 +466,42 @@ export class InsuranceService
return itemToReturnClone; return itemToReturnClone;
} }
/**
* For the passed in items, find the trader it was insured against
* @param sessionId Session id
* @param lostInsuredItems Insured items lost in a raid
* @param pmcProfile Player profile
* @returns IInsuranceEquipmentPkg array
*/
public mapInsuredItemsToTrader(
sessionId: string,
lostInsuredItems: Item[],
pmcProfile: IPmcData): IInsuranceEquipmentPkg[]
{
const result: IInsuranceEquipmentPkg[] = [];
for (const lostItem of lostInsuredItems)
{
const insuranceDetails = pmcProfile.InsuredItems.find((insuredItem) => insuredItem.itemId == lostItem._id);
if (!insuranceDetails)
{
this.logger.error(`unable to find insurance details for item id: ${lostItem._id} with tpl: ${lostItem._tpl}`);
continue;
}
// Add insured item + details to return array
result.push({
sessionID: sessionId,
itemToReturnToPlayer: lostItem,
pmcData: pmcProfile,
traderId: insuranceDetails.tid,
});
}
return result;
}
/** /**
* Reset slotId property to "hideout" when necessary (used to be in ) * Reset slotId property to "hideout" when necessary (used to be in )
* @param pmcData Players pmcData.Inventory.equipment value * @param pmcData Players pmcData.Inventory.equipment value

View File

@ -224,7 +224,8 @@ export class LocationLifecycleService
scavProfile, scavProfile,
postRaidProfile, postRaidProfile,
isDead, isDead,
request); request,
locationName);
// Handle car extracts // Handle car extracts
if (this.extractWasViaCar(request.results.exitName)) if (this.extractWasViaCar(request.results.exitName))
@ -432,6 +433,7 @@ export class LocationLifecycleService
postRaidProfile: IPmcData, postRaidProfile: IPmcData,
isDead: boolean, isDead: boolean,
request: IEndLocalRaidRequestData, request: IEndLocalRaidRequestData,
locationName: string,
): void ): void
{ {
// Update inventory // Update inventory
@ -464,7 +466,11 @@ export class LocationLifecycleService
this.mergePmcAndScavEncyclopedias(pmcProfile, scavProfile); this.mergePmcAndScavEncyclopedias(pmcProfile, scavProfile);
// Handle temp, hydration, limb hp/effects // Handle temp, hydration, limb hp/effects
this.healthHelper.updateProfileHealthPostRaid(pmcProfile, postRaidProfile.Health, sessionId, isDead); this.healthHelper.updateProfileHealthPostRaid(
pmcProfile,
postRaidProfile.Health,
sessionId,
isDead);
if (isDead) if (isDead)
{ {
@ -498,25 +504,90 @@ export class LocationLifecycleService
if (request.lostInsuredItems?.length > 0) if (request.lostInsuredItems?.length > 0)
{ {
// request.lostInsuredItems; const mappedItems = this.insuranceService.mapInsuredItemsToTrader(
// TODO - refactor code to work sessionId,
request.lostInsuredItems,
request.results.profile);
// Get array of insured items+child that were lost in raid this.insuranceService.storeGearLostInRaidToSendLater(
// const gearToStore = this.insuranceService.getGearLostInRaid( sessionId,
// pmcProfile, mappedItems,
// postRaidRequest, );
// preRaidGear,
// sessionId,
// isDead,
// );
// this.insuranceService.storeGearLostInRaidToSendLater( this.insuranceService.sendInsuredItems(pmcProfile, sessionId, locationName);
// sessionId,
// gearToStore,
// );
} }
} }
/**
* Return the equipped items from a players inventory
* @param items Players inventory to search through
* @returns an array of equipped items
*/
protected getEquippedGear(items: Item[]): Item[]
{
// Player Slots we care about
const inventorySlots = [
"FirstPrimaryWeapon",
"SecondPrimaryWeapon",
"Holster",
"Scabbard",
"Compass",
"Headwear",
"Earpiece",
"Eyewear",
"FaceCover",
"ArmBand",
"ArmorVest",
"TacticalVest",
"Backpack",
"pocket1",
"pocket2",
"pocket3",
"pocket4",
"SpecialSlot1",
"SpecialSlot2",
"SpecialSlot3",
];
let inventoryItems: Item[] = [];
// Get an array of root player items
for (const item of items)
{
if (inventorySlots.includes(item.slotId))
{
inventoryItems.push(item);
}
}
// Loop through these items and get all of their children
let newItems = inventoryItems;
while (newItems.length > 0)
{
const foundItems = [];
for (const item of newItems)
{
// Find children of this item
for (const newItem of items)
{
if (newItem.parentId === item._id)
{
foundItems.push(newItem);
}
}
}
// Add these new found items to our list of inventory items
inventoryItems = [...inventoryItems, ...foundItems];
// Now find the children of these items
newItems = foundItems;
}
return inventoryItems;
}
/** /**
* Handle singleplayer/traderServices/itemDelivery * Handle singleplayer/traderServices/itemDelivery
*/ */