Converted PlayerIsFleaBanned into extension method

Formatting changes to `ProfileHelper`

Fixed method name typo
This commit is contained in:
Chomp
2025-06-28 13:27:11 +01:00
parent 9c9ac638c0
commit ca3d0730f5
6 changed files with 40 additions and 50 deletions
@@ -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;
}
}
}
@@ -40,7 +40,7 @@ public class GiveMeSpaceMessageHandler(
var maxGiftsToSendCount =
_coreConfig.Features.ChatbotFeatures.CommandUseLimits[stashRowGiftId] ?? 5;
if (
_profileHelper.PlayerHasRecievedMaxNumberOfGift(
_profileHelper.PlayerHasReceivedMaxNumberOfGift(
sessionId,
stashRowGiftId,
maxGiftsToSendCount
@@ -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<string> gameEditionsWithFreeRefresh =
protected static readonly FrozenSet<string> _gameEditionsWithFreeRefresh =
[
"edge_of_darkness",
"unheard_edition",
@@ -38,7 +37,7 @@ public class ProfileHelper(
_configServer.GetConfig<InventoryConfig>();
/// <summary>
/// Remove/reset a completed quest condtion from players profile quest data
/// Remove/reset a completed quest condition from players profile quest data
/// </summary>
/// <param name="sessionID">Session id</param>
/// <param name="questConditionId">Quest with condition to remove</param>
@@ -213,9 +212,9 @@ public class ProfileHelper(
return new Spt
{
Version = _watermark.GetVersionTag(true),
Mods = new List<ModDetails>(),
ReceivedGifts = new List<ReceivedGift>(),
BlacklistedItemTemplates = new HashSet<string>(),
Mods = [],
ReceivedGifts = [],
BlacklistedItemTemplates = [],
FreeRepeatableRefreshUsedCount = new Dictionary<string, int>(),
Migrations = new Dictionary<string, long>(),
CultistRewards = new Dictionary<string, AcceptedCultistReward>(),
@@ -239,12 +238,12 @@ public class ProfileHelper(
/// </summary>
/// <param name="accountId">Account ID to find</param>
/// <returns></returns>
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(
/// <returns>PmcData object</returns>
public PmcData? GetPmcProfile(string sessionID)
{
var fullProfile = GetFullProfile(sessionID);
return fullProfile?.CharacterData?.PmcData;
return GetFullProfile(sessionID)?.CharacterData?.PmcData;
}
/// <summary>
@@ -334,16 +331,16 @@ public class ProfileHelper(
{
Eft = new EftStats
{
CarriedQuestItems = new List<string>(),
CarriedQuestItems = [],
DamageHistory = new DamageHistory
{
LethalDamagePart = "Head",
LethalDamage = null,
BodyParts = new BodyPartsDamageHistory(),
},
DroppedItems = new List<DroppedItem>(),
DroppedItems = [],
ExperienceBonusMult = 0,
FoundInRaidItems = new List<FoundInRaidItem>(),
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<Victim>(),
Victims = [],
},
};
}
@@ -362,7 +359,7 @@ public class ProfileHelper(
/// </summary>
/// <param name="sessionID">Profile id</param>
/// <returns>True if profile is to be wiped of data/progress</returns>
/// 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(
/// <summary>
/// Flag a profile as having received a gift
/// Store giftid in profile spt object
/// Store giftId in profile spt object
/// </summary>
/// <param name="playerId">Player to add gift flag to</param>
/// <param name="giftId">Gift player received</param>
@@ -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<ReceivedGift>();
profileToUpdate.SptData.ReceivedGifts ??= [];
var giftData = profileToUpdate.SptData.ReceivedGifts.FirstOrDefault(g =>
g.GiftId == giftId
@@ -427,13 +424,13 @@ public class ProfileHelper(
}
/// <summary>
/// Check if profile has recieved a gift by id
/// Check if profile has received a gift by id
/// </summary>
/// <param name="playerId">Player profile to check for gift</param>
/// <param name="giftId">Gift to check for</param>
/// <param name="maxGiftCount">Max times gift can be given to player</param>
/// <returns>True if player has recieved gift previously</returns>
public bool PlayerHasRecievedMaxNumberOfGift(string playerId, string giftId, int maxGiftCount)
/// <returns>True if player has received gift previously</returns>
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(
/// </summary>
/// <param name="pmcProfile">Player profile with skill</param>
/// <param name="skill">Skill to add points to</param>
/// <param name="pointsToAdd">Points to add</param>
/// <param name="pointsToAddToSkill">Points to add</param>
/// <param name="useSkillProgressRateMultiplier">Skills are multiplied by a value in globals, default is off to maintain compatibility with legacy code</param>
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);
}
/// <summary>
@@ -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<string, List<RagfairOffer>>();
var offersToReturn = new List<RagfairOffer>();
var playerIsFleaBanned = _profileHelper.PlayerIsFleaBanned(pmcData);
var playerIsFleaBanned = pmcData.PlayerIsFleaBanned(_timeUtil.GetTimeStamp());
var tieredFlea = _ragfairConfig.TieredFlea;
var tieredFleaLimitTypes = tieredFlea.UnlocksType;
@@ -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(
/// <param name="giftCount"> Optional, how many to send </param>
public void SendGiftWithSilentReceivedCheck(string giftId, string? sessionId, int giftCount)
{
if (!_profileHelper.PlayerHasRecievedMaxNumberOfGift(sessionId, giftId, giftCount))
if (!_profileHelper.PlayerHasReceivedMaxNumberOfGift(sessionId, giftId, giftCount))
{
SendGiftToPlayer(sessionId, giftId);
}
@@ -1269,7 +1269,7 @@ public class SeasonalEventService(
{
var giftData = _giftService.GetGiftById(giftKey);
if (
!_profileHelper.PlayerHasRecievedMaxNumberOfGift(
!_profileHelper.PlayerHasReceivedMaxNumberOfGift(
playerId,
giftKey,
giftData.MaxToSendPlayer ?? 5