64 lines
No EOL
2.2 KiB
C#
64 lines
No EOL
2.2 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;
|
|
using WingsEmu.Plugins.BasicImplementations.ServerConfigs.Persistence;
|
|
|
|
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;
|
|
var allBoxes = new List<ItemBoxDto>();
|
|
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");
|
|
}
|
|
} |