diff --git a/project/assets/configs/gifts.json b/project/assets/configs/gifts.json index 81286e4b..78d4b96c 100644 --- a/project/assets/configs/gifts.json +++ b/project/assets/configs/gifts.json @@ -1235,7 +1235,7 @@ "trader": "PRAPOR", "localeTextId": "5fd4c8b59e4b2a58b34bbd28 0", "collectionTimeHours": 48, - "maxToSendPlayer": 1 + "maxToSendPlayer": 5 }, "PraporGiftDay2": { "items": [ @@ -1271,7 +1271,7 @@ "trader": "PRAPOR", "localeTextId": "5fd4c8d49e4b2a58b34bbd29 0", "collectionTimeHours": 48, - "maxToSendPlayer": 1 + "maxToSendPlayer": 5 }, "KAPPA4U": { "items": [ diff --git a/project/src/helpers/Dialogue/SptDialogueChatBot.ts b/project/src/helpers/Dialogue/SptDialogueChatBot.ts index 419e82f2..cd4b539f 100644 --- a/project/src/helpers/Dialogue/SptDialogueChatBot.ts +++ b/project/src/helpers/Dialogue/SptDialogueChatBot.ts @@ -167,8 +167,12 @@ export class SptDialogueChatBot implements IDialogueChatBot if (requestInput === "givemespace") { const stashRowGiftId = "StashRows"; + const maxGiftsToSendCount = this.coreConfig.features.chatbotFeatures.commandUseLimits[stashRowGiftId] ?? 5; if ( - this.profileHelper.playerHasRecievedMaxNumberOfGift(sessionId, stashRowGiftId)) + this.profileHelper.playerHasRecievedMaxNumberOfGift( + sessionId, + stashRowGiftId, + maxGiftsToSendCount)) { this.mailSendService.sendUserMessageToPlayer( sessionId, @@ -189,7 +193,7 @@ export class SptDialogueChatBot implements IDialogueChatBot this.profileHelper.flagGiftReceivedInProfile( sessionId, stashRowGiftId, - this.coreConfig.features.chatbotFeatures.commandUseLimits[stashRowGiftId], + maxGiftsToSendCount, ); } } diff --git a/project/src/helpers/ProfileHelper.ts b/project/src/helpers/ProfileHelper.ts index da2ca0f1..5e6b5115 100644 --- a/project/src/helpers/ProfileHelper.ts +++ b/project/src/helpers/ProfileHelper.ts @@ -381,27 +381,27 @@ export class ProfileHelper { // Increment counter giftData.current++; + + return; } - else - { - // Player has never received gift, make a new object - profileToUpdate.spt.receivedGifts.push( - { - giftId: giftId, - timestampLastAccepted: this.timeUtil.getTimestamp(), - max: maxCount, - current: 1, - }); - } + + // Player has never received gift, make a new object + profileToUpdate.spt.receivedGifts.push( + { + giftId: giftId, + timestampLastAccepted: this.timeUtil.getTimestamp(), + current: 1, + }); } /** * Check if profile has recieved a gift by id * @param playerId Player profile to check for gift * @param giftId Gift to check for + * @param maxGiftCount Max times gift can be given to player * @returns True if player has recieved gift previously */ - public playerHasRecievedMaxNumberOfGift(playerId: string, giftId: string): boolean + public playerHasRecievedMaxNumberOfGift(playerId: string, giftId: string, maxGiftCount: number): boolean { const profile = this.getFullProfile(playerId); if (!profile) @@ -421,7 +421,7 @@ export class ProfileHelper return false; } - return giftDataFromProfile.current >= giftDataFromProfile.max; + return giftDataFromProfile.current >= maxGiftCount; } /** diff --git a/project/src/models/eft/profile/ISptProfile.ts b/project/src/models/eft/profile/ISptProfile.ts index 544cc37b..c20f7400 100644 --- a/project/src/models/eft/profile/ISptProfile.ts +++ b/project/src/models/eft/profile/ISptProfile.ts @@ -233,7 +233,6 @@ export interface ReceivedGift giftId: string timestampLastAccepted: number current: number - max: number } export interface Vitality diff --git a/project/src/services/GiftService.ts b/project/src/services/GiftService.ts index 611ab92d..9d493c80 100644 --- a/project/src/services/GiftService.ts +++ b/project/src/services/GiftService.ts @@ -42,6 +42,29 @@ export class GiftService return !!this.giftConfig.gifts[giftId]; } + public getGiftById(giftId: string): Gift + { + return this.giftConfig.gifts[giftId]; + } + + /** + * Get dictionary of all gifts + * @returns Dict keyed by gift id + */ + public getGifts(): Record + { + return this.giftConfig.gifts; + } + + /** + * Get an array of all gift ids + * @returns string array of gift ids + */ + public getGiftIds(): string[] + { + return Object.keys(this.giftConfig.gifts); + } + /** * Send player a gift from a range of sources * @param playerId Player to send gift to / sessionId @@ -55,8 +78,8 @@ export class GiftService { return GiftSentResult.FAILED_GIFT_DOESNT_EXIST; } - - if (this.profileHelper.playerHasRecievedMaxNumberOfGift(playerId, giftId)) + const maxGiftsToSendCount = giftData.maxToSendPlayer ?? 1; + if (this.profileHelper.playerHasRecievedMaxNumberOfGift(playerId, giftId, maxGiftsToSendCount)) { this.logger.debug(`Player already recieved gift: ${giftId}`); @@ -154,7 +177,7 @@ export class GiftService this.mailSendService.sendMessageToPlayer(details); } - this.profileHelper.flagGiftReceivedInProfile(playerId, giftId, giftData.maxToSendPlayer ?? 1); + this.profileHelper.flagGiftReceivedInProfile(playerId, giftId, maxGiftsToSendCount); return GiftSentResult.SUCCESS; } @@ -205,20 +228,30 @@ export class GiftService */ public sendPraporStartingGift(sessionId: string, day: number): void { + let giftId: string; switch (day) { case 1: - if (this.profileHelper.playerHasRecievedMaxNumberOfGift(sessionId, "PraporGiftDay1")) - { - this.sendGiftToPlayer(sessionId, "PraporGiftDay1"); - } + { + giftId = "PraporGiftDay1"; + break; + } case 2: - if (this.profileHelper.playerHasRecievedMaxNumberOfGift(sessionId, "PraporGiftDay2")) - { - this.sendGiftToPlayer(sessionId, "PraporGiftDay2"); - } + { + giftId = "PraporGiftDay2"; + break; + } + } + + if (giftId) + { + const giftData = this.getGiftById(giftId); + if (!this.profileHelper.playerHasRecievedMaxNumberOfGift(sessionId, giftId, giftData.maxToSendPlayer ?? 5)) + { + this.sendGiftToPlayer(sessionId, giftId); + } } } } diff --git a/project/src/services/PmcChatResponseService.ts b/project/src/services/PmcChatResponseService.ts index c0776940..8d7e646f 100644 --- a/project/src/services/PmcChatResponseService.ts +++ b/project/src/services/PmcChatResponseService.ts @@ -11,6 +11,7 @@ import { IGiftsConfig } from "@spt/models/spt/config/IGiftsConfig"; import { IPmcChatResponse } from "@spt/models/spt/config/IPmChatResponse"; import { ILogger } from "@spt/models/spt/utils/ILogger"; import { ConfigServer } from "@spt/servers/ConfigServer"; +import { GiftService } from "@spt/services/GiftService"; import { LocalisationService } from "@spt/services/LocalisationService"; import { MatchBotDetailsCacheService } from "@spt/services/MatchBotDetailsCacheService"; import { HashUtil } from "@spt/utils/HashUtil"; @@ -29,6 +30,7 @@ export class PmcChatResponseService @inject("NotificationSendHelper") protected notificationSendHelper: NotificationSendHelper, @inject("MatchBotDetailsCacheService") protected matchBotDetailsCacheService: MatchBotDetailsCacheService, @inject("LocalisationService") protected localisationService: LocalisationService, + @inject("GiftService") protected giftService: GiftService, @inject("WeightedRandomHelper") protected weightedRandomHelper: WeightedRandomHelper, @inject("ConfigServer") protected configServer: ConfigServer, ) @@ -147,7 +149,7 @@ export class PmcChatResponseService // Give the player a gift code if they were killed adn response is 'pity'. if (responseType === "pity") { - const giftKeys = Object.keys(this.giftConfig.gifts); + const giftKeys = this.giftService.getGiftIds(); const randomGiftKey = this.randomUtil.getStringArrayValue(giftKeys); const regex: RegExp = /(%giftcode%)/gi; diff --git a/project/src/services/SeasonalEventService.ts b/project/src/services/SeasonalEventService.ts index 01c82e66..32f3a0f0 100644 --- a/project/src/services/SeasonalEventService.ts +++ b/project/src/services/SeasonalEventService.ts @@ -610,13 +610,14 @@ export class SeasonalEventService /** * Send gift to player if they'e not already received it * @param playerId Player to send gift to - * @param giftkey Key of gift to give + * @param giftKey Key of gift to give */ - protected giveGift(playerId: string, giftkey: string): void + protected giveGift(playerId: string, giftKey: string): void { - if (!this.profileHelper.playerHasRecievedMaxNumberOfGift(playerId, giftkey)) + const gitftData = this.giftService.getGiftById(giftKey); + if (!this.profileHelper.playerHasRecievedMaxNumberOfGift(playerId, giftKey, gitftData.maxToSendPlayer ?? 5)) { - this.giftService.sendGiftToPlayer(playerId, giftkey); + this.giftService.sendGiftToPlayer(playerId, giftKey); } }