Example #1
0
        // move item to panel but the owner is not the trader
        public bool MoveItemFromBag(BasePlayerItem item, Trader owner, int quantity)
        {
            if (quantity > 0)
            {
                if (quantity > item.Stack)
                {
                    return(false);
                }

                if (RuneCraftDialog.IsItemEditable(item) && quantity > 1)
                {
                    quantity = 1;
                }

                var existingItem = Items.OfType <PlayerTradeItem>().FirstOrDefault(x => x.Guid == item.Guid);
                if (existingItem != null)
                {
                    if (RuneCraftDialog.IsItemEditable(existingItem)) // cannot stack item to edit
                    {
                        MoveItemFromBag(existingItem.PlayerItem, owner, (int)-existingItem.Stack);
                    }
                    else
                    {
                        if (existingItem.Stack + quantity > item.Stack)
                        {
                            quantity = (int)(item.Stack - existingItem.Stack);
                        }

                        existingItem.Stack += (uint)quantity;

                        OnItemMoved(existingItem, true, quantity);

                        return(true);
                    }
                }

                if (RuneCraftDialog.IsItemEditable(item) && item.Stack > 1)
                {
                    item = item.Owner.Inventory.CutItem(item, 1);
                }

                var newItem = new PlayerTradeItem(owner, item, (uint)quantity);
                AddItem(newItem);
                OnItemMoved(newItem, false, quantity);

                return(true);
            }

            var panelItem = Items.FirstOrDefault(x => x.Guid == item.Guid);

            if (item == null)
            {
                return(false);
            }

            BasePlayerItem stackableWith;

            if (item.Owner.Inventory.IsStackable(item, out stackableWith))
            {
                if (quantity >= item.Stack || quantity == 0)
                {
                    item.Owner.Inventory.StackItem(stackableWith, (int)item.Stack);
                    item.Owner.Inventory.RemoveItem(item);
                }
                else
                {
                    item.Owner.Inventory.StackItem(stackableWith, quantity);
                    item.Owner.Inventory.RemoveItem(item, quantity);
                }
            }

            if (-quantity >= item.Stack || quantity == 0)
            {
                if (RemoveItem(panelItem))
                {
                    OnItemMoved(panelItem, true, quantity);
                }
            }
            else
            {
                item.Stack += (uint)quantity;
                OnItemMoved(panelItem, true, quantity);
            }

            owner.MoveItem(item.Guid, quantity != 0 ? -quantity : (int)item.Stack);

            return(false);
        }
Example #2
0
 public DecraftResult(PlayerTradeItem item)
 {
     Item  = item;
     Runes = new Dictionary <ItemTemplate, int>();
 }
        public bool MoveItemToPanel(int guid, uint amount)
        {
            BasePlayerItem basePlayerItem = this.Character.Inventory[guid];
            TradeItem      tradeItem      = base.Items.SingleOrDefault((TradeItem entry) => entry.Guid == guid);

            this.ToggleReady(false);
            bool result;

            if (basePlayerItem == null)
            {
                result = false;
            }
            else
            {
                if (amount > basePlayerItem.Stack || amount <= 0u)
                {
                    result = false;
                }
                else
                {
                    if (basePlayerItem.IsLinked() && base.Trade is PlayerTrade)
                    {
                        BasicHandler.SendTextInformationMessage(this.Character.Client, TextInformationTypeEnum.TEXT_INFORMATION_ERROR, 345, new object[]
                        {
                            basePlayerItem.Template.Id,
                            basePlayerItem.Guid
                        });
                        result = false;
                    }
                    else
                    {
                        if (tradeItem != null)
                        {
                            if (basePlayerItem.Stack < tradeItem.Stack + amount)
                            {
                                result = false;
                            }
                            else
                            {
                                uint stack = tradeItem.Stack;
                                tradeItem.Stack += amount;
                                if (tradeItem.Stack <= 0u)
                                {
                                    base.RemoveItem(tradeItem);
                                }
                                this.OnItemMoved(tradeItem, true, (int)(tradeItem.Stack - stack));
                                result = true;
                            }
                        }
                        else
                        {
                            tradeItem = new PlayerTradeItem(basePlayerItem, amount);
                            base.AddItem(tradeItem);
                            this.OnItemMoved(tradeItem, false, (int)amount);
                            result = true;
                        }
                    }
                }
            }
            return(result);
        }