Example #1
0
        private void MoveFromContainer(ItemMovePacket itemMovePacket)
        {
            var container = Player.GetContainer(itemMovePacket.FromLocation.Container);
            var thing     = container.Content[container.Content.Count - itemMovePacket.FromLocation.Z - 1];

            var    delayTime = TimeSpan.FromMilliseconds(200);
            IEvent movement  = null;

            switch (itemMovePacket.ToLocation.Type)
            {
            case LocationType.Ground:
                movement = new ThingMovementContainerToGround(Player.CreatureId, thing, itemMovePacket.FromLocation, itemMovePacket.ToLocation, itemMovePacket.Count);
                break;

            case LocationType.Container:
                movement = new ThingMovementContainerToContainer(Player.CreatureId, thing, itemMovePacket.FromLocation, itemMovePacket.ToLocation, itemMovePacket.Count);
                break;

            case LocationType.Slot:
                movement = new ThingMovementContainerToSlot(Player.CreatureId, thing, itemMovePacket.FromLocation, itemMovePacket.ToLocation, itemMovePacket.Count);
                break;
            }

            // submit the movement.
            if (movement != null)
            {
                Game.Instance.ScheduleEvent(movement, delayTime);
            }
        }
Example #2
0
        public override void HandleMessageContents(NetworkMessage message, Connection connection)
        {
            var itemMovePacket = new ItemMovePacket(message);
            var player         = Game.Instance.GetCreatureWithId(connection.PlayerId) as Player;

            if (player == null)
            {
                return;
            }

            player.ClearPendingActions();

            // Before actually moving the item, check if we're close enough to use it.
            if (itemMovePacket.FromLocation.Type == LocationType.Ground)
            {
                var locationDiff = itemMovePacket.FromLocation - player.Location;

                if (locationDiff.Z != 0) // it's on a different floor...
                {
                    ResponsePackets.Add(new TextMessagePacket
                    {
                        Type    = MessageType.StatusSmall,
                        Message = "There is no way."
                    });

                    return;
                }

                if (locationDiff.MaxValueIn2D > 1)
                {
                    // Too far away to use it.
                    Location retryLoc;
                    var      directions = Game.Instance.Pathfind(player.Location, itemMovePacket.FromLocation, out retryLoc).ToArray();

                    player.SetPendingAction(new MoveItemPlayerAction(player, itemMovePacket, retryLoc));

                    if (directions.Length > 0)
                    {
                        player.AutoWalk(directions);
                    }
                    else // we found no way...
                    {
                        ResponsePackets.Add(new TextMessagePacket
                        {
                            Type    = MessageType.StatusSmall,
                            Message = "There is no way."
                        });
                    }

                    return;
                }
            }

            new MoveItemPlayerAction(player, itemMovePacket, itemMovePacket.FromLocation).Perform();
        }
Example #3
0
        public static ItemMovePacket Parse(NetworkMessage message)
        {
            ItemMovePacket packet = new ItemMovePacket();

            packet.FromLocation      = message.GetLocation();
            packet.SpriteId          = message.GetUInt16();
            packet.FromStackPosition = message.GetByte();
            packet.ToLocation        = message.GetLocation();
            packet.Count             = message.GetByte();

            return(packet);
        }
Example #4
0
        private void MoveFromGround(ItemMovePacket itemMovePacket)
        {
            var fromTile = Game.Instance.GetTileAt(itemMovePacket.FromLocation);
            var thing    = fromTile?.GetThingAtStackPosition(itemMovePacket.FromStackPos);

            var    delayTime = TimeSpan.FromMilliseconds(200);
            IEvent movement  = null;

            switch (itemMovePacket.ToLocation.Type)
            {
            case LocationType.Ground:
                if (thing is ICreature)
                {
                    delayTime = TimeSpan.FromSeconds(1);
                    movement  = new CreatureMovementOnMap(Player.CreatureId, thing as ICreature, itemMovePacket.FromLocation, itemMovePacket.ToLocation);
                }
                else
                {
                    movement = new ThingMovementOnMap(Player.CreatureId, thing, itemMovePacket.FromLocation, itemMovePacket.FromStackPos, itemMovePacket.ToLocation, itemMovePacket.Count);
                }

                break;

            case LocationType.Container:
                movement = new ThingMovementGroundToContainer(Player.CreatureId, thing, itemMovePacket.FromLocation, itemMovePacket.FromStackPos, itemMovePacket.ToLocation, itemMovePacket.Count);
                break;

            case LocationType.Slot:
                movement = new ThingMovementGroundToSlot(Player.CreatureId, thing, itemMovePacket.FromLocation, itemMovePacket.FromStackPos, itemMovePacket.ToLocation, itemMovePacket.Count);
                break;
            }

            // submit the movement.
            if (movement != null)
            {
                Game.Instance.ScheduleEvent(movement, delayTime);
            }
        }
Example #5
0
 public MoveItemPlayerAction(IPlayer player, ItemMovePacket itemMovePacket, Location retryAtLocation)
     : base(player, itemMovePacket, retryAtLocation)
 {
 }
Example #6
0
        public void ParseItemMove(NetworkMessage message)
        {
            ItemMovePacket packet = ItemMovePacket.Parse(message);

            Game.ThingMove(Player, packet.SpriteId, packet.FromLocation, packet.FromStackPosition, packet.ToLocation, packet.Count);
        }