/// <summary> /// Sends a position update to the server. /// </summary> /// <param name="currentAreaId"></param> /// <param name="shipsToSend"></param> /// <param name="sendingPlayerId">Null if sent from simulator, otherwise must be sent so that a client is not forwarded its own position updates</param> public void SendPositionUpdate(IGameTimeService gameTime, int currentAreaId, IEnumerable <Ship> shipsToSend, int?sendingPlayerId = null) { if (shipsToSend == null || shipsToSend.Count() == 0) { return; } var positionUpdateData = new MessagePositionUpdateData(sendingPlayerId, currentAreaId); //PositionUpdateData playerShipData = new PositionUpdateData(ClientShipManager.PlayerShip.Id, ClientShipManager.PlayerShip.Position.X, ClientShipManager.PlayerShip.Position.Y, ClientShipManager.PlayerShip.Rotated, ClientShipManager.PlayerShip.LinearVelocity.X, ClientShipManager.PlayerShip.LinearVelocity.Y, ClientShipManager.PlayerShip.AngularVelocity, ClientShipManager.PlayerShip.Shields.CurrentShields, ClientShipManager.PlayerShip.CurrentHealth, ClientShipManager.PlayerShip.ThrustStatusForServer); //data.UpdateDataObjects.Add(playerShipData); //ClientShipManager.PlayerShip.ThrustStatusForServer = false; var positionUpdates = shipsToSend.Where(s => s.IsBodyValid && s.SendPositionUpdates).Select(s => { s.ThrustStatusForServer = false; return(s.GetPositionUpdate(gameTime)); }); positionUpdateData.UpdateDataObjects.AddRange(positionUpdates); _messenger.SendMessageToServer(MessageTypes.PositionUpdateData, positionUpdateData); }
/// <summary> /// Forwards the data to online players as necessary. Does not send to the client corresponding to the given idToIgnore /// </summary> /// <param name="area"></param> /// <param name="data"></param> /// <param name="idToIgnore"></param> public void ForwardPositionUpdates(int?idToIgnore, IArea area, MessagePositionUpdateData data) { area.BroadcastMessage(new NetworkMessageContainer(data, MessageTypes.PositionUpdateData), idToIgnore, data.SendingPlayerID == null); }