diff --git a/Core/Controllers/ClientLogController.cs b/Core/Controllers/ClientLogController.cs index 8e61faa1..1f3144fa 100644 --- a/Core/Controllers/ClientLogController.cs +++ b/Core/Controllers/ClientLogController.cs @@ -34,20 +34,20 @@ public class ClientLogController switch (logRequest.Level) { - case LogLevel.ERROR: + case LogLevel.Error: this._logger.Error(message); break; - case LogLevel.WARN: + case LogLevel.Warn: this._logger.Warning(message); break; - case LogLevel.SUCCESS: - case LogLevel.INFO: + case LogLevel.Success: + case LogLevel.Info: this._logger.Info(message); break; - case LogLevel.CUSTOM: + case LogLevel.Custom: this._logger.Info(message /* TODO: , color.ToString(), backgroundColor.ToString()*/); break; - case LogLevel.DEBUG: + case LogLevel.Debug: this._logger.Debug(message); break; default: diff --git a/Core/Controllers/DialogueController.cs b/Core/Controllers/DialogueController.cs index f3830bf3..cc76107e 100644 --- a/Core/Controllers/DialogueController.cs +++ b/Core/Controllers/DialogueController.cs @@ -94,6 +94,7 @@ public class DialogueController var activeBots = new List(); var chatBotConfig = _coreConfig.Features.ChatbotFeatures; + /* foreach (var bot in _dialogueChatBots) { var botData = bot.GetChatBot(); @@ -101,6 +102,8 @@ public class DialogueController activeBots.Add(botData); } } + TODO: FUCK THESE BOTS STOPPING US GETTING TO THE FUCKING MENU + */ return activeBots; } diff --git a/Core/Helpers/HttpServerHelper.cs b/Core/Helpers/HttpServerHelper.cs index b49ec0ee..5c185eb8 100644 --- a/Core/Helpers/HttpServerHelper.cs +++ b/Core/Helpers/HttpServerHelper.cs @@ -55,7 +55,7 @@ public class HttpServerHelper /** Get websocket url + port */ public string GetWebsocketUrl() { - return $"ws://${BuildUrl()}"; + return $"ws://{BuildUrl()}"; } public void SendTextJson(HttpResponse resp, object output) diff --git a/Core/Helpers/ItemHelper.cs b/Core/Helpers/ItemHelper.cs index f73341df..88a33edc 100644 --- a/Core/Helpers/ItemHelper.cs +++ b/Core/Helpers/ItemHelper.cs @@ -222,7 +222,7 @@ public class ItemHelper /// /// Item to look price up of /// Price in roubles - public decimal GetItemPrice(string tpl) + public double GetItemPrice(string tpl) { throw new NotImplementedException(); } @@ -233,7 +233,7 @@ public class ItemHelper /// /// Item to look price up of /// Price in roubles - public decimal GetItemMaxPrice(string tpl) + public double GetItemMaxPrice(string tpl) { throw new NotImplementedException(); } @@ -243,7 +243,7 @@ public class ItemHelper /// /// Items tpl id to look up price /// Price in roubles (0 if not found) - public decimal GetStaticItemPrice(string tpl) + public double GetStaticItemPrice(string tpl) { throw new NotImplementedException(); } @@ -253,7 +253,7 @@ public class ItemHelper /// /// Items tpl id to look up price /// Price in roubles (undefined if not found) - public decimal GetDynamicItemPrice(string tpl) + public double GetDynamicItemPrice(string tpl) { throw new NotImplementedException(); } diff --git a/Core/Helpers/NotifierHelper.cs b/Core/Helpers/NotifierHelper.cs index b3d3ba62..d67f857b 100644 --- a/Core/Helpers/NotifierHelper.cs +++ b/Core/Helpers/NotifierHelper.cs @@ -4,20 +4,19 @@ using Core.Models.Eft.Ws; namespace Core.Helpers; -[Injectable] +[Injectable(InjectionType.Singleton)] public class NotifierHelper { private readonly HttpServerHelper _httpServerHelper; + protected WsPing ping = new WsPing(); public NotifierHelper( HttpServerHelper httpServerHelper) { _httpServerHelper = httpServerHelper; } - public WsNotificationEvent GetDefaultNotification() - { - throw new NotImplementedException(); - } + + public WsNotificationEvent GetDefaultNotification() => ping; /** * Create a new notification that displays the "Your offer was sold!" prompt and removes sold offer from "My Offers" on clientside @@ -55,6 +54,6 @@ public class NotifierHelper public string GetWebSocketServer(string sessionID) { - return $"{ _httpServerHelper.GetWebsocketUrl()}/ notifierServer / getwebsocket /{sessionID}"; + return $"{_httpServerHelper.GetWebsocketUrl()}/notifierServer/getwebsocket/{sessionID}"; } } diff --git a/Core/Helpers/QuestHelper.cs b/Core/Helpers/QuestHelper.cs index b520af25..603249c5 100644 --- a/Core/Helpers/QuestHelper.cs +++ b/Core/Helpers/QuestHelper.cs @@ -210,7 +210,8 @@ public class QuestHelper */ public bool ShowEventQuestToPlayer(string questId) { - throw new NotImplementedException(); + _logger.Error($"NOT IMPLEMENTED"); + return false; } /** diff --git a/Core/Models/Eft/Profile/SptProfile.cs b/Core/Models/Eft/Profile/SptProfile.cs index 2950bbdc..160aacfd 100644 --- a/Core/Models/Eft/Profile/SptProfile.cs +++ b/Core/Models/Eft/Profile/SptProfile.cs @@ -135,6 +135,7 @@ public class EquipmentBuild : UserBuild public List? Items { get; set; } // Same as PMC inventory items [JsonPropertyName("BuildType")] + [JsonConverter(typeof(JsonStringEnumConverter))] public EquipmentBuildType? BuildType { get; set; } } @@ -165,15 +166,6 @@ public class MagazineTemplateAmmoItem /** Used by defaultEquipmentPresets.json */ public class DefaultEquipmentPreset : EquipmentBuild { - [JsonPropertyName("Items")] - public List? Items { get; set; } - - [JsonPropertyName("Root")] - public string? Root { get; set; } - - [JsonPropertyName("BuildType")] - public string? BuildType { get; set; } - [JsonPropertyName("type")] public string? Type { get; set; } } diff --git a/Core/Models/Enums/EquipmentBuildType.cs b/Core/Models/Enums/EquipmentBuildType.cs index 073f4169..36dd56de 100644 --- a/Core/Models/Enums/EquipmentBuildType.cs +++ b/Core/Models/Enums/EquipmentBuildType.cs @@ -2,6 +2,7 @@ public enum EquipmentBuildType { - CUSTOM = 0, - STANDARD = 1 -} \ No newline at end of file + Custom, + Standard, + Storage +} diff --git a/Core/Models/Spt/Logging/ClientLogRequest.cs b/Core/Models/Spt/Logging/ClientLogRequest.cs index a641d3ff..f015f80d 100644 --- a/Core/Models/Spt/Logging/ClientLogRequest.cs +++ b/Core/Models/Spt/Logging/ClientLogRequest.cs @@ -10,14 +10,15 @@ public class ClientLogRequest : IRequestData public string? Source { get; set; } [JsonPropertyName("Level")] + [JsonConverter(typeof(JsonStringEnumConverter))] // TODO: Fix in modules to send enumValue instead of string public LogLevel? Level { get; set; } [JsonPropertyName("Message")] public string? Message { get; set; } [JsonPropertyName("Color")] - public LogTextColor? Color { get; set; } + public string? Color { get; set; } // TODO: FIX THIS SHIT FOR COLOURS [JsonPropertyName("BackgroundColor")] - public LogBackgroundColor? BackgroundColor { get; set; } + public string? BackgroundColor { get; set; } } diff --git a/Core/Models/Spt/Logging/LogLevel.cs b/Core/Models/Spt/Logging/LogLevel.cs index 051cde1a..ee66cd1d 100644 --- a/Core/Models/Spt/Logging/LogLevel.cs +++ b/Core/Models/Spt/Logging/LogLevel.cs @@ -2,12 +2,12 @@ public enum LogLevel { - ERROR = 0, - WARN = 1, - SUCCESS = 2, - INFO = 3, - CUSTOM = 4, - DEBUG = 5 + Error, + Warn, + Success, + Info, + Custom, + Debug } -// TODO: needs to be moved to enums namespace \ No newline at end of file +// TODO: needs to be moved to enums namespace diff --git a/Core/Routers/Static/QuestStaticRouter.cs b/Core/Routers/Static/QuestStaticRouter.cs index dcbbfc25..fcc682e7 100644 --- a/Core/Routers/Static/QuestStaticRouter.cs +++ b/Core/Routers/Static/QuestStaticRouter.cs @@ -19,7 +19,7 @@ public class QuestStaticRouter : StaticRouter jsonUtil, [ new RouteAction( - "", + "/client/quest/list", ( url, info, @@ -28,7 +28,7 @@ public class QuestStaticRouter : StaticRouter ) => _questCallbacks.ListQuests(url, info as ListQuestsRequestData, sessionID), typeof(ListQuestsRequestData)), new RouteAction( - "", + "/client/repeatalbeQuests/activityPeriods", ( url, info, diff --git a/Core/Services/BotLootCacheService.cs b/Core/Services/BotLootCacheService.cs index d62669eb..bcbedf96 100644 --- a/Core/Services/BotLootCacheService.cs +++ b/Core/Services/BotLootCacheService.cs @@ -17,6 +17,7 @@ public class BotLootCacheService protected ISptLogger _logger; protected ItemHelper _itemHelper; protected PMCLootGenerator _pmcLootGenerator; + protected LocalisationService _localisationService; protected RagfairPriceService _ragfairPriceService; protected ICloner _cloner; @@ -26,13 +27,15 @@ public class BotLootCacheService ISptLogger logger, ItemHelper itemHelper, PMCLootGenerator pmcLootGenerator, + LocalisationService localisationService, RagfairPriceService ragfairPriceService, ICloner cloner - ) + ) { _logger = logger; _itemHelper = itemHelper; _pmcLootGenerator = pmcLootGenerator; + _localisationService = localisationService; _ragfairPriceService = ragfairPriceService; _cloner = cloner; } @@ -60,7 +63,98 @@ public class BotLootCacheService BotType botJsonTemplate, MinMax? itemPriceMinMax = null) { - throw new NotImplementedException(); + if (!BotRoleExistsInCache(botRole)) + { + InitCacheForBotRole(botRole); + AddLootToCache(botRole, isPmc, botJsonTemplate); + } + + Dictionary result = null; + switch (lootType) + { + case LootCacheType.Special: + result = _lootCache[botRole].SpecialItems; + break; + case LootCacheType.Backpack: + result = _lootCache[botRole].BackpackLoot; + break; + case LootCacheType.Pocket: + result = _lootCache[botRole].PocketLoot; + break; + case LootCacheType.Vest: + result = _lootCache[botRole].VestLoot; + break; + case LootCacheType.Secure: + result = _lootCache[botRole].SecureLoot; + break; + case LootCacheType.Combined: + result = _lootCache[botRole].CombinedPoolLoot; + break; + case LootCacheType.HealingItems: + result = _lootCache[botRole].HealingItems; + break; + case LootCacheType.GrenadeItems: + result = _lootCache[botRole].GrenadeItems; + break; + case LootCacheType.DrugItems: + result = _lootCache[botRole].DrugItems; + break; + case LootCacheType.FoodItems: + result = _lootCache[botRole].FoodItems; + break; + case LootCacheType.DrinkItems: + result = _lootCache[botRole].DrinkItems; + break; + case LootCacheType.CurrencyItems: + result = _lootCache[botRole].CurrencyItems; + break; + case LootCacheType.StimItems: + result = _lootCache[botRole].StimItems; + break; + default: + _logger.Error( + _localisationService.GetText( + "bot-loot_type_not_found", + new + { + lootType = lootType, + botRole = botRole, + isPmc = isPmc + } + ) + ); + break; + } + + if (itemPriceMinMax is not null) + { + var filteredResult = result.Where( + i => + { + var itemPrice = _itemHelper.GetItemPrice(i.Key); + if (itemPriceMinMax?.Min is not null && itemPriceMinMax?.Max is not null) + { + return itemPrice >= itemPriceMinMax?.Min && itemPrice <= itemPriceMinMax?.Max; + } + + if (itemPriceMinMax?.Min is not null && itemPriceMinMax?.Max is null) + { + return itemPrice >= itemPriceMinMax?.Min; + } + + if (itemPriceMinMax?.Min is null && itemPriceMinMax?.Max is not null) + { + return itemPrice <= itemPriceMinMax?.Max; + } + + return false; + } + ); + + return _cloner.Clone(filteredResult.ToDictionary(pair => pair.Key, pair => pair.Value)); + } + + return _cloner.Clone(result); } /// @@ -76,7 +170,7 @@ public class BotLootCacheService // Flatten all individual slot loot pools into one big pool, while filtering out potentially missing templates Dictionary specialLootPool = new(); - Dictionary backpackLootPool= new(); + Dictionary backpackLootPool = new(); Dictionary pocketLootPool = new(); Dictionary vestLootPool = new(); Dictionary secureLootTPool = new(); @@ -100,7 +194,7 @@ public class BotLootCacheService { "SpecialLoot", lootPool.SpecialLoot }, { "TacticalVest", lootPool.TacticalVest } }; - + foreach (var kvp in poolsToProcess) { @@ -150,7 +244,8 @@ public class BotLootCacheService if (!specialLootItems.Any()) { // key = tpl, value = weight - foreach (var itemKvP in specialLootPool) { + foreach (var itemKvP in specialLootPool) + { var itemTemplate = _itemHelper.GetItem(itemKvP.Key).Value; if (!(IsBulletOrGrenade(itemTemplate.Properties) || IsMagazine(itemTemplate.Properties))) { @@ -169,7 +264,8 @@ public class BotLootCacheService if (!healingItems.Any()) { // key = tpl, value = weight - foreach (var itemKvP in combinedLootPool) { + foreach (var itemKvP in combinedLootPool) + { var itemTemplate = _itemHelper.GetItem(itemKvP.Key).Value; if ( IsMedicalItem(itemTemplate.Properties) && @@ -187,7 +283,8 @@ public class BotLootCacheService // no drugs whitelist, find and assign from combined item pool if (!drugItems.Any()) { - foreach (var itemKvP in (combinedLootPool)) { + foreach (var itemKvP in (combinedLootPool)) + { var itemTemplate = _itemHelper.GetItem(itemKvP.Key).Value; if (IsMedicalItem(itemTemplate.Properties) && itemTemplate.Parent == BaseClasses.DRUGS) { @@ -201,7 +298,8 @@ public class BotLootCacheService // No food whitelist, find and assign from combined item pool if (!foodItems.Any()) { - foreach (var itemKvP in (combinedLootPool)) { + foreach (var itemKvP in (combinedLootPool)) + { var itemTemplate = _itemHelper.GetItem(itemKvP.Key).Value; if (_itemHelper.IsOfBaseclass(itemTemplate.Id, BaseClasses.FOOD)) { @@ -215,7 +313,8 @@ public class BotLootCacheService // No drink whitelist, find and assign from combined item pool if (!drinkItems.Any()) { - foreach (var itemKvP in combinedLootPool) { + foreach (var itemKvP in combinedLootPool) + { var itemTemplate = _itemHelper.GetItem(itemKvP.Key).Value; if (_itemHelper.IsOfBaseclass(itemTemplate.Id, BaseClasses.DRINK)) { @@ -229,7 +328,8 @@ public class BotLootCacheService // No currency whitelist, find and assign from combined item pool if (!currencyItems.Any()) { - foreach (var itemKvP in combinedLootPool) { + foreach (var itemKvP in combinedLootPool) + { var itemTemplate = _itemHelper.GetItem(itemKvP.Key).Value; if (_itemHelper.IsOfBaseclass(itemTemplate.Id, BaseClasses.MONEY)) { @@ -243,7 +343,8 @@ public class BotLootCacheService // No whitelist, find and assign from combined item pool if (!stimItems.Any()) { - foreach (var itemKvP in combinedLootPool) { + foreach (var itemKvP in combinedLootPool) + { var itemTemplate = _itemHelper.GetItem(itemKvP.Key).Value; if (IsMedicalItem(itemTemplate.Properties) && itemTemplate.Parent == BaseClasses.STIMULATOR) { @@ -257,7 +358,8 @@ public class BotLootCacheService // no whitelist, find and assign from combined item pool if (!grenadeItems.Any()) { - foreach (var itemKvP in combinedLootPool) { + foreach (var itemKvP in combinedLootPool) + { var itemTemplate = _itemHelper.GetItem(itemKvP.Key).Value; if (IsGrenade(itemTemplate.Properties)) { @@ -268,12 +370,14 @@ public class BotLootCacheService // Get backpack loot (excluding magazines, bullets, grenades, drink, food and healing/stim items) var filteredBackpackItems = new Dictionary(); - foreach (var itemKvP in backpackLootPool) { + foreach (var itemKvP in backpackLootPool) + { var itemResult = _itemHelper.GetItem(itemKvP.Key); if (itemResult.Value is null) { continue; } + var itemTemplate = itemResult.Value; if ( IsBulletOrGrenade(itemTemplate.Properties) || @@ -294,12 +398,14 @@ public class BotLootCacheService // Get pocket loot (excluding magazines, bullets, grenades, drink, food medical and healing/stim items) var filteredPocketItems = new Dictionary(); - foreach (var itemKvP in pocketLootPool) { + foreach (var itemKvP in pocketLootPool) + { var itemResult = _itemHelper.GetItem(itemKvP.Key); if (itemResult.Value is null) { continue; } + var itemTemplate = itemResult.Value; if ( IsBulletOrGrenade(itemTemplate.Properties) || @@ -308,10 +414,11 @@ public class BotLootCacheService IsGrenade(itemTemplate.Properties) || IsFood(itemTemplate.Id) || IsDrink(itemTemplate.Id) || - IsCurrency(itemTemplate.Id) || + IsCurrency(itemTemplate.Id) || itemTemplate.Properties.Height is null || // lacks height itemTemplate.Properties.Width is null // lacks width - ) { + ) + { continue; } @@ -320,7 +427,8 @@ public class BotLootCacheService // Get vest loot (excluding magazines, bullets, grenades, medical and healing/stim items) var filteredVestItems = new Dictionary(); - foreach (var itemKvP in vestLootPool) { + foreach (var itemKvP in vestLootPool) + { var itemResult = _itemHelper.GetItem(itemKvP.Key); if (itemResult.Value is null) { @@ -368,12 +476,25 @@ public class BotLootCacheService /// items to add to combined pool if unique protected void AddUniqueItemsToPool(List poolToAddTo, List itemsToAdd) { - throw new NotImplementedException(); + if (poolToAddTo.Count() == 0) { + poolToAddTo.AddRange(itemsToAdd); + return; + } + + poolToAddTo.Concat(itemsToAdd); + poolToAddTo = poolToAddTo.Distinct().ToList(); } protected void AddItemsToPool(Dictionary poolToAddTo, Dictionary poolOfItemsToAdd) { - throw new NotImplementedException(); + foreach (var tpl in poolOfItemsToAdd) { + // Skip adding items that already exist + if (poolToAddTo.ContainsKey(tpl.Key)) { + continue; + } + + poolToAddTo[tpl.Key] = poolOfItemsToAdd[tpl.Key]; + } } /// @@ -383,7 +504,7 @@ public class BotLootCacheService /// protected bool IsBulletOrGrenade(Props props) { - throw new NotImplementedException(); + return props.AmmoType is not null; } ///