// WingsEmu // // Developed by NosWings Team using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using PhoenixLib.Logging; using WingsEmu.Core.Extensions; using WingsEmu.DTOs.ServerDatas; using WingsEmu.Game.Battle; using WingsEmu.Plugins.BasicImplementations.ServerConfigs.ImportObjects; using WingsEmu.Plugins.BasicImplementations.ServerConfigs.ImportObjects.Teleporters; namespace WingsEmu.Plugins.BasicImplementations.ServerConfigs; public class TeleporterManager : ITeleporterManager { private readonly IEnumerable _teleporterConfigurations; private readonly Dictionary> _teleporters = new(); private readonly Dictionary> _teleportersByNpcId = new(); public TeleporterManager(IEnumerable teleporterConfigurations) => _teleporterConfigurations = teleporterConfigurations; public async Task InitializeAsync() { int count = 0; foreach (TeleporterImportFile file in _teleporterConfigurations) { var teleporters = file.Teleporters.Select(s => { s.MapId = file.MapId; count++; return s.ToDto(); }).ToList(); _teleporters[file.MapId] = teleporters; foreach (TeleporterDTO teleporter in teleporters) { if (!_teleportersByNpcId.TryGetValue(teleporter.MapNpcId, out List teleporterDtos)) { teleporterDtos = new List(); _teleportersByNpcId[teleporter.MapNpcId] = teleporterDtos; } teleporterDtos.Add(teleporter); } } Log.Info($"[DATABASE] Loaded {count.ToString()} teleporters."); } public IReadOnlyList GetTeleportByNpcId(long npcId) => _teleportersByNpcId.GetOrDefault(npcId); public IReadOnlyList GetTeleportByMapId(int mapId) => _teleporters.GetOrDefault(mapId); }