server-master/srcs/_plugins/WingsEmu.Plugins.BasicImplementation/ServerConfigs/ItemBoxManager.cs
2026-02-10 18:21:30 +01:00

59 lines
No EOL
1.9 KiB
C#

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;
namespace WingsEmu.Plugins.BasicImplementations.ServerConfigs;
public class ItemBoxManager : IItemBoxManager
{
private readonly IEnumerable<ItemBoxImportFile> _itemBoxConfigurations;
private readonly IKeyValueCache<ItemBoxDto> _itemBoxesCache;
private readonly IEnumerable<RandomBoxImportFile> _randomBoxConfigurations;
public ItemBoxManager(IEnumerable<ItemBoxImportFile> itemBoxConfigurations, IEnumerable<RandomBoxImportFile> randomBoxConfigurations, IKeyValueCache<ItemBoxDto> itemBoxesCache)
{
_itemBoxConfigurations = itemBoxConfigurations;
_randomBoxConfigurations = randomBoxConfigurations;
_itemBoxesCache = itemBoxesCache;
}
public ItemBoxDto GetItemBoxByItemVnumAndDesign(int itemVnum) => _itemBoxesCache.Get(itemVnum.ToString());
public void Initialize()
{
int boxesCount = 0;
foreach (ItemBoxImportFile file in _itemBoxConfigurations)
{
ItemBoxDto box = file.ToDto();
if (box == null)
{
continue;
}
// just the item box itself
_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;
}
_itemBoxesCache.Set(box.Id.ToString(), box);
boxesCount++;
}
}
Log.Info($"[ITEMBOX_MANAGER] Loaded {boxesCount} itemBoxes");
}
}