Esempio n. 1
0
        public void RemovePlayerEntity(PlayerEntity playerEntity)
        {
            var coincidence = PlayerEntities.FirstOrDefault(x => x == playerEntity);

            // Он был зарегестрирован.
            if (coincidence != null)
            {
                PlayerEntities.Remove(playerEntity);
                OnPlayerEntityRemove(playerEntity);
            }
        }
Esempio n. 2
0
        public void UnregisterEntity <T>(T entity) where T : IEntity
        {
            switch (entity)
            {
            case null:
                return;

            case IPlayerEntity playerEntity:
                PlayerEntities.Remove(playerEntity.Id);
                Entities.Remove(playerEntity.Id);
                break;

            default:
                Entities.Remove(entity.Id);
                break;
            }
        }
Esempio n. 3
0
        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;
                    }
                }
            }
        }
Esempio n. 4
0
        public void UnregisterEntity <T>(T entity) where T : ISubstantialEntity
        {
            switch (entity)
            {
            case null:
                break;

            case IPlayerEntity playerEntity:
                PlayerEntities.Remove(playerEntity.Id);
                SubstantialEntities.Remove(playerEntity.Id);
                break;

            default:
                SubstantialEntities.Remove(entity.Id);
                break;
            }

            if (SubstantialEntities.Count == 0)
            {
                Dispose();
            }
        }
Esempio n. 5
0
 public override void EntityRemoved(EntityWrapper entityWrapper)
 {
     PlayerEntities.Remove(entityWrapper);
 }