0
0
mirror of https://github.com/sp-tarkov/server.git synced 2025-02-13 02:50:44 -05:00

Store the location insured gear was lost on + time it was lost against insured items in profile

This commit is contained in:
Dev 2023-05-27 22:31:24 +01:00
parent 1a3c107f0a
commit 77508ace73
3 changed files with 47 additions and 17 deletions

View File

@ -135,7 +135,7 @@ export class InraidController
// Remove inventory if player died and send insurance items // Remove inventory if player died and send insurance items
if (insuranceEnabled) if (insuranceEnabled)
{ {
this.insuranceService.storeLostGear(pmcData, offraidData, preRaidGear, sessionID, isDead); this.insuranceService.storeLostGear(pmcData, offraidData, preRaidGear, sessionID, isDead, locationName);
} }
else else
{ {

View File

@ -230,6 +230,8 @@ export interface Insurance
traderId: string traderId: string
messageContent: MessageContent messageContent: MessageContent
items: Item[] items: Item[]
locationlost?: string
timeStampLost?: number
} }
export interface MessageContent export interface MessageContent

View File

@ -20,10 +20,17 @@ import { RandomUtil } from "../utils/RandomUtil";
import { TimeUtil } from "../utils/TimeUtil"; import { TimeUtil } from "../utils/TimeUtil";
import { LocalisationService } from "./LocalisationService"; import { LocalisationService } from "./LocalisationService";
export interface IInsuranceData
{
locationLost?: string
timestampLost?: number
items: Item[]
}
@injectable() @injectable()
export class InsuranceService export class InsuranceService
{ {
protected insured: Record<string, Record<string, Item[]>> = {}; protected insured: Record<string, Record<string, IInsuranceData>> = {};
protected insuranceConfig: IInsuranceConfig; protected insuranceConfig: IInsuranceConfig;
constructor( constructor(
@ -53,14 +60,14 @@ export class InsuranceService
return this.insured[sessionId][traderId] !== undefined; return this.insured[sessionId][traderId] !== undefined;
} }
public getInsurance(sessionId: string): Record<string, Item[]> public getInsurance(sessionId: string): Record<string, IInsuranceData>
{ {
return this.insured[sessionId]; return this.insured[sessionId];
} }
public getInsuranceItems(sessionId: string, traderId: string): Item[] public getInsuranceItems(sessionId: string, traderId: string): Item[]
{ {
return this.insured[sessionId][traderId]; return this.insured[sessionId][traderId].items;
} }
public resetInsurance(sessionId: string): void public resetInsurance(sessionId: string): void
@ -70,12 +77,22 @@ export class InsuranceService
public resetInsuranceTraderArray(sessionId: string, traderId: string): void public resetInsuranceTraderArray(sessionId: string, traderId: string): void
{ {
this.insured[sessionId][traderId] = []; this.insured[sessionId][traderId] = {items: []};
} }
public addInsuranceItemToArray(sessionId: string, traderId: string, itemToAdd: any): void public addInsuranceItemToArray(sessionId: string, traderId: string, itemToAdd: Item): void
{ {
this.insured[sessionId][traderId].push(itemToAdd); this.insured[sessionId][traderId].items.push(itemToAdd);
}
public addLocationLostToInsuranceItem(sessionId: string, traderId: string, locationName: string): void
{
this.insured[sessionId][traderId].locationLost = locationName;
}
public addTimestampLostToInsuranceItem(sessionId: string, traderId: string, timestampLost: number): void
{
this.insured[sessionId][traderId].timestampLost = timestampLost;
} }
/** /**
@ -106,7 +123,9 @@ export class InsuranceService
{ {
const trader = this.traderHelper.getTrader(traderId, sessionID); const trader = this.traderHelper.getTrader(traderId, sessionID);
const insuranceReturnTimestamp = this.getInsuranceReturnTimestamp(pmcData, trader); const insuranceReturnTimestamp = this.getInsuranceReturnTimestamp(pmcData, trader);
const insurance = this.getInsurance(sessionID)[traderId];
const dialogueTemplates = this.databaseServer.getTables().traders[traderId].dialogue; const dialogueTemplates = this.databaseServer.getTables().traders[traderId].dialogue;
let messageContent = this.dialogueHelper.createMessageContext(this.randomUtil.getArrayValue(dialogueTemplates.insuranceStart), MessageType.NPC_TRADER, trader.insurance.max_storage_time); let messageContent = this.dialogueHelper.createMessageContext(this.randomUtil.getArrayValue(dialogueTemplates.insuranceStart), MessageType.NPC_TRADER, trader.insurance.max_storage_time);
this.dialogueHelper.addDialogueMessage(traderId, messageContent, sessionID); this.dialogueHelper.addDialogueMessage(traderId, messageContent, sessionID);
@ -131,7 +150,9 @@ export class InsuranceService
scheduledTime: insuranceReturnTimestamp, scheduledTime: insuranceReturnTimestamp,
traderId: traderId, traderId: traderId,
messageContent: messageContent, messageContent: messageContent,
items: this.getInsurance(sessionID)[traderId] items: insurance.items,
locationlost: insurance.locationLost,
timeStampLost: insurance.timestampLost
}); });
} }
@ -140,8 +161,8 @@ export class InsuranceService
protected removeLocationProperty(sessionId: string, traderId: string): void protected removeLocationProperty(sessionId: string, traderId: string): void
{ {
const insuredItems = this.getInsurance(sessionId)[traderId]; const insuredItems = this.getInsurance(sessionId)[traderId].items;
for (const insuredItem of this.getInsurance(sessionId)[traderId]) for (const insuredItem of this.getInsurance(sessionId)[traderId].items)
{ {
const isParentHere = insuredItems.find(isParent => isParent._id === insuredItem.parentId); const isParentHere = insuredItems.find(isParent => isParent._id === insuredItem.parentId);
if (!isParentHere) if (!isParentHere)
@ -184,8 +205,9 @@ export class InsuranceService
* @param preRaidGear gear player wore prior to raid * @param preRaidGear gear player wore prior to raid
* @param sessionID Session id * @param sessionID Session id
* @param playerDied did the player die in raid * @param playerDied did the player die in raid
* @param locationName Name of map gear was lost on
*/ */
public storeLostGear(pmcData: IPmcData, offraidData: ISaveProgressRequestData, preRaidGear: Item[], sessionID: string, playerDied: boolean): void public storeLostGear(pmcData: IPmcData, offraidData: ISaveProgressRequestData, preRaidGear: Item[], sessionID: string, playerDied: boolean, locationName: string): void
{ {
const preRaidGearHash = this.createItemHashTable(preRaidGear); const preRaidGearHash = this.createItemHashTable(preRaidGear);
const offRaidGearHash = this.createItemHashTable(offraidData.profile.Inventory.items); const offRaidGearHash = this.createItemHashTable(offraidData.profile.Inventory.items);
@ -213,7 +235,7 @@ export class InsuranceService
// Process all insured items lost in-raid // Process all insured items lost in-raid
for (const gear of equipmentToSendToPlayer) for (const gear of equipmentToSendToPlayer)
{ {
this.addGearToSend(gear.pmcData, gear.insuredItem, gear.item, gear.sessionID); this.addGearToSend(gear, locationName);
} }
} }
@ -235,13 +257,16 @@ export class InsuranceService
/** /**
* Add gear item to InsuredItems array in player profile * Add gear item to InsuredItems array in player profile
* @param pmcData profile to store item in * @param gear Details on what item to store (player profile/item to store in profile/item db details/session id)
* @param insuredItem Item to store in profile * @param locationName Name of map gear was lost on
* @param actualItem item to store
* @param sessionID Session id
*/ */
protected addGearToSend(pmcData: IPmcData, insuredItem: InsuredItem, actualItem: Item, sessionID: string): void protected addGearToSend(gear: { pmcData: any; insuredItem: InsuredItem, item: Item, sessionID: string; }, locationName: string): void
{ {
const pmcData = gear.pmcData;
const insuredItem = gear.insuredItem;
const actualItem = gear.item;
const sessionID = gear.sessionID;
// Skip items defined in config // Skip items defined in config
if (this.insuranceConfig.blacklistedEquipment.includes(actualItem.slotId)) if (this.insuranceConfig.blacklistedEquipment.includes(actualItem.slotId))
{ {
@ -291,6 +316,9 @@ export class InsuranceService
} }
this.addInsuranceItemToArray(sessionID, insuredItem.tid, actualItem); this.addInsuranceItemToArray(sessionID, insuredItem.tid, actualItem);
this.addLocationLostToInsuranceItem(sessionID, insuredItem.tid, locationName);
this.addTimestampLostToInsuranceItem(sessionID, insuredItem.tid, this.timeUtil.getTimestamp());
// Remove processed item from array // Remove processed item from array
pmcData.InsuredItems = pmcData.InsuredItems.filter((item) => pmcData.InsuredItems = pmcData.InsuredItems.filter((item) =>