using System; using System.Linq; using System.Net.Sockets; using GuildWarsInterface; using GuildWarsInterface.Declarations; using Mod.Datastructures; using Protocol.Components; using Protocol.Messages; using Protocol.Messages.Update; using Protocol.Types; namespace Mod { public static class GameUpdate { public static void Handler(UpdateCommand gameUpdate, Socket socket) { if (Game.State != GameState.Playing) return; Game.TimePassed(gameUpdate.timeDelta); foreach (Entity entity in gameUpdate.removed) { EnticeAgent agentToRemove; if (Agents.TryGetAgent(entity.uuid, out agentToRemove)) { EnticeZone.Zone.RemoveAgent(agentToRemove.Agent); Console.WriteLine("removed agent " + agentToRemove.Agent.Name); } else { throw new Exception("non existing entity should be removed"); } } if (gameUpdate.entityViews.Any(entityView => entityView.added.Concat(entityView.changed).Any(component => component is GroupLeader))) { while (EnticeZone.Zone.Parties.Any()) { EnticeZone.Zone.RemoveParty(EnticeZone.Zone.Parties.First()); } } foreach (Entity entity in gameUpdate.added) { EnticeAgent agent = Agents.CreateAgent(entity.uuid); EnticeZone.Zone.AddAgent(agent.Agent); Console.WriteLine("spawned agent " + agent.Agent.Name); } foreach (EntityView entityDiff in gameUpdate.entityViews) { EnticeAgent agentToUpdate; if (Agents.TryGetAgent(entityDiff.entity.uuid, out agentToUpdate)) { Agents.UpdateAgent(entityDiff); } else { throw new Exception("trying to update non existing agent"); } } } } }