protected override void Handle(Client client, DropPacket packet)
        {
            Map map = client.Character.Map;

            if (map == null)
            {
                _logger.Warn("Handling InPacket but character map is null");
                return;
            }

            if (map.Contains(EntityType.GROUND_ITEM, packet.VNum))
            {
                _logger.Warn($"Entity {EntityType.GROUND_ITEM} {packet.VNum} already on map");
                return;
            }

            Entity entity = _entityFactory.CreateGroundItem(packet.DropId, packet.VNum, packet.Amount);

            entity.Position = new Position(packet.PositionX, packet.PositionY);

            if (entity is GroundItem drop)
            {
                drop.Owner = map.GetEntity <Player>(packet.OwnerId);
            }

            map.AddEntity(entity);
            _logger.Info($"Entity {entity.EntityType} {entity.Id} joined map");

            _eventManager.Emit(new EntityJoinEvent(client)
            {
                Map    = map,
                Entity = entity
            });
        }
Beispiel #2
0
        protected override void Handle(Client client, ThrowPacket packet)
        {
            Map map = client.Character?.Map;

            if (map == null)
            {
                _logger.Warn("Handling InPacket but character map is null");
                return;
            }

            if (map.Contains(EntityType.GROUND_ITEM, packet.TransportId))
            {
                _logger.Warn($"Entity {EntityType.GROUND_ITEM} {packet.TransportId} already on map");
                return;
            }

            GroundItem entity = _entityFactory.CreateGroundItem(packet.TransportId, packet.VNum, packet.Amount);

            entity.Position = new Position(packet.PositionX, packet.PositionY);

            map.AddEntity(entity);
            _logger.Info($"Item {entity.Id} was thrown on map");

            // TODO: thrown event
        }
Beispiel #3
0
        public void Entity_Factory_Create_Correct_Ground_Item()
        {
            GroundItem groundItem = _entityFactory.CreateGroundItem(1, 759, 10);

            Check.That(groundItem).IsNotNull();
            Check.That(groundItem.Id).Is(1);
            Check.That(groundItem.Amount).Is(10);
            Check.That(groundItem.Name).Is("Archmage Wand");
        }
        protected override void Handle(Client client, InPacket packet)
        {
            Map map = client.Character?.Map;

            if (map == null)
            {
                _logger.Warn("Handling InPacket but character map is null");
                return;
            }

            if (map.Contains(packet.EntityType, packet.EntityId))
            {
                _logger.Warn($"Entity {packet.EntityType} {packet.EntityId} already on map");
                return;
            }

            Entity entity;

            switch (packet.EntityType)
            {
            case EntityType.MONSTER:
                entity = _entityFactory.CreateMonster(packet.EntityId, packet.Vnum);
                break;

            case EntityType.NPC:
                entity = _entityFactory.CreateNpc(packet.EntityId, packet.Vnum, packet.NpcSubPacket.Name);
                break;

            case EntityType.PLAYER:
                entity = _entityFactory.CreatePlayer(packet.EntityId, packet.Name);
                break;

            case EntityType.GROUND_ITEM:
                entity = _entityFactory.CreateGroundItem(packet.EntityId, packet.Vnum, packet.DropSubPacket.Amount);
                break;

            default:
                throw new InvalidOperationException("Undefined entity type");
            }

            entity.Position = new Position(packet.PositionX, packet.PositionY);

            if (entity is Player player)
            {
                player.Level        = packet.PlayerSubPacket.Level;
                player.Class        = packet.PlayerSubPacket.Class;
                player.Gender       = packet.PlayerSubPacket.Gender;
                player.Direction    = packet.Direction;
                player.HpPercentage = packet.PlayerSubPacket.HpPercentage;
                player.MpPercentage = packet.PlayerSubPacket.MpPercentage;
            }

            if (entity is Monster monster)
            {
                monster.Direction    = packet.Direction;
                monster.HpPercentage = packet.NpcSubPacket.HpPercentage;
                monster.MpPercentage = packet.NpcSubPacket.MpPercentage;
                monster.Faction      = packet.NpcSubPacket.Faction;
            }

            if (entity is Npc npc)
            {
                npc.Direction    = packet.Direction;
                npc.HpPercentage = packet.NpcSubPacket.HpPercentage;
                npc.MpPercentage = packet.NpcSubPacket.MpPercentage;
                npc.Faction      = packet.NpcSubPacket.Faction;
            }

            if (entity is GroundItem drop)
            {
                drop.Owner = map.GetEntity <Player>(packet.DropSubPacket.Owner);
            }

            map.AddEntity(entity);
            _logger.Info($"Entity {entity.EntityType} {entity.Id} joined map");

            _eventManager.Emit(new EntityJoinEvent(client)
            {
                Map    = map,
                Entity = entity
            });
        }