From 75a34f5ca2b00cb94dd119318f2eac8493d969ff Mon Sep 17 00:00:00 2001 From: Dev Date: Sat, 8 Jun 2024 17:54:05 +0100 Subject: [PATCH] Expanded gift system used by spt bot Gifts can be given multiple times stash expansions are limited to 5 max by default dev balaclava can be given 5 times, majority of gifts are 1 use still Updated data structure to persist gifts received, this will break profiles --- project/assets/configs/core.json | 5 +- project/assets/configs/gifts.json | 118 ++++++++++++------ .../helpers/Dialogue/SptDialogueChatBot.ts | 49 +++++--- project/src/helpers/ProfileHelper.ts | 39 ++++-- project/src/models/eft/profile/ISptProfile.ts | 4 +- project/src/models/spt/config/ICoreConfig.ts | 1 + project/src/models/spt/config/IGiftsConfig.ts | 1 + project/src/services/GiftService.ts | 8 +- project/src/services/SeasonalEventService.ts | 2 +- 9 files changed, 158 insertions(+), 69 deletions(-) diff --git a/project/assets/configs/core.json b/project/assets/configs/core.json index 5f5841bf..35ea46ac 100644 --- a/project/assets/configs/core.json +++ b/project/assets/configs/core.json @@ -26,7 +26,10 @@ "commandoEnabled": true, "commandoFeatures": { "giveCommandEnabled": true - } + }, + "commandUseLimits": { + "StashRows": 5 + } } }, "customWatermarkLocaleKeys": [] diff --git a/project/assets/configs/gifts.json b/project/assets/configs/gifts.json index 1f1bd287..81286e4b 100644 --- a/project/assets/configs/gifts.json +++ b/project/assets/configs/gifts.json @@ -219,7 +219,8 @@ "parentId": "658efad286f149afb701c2cc", "slotId": "Helmet_back" } - ] + ], + "maxToSendPlayer": 1 }, "NewYear2021": { "sender": "System", @@ -447,7 +448,8 @@ "parentId": "64b4473f3b4c4dd8cdf9999", "slotId": "mod_charge" } - ] + ], + "maxToSendPlayer": 1 }, "Christmas2022": { "items": [ @@ -501,7 +503,8 @@ "messageText": "Merry christmas!", "timestampToSend": 42069, "associatedEvent": "Christmas", - "collectionTimeHours": 48 + "collectionTimeHours": 48, + "maxToSendPlayer": 1 }, "1CLICKDRESSUP": { "items": [ @@ -665,7 +668,8 @@ "messageText": "1CLICKDRESSUP", "timestampToSend": 42069, "collectionTimeHours": 48, - "associatedEvent": "Promo" + "associatedEvent": "Promo", + "maxToSendPlayer": 1 }, "BARMALEY": { "items": [ @@ -826,7 +830,8 @@ "messageText": "BARMALEY", "timestampToSend": 42069, "collectionTimeHours": 48, - "associatedEvent": "Promo" + "associatedEvent": "Promo", + "maxToSendPlayer": 1 }, "S00NS00N": { "items": [ @@ -907,7 +912,8 @@ "messageText": "S00NS00N", "timestampToSend": 42069, "collectionTimeHours": 48, - "associatedEvent": "Promo" + "associatedEvent": "Promo", + "maxToSendPlayer": 1 }, "TRAMBON": { "items": [ @@ -1084,7 +1090,8 @@ "messageText": "TRAMBON", "timestampToSend": 42069, "collectionTimeHours": 48, - "associatedEvent": "Promo" + "associatedEvent": "Promo", + "maxToSendPlayer": 1 }, "PINEWOOD": { "items": [ @@ -1173,7 +1180,8 @@ "messageText": "PINEWOOD", "timestampToSend": 42069, "collectionTimeHours": 48, - "associatedEvent": "Promo" + "associatedEvent": "Promo", + "maxToSendPlayer": 1 }, "HESOYAM": { "items": [ @@ -1190,7 +1198,8 @@ "sender": "System", "messageText": "HESOYAM", "collectionTimeHours": 48, - "associatedEvent": "Promo" + "associatedEvent": "Promo", + "maxToSendPlayer": 1 }, "PraporGiftDay1": { "items": [ @@ -1225,7 +1234,8 @@ "sender": "Trader", "trader": "PRAPOR", "localeTextId": "5fd4c8b59e4b2a58b34bbd28 0", - "collectionTimeHours": 48 + "collectionTimeHours": 48, + "maxToSendPlayer": 1 }, "PraporGiftDay2": { "items": [ @@ -1260,7 +1270,8 @@ "sender": "Trader", "trader": "PRAPOR", "localeTextId": "5fd4c8d49e4b2a58b34bbd29 0", - "collectionTimeHours": 48 + "collectionTimeHours": 48, + "maxToSendPlayer": 1 }, "KAPPA4U": { "items": [ @@ -1277,7 +1288,8 @@ "sender": "System", "messageText": "Easy Kappa", "collectionTimeHours": 48, - "associatedEvent": "Promo" + "associatedEvent": "Promo", + "maxToSendPlayer": 1 }, "ENDOFWIPE": { "items": [ @@ -1303,7 +1315,8 @@ "sender": "System", "localeTextId": "626e5d63bc92c87fd22a943f 0", "collectionTimeHours": 48, - "associatedEvent": "Promo" + "associatedEvent": "Promo", + "maxToSendPlayer": 1 }, "IAMADIRTYLITTLEGOBLIN": { "items": [ @@ -1320,7 +1333,8 @@ "sender": "System", "messageText": "You dirty little cheating goblin", "collectionTimeHours": 48, - "associatedEvent": "Promo" + "associatedEvent": "Promo", + "maxToSendPlayer": 5 }, "CHOMP": { "items": [ @@ -1337,7 +1351,8 @@ "sender": "System", "messageText": "caw caw", "collectionTimeHours": 48, - "associatedEvent": "Promo" + "associatedEvent": "Promo", + "maxToSendPlayer": 1 }, "CWX": { "items": [ @@ -1354,7 +1369,8 @@ "sender": "System", "messageText": "un oh stinky", "collectionTimeHours": 48, - "associatedEvent": "Promo" + "associatedEvent": "Promo", + "maxToSendPlayer": 1 }, "VALENS": { "items": [ @@ -1494,7 +1510,8 @@ "sender": "System", "messageText": "It's time to pew pew.", "collectionTimeHours": 48, - "associatedEvent": "Promo" + "associatedEvent": "Promo", + "maxToSendPlayer": 1 }, "TERKOIZ": { "items": [ @@ -1511,7 +1528,8 @@ "sender": "System", "messageText": "Out of the way, i'm a motorist", "collectionTimeHours": 48, - "associatedEvent": "Promo" + "associatedEvent": "Promo", + "maxToSendPlayer": 1 }, "WAFFLE": { "items": [ @@ -1537,7 +1555,8 @@ "sender": "System", "messageText": "JONKLER NO", "collectionTimeHours": 48, - "associatedEvent": "Promo" + "associatedEvent": "Promo", + "maxToSendPlayer": 1 }, "NIGHTWING": { "items": [ @@ -1563,7 +1582,9 @@ "sender": "System", "messageText": "JONKLER NO", "collectionTimeHours": 48, - "associatedEvent": "Promo" + "associatedEvent": "Promo", + "maxToSendToPlayer": 1, + "maxToSendPlayer": 1 }, "BSGBIRTHDAY2023": { "sender": "System", @@ -1709,7 +1730,8 @@ "parentId": "652a6f5c35258f985804aa0b", "slotId": "main" } - ] + ], + "maxToSendPlayer": 1 }, "GROUNDZERO": { "items": [ @@ -1722,7 +1744,8 @@ "sender": "System", "messageText": "GROUNDZERO", "collectionTimeHours": 48, - "associatedEvent": "Promo" + "associatedEvent": "Promo", + "maxToSendPlayer": 1 }, "IAMMIGHTY": { "items": [ @@ -1962,7 +1985,8 @@ "sender": "System", "messageText": "IAMMIGHTY", "collectionTimeHours": 48, - "associatedEvent": "Promo" + "associatedEvent": "Promo", + "maxToSendPlayer": 1 }, "ARMORPLATES": { "items": [ @@ -2096,7 +2120,8 @@ "sender": "System", "messageText": "ARMORPLATES", "collectionTimeHours": 48, - "associatedEvent": "Promo" + "associatedEvent": "Promo", + "maxToSendPlayer": 1 }, "RICHANDEXPENSIVE": { "items": [ @@ -2164,7 +2189,8 @@ "sender": "System", "messageText": "RICHANDEXPENSIVE", "collectionTimeHours": 48, - "associatedEvent": "Promo" + "associatedEvent": "Promo", + "maxToSendPlayer": 1 }, "LEFTHANDHEADEYES": { "items": [ @@ -2190,7 +2216,8 @@ "sender": "System", "messageText": "LEFTHANDHEADEYES", "collectionTimeHours": 48, - "associatedEvent": "Promo" + "associatedEvent": "Promo", + "maxToSendPlayer": 1 }, "EDITPROFILE": { "items": [ @@ -2612,7 +2639,8 @@ "sender": "System", "localeTextId": "5a2d28f786f77436023be4a5 0", "collectionTimeHours": 72, - "associatedEvent": "Promo" + "associatedEvent": "Promo", + "maxToSendPlayer": 1 }, "TWITCHNEWYEARS2023": { "items": [ @@ -3026,7 +3054,8 @@ "sender": "System", "localeTextId": "5e0653ba86f774478f700632 3", "collectionTimeHours": 72, - "associatedEvent": "Promo" + "associatedEvent": "Promo", + "maxToSendPlayer": 1 }, "LUNARNEWYEAR2024": { "items": [ @@ -3219,7 +3248,8 @@ "sender": "System", "associatedEvent": "Promo", "collectionTimeHours": 72, - "messageText": "Thank you for activating the code.Thank you for activating the code.Thank you for activating the code.Thank you for activating the code.Thank you for activating the code.Thank you for activating the code.Thank you for activating the code.Thank you for activating the code.Thank you for activating the code.Thank you for activating the code.Thank you for activating the code.Thank you for activating the code.Thank you for activating the code.Thank you for activating the code.Thank you for activating the code.Thank you for activating the code.Thank you for activating the code." + "messageText": "Thank you for activating the code.Thank you for activating the code.Thank you for activating the code.Thank you for activating the code.Thank you for activating the code.Thank you for activating the code.Thank you for activating the code.Thank you for activating the code.Thank you for activating the code.Thank you for activating the code.Thank you for activating the code.Thank you for activating the code.Thank you for activating the code.Thank you for activating the code.Thank you for activating the code.Thank you for activating the code.Thank you for activating the code.", + "maxToSendPlayer": 1 }, "ETSREWARD": { "items": [ @@ -3466,7 +3496,8 @@ "sender": "System", "associatedEvent": "Promo", "collectionTimeHours": 72, - "messageText": "Greetings, warrior. I've heard you've been helping out our local hard workers with their stuff, testing everything out, so to speak. That's a good deed, soldier, great job. The higher-ups sent you a little present as a token of gratitude. Keep it up!Greetings, warrior. I've heard you've been helping out our local hard workers with their stuff, testing everything out, so to speak. That's a good deed, soldier, great job. The higher-ups sent you a little present as a token of gratitude. Keep it up!Greetings, warrior. I've heard you've been helping out our local hard workers with their stuff, testing everything out, so to speak. That's a good deed, soldier, great job. The higher-ups sent you a little present as a token of gratitude. Keep it up!Greetings, warrior. I've heard you've been helping out our local hard workers with their stuff, testing everything out, so to speak. That's a good deed, soldier, great job. The higher-ups sent you a little present as a token of gratitude. Keep it up!Greetings, warrior. I've heard you've been helping out our local hard workers with their stuff, testing everything out, so to speak. That's a good deed, soldier, great job. The higher-ups sent you a little present as a token of gratitude. Keep it up!Greetings, warrior. I've heard you've been helping out our local hard workers with their stuff, testing everything out, so to speak. That's a good deed, soldier, great job. The higher-ups sent you a little present as a token of gratitude. Keep it up!Greetings, warrior. I've heard you've been helping out our local hard workers with their stuff, testing everything out, so to speak. That's a good deed, soldier, great job. The higher-ups sent you a little present as a token of gratitude. Keep it up!Greetings, warrior. I've heard you've been helping out our local hard workers with their stuff, testing everything out, so to speak. That's a good deed, soldier, great job. The higher-ups sent you a little present as a token of gratitude. Keep it up!Greetings, warrior. I've heard you've been helping out our local hard workers with their stuff, testing everything out, so to speak. That's a good deed, soldier, great job. The higher-ups sent you a little present as a token of gratitude. Keep it up!Greetings, warrior. I've heard you've been helping out our local hard workers with their stuff, testing everything out, so to speak. That's a good deed, soldier, great job. The higher-ups sent you a little present as a token of gratitude. Keep it up!Greetings, warrior. I've heard you've been helping out our local hard workers with their stuff, testing everything out, so to speak. That's a good deed, soldier, great job. The higher-ups sent you a little present as a token of gratitude. Keep it up!Greetings, warrior. I've heard you've been helping out our local hard workers with their stuff, testing everything out, so to speak. That's a good deed, soldier, great job. The higher-ups sent you a little present as a token of gratitude. Keep it up!Greetings, warrior. I've heard you've been helping out our local hard workers with their stuff, testing everything out, so to speak. That's a good deed, soldier, great job. The higher-ups sent you a little present as a token of gratitude. Keep it up!Greetings, warrior. I've heard you've been helping out our local hard workers with their stuff, testing everything out, so to speak. That's a good deed, soldier, great job. The higher-ups sent you a little present as a token of gratitude. Keep it up!Greetings, warrior. I've heard you've been helping out our local hard workers with their stuff, testing everything out, so to speak. That's a good deed, soldier, great job. The higher-ups sent you a little present as a token of gratitude. Keep it up!Привет, боец. Слыхал, ты местным работягам активно помогал, проверял всё на прочность, так сказать. Это дело правильное, молодец, вояка. Ребята сверху тебе за это подарочек передали в знак благодарности. Продолжай в том же духе!Promo code is activated" + "messageText": "Greetings, warrior. I've heard you've been helping out our local hard workers with their stuff, testing everything out, so to speak. That's a good deed, soldier, great job. The higher-ups sent you a little present as a token of gratitude. Keep it up!Greetings, warrior. I've heard you've been helping out our local hard workers with their stuff, testing everything out, so to speak. That's a good deed, soldier, great job. The higher-ups sent you a little present as a token of gratitude. Keep it up!Greetings, warrior. I've heard you've been helping out our local hard workers with their stuff, testing everything out, so to speak. That's a good deed, soldier, great job. The higher-ups sent you a little present as a token of gratitude. Keep it up!Greetings, warrior. I've heard you've been helping out our local hard workers with their stuff, testing everything out, so to speak. That's a good deed, soldier, great job. The higher-ups sent you a little present as a token of gratitude. Keep it up!Greetings, warrior. I've heard you've been helping out our local hard workers with their stuff, testing everything out, so to speak. That's a good deed, soldier, great job. The higher-ups sent you a little present as a token of gratitude. Keep it up!Greetings, warrior. I've heard you've been helping out our local hard workers with their stuff, testing everything out, so to speak. That's a good deed, soldier, great job. The higher-ups sent you a little present as a token of gratitude. Keep it up!Greetings, warrior. I've heard you've been helping out our local hard workers with their stuff, testing everything out, so to speak. That's a good deed, soldier, great job. The higher-ups sent you a little present as a token of gratitude. Keep it up!Greetings, warrior. I've heard you've been helping out our local hard workers with their stuff, testing everything out, so to speak. That's a good deed, soldier, great job. The higher-ups sent you a little present as a token of gratitude. Keep it up!Greetings, warrior. I've heard you've been helping out our local hard workers with their stuff, testing everything out, so to speak. That's a good deed, soldier, great job. The higher-ups sent you a little present as a token of gratitude. Keep it up!Greetings, warrior. I've heard you've been helping out our local hard workers with their stuff, testing everything out, so to speak. That's a good deed, soldier, great job. The higher-ups sent you a little present as a token of gratitude. Keep it up!Greetings, warrior. I've heard you've been helping out our local hard workers with their stuff, testing everything out, so to speak. That's a good deed, soldier, great job. The higher-ups sent you a little present as a token of gratitude. Keep it up!Greetings, warrior. I've heard you've been helping out our local hard workers with their stuff, testing everything out, so to speak. That's a good deed, soldier, great job. The higher-ups sent you a little present as a token of gratitude. Keep it up!Greetings, warrior. I've heard you've been helping out our local hard workers with their stuff, testing everything out, so to speak. That's a good deed, soldier, great job. The higher-ups sent you a little present as a token of gratitude. Keep it up!Greetings, warrior. I've heard you've been helping out our local hard workers with their stuff, testing everything out, so to speak. That's a good deed, soldier, great job. The higher-ups sent you a little present as a token of gratitude. Keep it up!Greetings, warrior. I've heard you've been helping out our local hard workers with their stuff, testing everything out, so to speak. That's a good deed, soldier, great job. The higher-ups sent you a little present as a token of gratitude. Keep it up!Привет, боец. Слыхал, ты местным работягам активно помогал, проверял всё на прочность, так сказать. Это дело правильное, молодец, вояка. Ребята сверху тебе за это подарочек передали в знак благодарности. Продолжай в том же духе!Promo code is activated", + "maxToSendPlayer": 1 }, "KONTOROVICH": { "items": [ @@ -3662,7 +3693,8 @@ "sender": "System", "associatedEvent": "Promo", "collectionTimeHours": 72, - "messageText": "Thank you for purchasing of the first book in EFT series by A, Kontorovich. We are glad to give you this theme package with ingame items." + "messageText": "Thank you for purchasing of the first book in EFT series by A, Kontorovich. We are glad to give you this theme package with ingame items.", + "maxToSendPlayer": 1 }, "UNHEARD": { "items": [ @@ -3679,7 +3711,8 @@ "sender": "System", "messageText": "Have a nice 20 minute adventure in the blatant plagiarist game. In and out", "collectionTimeHours": 72, - "associatedEvent": "Promo" + "associatedEvent": "Promo", + "maxToSendPlayer": 1 }, "TOURNAMENTGIFT": { "items": [{ @@ -5440,7 +5473,8 @@ "value": 1, "entity": "5c0647fdd443bc2504c2d371" } - ] + ], + "maxToSendPlayer": 1 }, "HIDEOUTCAT": { "items": [ @@ -5457,7 +5491,8 @@ "sender": "System", "associatedEvent": "Promo", "collectionTimeHours": 72, - "messageText": "Hideout cat." + "messageText": "Hideout cat.", + "maxToSendPlayer": 1 }, "KILLA": { "items": [{ @@ -5481,7 +5516,8 @@ "sender": "System", "messageText": "TarkovTV May 2024 gift", "collectionTimeHours": 48, - "associatedEvent": "Promo" + "associatedEvent": "Promo", + "maxToSendPlayer": 1 }, "BITCOIN": { "items": [{ @@ -5709,7 +5745,8 @@ "sender": "System", "messageText": "TarkovTV May 2024 gift", "collectionTimeHours": 48, - "associatedEvent": "Promo" + "associatedEvent": "Promo", + "maxToSendPlayer": 1 }, "GROUNDZERO2": { "items": [{ @@ -5865,7 +5902,8 @@ "sender": "System", "messageText": "TarkovTV May 2024 gift", "collectionTimeHours": 48, - "associatedEvent": "Promo" + "associatedEvent": "Promo", + "maxToSendPlayer": 1 }, "OBDOLBOS": { "items": [{ @@ -6001,7 +6039,8 @@ "sender": "System", "messageText": "TarkovTV May 2024 gift", "collectionTimeHours": 48, - "associatedEvent": "Promo" + "associatedEvent": "Promo", + "maxToSendPlayer": 1 }, "THICC": { "items": [{ @@ -6136,7 +6175,8 @@ "sender": "System", "messageText": "TarkovTV May 2024 gift", "collectionTimeHours": 48, - "associatedEvent": "Promo" + "associatedEvent": "Promo", + "maxToSendPlayer": 1 } } } \ No newline at end of file diff --git a/project/src/helpers/Dialogue/SptDialogueChatBot.ts b/project/src/helpers/Dialogue/SptDialogueChatBot.ts index 7d453f56..419e82f2 100644 --- a/project/src/helpers/Dialogue/SptDialogueChatBot.ts +++ b/project/src/helpers/Dialogue/SptDialogueChatBot.ts @@ -59,6 +59,8 @@ export class SptDialogueChatBot implements IDialogueChatBot const giftSent = this.giftService.sendGiftToPlayer(sessionId, request.text); + const requestInput = request.text.toLowerCase(); + if (giftSent === GiftSentResult.SUCCESS) { this.mailSendService.sendUserMessageToPlayer( @@ -85,7 +87,7 @@ export class SptDialogueChatBot implements IDialogueChatBot return; } - if (request.text.toLowerCase().includes("love you")) + if (requestInput.includes("love you")) { this.mailSendService.sendUserMessageToPlayer( sessionId, @@ -99,7 +101,7 @@ export class SptDialogueChatBot implements IDialogueChatBot ); } - if (request.text.toLowerCase() === "spt") + if (requestInput === "spt") { this.mailSendService.sendUserMessageToPlayer( sessionId, @@ -108,7 +110,7 @@ export class SptDialogueChatBot implements IDialogueChatBot ); } - if (["hello", "hi", "sup", "yo", "hey"].includes(request.text.toLowerCase())) + if (["hello", "hi", "sup", "yo", "hey"].includes(requestInput)) { this.mailSendService.sendUserMessageToPlayer( sessionId, @@ -128,7 +130,7 @@ export class SptDialogueChatBot implements IDialogueChatBot ); } - if (request.text.toLowerCase() === "nikita") + if (requestInput === "nikita") { this.mailSendService.sendUserMessageToPlayer( sessionId, @@ -137,12 +139,12 @@ export class SptDialogueChatBot implements IDialogueChatBot "I know that guy!", "Cool guy, he made EFT!", "Legend", - "Remember when he said webel-webel-webel-webel, classic nikita moment", + "Remember when he said webel-webel-webel-webel, classic Nikita moment", ]), ); } - if (request.text.toLowerCase() === "are you a bot") + if (requestInput === "are you a bot") { this.mailSendService.sendUserMessageToPlayer( sessionId, @@ -151,7 +153,7 @@ export class SptDialogueChatBot implements IDialogueChatBot ); } - if (request.text.toLowerCase() === "itsonlysnowalan") + if (requestInput === "itsonlysnowalan") { this.weatherConfig.overrideSeason = Season.WINTER; @@ -162,15 +164,34 @@ export class SptDialogueChatBot implements IDialogueChatBot ); } - if (request.text.toLowerCase() === "givemespace") + if (requestInput === "givemespace") { - this.profileHelper.addStashRowsBonusToProfile(sessionId, 2); + const stashRowGiftId = "StashRows"; + if ( + this.profileHelper.playerHasRecievedMaxNumberOfGift(sessionId, stashRowGiftId)) + { + this.mailSendService.sendUserMessageToPlayer( + sessionId, + sptFriendUser, + "You cannot accept any more of this gift", + ); + } + else + { + this.profileHelper.addStashRowsBonusToProfile(sessionId, 2); - this.mailSendService.sendUserMessageToPlayer( - sessionId, - sptFriendUser, - this.randomUtil.getArrayValue(["Added 2 rows to stash, please restart your game to see them"]), - ); + this.mailSendService.sendUserMessageToPlayer( + sessionId, + sptFriendUser, + this.randomUtil.getArrayValue(["Added 2 rows to stash, please restart your game to see them"]), + ); + + this.profileHelper.flagGiftReceivedInProfile( + sessionId, + stashRowGiftId, + this.coreConfig.features.chatbotFeatures.commandUseLimits[stashRowGiftId], + ); + } } return request.dialogId; diff --git a/project/src/helpers/ProfileHelper.ts b/project/src/helpers/ProfileHelper.ts index acacd0a9..da2ca0f1 100644 --- a/project/src/helpers/ProfileHelper.ts +++ b/project/src/helpers/ProfileHelper.ts @@ -367,17 +367,32 @@ export class ProfileHelper * Store giftid in profile spt object * @param playerId Player to add gift flag to * @param giftId Gift player received + * @param maxCount Limit of how many of this gift a player can have */ - public addGiftReceivedFlagToProfile(playerId: string, giftId: string): void + public flagGiftReceivedInProfile(playerId: string, giftId: string, maxCount: number): void { const profileToUpdate = this.getFullProfile(playerId); - const giftHistory = profileToUpdate.spt.receivedGifts; - if (!giftHistory) - { - profileToUpdate.spt.receivedGifts = []; - } - profileToUpdate.spt.receivedGifts.push({ giftId: giftId, timestampAccepted: this.timeUtil.getTimestamp() }); + // nullguard receivedGifts + profileToUpdate.spt.receivedGifts ||= []; + + const giftData = profileToUpdate.spt.receivedGifts.find((gift) => gift.giftId === giftId); + if (giftData) + { + // Increment counter + giftData.current++; + } + else + { + // Player has never received gift, make a new object + profileToUpdate.spt.receivedGifts.push( + { + giftId: giftId, + timestampLastAccepted: this.timeUtil.getTimestamp(), + max: maxCount, + current: 1, + }); + } } /** @@ -386,7 +401,7 @@ export class ProfileHelper * @param giftId Gift to check for * @returns True if player has recieved gift previously */ - public playerHasRecievedGift(playerId: string, giftId: string): boolean + public playerHasRecievedMaxNumberOfGift(playerId: string, giftId: string): boolean { const profile = this.getFullProfile(playerId); if (!profile) @@ -400,7 +415,13 @@ export class ProfileHelper return false; } - return !!profile.spt.receivedGifts.find((x) => x.giftId === giftId); + const giftDataFromProfile = profile.spt.receivedGifts.find((x) => x.giftId === giftId); + if (!giftDataFromProfile) + { + return false; + } + + return giftDataFromProfile.current >= giftDataFromProfile.max; } /** diff --git a/project/src/models/eft/profile/ISptProfile.ts b/project/src/models/eft/profile/ISptProfile.ts index aac1bd45..544cc37b 100644 --- a/project/src/models/eft/profile/ISptProfile.ts +++ b/project/src/models/eft/profile/ISptProfile.ts @@ -231,7 +231,9 @@ export interface ModDetails export interface ReceivedGift { giftId: string - timestampAccepted: number + timestampLastAccepted: number + current: number + max: number } export interface Vitality diff --git a/project/src/models/spt/config/ICoreConfig.ts b/project/src/models/spt/config/ICoreConfig.ts index dc4e2ae8..a1d1de61 100644 --- a/project/src/models/spt/config/ICoreConfig.ts +++ b/project/src/models/spt/config/ICoreConfig.ts @@ -94,6 +94,7 @@ export interface IChatbotFeatures sptFriendEnabled: boolean commandoEnabled: boolean commandoFeatures: ICommandoFeatures + commandUseLimits: Record } export interface ICommandoFeatures diff --git a/project/src/models/spt/config/IGiftsConfig.ts b/project/src/models/spt/config/IGiftsConfig.ts index 1119b759..290ea5d0 100644 --- a/project/src/models/spt/config/IGiftsConfig.ts +++ b/project/src/models/spt/config/IGiftsConfig.ts @@ -32,4 +32,5 @@ export interface Gift collectionTimeHours: number /** Optional, can be used to change profile settings like level/skills */ profileChangeEvents?: IProfileChangeEvent[] + maxToSendPlayer?: number } diff --git a/project/src/services/GiftService.ts b/project/src/services/GiftService.ts index a785acaa..611ab92d 100644 --- a/project/src/services/GiftService.ts +++ b/project/src/services/GiftService.ts @@ -56,7 +56,7 @@ export class GiftService return GiftSentResult.FAILED_GIFT_DOESNT_EXIST; } - if (this.profileHelper.playerHasRecievedGift(playerId, giftId)) + if (this.profileHelper.playerHasRecievedMaxNumberOfGift(playerId, giftId)) { this.logger.debug(`Player already recieved gift: ${giftId}`); @@ -154,7 +154,7 @@ export class GiftService this.mailSendService.sendMessageToPlayer(details); } - this.profileHelper.addGiftReceivedFlagToProfile(playerId, giftId); + this.profileHelper.flagGiftReceivedInProfile(playerId, giftId, giftData.maxToSendPlayer ?? 1); return GiftSentResult.SUCCESS; } @@ -208,13 +208,13 @@ export class GiftService switch (day) { case 1: - if (this.profileHelper.playerHasRecievedGift(sessionId, "PraporGiftDay1")) + if (this.profileHelper.playerHasRecievedMaxNumberOfGift(sessionId, "PraporGiftDay1")) { this.sendGiftToPlayer(sessionId, "PraporGiftDay1"); } break; case 2: - if (this.profileHelper.playerHasRecievedGift(sessionId, "PraporGiftDay2")) + if (this.profileHelper.playerHasRecievedMaxNumberOfGift(sessionId, "PraporGiftDay2")) { this.sendGiftToPlayer(sessionId, "PraporGiftDay2"); } diff --git a/project/src/services/SeasonalEventService.ts b/project/src/services/SeasonalEventService.ts index 56ed970f..01c82e66 100644 --- a/project/src/services/SeasonalEventService.ts +++ b/project/src/services/SeasonalEventService.ts @@ -614,7 +614,7 @@ export class SeasonalEventService */ protected giveGift(playerId: string, giftkey: string): void { - if (!this.profileHelper.playerHasRecievedGift(playerId, giftkey)) + if (!this.profileHelper.playerHasRecievedMaxNumberOfGift(playerId, giftkey)) { this.giftService.sendGiftToPlayer(playerId, giftkey); }