public void Update(float deltaTime) { //add clients while (_clientsToAdd.Count > 0) { GameClient client = _clientsToAdd[0]; if (client != null) { _clients.Add(client); _mapInstance.AddMapPlayer(client.GetMapPlayer()); _clientsToAdd.RemoveAt(0); } } //remove clients while (_clientsToRemove.Count > 0) { GameClient client = _clientsToRemove[0]; if (client != null) { int index = _clients.IndexOf(client); _mapInstance.RemoveMapPlayer(client.GetMapPlayer()); _clients.Remove(client); _clientsToRemove.RemoveAt(0); } } //update interpreter _eventInterpreter.Update(deltaTime); //update clients for (int i = 0; i < _clients.Count; i++) { _clients[i].Update(deltaTime); if (!_clients[i].Connected()) { RemoveClient(_clients[i]); } } //update map instance _mapInstance.Update(deltaTime); }
public void SetPlayers(Dictionary <int, PlayerPacket> playerPackets) { for (int i = 0; i < PlayerEntities.Count; i++) { int id = PlayerEntities.ElementAt(i).Key; if (playerPackets.ContainsKey(id) == false) { PlayerEntities[id].Destroy(); PlayerEntities.Remove(id); _mapInstance.RemoveMapPlayer(i); i--; } } for (int i = 0; i < playerPackets.Count; i++) { PlayerPacket packet = playerPackets.ElementAt(i).Value; if (packet.PlayerID == RpgClientConnection.Instance.GetLocalPlayerID()) { _localPlayerPacket = packet; } if (PlayerEntities.ContainsKey(packet.PlayerID)) { Entity clientEntity = PlayerEntities[packet.PlayerID]; PlayerComponent playerComponent = (PlayerComponent)clientEntity.FindComponent <PlayerComponent>(); playerComponent.SetPlayerPacket(packet); } else { Entity clientEntity = Entity.CreateInstance(this.Parent.GetManager()); clientEntity.GetTransform().Parent = this.Parent.GetTransform(); MapPlayer mapPlayer = new MapPlayer(packet, null); _mapInstance.AddMapPlayer(mapPlayer); new PlayerComponent(clientEntity, mapPlayer); PlayerEntities.Add(packet.PlayerID, clientEntity); if (_localPlayerPacket == packet) { _localMapPlayer = mapPlayer; } } } }