mirror of
https://github.com/sp-tarkov/server.git
synced 2025-02-13 06:10:44 -05:00
Reworked gift sending/storage sytem to not store the max sends in profile and use the existing gift data
Fixed `sendPraporStartingGift()` not sending gifts Expanded `GiftService` to include methods to get gift by id / all gifts / all gift ids
This commit is contained in:
parent
19bcfe2e87
commit
ca642b94a7
@ -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": [
|
||||
|
@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -233,7 +233,6 @@ export interface ReceivedGift
|
||||
giftId: string
|
||||
timestampLastAccepted: number
|
||||
current: number
|
||||
max: number
|
||||
}
|
||||
|
||||
export interface Vitality
|
||||
|
@ -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<string, Gift>
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user