/// <summary> /// Sends a server tick message /// </summary> /// <param name="time">Time elapsed in seconds since game started</param> /// <param name="hits">Hits</param> public void SendServerTickMessage(double time, IEnumerable <IHit> hits) { if (!Protection.IsValid(hits)) { throw new ArgumentException("Hits contain invalid hits.", nameof(hits)); } OnServerTicked?.Invoke(time, EntityStreamer.GetEntityDeltas(Lobby.Users.Values, Lobby.Entities.Values, ref lastEntityDeltas), hits); SendMessage(new ServerTickMessageData(time, lastEntityDeltas, hits)); }
/// <summary> /// Constructs a game user /// </summary> /// <param name="serverUser">Server user</param> public AGameUser(IServerUser serverUser) { if (serverUser == null) { throw new ArgumentNullException(nameof(serverUser)); } if (!serverUser.IsValid) { throw new ArgumentException("Server user is not valid.", nameof(serverUser)); } ServerUser = serverUser; serverUser.OnUsernameUpdated += () => OnUsernameUpdated?.Invoke(); serverUser.OnUserLobbyColorUpdated += () => OnUserLobbyColorUpdated?.Invoke(); serverUser.OnGameLoadingFinished += () => OnGameLoadingFinished?.Invoke(); serverUser.OnClientTicked += (entityDeltas, hits) => OnClientTicked?.Invoke(entityDeltas, hits); serverUser.OnServerTicked += (time, entityDeltas, hits) => OnServerTicked?.Invoke(time, entityDeltas, hits); }
/// <summary> /// Invokes the server ticked event /// </summary> /// <param name="time">Time in seconds elapsed since game start</param> /// <param name="entityDeltas">Entity deltas</param> /// <param name="hits">Hits</param> public void InvokeServerTickedEvent(double time, IEnumerable <IEntityDelta> entityDeltas, IEnumerable <IHit> hits) => OnServerTicked?.Invoke(time, entityDeltas, hits);