public override void EntityAdded(EntityWrapper entityWrapper) { if (entityWrapper.HasComponent <Player>()) { PlayerEntities.Add(entityWrapper); } }
// Эти методы не особо нужны. Они создавались только для поддержки серверной сущности. public void AddPlayerEntity(PlayerEntity playerEntity) { var coincidence = PlayerEntities.FirstOrDefault(x => x == playerEntity); // Он не был зарегестрирован. if (coincidence == null) { PlayerEntities.Add(playerEntity); OnPlayerEntityAdd(playerEntity); } }
public void RegisterEntity <T>(T entity) where T : ISubstantialEntity { switch (entity) { case null: return; case IPlayerEntity playerEntity: PlayerEntities.Add(playerEntity.Id, playerEntity); SubstantialEntities.Add(entity.Id, entity); break; default: SubstantialEntities.Add(entity.Id, entity); break; } }
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; } } } }