From f55b2a51f9bdd030ccdacedfcfe7e2f98318f8bc Mon Sep 17 00:00:00 2001 From: Chomp Date: Tue, 14 Jan 2025 21:33:13 +0000 Subject: [PATCH] Partially implemented seasonalEventConfig --- Core/Models/Spt/Config/SeasonalEventConfig.cs | 6 +- Core/Services/SeasonalEventService.cs | 211 +++++++++++++++--- 2 files changed, 186 insertions(+), 31 deletions(-) diff --git a/Core/Models/Spt/Config/SeasonalEventConfig.cs b/Core/Models/Spt/Config/SeasonalEventConfig.cs index 8a117b3e..103fc513 100644 --- a/Core/Models/Spt/Config/SeasonalEventConfig.cs +++ b/Core/Models/Spt/Config/SeasonalEventConfig.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Core.Models.Eft.Common; using Core.Models.Enums; using Core.Utils.Json.Converters; @@ -15,11 +15,11 @@ public class SeasonalEventConfig : BaseConfig /** event / botType / equipSlot / itemid */ [JsonPropertyName("eventGear")] - public Dictionary>>> EventGear { get; set; } + public Dictionary>>> EventGear { get; set; } /** event / bot type / equipSlot / itemid */ [JsonPropertyName("eventLoot")] - public Dictionary>>> EventLoot { get; set; } + public Dictionary>>> EventLoot { get; set; } [JsonPropertyName("events")] public List Events { get; set; } diff --git a/Core/Services/SeasonalEventService.cs b/Core/Services/SeasonalEventService.cs index 32832231..55e3fd26 100644 --- a/Core/Services/SeasonalEventService.cs +++ b/Core/Services/SeasonalEventService.cs @@ -1,40 +1,120 @@ using Core.Annotations; +using Core.Helpers; using Core.Models.Eft.Common; using Core.Models.Eft.Common.Tables; using Core.Models.Enums; using Core.Models.Spt.Config; +using Core.Servers; +using Core.Utils; +using ILogger = Core.Models.Utils.ILogger; namespace Core.Services; [Injectable(InjectionType.Singleton)] public class SeasonalEventService { + private readonly ILogger _logger; + private readonly DatabaseService _databaseService; + private readonly DatabaseImporter _databaseImporter; + private readonly GiftService _giftService; + private readonly LocalisationService _localisationService; + private readonly BotHelper _botHelper; + private readonly ProfileHelper _profileHelper; + private readonly ConfigServer _configServer; + + private bool _christmasEventActive = false; + private bool _halloweenEventActive = false; + + private readonly SeasonalEventConfig _seasonalEventConfig; + private readonly QuestConfig _questConfig; + private readonly HttpConfig _httpConfig; + private readonly WeatherConfig _weatherConfig; + private readonly LocationConfig _locationConfig; + + private readonly List _currentlyActiveEvents = []; + + private readonly IReadOnlyList _christmasEventItems = + [ + ItemTpl.FACECOVER_FAKE_WHITE_BEARD, + ItemTpl.BARTER_CHRISTMAS_TREE_ORNAMENT_RED, + ItemTpl.BARTER_CHRISTMAS_TREE_ORNAMENT_VIOLET, + ItemTpl.BARTER_CHRISTMAS_TREE_ORNAMENT_SILVER, + ItemTpl.HEADWEAR_DED_MOROZ_HAT, + ItemTpl.HEADWEAR_SANTA_HAT, + ItemTpl.BACKPACK_SANTAS_BAG, + ItemTpl.RANDOMLOOTCONTAINER_NEW_YEAR_GIFT_BIG, + ItemTpl.RANDOMLOOTCONTAINER_NEW_YEAR_GIFT_MEDIUM, + ItemTpl.RANDOMLOOTCONTAINER_NEW_YEAR_GIFT_SMALL + ]; + + private readonly IReadOnlyList _halloweenEventItems = + [ + ItemTpl.FACECOVER_SPOOKY_SKULL_MASK, + ItemTpl.RANDOMLOOTCONTAINER_PUMPKIN_RAND_LOOT_CONTAINER, + ItemTpl.HEADWEAR_JACKOLANTERN_TACTICAL_PUMPKIN_HELMET, + ItemTpl.FACECOVER_FACELESS_MASK, + ItemTpl.FACECOVER_JASON_MASK, + ItemTpl.FACECOVER_MISHA_MAYOROV_MASK, + ItemTpl.FACECOVER_SLENDER_MASK, + ItemTpl.FACECOVER_GHOUL_MASK, + ItemTpl.FACECOVER_HOCKEY_PLAYER_MASK_CAPTAIN, + ItemTpl.FACECOVER_HOCKEY_PLAYER_MASK_BRAWLER, + ItemTpl.FACECOVER_HOCKEY_PLAYER_MASK_QUIET + ]; + + public SeasonalEventService( + ILogger logger, + DatabaseService databaseService, + DatabaseImporter databaseImporter, + GiftService giftService, + LocalisationService localisationService, + BotHelper botHelper, + ProfileHelper profileHelper, + ConfigServer configServer + ) + { + _logger = logger; + _databaseService = databaseService; + _databaseImporter = databaseImporter; + _giftService = giftService; + _localisationService = localisationService; + _botHelper = botHelper; + _profileHelper = profileHelper; + _configServer = configServer; + + _seasonalEventConfig = _configServer.GetConfig(ConfigTypes.SEASONAL_EVENT); + _questConfig = _configServer.GetConfig(ConfigTypes.QUEST); + _httpConfig = _configServer.GetConfig(ConfigTypes.HTTP); + _weatherConfig = _configServer.GetConfig(ConfigTypes.WEATHER); + _locationConfig = _configServer.GetConfig(ConfigTypes.LOCATION); + } + /// /// Get an array of christmas items found in bots inventories as loot /// /// array - public string[] GetChristmasEventItems() + public IEnumerable GetChristmasEventItems() { - throw new NotImplementedException(); + return _christmasEventItems; } /// /// Get an array of halloween items found in bots inventories as loot /// /// array - public string[] GetHalloweenEventItems() + public IEnumerable GetHalloweenEventItems() { - throw new NotImplementedException(); + return _halloweenEventItems; } public bool ItemIsChristmasRelated(string itemTpl) { - throw new NotImplementedException(); + return _christmasEventItems.Contains(itemTpl); } public bool ItemIsHalloweenRelated(string itemTpl) { - throw new NotImplementedException(); + return _halloweenEventItems.Contains(itemTpl); } /// @@ -44,7 +124,7 @@ public class SeasonalEventService /// public bool ItemIsSeasonalRelated(string itemTpl) { - throw new NotImplementedException(); + return _christmasEventItems.Contains(itemTpl) || _halloweenEventItems.Contains(itemTpl); } /// @@ -53,7 +133,7 @@ public class SeasonalEventService /// Array of active events public List GetActiveEvents() { - throw new NotImplementedException(); + return _currentlyActiveEvents; } /// @@ -62,9 +142,20 @@ public class SeasonalEventService /// or, if halloween and christmas are inactive, return both sets of items /// /// array of tpl strings - public string[] GetInactiveSeasonalEventItems() + public List GetInactiveSeasonalEventItems() { - throw new NotImplementedException(); + var items = new List(); + if (!ChristmasEventEnabled()) + { + items.AddRange(_christmasEventItems); + } + + if (!HalloweenEventEnabled()) + { + items.AddRange(_halloweenEventItems); + } + + return items; } /// @@ -73,7 +164,7 @@ public class SeasonalEventService /// true if event is active public bool SeasonalEventEnabled() { - throw new NotImplementedException(); + return _christmasEventActive || _halloweenEventActive; } /// @@ -82,7 +173,7 @@ public class SeasonalEventService /// true if active public bool ChristmasEventEnabled() { - throw new NotImplementedException(); + return _christmasEventActive; } /// @@ -91,7 +182,7 @@ public class SeasonalEventService /// true if active public bool HalloweenEventEnabled() { - throw new NotImplementedException(); + return _halloweenEventActive; } /// @@ -100,7 +191,7 @@ public class SeasonalEventService /// true if seasonal events should be checked for public bool IsAutomaticEventDetectionEnabled() { - throw new NotImplementedException(); + return _seasonalEventConfig.EnableSeasonalEventDetection; } /// @@ -110,7 +201,7 @@ public class SeasonalEventService /// bots with equipment changes protected Dictionary>> GetEventBotGear(SeasonalEventType eventType) { - throw new NotImplementedException(); + return _seasonalEventConfig.EventGear.GetValueOrDefault(eventType, null); } /// @@ -120,7 +211,7 @@ public class SeasonalEventService /// bots with loot changes protected Dictionary>> GetEventBotLoot(SeasonalEventType eventType) { - throw new NotImplementedException(); + return _seasonalEventConfig.EventLoot.GetValueOrDefault(eventType, null); } /// @@ -129,7 +220,7 @@ public class SeasonalEventService /// Record with event name + start/end date public List GetEventDetails() { - throw new NotImplementedException(); + return _seasonalEventConfig.Events; } /// @@ -140,7 +231,12 @@ public class SeasonalEventService /// true if related public bool IsQuestRelatedToEvent(string questId, SeasonalEventType eventType) { - throw new NotImplementedException(); + var eventQuestData = _questConfig.EventQuests.GetValueOrDefault(questId, null); + if (eventQuestData?.Season == eventType) { + return true; + } + + return false; } /// @@ -148,7 +244,13 @@ public class SeasonalEventService /// public void EnableSeasonalEvents() { - throw new NotImplementedException(); + if (_currentlyActiveEvents.Count > 0) + { + var globalConfig = _databaseService.GetGlobals().Configuration; + foreach (var activeEvent in _currentlyActiveEvents) { + UpdateGlobalEvents(globalConfig, activeEvent); + } + } } /// @@ -175,7 +277,29 @@ public class SeasonalEventService /// Season enum value public Season GetActiveWeatherSeason() { - throw new NotImplementedException(); + if (_weatherConfig.OverrideSeason.HasValue) + { + return _weatherConfig.OverrideSeason.Value; + } + + var currentDate = new DateTime(); + foreach (var seasonRange in _weatherConfig.SeasonDates) { + if ( + DateIsBetweenTwoDates( + currentDate, + seasonRange.StartMonth, + seasonRange.StartDay, + seasonRange.EndMonth, + seasonRange.EndDay) + ) + { + return seasonRange.SeasonType; + } + } + + _logger.Warning(_localisationService.GetText("season-no_matching_season_found_for_date")); + + return Season.SUMMER; } /// @@ -191,7 +315,10 @@ public class SeasonalEventService /// True when inside date range protected bool DateIsBetweenTwoDates(DateTime dateToCheck, int startMonth, int startDay, int endMonth, int endDay) { - throw new NotImplementedException(); + var eventStartDate = new DateTime(dateToCheck.Year, startMonth, startDay); + var eventEndDate = new DateTime(dateToCheck.Year, endMonth, endDay, 23, 59, 0); + + return dateToCheck >= eventStartDate && dateToCheck <= eventEndDate; } /// @@ -246,7 +373,22 @@ public class SeasonalEventService public void GivePlayerSeasonalGifts(string sessionId) { - throw new NotImplementedException(); + if (_currentlyActiveEvents is null) + { + return; + } + + foreach (var seasonEvent in _currentlyActiveEvents) { + switch (seasonEvent.Type) { + case SeasonalEventType.Christmas: + GiveGift(sessionId, "Christmas2022"); + break; + case SeasonalEventType.NewYears: + GiveGift(sessionId, "NewYear2023"); + GiveGift(sessionId, "NewYear2024"); + break; + } + } } /// @@ -319,7 +461,12 @@ public class SeasonalEventService /// protected void AddLootItemsToGifterDropItemsList() { - throw new NotImplementedException(); + var gifterBot = _databaseService.GetBots().Types["gifter"]; + var items = gifterBot.BotInventory.Items.Backpack.Keys.ToList(); + gifterBot.BotDifficulty.Easy.Patrol["ITEMS_TO_DROP"] = items; + gifterBot.BotDifficulty.Normal.Patrol["ITEMS_TO_DROP"] = items; + gifterBot.BotDifficulty.Hard.Patrol["ITEMS_TO_DROP"] = items; + gifterBot.BotDifficulty.Impossible.Patrol["ITEMS_TO_DROP"] = items; } /// @@ -345,12 +492,16 @@ public class SeasonalEventService /// protected void AddPumpkinsToScavBackpacks() { - throw new NotImplementedException(); + _databaseService.GetBots().Types["assault"].BotInventory.Items.Backpack[ + ItemTpl.RANDOMLOOTCONTAINER_PUMPKIN_RAND_LOOT_CONTAINER + ] = 400; } protected void RenameBitcoin() { - throw new NotImplementedException(); + var enLocale = _databaseService.GetLocales().Global["en"]; + enLocale[$"{ItemTpl.BARTER_PHYSICAL_BITCOIN} Name"] = "Physical SPT Coin"; + enLocale[$"{ItemTpl.BARTER_PHYSICAL_BITCOIN} ShortName"] = "0.2SPT"; } /// @@ -381,7 +532,11 @@ public class SeasonalEventService /// Key of gift to give protected void GiveGift(string playerId, string giftKey) { - throw new NotImplementedException(); + var gitftData = _giftService.GetGiftById(giftKey); + if (!_profileHelper.PlayerHasRecievedMaxNumberOfGift(playerId, giftKey, gitftData.MaxToSendPlayer ?? 5)) + { + _giftService.SendGiftToPlayer(playerId, giftKey); + } } /// @@ -391,7 +546,7 @@ public class SeasonalEventService /// Bot role as string public string GetBaseRoleForEventBot(string eventBotRole) { - throw new NotImplementedException(); + return _seasonalEventConfig.EventBotMapping.GetValueOrDefault(eventBotRole, null); } /// @@ -399,6 +554,6 @@ public class SeasonalEventService /// public void EnableSnow() { - throw new NotImplementedException(); + _weatherConfig.OverrideSeason = Season.WINTER; } }