public override void Execute(Server server, Context context)
        {
            //Arrange

            Tile fromTile = server.Map.GetTile(FromPosition);

            if (fromTile != null)
            {
                Item fromItem = fromTile.GetContent(FromIndex) as Item;

                if (fromItem != null && fromItem.Metadata.TibiaId == ItemId)
                {
                    Creature toCreature = server.Map.GetCreature(ToCreatureId);

                    if (toCreature != null)
                    {
                        //Act

                        if (IsUseable(fromItem, server, context) &&

                            IsNextTo(fromTile, server, context))
                        {
                            UseItemWithCreature(fromItem, toCreature, server, context, () =>
                            {
                                MoveItemFromTileToInventoryCommand moveItemFromTileToInventoryCommand = new MoveItemFromTileToInventoryCommand(Player, FromPosition, FromIndex, ItemId, (byte)Slot.Extra, 1);

                                moveItemFromTileToInventoryCommand.Completed += (s, e) =>
                                {
                                    UseItemWithCreatureFromInventoryCommand useItemWithCreatureFromInventoryCommand = new UseItemWithCreatureFromInventoryCommand(Player, (byte)Slot.Extra, ItemId, ToCreatureId);

                                    useItemWithCreatureFromInventoryCommand.Completed += (s2, e2) =>
                                    {
                                        base.Execute(e2.Server, e2.Context);
                                    };

                                    useItemWithCreatureFromInventoryCommand.Execute(e.Server, e.Context);
                                };

                                moveItemFromTileToInventoryCommand.Execute(server, context);
                            });
                        }
                    }
                }
            }
        }
示例#2
0
        public override void Execute(Server server, Context context)
        {
            //Arrange

            Container fromContainer = Player.Client.ContainerCollection.GetContainer(FromContainerId);

            if (fromContainer != null)
            {
                Item fromItem = fromContainer.GetContent(FromContainerIndex) as Item;

                if (fromItem != null && fromItem.Metadata.TibiaId == ItemId)
                {
                    Creature toCreature = server.Map.GetCreature(ToCreatureId);

                    if (toCreature != null)
                    {
                        //Act

                        if (IsUseable(fromItem, server, context))
                        {
                            UseItemWithCreature(fromItem, toCreature, server, context, () =>
                            {
                                switch (fromContainer.GetRootContainer())
                                {
                                case Tile fromTile:

                                    MoveItemFromContainerToInventoryCommand moveItemFromTileToInventoryCommand = new MoveItemFromContainerToInventoryCommand(Player, FromContainerId, FromContainerIndex, ItemId, (byte)Slot.Extra, 1);

                                    moveItemFromTileToInventoryCommand.Completed += (s, e) =>
                                    {
                                        UseItemWithCreatureFromInventoryCommand useItemWithCreatureFromInventoryCommand = new UseItemWithCreatureFromInventoryCommand(Player, (byte)Slot.Extra, ItemId, ToCreatureId);

                                        useItemWithCreatureFromInventoryCommand.Completed += (s2, e2) =>
                                        {
                                            base.Execute(e2.Server, e2.Context);
                                        };

                                        useItemWithCreatureFromInventoryCommand.Execute(e.Server, e.Context);
                                    };

                                    moveItemFromTileToInventoryCommand.Execute(server, context);

                                    break;

                                case Inventory fromInventory:

                                    WalkToUnknownPathCommand walkToUnknownPathCommand = new WalkToUnknownPathCommand(Player, toCreature.Tile);

                                    walkToUnknownPathCommand.Completed += (s, e) =>
                                    {
                                        server.QueueForExecution(Constants.PlayerActionSchedulerEvent(Player), Constants.PlayerSchedulerEventDelay, this);
                                    };

                                    walkToUnknownPathCommand.Execute(server, context);

                                    break;
                                }
                            });
                        }
                    }
                }
            }
        }