예제 #1
0
        public override void run()
        {
            L2Player player = getClient().CurrentPlayer;

            if (_amount < 0)
            {
                _amount = 1;
            }

            if (player.LastRequestedMultiSellId != _listId)
            {
                player.sendMessage("You are not authorized to use this list now.");
                player.sendActionFailed();
                return;
            }

            MultiSellList list = null;

            if (player.CustomMultiSellList != null)
            {
                list = player.CustomMultiSellList;
                if (list.id != _listId)
                {
                    list = MultiSell.getInstance().getList(_listId);
                }
            }
            else
            {
                list = MultiSell.getInstance().getList(_listId);
            }

            if (list == null || list.container.Count < _entryId)
            {
                player.sendSystemMessage(1802);//The attempt to trade has failed.
                player.sendActionFailed();
                return;
            }

            MultiSellEntry entry = list.container[_entryId];

            bool ok = true;

            foreach (MultiSellItem i in entry.take)
            {
                if (i.id > 0)
                {
                    if (!player.hasItem(i.id, i.count))
                    {
                        ok = false;
                        break;
                    }
                }
                else
                {
                    switch (i.id)
                    {
                    case -100:     //pvppoint
                        if (player.Fame < i.count * _amount)
                        {
                            ok = false;
                        }
                        break;
                    }
                }
            }

            if (!ok)
            {
                player.sendSystemMessage(701);//You do not have enough required items.
                player.sendActionFailed();
                return;
            }

            foreach (MultiSellItem i in entry.take)
            {
                if (i.l2item != null)
                {
                    player.Inventory.destroyItem(i.l2item, 1, true, true);
                }
                else
                {
                    if (i.id > 0)
                    {
                        player.Inventory.destroyItem(i.id, i.count, true, true);
                    }
                    else
                    {
                        switch (i.id)
                        {
                        case -100:     //pvppoint
                            break;
                        }
                    }
                }
            }

            foreach (MultiSellItem i in entry.give)
            {
                if (i.id > 0)
                {
                    if (i.l2item != null)
                    {
                        L2Item item = new L2Item(i.template);
                        item.Enchant = i.l2item.Enchant;
                        player.Inventory.addItem(item, true, true);
                    }
                    else
                    {
                        if (i.template.isStackable())
                        {
                            player.Inventory.addItem(i.id, i.count * _amount, i.enchant, true, true);
                        }
                        else
                        {
                            player.Inventory.addItem(i.id, 1, i.enchant, true, true);
                        }
                    }
                }
                else
                {
                    switch (i.id)
                    {
                    case -100:     //pvppoint
                        break;
                    }
                }
            }

            player.sendSystemMessage(1656);//You have successfully traded the item with the NPC.
        }
예제 #2
0
        public override void RunImpl()
        {
            L2Player player = _client.CurrentPlayer;

            if (player.LastRequestedMultiSellId != _listId)
            {
                player.SendMessage("You are not authorized to use this list now.");
                player.SendActionFailed();
                return;
            }

            MultiSellList list;

            if (player.CustomMultiSellList != null)
            {
                list = player.CustomMultiSellList;
                if (list.Id != _listId)
                {
                    list = MultiSell.Instance.GetList(_listId);
                }
            }
            else
            {
                list = MultiSell.Instance.GetList(_listId);
            }

            if ((list == null) || (list.Container.Count < _entryId))
            {
                player.SendSystemMessage(SystemMessage.SystemMessageId.TradeAttemptFailed);
                player.SendActionFailed();
                return;
            }

            MultiSellEntry entry = list.Container[_entryId];

            bool ok = true;

            foreach (MultiSellItem i in entry.Take)
            {
                if (i.Id > 0)
                {
                    if (player.HasItem(i.Id, i.Count))
                    {
                        continue;
                    }

                    ok = false;
                    break;
                }

                switch (i.Id)
                {
                case -100:     //pvppoint
                    if (player.Fame < (i.Count * _amount))
                    {
                        ok = false;
                    }
                    break;
                }
            }

            if (!ok)
            {
                player.SendSystemMessage(SystemMessage.SystemMessageId.NotEnoughRequiredItems);
                player.SendActionFailed();
                return;
            }

            foreach (MultiSellItem i in entry.Take)
            {
                if (i.L2Item != null)
                {
                    player.DestroyItem(i.L2Item, 1);
                }
                else
                {
                    if (i.Id > 0)
                    {
                        player.DestroyItemById(i.Id, i.Count);
                    }
                    else
                    {
                        switch (i.Id)
                        {
                        case -100:     //pvppoint
                            break;
                        }
                    }
                }
            }

            player.SendSystemMessage(SystemMessage.SystemMessageId.SuccessfullyTradedWithNpc);
        }