// WingsEmu // // Developed by NosWings Team using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using PhoenixLib.Caching; using WingsAPI.Data.Drops; using WingsEmu.Game._enum; using WingsEmu.Game.Managers.ServerData; using WingsEmu.Plugins.BasicImplementations.ServerConfigs.ImportObjects; using WingsEmu.Plugins.BasicImplementations.ServerConfigs.ImportObjects.Drops; namespace WingsEmu.Plugins.BasicImplementations.ServerConfigs; public class DropManager : IDropManager { private static readonly List EmptyList = new(); private readonly IKeyValueCache> _dropCache; private readonly IEnumerable _dropConfigurations; private readonly List _generalDrops = new(); public DropManager(IEnumerable dropConfigurations, IKeyValueCache> dropCache) { _dropConfigurations = dropConfigurations; _dropCache = dropCache; } public async Task InitializeAsync() { var drops = new List(); foreach (DropImportFile dropImportExportFile in _dropConfigurations) { drops.AddRange(dropImportExportFile.Drops.SelectMany(s => s.ToDto())); } foreach (DropDTO drop in drops) { if (drop.MonsterVNum != null) { string key = $"monsterVnum-{drop.MonsterVNum.Value}"; List list = _dropCache.Get(key); if (list == null) { list = new List { drop }; _dropCache.Set(key, list); continue; } list.Add(drop); continue; } if (drop.MapId != null) { string key = $"mapId-{drop.MapId.Value}"; List list = _dropCache.Get(key); if (list == null) { list = new List { drop }; _dropCache.Set(key, list); continue; } list.Add(drop); continue; } if (drop.RaceType != null && drop.RaceSubType != null) { string key = $"race-{drop.RaceType.Value}.{drop.RaceSubType.Value}"; List list = _dropCache.Get(key); if (list == null) { list = new List { drop }; _dropCache.Set(key, list); continue; } list.Add(drop); continue; } _generalDrops.Add(drop); } } public IEnumerable GetGeneralDrops() => _generalDrops; public IReadOnlyList GetDropsByMapId(int mapId) => _dropCache.Get($"mapId-{mapId}") ?? EmptyList; public IReadOnlyList GetDropsByMonsterVnum(int monsterVnum) => _dropCache.Get($"monsterVnum-{monsterVnum}") ?? EmptyList; public IReadOnlyList GetDropsByMonsterRace(MonsterRaceType monsterRaceType, byte monsterSubRaceType) => _dropCache.Get($"race-{(byte)monsterRaceType}.{monsterSubRaceType}") ?? EmptyList; }