Implement websocket stash row change notification (#462)
* implement stash rows notification * rename class
This commit is contained in:
+28
-18
@@ -1,6 +1,8 @@
|
||||
using SPTarkov.DI.Annotations;
|
||||
using SPTarkov.Server.Core.Models.Common;
|
||||
using SPTarkov.Server.Core.Models.Eft.Common;
|
||||
using SPTarkov.Server.Core.Models.Eft.Profile;
|
||||
using SPTarkov.Server.Core.Models.Eft.Ws;
|
||||
using SPTarkov.Server.Core.Models.Spt.Config;
|
||||
using SPTarkov.Server.Core.Servers;
|
||||
using SPTarkov.Server.Core.Services;
|
||||
@@ -10,14 +12,15 @@ namespace SPTarkov.Server.Core.Helpers.Dialogue.SPTFriend.Commands;
|
||||
|
||||
[Injectable]
|
||||
public class GiveMeSpaceMessageHandler(
|
||||
ProfileHelper _profileHelper,
|
||||
ServerLocalisationService _serverLocalisationService,
|
||||
MailSendService _mailSendService,
|
||||
RandomUtil _randomUtil,
|
||||
ConfigServer _configServer
|
||||
ProfileHelper profileHelper,
|
||||
NotificationSendHelper notificationSendHelper,
|
||||
ServerLocalisationService serverLocalisationService,
|
||||
MailSendService mailSendService,
|
||||
RandomUtil randomUtil,
|
||||
ConfigServer configServer
|
||||
) : IChatMessageHandler
|
||||
{
|
||||
private readonly CoreConfig _coreConfig = _configServer.GetConfig<CoreConfig>();
|
||||
private readonly CoreConfig _coreConfig = configServer.GetConfig<CoreConfig>();
|
||||
|
||||
public int GetPriority()
|
||||
{
|
||||
@@ -40,40 +43,47 @@ public class GiveMeSpaceMessageHandler(
|
||||
var maxGiftsToSendCount =
|
||||
_coreConfig.Features.ChatbotFeatures.CommandUseLimits[stashRowGiftId] ?? 5;
|
||||
if (
|
||||
_profileHelper.PlayerHasReceivedMaxNumberOfGift(
|
||||
profileHelper.PlayerHasReceivedMaxNumberOfGift(
|
||||
sessionId,
|
||||
stashRowGiftId,
|
||||
maxGiftsToSendCount
|
||||
)
|
||||
)
|
||||
{
|
||||
_mailSendService.SendUserMessageToPlayer(
|
||||
mailSendService.SendUserMessageToPlayer(
|
||||
sessionId,
|
||||
sptFriendUser,
|
||||
_serverLocalisationService.GetText("chatbot-cannot_accept_any_more_of_gift"),
|
||||
serverLocalisationService.GetText("chatbot-cannot_accept_any_more_of_gift"),
|
||||
[],
|
||||
null
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
_profileHelper.AddStashRowsBonusToProfile(sessionId, 2);
|
||||
const int rowsToAdd = 2;
|
||||
var bonusId = profileHelper.AddStashRowsBonusToProfile(sessionId, rowsToAdd);
|
||||
|
||||
_mailSendService.SendUserMessageToPlayer(
|
||||
notificationSendHelper.SendMessage(
|
||||
sessionId,
|
||||
new WsProfileChangeEvent
|
||||
{
|
||||
EventIdentifier = new MongoId(),
|
||||
EventType = NotificationEventType.StashRows,
|
||||
Changes = new Dictionary<string, double?> { { bonusId, rowsToAdd } },
|
||||
}
|
||||
);
|
||||
|
||||
mailSendService.SendUserMessageToPlayer(
|
||||
sessionId,
|
||||
sptFriendUser,
|
||||
_randomUtil.GetArrayValue(
|
||||
[_serverLocalisationService.GetText("chatbot-added_stash_rows_please_restart")]
|
||||
randomUtil.GetArrayValue(
|
||||
[serverLocalisationService.GetText("chatbot-added_stash_rows_please_restart")]
|
||||
),
|
||||
[],
|
||||
null
|
||||
);
|
||||
|
||||
_profileHelper.FlagGiftReceivedInProfile(
|
||||
sessionId,
|
||||
stashRowGiftId,
|
||||
maxGiftsToSendCount
|
||||
);
|
||||
profileHelper.FlagGiftReceivedInProfile(sessionId, stashRowGiftId, maxGiftsToSendCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -569,21 +569,26 @@ public class ProfileHelper(
|
||||
/// </summary>
|
||||
/// <param name="sessionId">Profile id to give rows to</param>
|
||||
/// <param name="rowsToAdd">How many rows to give profile</param>
|
||||
public void AddStashRowsBonusToProfile(MongoId sessionId, int rowsToAdd)
|
||||
/// <returns>The stash rows bonus id, this is needed for ws notification if we send one</returns>
|
||||
public MongoId? AddStashRowsBonusToProfile(MongoId sessionId, int rowsToAdd)
|
||||
{
|
||||
var profile = GetPmcProfile(sessionId);
|
||||
if (profile?.Bonuses is null)
|
||||
{
|
||||
// Something is very wrong with profile to lack bonuses array, likely broken profile, exit early
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
var existingBonus = profile?.Bonuses.FirstOrDefault(b => b.Type == BonusType.StashRows);
|
||||
|
||||
var existingBonus = profile.Bonuses.FirstOrDefault(b => b.Type == BonusType.StashRows);
|
||||
|
||||
var bonusId = existingBonus?.Id;
|
||||
if (existingBonus is null)
|
||||
{
|
||||
profile!.Bonuses.Add(
|
||||
bonusId = new MongoId();
|
||||
profile.Bonuses.Add(
|
||||
new Bonus
|
||||
{
|
||||
Id = new MongoId(),
|
||||
Id = bonusId.Value,
|
||||
Value = rowsToAdd,
|
||||
Type = BonusType.StashRows,
|
||||
IsPassive = true,
|
||||
@@ -596,6 +601,8 @@ public class ProfileHelper(
|
||||
{
|
||||
existingBonus.Value += rowsToAdd;
|
||||
}
|
||||
|
||||
return bonusId!.Value;
|
||||
}
|
||||
|
||||
public bool HasAccessToRepeatableFreeRefreshSystem(PmcData pmcProfile)
|
||||
|
||||
@@ -107,7 +107,21 @@ public class RewardHelper(
|
||||
AddAchievementToProfile(fullProfile, reward.Target);
|
||||
break;
|
||||
case RewardType.StashRows:
|
||||
profileHelper.AddStashRowsBonusToProfile(sessionId.Value, (int)reward.Value); // Add specified stash rows from reward - requires client restart
|
||||
var bonusId = profileHelper.AddStashRowsBonusToProfile(
|
||||
sessionId.Value,
|
||||
(int)reward.Value
|
||||
); // Add specified stash rows from reward - requires client restart
|
||||
|
||||
notificationSendHelper.SendMessage(
|
||||
sessionId.Value,
|
||||
new WsProfileChangeEvent
|
||||
{
|
||||
EventIdentifier = new MongoId(),
|
||||
EventType = NotificationEventType.StashRows,
|
||||
Changes = new Dictionary<string, double?> { { bonusId, reward.Value } },
|
||||
}
|
||||
);
|
||||
|
||||
break;
|
||||
case RewardType.ProductionScheme:
|
||||
FindAndAddHideoutProductionIdToProfile(
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace SPTarkov.Server.Core.Models.Eft.Ws;
|
||||
|
||||
public record WsProfileChangeEvent : WsNotificationEvent
|
||||
{
|
||||
[JsonPropertyName("Changes")]
|
||||
public Dictionary<string, double?> Changes { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user