Fix issue with insurance message being incorrect

Moved `sendLostInsuranceMessage()` to `insuranceService` + make it read correct id from locale file
This commit is contained in:
Dev 2023-06-01 21:24:23 +01:00
parent 9bf533a1b1
commit cfbe2739f9
3 changed files with 50 additions and 38 deletions

View File

@ -6,7 +6,6 @@ import { PlayerScavGenerator } from "../generators/PlayerScavGenerator";
import { HealthHelper } from "../helpers/HealthHelper"; import { HealthHelper } from "../helpers/HealthHelper";
import { InRaidHelper } from "../helpers/InRaidHelper"; import { InRaidHelper } from "../helpers/InRaidHelper";
import { ItemHelper } from "../helpers/ItemHelper"; import { ItemHelper } from "../helpers/ItemHelper";
import { NotificationSendHelper } from "../helpers/NotificationSendHelper";
import { ProfileHelper } from "../helpers/ProfileHelper"; import { ProfileHelper } from "../helpers/ProfileHelper";
import { QuestHelper } from "../helpers/QuestHelper"; import { QuestHelper } from "../helpers/QuestHelper";
import { TraderHelper } from "../helpers/TraderHelper"; import { TraderHelper } from "../helpers/TraderHelper";
@ -16,10 +15,7 @@ import { BodyPartHealth } from "../models/eft/common/tables/IBotBase";
import { Item } from "../models/eft/common/tables/IItem"; import { Item } from "../models/eft/common/tables/IItem";
import { IRegisterPlayerRequestData } from "../models/eft/inRaid/IRegisterPlayerRequestData"; import { IRegisterPlayerRequestData } from "../models/eft/inRaid/IRegisterPlayerRequestData";
import { ISaveProgressRequestData } from "../models/eft/inRaid/ISaveProgressRequestData"; import { ISaveProgressRequestData } from "../models/eft/inRaid/ISaveProgressRequestData";
import { IUserDialogInfo } from "../models/eft/profile/IAkiProfile";
import { ConfigTypes } from "../models/enums/ConfigTypes"; import { ConfigTypes } from "../models/enums/ConfigTypes";
import { MemberCategory } from "../models/enums/MemberCategory";
import { MessageType } from "../models/enums/MessageType";
import { Traders } from "../models/enums/Traders"; import { Traders } from "../models/enums/Traders";
import { IAirdropConfig } from "../models/spt/config/IAirdropConfig"; import { IAirdropConfig } from "../models/spt/config/IAirdropConfig";
import { IInRaidConfig } from "../models/spt/config/IInRaidConfig"; import { IInRaidConfig } from "../models/spt/config/IInRaidConfig";
@ -28,7 +24,6 @@ import { ConfigServer } from "../servers/ConfigServer";
import { DatabaseServer } from "../servers/DatabaseServer"; import { DatabaseServer } from "../servers/DatabaseServer";
import { SaveServer } from "../servers/SaveServer"; import { SaveServer } from "../servers/SaveServer";
import { InsuranceService } from "../services/InsuranceService"; import { InsuranceService } from "../services/InsuranceService";
import { LocaleService } from "../services/LocaleService";
import { MatchBotDetailsCacheService } from "../services/MatchBotDetailsCacheService"; import { MatchBotDetailsCacheService } from "../services/MatchBotDetailsCacheService";
import { PmcChatResponseService } from "../services/PmcChatResponseService"; import { PmcChatResponseService } from "../services/PmcChatResponseService";
import { JsonUtil } from "../utils/JsonUtil"; import { JsonUtil } from "../utils/JsonUtil";
@ -49,14 +44,12 @@ export class InraidController
@inject("JsonUtil") protected jsonUtil: JsonUtil, @inject("JsonUtil") protected jsonUtil: JsonUtil,
@inject("TimeUtil") protected timeUtil: TimeUtil, @inject("TimeUtil") protected timeUtil: TimeUtil,
@inject("DatabaseServer") protected databaseServer: DatabaseServer, @inject("DatabaseServer") protected databaseServer: DatabaseServer,
@inject("LocaleService") protected localeService: LocaleService,
@inject("PmcChatResponseService") protected pmcChatResponseService: PmcChatResponseService, @inject("PmcChatResponseService") protected pmcChatResponseService: PmcChatResponseService,
@inject("MatchBotDetailsCacheService") protected matchBotDetailsCacheService: MatchBotDetailsCacheService, @inject("MatchBotDetailsCacheService") protected matchBotDetailsCacheService: MatchBotDetailsCacheService,
@inject("QuestHelper") protected questHelper: QuestHelper, @inject("QuestHelper") protected questHelper: QuestHelper,
@inject("ItemHelper") protected itemHelper: ItemHelper, @inject("ItemHelper") protected itemHelper: ItemHelper,
@inject("ProfileHelper") protected profileHelper: ProfileHelper, @inject("ProfileHelper") protected profileHelper: ProfileHelper,
@inject("PlayerScavGenerator") protected playerScavGenerator: PlayerScavGenerator, @inject("PlayerScavGenerator") protected playerScavGenerator: PlayerScavGenerator,
@inject("NotificationSendHelper") protected notificationSendHelper: NotificationSendHelper,
@inject("HealthHelper") protected healthHelper: HealthHelper, @inject("HealthHelper") protected healthHelper: HealthHelper,
@inject("TraderHelper") protected traderHelper: TraderHelper, @inject("TraderHelper") protected traderHelper: TraderHelper,
@inject("InsuranceService") protected insuranceService: InsuranceService, @inject("InsuranceService") protected insuranceService: InsuranceService,
@ -141,7 +134,7 @@ export class InraidController
{ {
if (locationName.toLowerCase() === "laboratory") if (locationName.toLowerCase() === "laboratory")
{ {
this.sendLostInsuranceMessage(sessionID); this.insuranceService.sendLostInsuranceMessage(sessionID);
} }
} }
@ -255,24 +248,6 @@ export class InraidController
this.handlePostRaidPlayerScavProcess(scavData, sessionID, offraidData, pmcData, isDead); this.handlePostRaidPlayerScavProcess(scavData, sessionID, offraidData, pmcData, isDead);
} }
protected sendLostInsuranceMessage(sessionID: string): void
{
const localeDb = this.localeService.getLocaleDb();
const failedText = localeDb["5a8fd75188a45036844e0b0c"];
const senderDetails: IUserDialogInfo = {
_id: Traders.PRAPOR,
info: {
Nickname: "Prapor",
Level: 1,
Side: "Bear",
MemberCategory: MemberCategory.TRADER
}
};
this.notificationSendHelper.sendMessageToPlayer(sessionID, senderDetails, failedText, MessageType.NPC_TRADER);
}
/** /**
* Is the player dead after a raid - dead is anything other than "survived" / "runner" * Is the player dead after a raid - dead is anything other than "survived" / "runner"
* @param statusOnExit exit value from offraidData object * @param statusOnExit exit value from offraidData object

View File

@ -28,6 +28,13 @@ export class DialogueHelper
) )
{ } { }
/**
* Create basic message context template
* @param templateId
* @param messageType
* @param maxStoreTime
* @returns
*/
public createMessageContext(templateId: string, messageType: MessageType, maxStoreTime: number): MessageContent public createMessageContext(templateId: string, messageType: MessageType, maxStoreTime: number): MessageContent
{ {
return { return {

View File

@ -3,14 +3,18 @@ import { ITraderBase } from "../models/eft/common/tables/ITrader";
import { DialogueHelper } from "../helpers/DialogueHelper"; import { DialogueHelper } from "../helpers/DialogueHelper";
import { HandbookHelper } from "../helpers/HandbookHelper"; import { HandbookHelper } from "../helpers/HandbookHelper";
import { NotificationSendHelper } from "../helpers/NotificationSendHelper";
import { SecureContainerHelper } from "../helpers/SecureContainerHelper"; import { SecureContainerHelper } from "../helpers/SecureContainerHelper";
import { TraderHelper } from "../helpers/TraderHelper"; import { TraderHelper } from "../helpers/TraderHelper";
import { IPmcData } from "../models/eft/common/IPmcData"; import { IPmcData } from "../models/eft/common/IPmcData";
import { InsuredItem } from "../models/eft/common/tables/IBotBase"; import { InsuredItem } from "../models/eft/common/tables/IBotBase";
import { Item } from "../models/eft/common/tables/IItem"; import { Item } from "../models/eft/common/tables/IItem";
import { ISaveProgressRequestData } from "../models/eft/inRaid/ISaveProgressRequestData"; import { ISaveProgressRequestData } from "../models/eft/inRaid/ISaveProgressRequestData";
import { IUserDialogInfo } from "../models/eft/profile/IAkiProfile";
import { ConfigTypes } from "../models/enums/ConfigTypes"; import { ConfigTypes } from "../models/enums/ConfigTypes";
import { MemberCategory } from "../models/enums/MemberCategory";
import { MessageType } from "../models/enums/MessageType"; import { MessageType } from "../models/enums/MessageType";
import { Traders } from "../models/enums/Traders";
import { IInsuranceConfig } from "../models/spt/config/IInsuranceConfig"; import { IInsuranceConfig } from "../models/spt/config/IInsuranceConfig";
import { ILogger } from "../models/spt/utils/ILogger"; import { ILogger } from "../models/spt/utils/ILogger";
import { ConfigServer } from "../servers/ConfigServer"; import { ConfigServer } from "../servers/ConfigServer";
@ -18,6 +22,7 @@ import { DatabaseServer } from "../servers/DatabaseServer";
import { SaveServer } from "../servers/SaveServer"; import { SaveServer } from "../servers/SaveServer";
import { RandomUtil } from "../utils/RandomUtil"; import { RandomUtil } from "../utils/RandomUtil";
import { TimeUtil } from "../utils/TimeUtil"; import { TimeUtil } from "../utils/TimeUtil";
import { LocaleService } from "./LocaleService";
import { LocalisationService } from "./LocalisationService"; import { LocalisationService } from "./LocalisationService";
@injectable() @injectable()
@ -37,6 +42,8 @@ export class InsuranceService
@inject("DialogueHelper") protected dialogueHelper: DialogueHelper, @inject("DialogueHelper") protected dialogueHelper: DialogueHelper,
@inject("HandbookHelper") protected handbookHelper: HandbookHelper, @inject("HandbookHelper") protected handbookHelper: HandbookHelper,
@inject("LocalisationService") protected localisationService: LocalisationService, @inject("LocalisationService") protected localisationService: LocalisationService,
@inject("LocaleService") protected localeService: LocaleService,
@inject("NotificationSendHelper") protected notificationSendHelper: NotificationSendHelper,
@inject("ConfigServer") protected configServer: ConfigServer @inject("ConfigServer") protected configServer: ConfigServer
) )
{ {
@ -108,18 +115,14 @@ export class InsuranceService
const insuranceReturnTimestamp = this.getInsuranceReturnTimestamp(pmcData, trader); const insuranceReturnTimestamp = this.getInsuranceReturnTimestamp(pmcData, trader);
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); // Send "i will go look for your stuff" message
messageContent = { const messageContent = this.dialogueHelper.createMessageContext(this.randomUtil.getArrayValue(dialogueTemplates.insuranceStart), MessageType.NPC_TRADER, trader.insurance.max_storage_time);
templateId: this.randomUtil.getArrayValue(dialogueTemplates.insuranceFound), messageContent.text = ""; // live insurance returns have an empty string for the text property
type: MessageType.INSURANCE_RETURN, messageContent.profileChangeEvents = [];
text: "", // live insurance returns have an empty string for the text property messageContent.systemData = {
maxStorageTime: trader.insurance.max_storage_time * TimeUtil.oneHourAsSeconds, date: this.timeUtil.getDateMailFormat(),
profileChangeEvents: [], time: this.timeUtil.getTimeMailFormat(),
systemData: { location: mapId
date: this.timeUtil.getDateMailFormat(),
time: this.timeUtil.getTimeMailFormat(),
location: mapId
}
}; };
// Must occur after systemData is hydrated // Must occur after systemData is hydrated
@ -128,6 +131,11 @@ export class InsuranceService
// Remove 'hideout' slotid property on all insurance items // Remove 'hideout' slotid property on all insurance items
this.removeLocationProperty(sessionID, traderId); this.removeLocationProperty(sessionID, traderId);
// Reuse existing context for message sent to player with insurance return
messageContent.templateId = this.randomUtil.getArrayValue(dialogueTemplates.insuranceFound);
messageContent.type = MessageType.INSURANCE_RETURN;
// Store insurance return details in profile + "hey i found your stuff, here you go!" message details to send player at a later date
this.saveServer.getProfile(sessionID).insurance.push({ this.saveServer.getProfile(sessionID).insurance.push({
scheduledTime: insuranceReturnTimestamp, scheduledTime: insuranceReturnTimestamp,
traderId: traderId, traderId: traderId,
@ -139,6 +147,28 @@ export class InsuranceService
this.resetInsurance(sessionID); this.resetInsurance(sessionID);
} }
/**
* Send a message to player informing them gear was lost
* @param sessionID Session id
*/
public sendLostInsuranceMessage(sessionID: string): void
{
const localeDb = this.localeService.getLocaleDb();
const dialogueTemplates = this.databaseServer.getTables().traders[Traders.PRAPOR].dialogue; // todo: get trader id instead of hard coded prapor
const failedText = localeDb[this.randomUtil.getArrayValue(dialogueTemplates.insuranceFailed)];
const senderDetails: IUserDialogInfo = {
_id: Traders.PRAPOR,
info: {
Nickname: "Prapor",
Level: 1,
Side: "Bear",
MemberCategory: MemberCategory.TRADER
}
};
this.notificationSendHelper.sendMessageToPlayer(sessionID, senderDetails, failedText, MessageType.NPC_TRADER);
}
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];