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

            Inventory fromInventory = Player.Inventory;

            Item fromItem = fromInventory.GetContent(FromSlot) 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, () =>
                        {
                            WalkToUnknownPathCommand walkToUnknownPathCommand = new WalkToUnknownPathCommand(Player, toCreature.Tile);

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

                            walkToUnknownPathCommand.Execute(server, context);
                        });
                    }
                }
            }
        }
示例#2
0
        protected bool IsNextTo(Tile fromTile, Server server, Context context)
        {
            if (!Player.Tile.Position.IsNextTo(fromTile.Position))
            {
                WalkToUnknownPathCommand walkToUnknownPathCommand = new WalkToUnknownPathCommand(Player, fromTile);

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

                walkToUnknownPathCommand.Execute(server, context);

                return(false);
            }

            return(true);
        }
示例#3
0
        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)
                {
                    Player toPlayer = server.Map.GetCreature(ToCreatureId) as Player;

                    if (toPlayer != null && toPlayer != Player)
                    {
                        //Act

                        if (!Player.Tile.Position.IsNextTo(fromTile.Position))
                        {
                            WalkToUnknownPathCommand walkToUnknownPathCommand = new WalkToUnknownPathCommand(Player, fromTile);

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

                            walkToUnknownPathCommand.Execute(server, context);
                        }
                        else
                        {
                            TradeWith(fromItem, toPlayer, server, context);
                        }
                    }
                }
            }
        }
示例#4
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;
                                }
                            });
                        }
                    }
                }
            }
        }