diff --git a/Libraries/SPTarkov.Server.Core/Extensions/ProfileExtensions.cs b/Libraries/SPTarkov.Server.Core/Extensions/ProfileExtensions.cs index e8144e79..aa13561c 100644 --- a/Libraries/SPTarkov.Server.Core/Extensions/ProfileExtensions.cs +++ b/Libraries/SPTarkov.Server.Core/Extensions/ProfileExtensions.cs @@ -164,5 +164,12 @@ namespace SPTarkov.Server.Core.Extensions // Sum all bonuses found above return bonuses?.Sum(bonus => bonus?.Value ?? 0) ?? 0; } + + public static bool PlayerIsFleaBanned(this PmcData pmcProfile, long currentTimestamp) + { + return pmcProfile?.Info?.Bans?.Any(b => + b.BanType == BanType.RagFair && currentTimestamp < b.DateTime + ) ?? false; + } } } diff --git a/Libraries/SPTarkov.Server.Core/Helpers/Dialogue/SPTFriend/Commands/GiveMeSpaceMessageHandler.cs b/Libraries/SPTarkov.Server.Core/Helpers/Dialogue/SPTFriend/Commands/GiveMeSpaceMessageHandler.cs index 799c7bbb..f4441529 100644 --- a/Libraries/SPTarkov.Server.Core/Helpers/Dialogue/SPTFriend/Commands/GiveMeSpaceMessageHandler.cs +++ b/Libraries/SPTarkov.Server.Core/Helpers/Dialogue/SPTFriend/Commands/GiveMeSpaceMessageHandler.cs @@ -40,7 +40,7 @@ public class GiveMeSpaceMessageHandler( var maxGiftsToSendCount = _coreConfig.Features.ChatbotFeatures.CommandUseLimits[stashRowGiftId] ?? 5; if ( - _profileHelper.PlayerHasRecievedMaxNumberOfGift( + _profileHelper.PlayerHasReceivedMaxNumberOfGift( sessionId, stashRowGiftId, maxGiftsToSendCount diff --git a/Libraries/SPTarkov.Server.Core/Helpers/ProfileHelper.cs b/Libraries/SPTarkov.Server.Core/Helpers/ProfileHelper.cs index 7488e228..3bdbda2a 100644 --- a/Libraries/SPTarkov.Server.Core/Helpers/ProfileHelper.cs +++ b/Libraries/SPTarkov.Server.Core/Helpers/ProfileHelper.cs @@ -22,14 +22,13 @@ public class ProfileHelper( SaveServer _saveServer, DatabaseService _databaseService, Watermark _watermark, - ItemHelper _itemHelper, TimeUtil _timeUtil, LocalisationService _localisationService, HashUtil _hashUtil, ConfigServer _configServer ) { - protected static readonly FrozenSet gameEditionsWithFreeRefresh = + protected static readonly FrozenSet _gameEditionsWithFreeRefresh = [ "edge_of_darkness", "unheard_edition", @@ -38,7 +37,7 @@ public class ProfileHelper( _configServer.GetConfig(); /// - /// Remove/reset a completed quest condtion from players profile quest data + /// Remove/reset a completed quest condition from players profile quest data /// /// Session id /// Quest with condition to remove @@ -213,9 +212,9 @@ public class ProfileHelper( return new Spt { Version = _watermark.GetVersionTag(true), - Mods = new List(), - ReceivedGifts = new List(), - BlacklistedItemTemplates = new HashSet(), + Mods = [], + ReceivedGifts = [], + BlacklistedItemTemplates = [], FreeRepeatableRefreshUsedCount = new Dictionary(), Migrations = new Dictionary(), CultistRewards = new Dictionary(), @@ -239,12 +238,12 @@ public class ProfileHelper( /// /// Account ID to find /// - public SptProfile? GetFullProfileByAccountId(string accountID) + public SptProfile? GetFullProfileByAccountId(string accountId) { - var check = int.TryParse(accountID, out var aid); + var check = int.TryParse(accountId, out var aid); if (!check) { - _logger.Error($"Account {accountID} does not exist"); + _logger.Error($"Account {accountId} does not exist"); } return _saveServer @@ -298,9 +297,7 @@ public class ProfileHelper( /// PmcData object public PmcData? GetPmcProfile(string sessionID) { - var fullProfile = GetFullProfile(sessionID); - - return fullProfile?.CharacterData?.PmcData; + return GetFullProfile(sessionID)?.CharacterData?.PmcData; } /// @@ -334,16 +331,16 @@ public class ProfileHelper( { Eft = new EftStats { - CarriedQuestItems = new List(), + CarriedQuestItems = [], DamageHistory = new DamageHistory { LethalDamagePart = "Head", LethalDamage = null, BodyParts = new BodyPartsDamageHistory(), }, - DroppedItems = new List(), + DroppedItems = [], ExperienceBonusMult = 0, - FoundInRaidItems = new List(), + FoundInRaidItems = [], LastPlayerState = null, LastSessionDate = 0, OverallCounters = new OverallCounters { Items = [] }, @@ -352,7 +349,7 @@ public class ProfileHelper( SurvivorClass = "Unknown", TotalInGameTime = 0, TotalSessionExperience = 0, - Victims = new List(), + Victims = [], }, }; } @@ -362,7 +359,7 @@ public class ProfileHelper( /// /// Profile id /// True if profile is to be wiped of data/progress - /// TODO: logic doesnt feel right to have IsWiped being nullable + /// TODO: logic doesn't feel right to have IsWiped being nullable protected bool IsWiped(string sessionID) { return _saveServer.GetProfile(sessionID)?.ProfileInfo?.IsWiped ?? false; @@ -395,7 +392,7 @@ public class ProfileHelper( /// /// Flag a profile as having received a gift - /// Store giftid in profile spt object + /// Store giftId in profile spt object /// /// Player to add gift flag to /// Gift player received @@ -403,7 +400,7 @@ public class ProfileHelper( public void FlagGiftReceivedInProfile(string playerId, string giftId, int maxCount) { var profileToUpdate = GetFullProfile(playerId); - profileToUpdate.SptData.ReceivedGifts ??= new List(); + profileToUpdate.SptData.ReceivedGifts ??= []; var giftData = profileToUpdate.SptData.ReceivedGifts.FirstOrDefault(g => g.GiftId == giftId @@ -427,13 +424,13 @@ public class ProfileHelper( } /// - /// Check if profile has recieved a gift by id + /// Check if profile has received a gift by id /// /// Player profile to check for gift /// Gift to check for /// Max times gift can be given to player - /// True if player has recieved gift previously - public bool PlayerHasRecievedMaxNumberOfGift(string playerId, string giftId, int maxGiftCount) + /// True if player has received gift previously + public bool PlayerHasReceivedMaxNumberOfGift(string playerId, string giftId, int maxGiftCount) { var profile = GetFullProfile(playerId); if (profile == null) @@ -446,12 +443,7 @@ public class ProfileHelper( return false; } - if (profile.SptData.ReceivedGifts == null) - { - return false; - } - - var giftDataFromProfile = profile.SptData.ReceivedGifts.FirstOrDefault(g => + var giftDataFromProfile = profile.SptData.ReceivedGifts?.FirstOrDefault(g => g.GiftId == giftId ); if (giftDataFromProfile == null) @@ -506,17 +498,15 @@ public class ProfileHelper( /// /// Player profile with skill /// Skill to add points to - /// Points to add + /// Points to add /// Skills are multiplied by a value in globals, default is off to maintain compatibility with legacy code public void AddSkillPointsToPlayer( PmcData pmcProfile, SkillTypes skill, - double? pointsToAdd, + double? pointsToAddToSkill, bool useSkillProgressRateMultiplier = false ) { - var pointsToAddToSkill = pointsToAdd; - if (pointsToAddToSkill < 0D) { _logger.Warning( @@ -532,7 +522,7 @@ public class ProfileHelper( if (profileSkills == null) { _logger.Warning( - $"Unable to add {pointsToAddToSkill} points to {skill}, Profile has no skills" + $"Unable to add: {pointsToAddToSkill} points to {skill}, Profile has no skills" ); return; } @@ -621,7 +611,7 @@ public class ProfileHelper( public double GetBonusValueFromProfile(PmcData pmcProfile, BonusType desiredBonus) { var bonuses = pmcProfile?.Bonuses?.Where(b => b.Type == desiredBonus); - if (!bonuses.Any()) + if (bonuses is null || !bonuses.Any()) { return 0; } @@ -630,17 +620,9 @@ public class ProfileHelper( return bonuses?.Sum(bonus => bonus?.Value ?? 0) ?? 0; } - public bool PlayerIsFleaBanned(PmcData pmcProfile) - { - var currentTimestamp = _timeUtil.GetTimeStamp(); - return pmcProfile?.Info?.Bans?.Any(b => - b.BanType == BanType.RagFair && currentTimestamp < b.DateTime - ) ?? false; - } - public bool HasAccessToRepeatableFreeRefreshSystem(PmcData pmcProfile) { - return gameEditionsWithFreeRefresh.Contains(pmcProfile.Info.GameVersion); + return _gameEditionsWithFreeRefresh.Contains(pmcProfile.Info.GameVersion); } /// diff --git a/Libraries/SPTarkov.Server.Core/Helpers/RagfairOfferHelper.cs b/Libraries/SPTarkov.Server.Core/Helpers/RagfairOfferHelper.cs index 8901cf78..c6878872 100644 --- a/Libraries/SPTarkov.Server.Core/Helpers/RagfairOfferHelper.cs +++ b/Libraries/SPTarkov.Server.Core/Helpers/RagfairOfferHelper.cs @@ -1,5 +1,6 @@ using SPTarkov.Common.Extensions; using SPTarkov.DI.Annotations; +using SPTarkov.Server.Core.Extensions; using SPTarkov.Server.Core.Models.Eft.Common; using SPTarkov.Server.Core.Models.Eft.Common.Tables; using SPTarkov.Server.Core.Models.Eft.ItemEvent; @@ -59,7 +60,7 @@ public class RagfairOfferHelper( PmcData pmcData ) { - var playerIsFleaBanned = _profileHelper.PlayerIsFleaBanned(pmcData); + var playerIsFleaBanned = pmcData.PlayerIsFleaBanned(_timeUtil.GetTimeStamp()); var tieredFlea = _ragfairConfig.TieredFlea; var tieredFleaLimitTypes = tieredFlea.UnlocksType; return _ragfairOfferService @@ -226,7 +227,7 @@ public class RagfairOfferHelper( { var offersMap = new Dictionary>(); var offersToReturn = new List(); - var playerIsFleaBanned = _profileHelper.PlayerIsFleaBanned(pmcData); + var playerIsFleaBanned = pmcData.PlayerIsFleaBanned(_timeUtil.GetTimeStamp()); var tieredFlea = _ragfairConfig.TieredFlea; var tieredFleaLimitTypes = tieredFlea.UnlocksType; diff --git a/Libraries/SPTarkov.Server.Core/Services/GiftService.cs b/Libraries/SPTarkov.Server.Core/Services/GiftService.cs index af502a6b..871d6337 100644 --- a/Libraries/SPTarkov.Server.Core/Services/GiftService.cs +++ b/Libraries/SPTarkov.Server.Core/Services/GiftService.cs @@ -75,7 +75,7 @@ public class GiftService( var maxGiftsToSendCount = giftData.MaxToSendPlayer ?? 1; - if (_profileHelper.PlayerHasRecievedMaxNumberOfGift(playerId, giftId, maxGiftsToSendCount)) + if (_profileHelper.PlayerHasReceivedMaxNumberOfGift(playerId, giftId, maxGiftsToSendCount)) { if (_logger.IsLogEnabled(LogLevel.Debug)) { @@ -249,7 +249,7 @@ public class GiftService( if (giftId is not null) { - if (!_profileHelper.PlayerHasRecievedMaxNumberOfGift(sessionId, giftId, 1)) + if (!_profileHelper.PlayerHasReceivedMaxNumberOfGift(sessionId, giftId, 1)) { SendGiftToPlayer(sessionId, giftId); } @@ -264,7 +264,7 @@ public class GiftService( /// Optional, how many to send public void SendGiftWithSilentReceivedCheck(string giftId, string? sessionId, int giftCount) { - if (!_profileHelper.PlayerHasRecievedMaxNumberOfGift(sessionId, giftId, giftCount)) + if (!_profileHelper.PlayerHasReceivedMaxNumberOfGift(sessionId, giftId, giftCount)) { SendGiftToPlayer(sessionId, giftId); } diff --git a/Libraries/SPTarkov.Server.Core/Services/SeasonalEventService.cs b/Libraries/SPTarkov.Server.Core/Services/SeasonalEventService.cs index 4ead2f83..67ff684f 100644 --- a/Libraries/SPTarkov.Server.Core/Services/SeasonalEventService.cs +++ b/Libraries/SPTarkov.Server.Core/Services/SeasonalEventService.cs @@ -1269,7 +1269,7 @@ public class SeasonalEventService( { var giftData = _giftService.GetGiftById(giftKey); if ( - !_profileHelper.PlayerHasRecievedMaxNumberOfGift( + !_profileHelper.PlayerHasReceivedMaxNumberOfGift( playerId, giftKey, giftData.MaxToSendPlayer ?? 5