diff --git a/Core/Callbacks/ItemEventCallbacks.cs b/Core/Callbacks/ItemEventCallbacks.cs index c5e43698..54e2c54f 100644 --- a/Core/Callbacks/ItemEventCallbacks.cs +++ b/Core/Callbacks/ItemEventCallbacks.cs @@ -1,22 +1,22 @@ -using Core.Annotations; -using Core.Models.Eft.HttpResponse; +using Core.Annotations; using Core.Models.Eft.ItemEvent; using Core.Models.Enums; +using Core.Routers; using Core.Utils; namespace Core.Callbacks; [Injectable] -public class ItemEventCallbacks(HttpResponseUtil _httpResponseUtil) // , ItemEventRouter _itemEventRouter TODO: Implement ItemEventRouter +public class ItemEventCallbacks(HttpResponseUtil _httpResponseUtil, ItemEventRouter _itemEventRouter) { - public Task> HandleEvents(string url, ItemEventRouterRequest info, string sessionID) + public async Task HandleEvents(string url, ItemEventRouterRequest info, string sessionID) { - // var eventResponse = await _itemEventRouter.HandleEvents(info, sessionID); - // var result = IsCriticalError(ItemEventRouterResponse.Warnings) - // ? _httpResponseUtil.GetBody(eventResponse, GetErrorCode(eventResponse.Warnings), eventResponse.Warnings[0].Errmsg) - // : _httpResponseUtil.GetBody(eventResponse); - // TODO: Implement ItemEventRouter - throw new NotImplementedException(); + var eventResponse = await _itemEventRouter.HandleEvents(info, sessionID); + var result = IsCriticalError(eventResponse.Warnings) + ? _httpResponseUtil.GetBody(eventResponse, GetErrorCode(eventResponse.Warnings), eventResponse.Warnings[0].ErrorMessage) + : _httpResponseUtil.GetBody(eventResponse); + + return result; } /// @@ -41,7 +41,7 @@ public class ItemEventCallbacks(HttpResponseUtil _httpResponseUtil) // , ItemEve return false; } - public int? GetErrorCode(List warnings) + public int GetErrorCode(List warnings) { return int.Parse((warnings[0].Code is null ? BackendErrorCodes.UNKNOWN_ERROR.ToString() diff --git a/Core/Controllers/BotController.cs b/Core/Controllers/BotController.cs index 84d79b1f..72c654f2 100644 --- a/Core/Controllers/BotController.cs +++ b/Core/Controllers/BotController.cs @@ -18,82 +18,38 @@ using Core.Utils.Cloners; namespace Core.Controllers; [Injectable] -public class BotController -{ - protected ISptLogger _logger; - - protected DatabaseService _databaseService; - protected BotGenerator _botGenerator; - protected BotHelper _botHelper; - protected BotDifficultyHelper _botDifficultyHelper; - protected WeightedRandomHelper _weightedRandomHelper; - protected BotGenerationCacheService _botGenerationCacheService; - protected MatchBotDeatilsCacheService _matchBotDeatilsCacheService; - protected LocalisationService _localisationService; - protected SeasonalEventService _seasonalEventService; - protected MatchBotDetailsCacheService _matchBotDetailsCacheService; - protected ProfileHelper _profileHelper; - protected ConfigServer _configServer; - protected ApplicationContext _applicationContext; - protected RandomUtil _randomUtil; - protected ICloner _cloner; - - protected BotConfig _botConfig; - protected PmcConfig _pmcConfig; - - public BotController - ( - ISptLogger logger, - DatabaseService databaseService, - BotGenerator botGenerator, - BotHelper botHelper, - BotDifficultyHelper botDifficultyHelper, - WeightedRandomHelper weightedRandomHelper, - BotGenerationCacheService botGenerationCacheService, - MatchBotDeatilsCacheService matchBotDeatilsCacheService, - LocalisationService localisationService, - SeasonalEventService seasonalEventService, - MatchBotDetailsCacheService matchBotDetailsCacheService, - ProfileHelper profileHelper, - ConfigServer configServer, - ApplicationContext applicationContext, - RandomUtil randomUtil, - ICloner cloner +public class BotController( + ISptLogger _logger, + DatabaseService _databaseService, + BotGenerator _botGenerator, + BotHelper _botHelper, + BotDifficultyHelper _botDifficultyHelper, + WeightedRandomHelper _weightedRandomHelper, + BotGenerationCacheService _botGenerationCacheService, + MatchBotDeatilsCacheService _matchBotDeatilsCacheService, + LocalisationService _localisationService, + SeasonalEventService _seasonalEventService, + MatchBotDetailsCacheService _matchBotDetailsCacheService, + ProfileHelper _profileHelper, + ConfigServer _configServer, + ApplicationContext _applicationContext, + RandomUtil _randomUtil, + ICloner _cloner ) - { - _logger = logger; - _databaseService = databaseService; - _botGenerator = botGenerator; - _botHelper = botHelper; - _botDifficultyHelper = botDifficultyHelper; - _weightedRandomHelper = weightedRandomHelper; - _botGenerationCacheService = botGenerationCacheService; - _matchBotDeatilsCacheService = matchBotDeatilsCacheService; - _localisationService = localisationService; - _seasonalEventService = seasonalEventService; - _matchBotDetailsCacheService = matchBotDetailsCacheService; - _profileHelper = profileHelper; - _configServer = configServer; - _applicationContext = applicationContext; - _randomUtil = randomUtil; - _cloner = cloner; - _botConfig = _configServer.GetConfig(); - _pmcConfig = _configServer.GetConfig(); - } +{ + private readonly BotConfig _botConfig = _configServer.GetConfig(); + private readonly PmcConfig _pmcConfig = _configServer.GetConfig(); - public int GetBotPresetGenerationLimit(string type) + public int? GetBotPresetGenerationLimit(string type) { var typeInLower = type.ToLower(); - var value = (int)typeof(PresetBatch).GetProperties().First(p => p.Name.ToLower() == (typeInLower == "assaultgroup" ? "assault" : typeInLower)) + var value = (int?)typeof(PresetBatch).GetProperties().First(p => p.Name.ToLower() == (typeInLower == "assaultgroup" ? "assault" : typeInLower)) .GetValue(_botConfig.PresetBatch); - if (value == null) - { - _logger.Warning(_localisationService.GetText("bot-bot_preset_count_value_missing", type)); - return 30; - } - - return value; + if (value != null) return value; + + _logger.Warning(_localisationService.GetText("bot-bot_preset_count_value_missing", type)); + return 30; } public Dictionary GetBotCoreDifficulty() diff --git a/Core/Routers/ItemEvents/HealthItemEventRouter.cs b/Core/Routers/ItemEvents/HealthItemEventRouter.cs index 65e0b66d..719f501b 100644 --- a/Core/Routers/ItemEvents/HealthItemEventRouter.cs +++ b/Core/Routers/ItemEvents/HealthItemEventRouter.cs @@ -22,15 +22,15 @@ public class HealthItemEventRouter : ItemEventRouterDefinition protected override List GetHandledRoutes() { - return new() - { + return + [ new HandledRoute("Eat", false), new HandledRoute("Heal", false), new HandledRoute("RestoreHealth", false) - }; + ]; } - public override Task? HandleItemEvent(string url, PmcData pmcData, object body, string sessionID, ItemEventRouterResponse output) + public override Task HandleItemEvent(string url, PmcData pmcData, object body, string sessionID, ItemEventRouterResponse output) { switch (url) { diff --git a/Core/Routers/ItemEvents/HideoutItemEventRouter.cs b/Core/Routers/ItemEvents/HideoutItemEventRouter.cs index 32ddfc77..83c8eeca 100644 --- a/Core/Routers/ItemEvents/HideoutItemEventRouter.cs +++ b/Core/Routers/ItemEvents/HideoutItemEventRouter.cs @@ -22,8 +22,8 @@ public class HideoutItemEventRouter : ItemEventRouterDefinition protected override List GetHandledRoutes() { - return new() - { + return + [ new HandledRoute(HideoutEventActions.HIDEOUT_UPGRADE, false), new HandledRoute(HideoutEventActions.HIDEOUT_UPGRADE_COMPLETE, false), new HandledRoute(HideoutEventActions.HIDEOUT_PUT_ITEMS_IN_AREA_SLOTS, false), @@ -40,7 +40,7 @@ public class HideoutItemEventRouter : ItemEventRouterDefinition new HandledRoute(HideoutEventActions.HIDEOUT_DELETE_PRODUCTION_COMMAND, false), new HandledRoute(HideoutEventActions.HIDEOUT_CUSTOMIZATION_APPLY_COMMAND, false), new HandledRoute(HideoutEventActions.HIDEOUT_CUSTOMIZATION_SET_MANNEQUIN_POSE, false) - }; + ]; } public override Task HandleItemEvent(string url, PmcData pmcData, object body, string sessionID, ItemEventRouterResponse output) diff --git a/Core/Services/BackupService.cs b/Core/Services/BackupService.cs index 3bf48683..379db090 100644 --- a/Core/Services/BackupService.cs +++ b/Core/Services/BackupService.cs @@ -1,4 +1,4 @@ -using Core.Annotations; +using Core.Annotations; namespace Core.Services; @@ -15,8 +15,7 @@ public class BackupService */ public async Task InitAsync() { - Console.WriteLine("NEEDS IMPLEMENTING: BackupService"); - return; + // TODO implement } /**