Example #1
0
 public override void EntityAdded(EntityWrapper entityWrapper)
 {
     if (entityWrapper.HasComponent <Player>())
     {
         PlayerEntities.Add(entityWrapper);
     }
 }
Example #2
0
        // Эти методы не особо нужны. Они создавались только для поддержки серверной сущности.

        public void AddPlayerEntity(PlayerEntity playerEntity)
        {
            var coincidence = PlayerEntities.FirstOrDefault(x => x == playerEntity);

            // Он не был зарегестрирован.
            if (coincidence == null)
            {
                PlayerEntities.Add(playerEntity);
                OnPlayerEntityAdd(playerEntity);
            }
        }
Example #3
0
        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;
            }
        }
Example #4
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;
                    }
                }
            }
        }