From abb9e02869560ea06d75dc439a7ffdda824ef7c6 Mon Sep 17 00:00:00 2001 From: Chomp Date: Sat, 18 Jan 2025 13:09:28 +0000 Subject: [PATCH] Implemented `getAllBotDifficulties` --- Core/Callbacks/InsuranceCallbacks.cs | 4 +- Core/Callbacks/NotifierCallbacks.cs | 4 +- Core/Controllers/BotController.cs | 42 +++++++++++++-- Core/Controllers/InsuranceController.cs | 67 +++++++++++++++++++++++- Core/Models/Eft/Common/LocationBase.cs | 66 +++++++++++++++++++++-- Core/Models/Eft/Common/Tables/BotType.cs | 2 +- Core/Services/SeasonalEventService.cs | 8 +-- 7 files changed, 173 insertions(+), 20 deletions(-) diff --git a/Core/Callbacks/InsuranceCallbacks.cs b/Core/Callbacks/InsuranceCallbacks.cs index 99ef1c0e..e3a724df 100644 --- a/Core/Callbacks/InsuranceCallbacks.cs +++ b/Core/Callbacks/InsuranceCallbacks.cs @@ -48,9 +48,7 @@ public class InsuranceCallbacks : OnUpdate /// public string GetInsuranceCost(string url, GetInsuranceCostRequestData info, string sessionID) { - // return _httpResponseUtil.GetBody(_insuranceController.Cost(info, sessionID)); - // TODO: InsuranceController is not implemented rn - throw new NotImplementedException(); + return _httpResponseUtil.GetBody(_insuranceController.Cost(info, sessionID)); } /// diff --git a/Core/Callbacks/NotifierCallbacks.cs b/Core/Callbacks/NotifierCallbacks.cs index 907cdd66..a7ce1b6f 100644 --- a/Core/Callbacks/NotifierCallbacks.cs +++ b/Core/Callbacks/NotifierCallbacks.cs @@ -57,10 +57,10 @@ public class NotifierCallbacks /// /// /// - /// + /// /// /// - public string GetNotifier(string url, object info, string sessionID) // TODO: no types were given + public string GetNotifier(string url, object info, string sessionId) { return _httpResponseUtil.EmptyArrayResponse(); } diff --git a/Core/Controllers/BotController.cs b/Core/Controllers/BotController.cs index fda832a9..e4d08d80 100644 --- a/Core/Controllers/BotController.cs +++ b/Core/Controllers/BotController.cs @@ -105,7 +105,7 @@ public class BotController { var difficulty = diffLevel.ToLower(); - if (!(raidConfig != null || ignoreRaidSettings)) // TODD: this might be wrong logic + if (!(raidConfig != null || ignoreRaidSettings)) _logger.Error(_localisationService.GetText("bot-missing_application_context", "RAID_CONFIGURATION")); // Check value chosen in pre-raid difficulty dropdown @@ -118,12 +118,46 @@ public class BotController return _botDifficultyHelper.GetBotDifficultySettings(type, difficulty, botDb); } - public Dictionary GetAllBotDifficulties() + public Dictionary> GetAllBotDifficulties() { - var result = new Dictionary(); + var result = new Dictionary>(); var botTypesDb = _databaseService.GetBots().Types; - // TODO: Come back to this, brainfuck + //Get all bot types as sting array + var botTypes = Enum.GetValues().Select(item => item.ToString()).ToList(); + foreach (var botType in botTypes) + { + // If bot is usec/bear, swap to different name + var botTypeLower = _botHelper.IsBotPmc(botType) + ? _botHelper.GetPmcSideByRole(botType).ToLower() + : botType.ToLower(); + + // Get details from db + if (!botTypesDb.TryGetValue(botTypeLower, out var botDetails)) + { + // No bot of this type found, skip + continue; + }; + + if (botDetails.BotDifficulty is null) + { + // Bot has no difficulty values, skip + continue; + } + + var botNameKey = botType.ToLower(); + foreach (var (difficultyName, difficultyValues) in botDetails.BotDifficulty) + { + // Bot doesnt exist in result, add + if (!result.ContainsKey(botNameKey)) + { + result.TryAdd(botNameKey, new Dictionary()); + } + + // Store all difficulty values in dict keyed by difficulty type e.g. easy/normal/impossible + result[botNameKey].Add(difficultyName, GetBotDifficulty(botNameKey, difficultyName, null, true)); + } + } return result; } diff --git a/Core/Controllers/InsuranceController.cs b/Core/Controllers/InsuranceController.cs index 69cbce55..b4ab2a56 100644 --- a/Core/Controllers/InsuranceController.cs +++ b/Core/Controllers/InsuranceController.cs @@ -1,9 +1,74 @@ using Core.Annotations; +using Core.Helpers; +using Core.Models.Eft.Common.Tables; +using Core.Models.Eft.Insurance; +using Core.Models.Spt.Config; +using Core.Models.Utils; +using Core.Servers; +using Core.Services; namespace Core.Controllers; [Injectable] public class InsuranceController { - // TODO + private readonly ISptLogger _logger; + private readonly ProfileHelper _profileHelper; + private readonly InsuranceService _insuranceService; + private readonly ConfigServer _configServer; + private readonly InsuranceConfig _insuranceConfig; + + public InsuranceController( + ISptLogger logger, + ProfileHelper profileHelper, + InsuranceService insuranceService, + ConfigServer configServer + ) + { + _logger = logger; + _profileHelper = profileHelper; + _insuranceService = insuranceService; + _configServer = configServer; + + _insuranceConfig = _configServer.GetConfig(); + } + + /** + * Handle client/insurance/items/list/cost + * Calculate insurance cost + * + * @param request request object + * @param sessionID session id + * @returns IGetInsuranceCostResponseData object to send to client + */ + public GetInsuranceCostResponseData Cost(GetInsuranceCostRequestData request, string sessionId) + { + var response = new GetInsuranceCostResponseData(); + var pmcData = _profileHelper.GetPmcProfile(sessionId); + var inventoryItemsHash = new Dictionary(); + + foreach (var item in pmcData.Inventory.Items) { + inventoryItemsHash[item.Id] = item; + } + + // Loop over each trader in request + foreach(var trader in request.Traders) + { + var items = new Dictionary(); + + foreach (var itemId in request.Items) { + // Ensure hash has item in it + if (!inventoryItemsHash.ContainsKey(itemId)) + { + _logger.Debug("Item with id: ${ itemId} missing from player inventory, skipping"); + continue; + } + items[inventoryItemsHash[itemId].Template] = _insuranceService.GetRoublePriceToInsureItemWithTrader(pmcData, inventoryItemsHash[itemId], trader); + } + + response[trader] = items; + } + + return response; + } } diff --git a/Core/Models/Eft/Common/LocationBase.cs b/Core/Models/Eft/Common/LocationBase.cs index 2d94887e..b5564433 100644 --- a/Core/Models/Eft/Common/LocationBase.cs +++ b/Core/Models/Eft/Common/LocationBase.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Core.Models.Common; namespace Core.Models.Eft.Common; @@ -937,9 +937,65 @@ public record Area public enum WildSpawnType { - assault, marksman, - pmcbot, - bosskilla, - bossknight + assault, + bossTest, + bossBully, + followerTest, + followerBully, + bossKilla, + bossKojaniy, + followerKojaniy, + pmcBot, + cursedAssault, + bossGluhar, + followerGluharAssault, + followerGluharSecurity, + followerGluharScout, + followerGluharSnipe, + followerSanitar, + bossSanitar, + test, + assaultGroup, + sectantWarrior, + sectantPriest, + bossTagilla, + followerTagilla, + exUsec, + gifter, + bossKnight, + followerBigPipe, + followerBirdEye, + bossZryachiy, + followerZryachiy, + bossBoar = 32, + followerBoar, + arenaFighter, + arenaFighterEvent, + bossBoarSniper, + crazyAssaultEvent, + peacefullZryachiyEvent, + sectactPriestEvent, + ravangeZryachiyEvent, + followerBoarClose1, + followerBoarClose2, + bossKolontay, + followerKolontayAssault, + followerKolontaySecurity, + shooterBTR, + bossPartisan, + spiritWinter, + spiritSpring, + peacemaker, + pmcBEAR, + pmcUSEC, + skier, + sectantPredvestnik = 57, + sectantPrizrak, + sectantOni, + infectedAssault, + infectedPmc, + infectedCivil, + infectedLaborant, + infectedTagilla } diff --git a/Core/Models/Eft/Common/Tables/BotType.cs b/Core/Models/Eft/Common/Tables/BotType.cs index 9806b7e8..c95094d9 100644 --- a/Core/Models/Eft/Common/Tables/BotType.cs +++ b/Core/Models/Eft/Common/Tables/BotType.cs @@ -14,7 +14,7 @@ public record BotType public Chances? BotChances { get; set; } [JsonPropertyName("difficulty")] - public Difficulties? BotDifficulty { get; set; } + public Dictionary? BotDifficulty { get; set; } [JsonPropertyName("experience")] public Experience? BotExperience { get; set; } diff --git a/Core/Services/SeasonalEventService.cs b/Core/Services/SeasonalEventService.cs index 69ad647b..34e7926a 100644 --- a/Core/Services/SeasonalEventService.cs +++ b/Core/Services/SeasonalEventService.cs @@ -750,10 +750,10 @@ public class SeasonalEventService { 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; + 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; } ///