using System.Collections.Generic; using PhoenixLib.Caching; using PhoenixLib.Logging; using WingsEmu.DTOs.ServerDatas; using WingsEmu.Game.Items; using WingsEmu.Plugins.BasicImplementations.ServerConfigs.ImportObjects; using WingsEmu.Plugins.BasicImplementations.ServerConfigs.ImportObjects.ItemBoxes; using WingsEmu.Plugins.BasicImplementations.ServerConfigs.Persistence; namespace WingsEmu.Plugins.BasicImplementations.ServerConfigs; public class ItemBoxManager : IItemBoxManager { private readonly IEnumerable _itemBoxConfigurations; private readonly IKeyValueCache _itemBoxesCache; private readonly IEnumerable _randomBoxConfigurations; public ItemBoxManager(IEnumerable itemBoxConfigurations, IEnumerable randomBoxConfigurations, IKeyValueCache itemBoxesCache) { _itemBoxConfigurations = itemBoxConfigurations; _randomBoxConfigurations = randomBoxConfigurations; _itemBoxesCache = itemBoxesCache; } public ItemBoxDto GetItemBoxByItemVnumAndDesign(int itemVnum) => _itemBoxesCache.Get(itemVnum.ToString()); public void Initialize() { int boxesCount = 0; var allBoxes = new List(); foreach (ItemBoxImportFile file in _itemBoxConfigurations) { ItemBoxDto box = file.ToDto(); if (box == null) { continue; } // just the item box itself allBoxes.Add(box); _itemBoxesCache.Set(box.Id.ToString(), box); boxesCount++; } foreach (RandomBoxImportFile file in _randomBoxConfigurations) { foreach (RandomBoxObject obj in file.Items) { ItemBoxDto box = obj.ToDtos(); if (box == null) { continue; } allBoxes.Add(box); _itemBoxesCache.Set(box.Id.ToString(), box); boxesCount++; } } ParserDataPostgresSync.SyncItemBoxes(allBoxes); Log.Info($"[ITEMBOX_MANAGER] Loaded {boxesCount} itemBoxes"); } }