diff --git a/Core/Models/Spt/Config/GiftsConfig.cs b/Core/Models/Spt/Config/GiftsConfig.cs index ceeebed8..16e2177b 100644 --- a/Core/Models/Spt/Config/GiftsConfig.cs +++ b/Core/Models/Spt/Config/GiftsConfig.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Core.Models.Eft.Common.Tables; using Core.Models.Eft.Profile; using Core.Models.Enums; @@ -63,7 +63,7 @@ public class Gift public SeasonalEventType AssociatedEvent { get; set; } [JsonPropertyName("collectionTimeHours")] - public int CollectionTimeHours { get; set; } + public int? CollectionTimeHours { get; set; } /// /// Optional, can be used to change profile settings like level/skills diff --git a/Core/Services/GiftService.cs b/Core/Services/GiftService.cs index d513f58b..c5c7b952 100644 --- a/Core/Services/GiftService.cs +++ b/Core/Services/GiftService.cs @@ -1,12 +1,32 @@ -using Core.Annotations; +using Core.Annotations; +using Core.Helpers; using Core.Models.Enums; using Core.Models.Spt.Config; +using Core.Servers; +using ILogger = Core.Models.Utils.ILogger; namespace Core.Services; [Injectable(InjectionType.Singleton)] public class GiftService { + private readonly ILogger _logger; + private readonly ConfigServer _configServer; + private readonly ProfileHelper _profileHelper; + private readonly GiftsConfig _giftConfig; + + public GiftService( + ILogger logger, + ConfigServer configServer, + ProfileHelper profileHelper) + { + _logger = logger; + _configServer = configServer; + _profileHelper = profileHelper; + + _giftConfig = _configServer.GetConfig(ConfigTypes.GIFTS); + } + /** * Does a gift with a specific ID exist in db * @param giftId Gift id to check for @@ -19,7 +39,9 @@ public class GiftService public Gift GetGiftById(string giftId) { - throw new NotImplementedException(); + _giftConfig.Gifts.TryGetValue(giftId, out var gift); + + return gift; } /** @@ -48,6 +70,26 @@ public class GiftService */ public GiftSentResult SendGiftToPlayer(string playerId, string giftId) { + var giftData = GetGiftById(giftId); + if (giftData is null) + { + return GiftSentResult.FAILED_GIFT_DOESNT_EXIST; + } + + var maxGiftsToSendCount = giftData.MaxToSendPlayer ?? 1; + + if (_profileHelper.PlayerHasRecievedMaxNumberOfGift(playerId, giftId, maxGiftsToSendCount)) + { + _logger.Debug($"Player already received gift: {giftId}"); + + return GiftSentResult.FAILED_GIFT_ALREADY_RECEIVED; + } + + if (giftData.Items?.Count > 0 && giftData.CollectionTimeHours is not null) + { + _logger.Warning($"Gift {giftId} has items but no collection time limit, defaulting to 48 hours"); + } + throw new NotImplementedException(); } @@ -78,6 +120,20 @@ public class GiftService */ public void SendPraporStartingGift(string sessionId, int day) { - throw new NotImplementedException(); + var giftId = day switch + { + 1 => "PraporGiftDay1", + 2 => "PraporGiftDay2", + _ => null + }; + + if (giftId is not null) + { + //var giftData = GetGiftById(giftId); + if (!_profileHelper.PlayerHasRecievedMaxNumberOfGift(sessionId, giftId, 1)) + { + SendGiftToPlayer(sessionId, giftId); + } + } } }