mirror of
https://github.com/sp-tarkov/server.git
synced 2025-02-13 09:50:43 -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",
|
"trader": "PRAPOR",
|
||||||
"localeTextId": "5fd4c8b59e4b2a58b34bbd28 0",
|
"localeTextId": "5fd4c8b59e4b2a58b34bbd28 0",
|
||||||
"collectionTimeHours": 48,
|
"collectionTimeHours": 48,
|
||||||
"maxToSendPlayer": 1
|
"maxToSendPlayer": 5
|
||||||
},
|
},
|
||||||
"PraporGiftDay2": {
|
"PraporGiftDay2": {
|
||||||
"items": [
|
"items": [
|
||||||
@ -1271,7 +1271,7 @@
|
|||||||
"trader": "PRAPOR",
|
"trader": "PRAPOR",
|
||||||
"localeTextId": "5fd4c8d49e4b2a58b34bbd29 0",
|
"localeTextId": "5fd4c8d49e4b2a58b34bbd29 0",
|
||||||
"collectionTimeHours": 48,
|
"collectionTimeHours": 48,
|
||||||
"maxToSendPlayer": 1
|
"maxToSendPlayer": 5
|
||||||
},
|
},
|
||||||
"KAPPA4U": {
|
"KAPPA4U": {
|
||||||
"items": [
|
"items": [
|
||||||
|
@ -167,8 +167,12 @@ export class SptDialogueChatBot implements IDialogueChatBot
|
|||||||
if (requestInput === "givemespace")
|
if (requestInput === "givemespace")
|
||||||
{
|
{
|
||||||
const stashRowGiftId = "StashRows";
|
const stashRowGiftId = "StashRows";
|
||||||
|
const maxGiftsToSendCount = this.coreConfig.features.chatbotFeatures.commandUseLimits[stashRowGiftId] ?? 5;
|
||||||
if (
|
if (
|
||||||
this.profileHelper.playerHasRecievedMaxNumberOfGift(sessionId, stashRowGiftId))
|
this.profileHelper.playerHasRecievedMaxNumberOfGift(
|
||||||
|
sessionId,
|
||||||
|
stashRowGiftId,
|
||||||
|
maxGiftsToSendCount))
|
||||||
{
|
{
|
||||||
this.mailSendService.sendUserMessageToPlayer(
|
this.mailSendService.sendUserMessageToPlayer(
|
||||||
sessionId,
|
sessionId,
|
||||||
@ -189,7 +193,7 @@ export class SptDialogueChatBot implements IDialogueChatBot
|
|||||||
this.profileHelper.flagGiftReceivedInProfile(
|
this.profileHelper.flagGiftReceivedInProfile(
|
||||||
sessionId,
|
sessionId,
|
||||||
stashRowGiftId,
|
stashRowGiftId,
|
||||||
this.coreConfig.features.chatbotFeatures.commandUseLimits[stashRowGiftId],
|
maxGiftsToSendCount,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -381,27 +381,27 @@ export class ProfileHelper
|
|||||||
{
|
{
|
||||||
// Increment counter
|
// Increment counter
|
||||||
giftData.current++;
|
giftData.current++;
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
// Player has never received gift, make a new object
|
||||||
// Player has never received gift, make a new object
|
profileToUpdate.spt.receivedGifts.push(
|
||||||
profileToUpdate.spt.receivedGifts.push(
|
{
|
||||||
{
|
giftId: giftId,
|
||||||
giftId: giftId,
|
timestampLastAccepted: this.timeUtil.getTimestamp(),
|
||||||
timestampLastAccepted: this.timeUtil.getTimestamp(),
|
current: 1,
|
||||||
max: maxCount,
|
});
|
||||||
current: 1,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if profile has recieved a gift by id
|
* Check if profile has recieved a gift by id
|
||||||
* @param playerId Player profile to check for gift
|
* @param playerId Player profile to check for gift
|
||||||
* @param giftId Gift to check for
|
* @param giftId Gift to check for
|
||||||
|
* @param maxGiftCount Max times gift can be given to player
|
||||||
* @returns True if player has recieved gift previously
|
* @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);
|
const profile = this.getFullProfile(playerId);
|
||||||
if (!profile)
|
if (!profile)
|
||||||
@ -421,7 +421,7 @@ export class ProfileHelper
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return giftDataFromProfile.current >= giftDataFromProfile.max;
|
return giftDataFromProfile.current >= maxGiftCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -233,7 +233,6 @@ export interface ReceivedGift
|
|||||||
giftId: string
|
giftId: string
|
||||||
timestampLastAccepted: number
|
timestampLastAccepted: number
|
||||||
current: number
|
current: number
|
||||||
max: number
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Vitality
|
export interface Vitality
|
||||||
|
@ -42,6 +42,29 @@ export class GiftService
|
|||||||
return !!this.giftConfig.gifts[giftId];
|
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
|
* Send player a gift from a range of sources
|
||||||
* @param playerId Player to send gift to / sessionId
|
* @param playerId Player to send gift to / sessionId
|
||||||
@ -55,8 +78,8 @@ export class GiftService
|
|||||||
{
|
{
|
||||||
return GiftSentResult.FAILED_GIFT_DOESNT_EXIST;
|
return GiftSentResult.FAILED_GIFT_DOESNT_EXIST;
|
||||||
}
|
}
|
||||||
|
const maxGiftsToSendCount = giftData.maxToSendPlayer ?? 1;
|
||||||
if (this.profileHelper.playerHasRecievedMaxNumberOfGift(playerId, giftId))
|
if (this.profileHelper.playerHasRecievedMaxNumberOfGift(playerId, giftId, maxGiftsToSendCount))
|
||||||
{
|
{
|
||||||
this.logger.debug(`Player already recieved gift: ${giftId}`);
|
this.logger.debug(`Player already recieved gift: ${giftId}`);
|
||||||
|
|
||||||
@ -154,7 +177,7 @@ export class GiftService
|
|||||||
this.mailSendService.sendMessageToPlayer(details);
|
this.mailSendService.sendMessageToPlayer(details);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.profileHelper.flagGiftReceivedInProfile(playerId, giftId, giftData.maxToSendPlayer ?? 1);
|
this.profileHelper.flagGiftReceivedInProfile(playerId, giftId, maxGiftsToSendCount);
|
||||||
|
|
||||||
return GiftSentResult.SUCCESS;
|
return GiftSentResult.SUCCESS;
|
||||||
}
|
}
|
||||||
@ -205,20 +228,30 @@ export class GiftService
|
|||||||
*/
|
*/
|
||||||
public sendPraporStartingGift(sessionId: string, day: number): void
|
public sendPraporStartingGift(sessionId: string, day: number): void
|
||||||
{
|
{
|
||||||
|
let giftId: string;
|
||||||
switch (day)
|
switch (day)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
if (this.profileHelper.playerHasRecievedMaxNumberOfGift(sessionId, "PraporGiftDay1"))
|
{
|
||||||
{
|
giftId = "PraporGiftDay1";
|
||||||
this.sendGiftToPlayer(sessionId, "PraporGiftDay1");
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case 2:
|
case 2:
|
||||||
if (this.profileHelper.playerHasRecievedMaxNumberOfGift(sessionId, "PraporGiftDay2"))
|
{
|
||||||
{
|
giftId = "PraporGiftDay2";
|
||||||
this.sendGiftToPlayer(sessionId, "PraporGiftDay2");
|
|
||||||
}
|
|
||||||
break;
|
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 { IPmcChatResponse } from "@spt/models/spt/config/IPmChatResponse";
|
||||||
import { ILogger } from "@spt/models/spt/utils/ILogger";
|
import { ILogger } from "@spt/models/spt/utils/ILogger";
|
||||||
import { ConfigServer } from "@spt/servers/ConfigServer";
|
import { ConfigServer } from "@spt/servers/ConfigServer";
|
||||||
|
import { GiftService } from "@spt/services/GiftService";
|
||||||
import { LocalisationService } from "@spt/services/LocalisationService";
|
import { LocalisationService } from "@spt/services/LocalisationService";
|
||||||
import { MatchBotDetailsCacheService } from "@spt/services/MatchBotDetailsCacheService";
|
import { MatchBotDetailsCacheService } from "@spt/services/MatchBotDetailsCacheService";
|
||||||
import { HashUtil } from "@spt/utils/HashUtil";
|
import { HashUtil } from "@spt/utils/HashUtil";
|
||||||
@ -29,6 +30,7 @@ export class PmcChatResponseService
|
|||||||
@inject("NotificationSendHelper") protected notificationSendHelper: NotificationSendHelper,
|
@inject("NotificationSendHelper") protected notificationSendHelper: NotificationSendHelper,
|
||||||
@inject("MatchBotDetailsCacheService") protected matchBotDetailsCacheService: MatchBotDetailsCacheService,
|
@inject("MatchBotDetailsCacheService") protected matchBotDetailsCacheService: MatchBotDetailsCacheService,
|
||||||
@inject("LocalisationService") protected localisationService: LocalisationService,
|
@inject("LocalisationService") protected localisationService: LocalisationService,
|
||||||
|
@inject("GiftService") protected giftService: GiftService,
|
||||||
@inject("WeightedRandomHelper") protected weightedRandomHelper: WeightedRandomHelper,
|
@inject("WeightedRandomHelper") protected weightedRandomHelper: WeightedRandomHelper,
|
||||||
@inject("ConfigServer") protected configServer: ConfigServer,
|
@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'.
|
// Give the player a gift code if they were killed adn response is 'pity'.
|
||||||
if (responseType === "pity")
|
if (responseType === "pity")
|
||||||
{
|
{
|
||||||
const giftKeys = Object.keys(this.giftConfig.gifts);
|
const giftKeys = this.giftService.getGiftIds();
|
||||||
const randomGiftKey = this.randomUtil.getStringArrayValue(giftKeys);
|
const randomGiftKey = this.randomUtil.getStringArrayValue(giftKeys);
|
||||||
|
|
||||||
const regex: RegExp = /(%giftcode%)/gi;
|
const regex: RegExp = /(%giftcode%)/gi;
|
||||||
|
@ -610,13 +610,14 @@ export class SeasonalEventService
|
|||||||
/**
|
/**
|
||||||
* Send gift to player if they'e not already received it
|
* Send gift to player if they'e not already received it
|
||||||
* @param playerId Player to send gift to
|
* @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