using System; using System.Collections.Generic; using System.Linq; using GuildWarsInterface.Datastructures; using Protocol.Components; using Protocol.Messages; using Protocol.Types; namespace Mod.Datastructures { public static class Agents { private static readonly Dictionary _agents = new Dictionary(); public static EnticeAgent CreateAgent(EntityView entityView) { var agent = CreateAgent(entityView.entity.uuid); UpdateAgent(entityView); return agent; } public static EnticeAgent CreateAgent(UUID uuid) { var agent = new EnticeAgent(); _agents.Add(uuid, agent); return agent; } public static UUID GetUuid(PlayerCharacter agent) { return _agents.FirstOrDefault(kv => kv.Value.Agent == agent).Key; } public static bool TryGetAgent(UUID uuid, out EnticeAgent result) { return _agents.TryGetValue(uuid, out result); } public static void UpdateAgent(EntityView entityDiff) { EnticeAgent agent; if (!TryGetAgent(entityDiff.entity.uuid, out agent)) { throw new Exception("trying to update an unknown entity"); } agent.Update(entityDiff); } public static void RemoveAgent(UUID uuid) { _agents.Remove(uuid); } } }