Exemplo n.º 1
0
        public override void OnResponse(NetState sender, RelayInfo info)
        {
            try
            {
                //read in the text field and set the withdraw amount based on the contents
                //bounded by max storage, and 1
                if (!_Store.LockWithdrawalAmount)
                {
                    _Store.WithdrawAmount = Math.Max(_Store.MinWithdrawAmount, Math.Min(ItemStore.MaxAmount, Int32.Parse(GetTextField(info, 0))));
                }
            }
            catch
            {
                _Owner.SendMessage("Invalid entry in withdrawl amount: " + GetTextField(info, 0));
            }

            if (!_Store.CanUse(_Owner))
            {
                return;
            }

            //store flags
            int  buttonid = info.ButtonID;
            bool deed     = false;

            //right click
            if (buttonid == 0)
            {
                return;
            }

            //toggle lock button
            if (buttonid == _Store.StoreEntries.Count * 2 + 1)
            {
                _Store.LockWithdrawalAmount = !_Store.LockWithdrawalAmount;
                _Owner.SendGump(new ItemStoreGump(this));
                return;
            }

            //add button
            if (buttonid == _Store.StoreEntries.Count * 2 + 2)
            {
                _Store.AddItem(_Owner);

                _Owner.SendGump(new ItemStoreGump(this));
                return;
            }

            //fill from backpack button
            if (buttonid == _Store.StoreEntries.Count * 2 + 3)
            {
                _Store.FillFromBackpack(_Owner);

                _Owner.SendGump(new ItemStoreGump(this));
                return;
            }

            //previous page button
            if (buttonid == _Store.StoreEntries.Count * 2 + 4)
            {
                if (_Page > 0)
                {
                    _Owner.SendGump(new ItemStoreGump(_Owner, _Store, _Page - 1));
                }
                return;
            }

            //next page button
            if (buttonid == _Store.StoreEntries.Count * 2 + 5)
            {
                if (_Page < _MaxPages - 1)
                {
                    _Owner.SendGump(new ItemStoreGump(_Owner, _Store, _Page + 1));
                }
                return;
            }

            //flag if a deed is requested
            if (buttonid > _Store.StoreEntries.Count)
            {
                deed      = true;
                buttonid -= _Store.StoreEntries.Count;
            }

            //any button that is left is a withdraw request
            //offset of 1 between the passed value and the list index
            _Store.WithdrawItem(_Owner, buttonid - 1, deed);
            _Owner.SendGump(new ItemStoreGump(this));
        }