Exemple #1
0
        /// <summary>
        /// Attempts to start a transfer of the given item to the bank the
        /// creature is currently using.
        /// </summary>
        /// <param name="creature"></param>
        /// <param name="itemEntityId"></param>
        /// <param name="instantTransfer"></param>
        /// <returns></returns>
        public bool Transfer(Creature creature, long itemEntityId, bool instantTransfer)
        {
            // Check bank
            var currentBank = creature.Temp.CurrentBankId;

            if (string.IsNullOrWhiteSpace(currentBank))
            {
                Log.Warning("BankTransferRequest: Player '0x{0:X16}' (Account: '{1}') tried to transfer item while not being in a bank.", creature.EntityId, creature.Client.Account.Id);
                return(false);
            }

            // Get item and tab
            Item   item    = null;
            string tabName = null;

            foreach (var tab in this.Tabs.Values)
            {
                item = tab.GetItem(itemEntityId);
                if (item != null)
                {
                    tabName = tab.Name;
                    break;
                }
            }

            if (item == null)
            {
                Log.Warning("BankTransferRequest: Player '0x{0:X16}' (Account: '{1}') tried to transfer a non-existing or in-transit item.", creature.EntityId, creature.Client.Account.Id);
                return(false);
            }

            // Get fee and time
            var fee  = BankInventory.GetTransferFee(item, item.Bank, currentBank);
            var time = BankInventory.GetTransferTime(item.Bank, currentBank);

            // Incrase fee for instant transfer.
            if (instantTransfer)
            {
                // Don't change, hardcoded in the client.
                fee  = 100 + (fee * 5);
                time = 0;
            }

            // Check gold
            if (this.Gold < fee)
            {
                Send.MsgBox(creature, Localization.Get("Unable to pay the fee, Insufficient balance."));
                return(false);
            }

            // Transfer
            item.Bank = currentBank;
            item.BankTransferStart    = DateTime.Now;
            item.BankTransferDuration = time;

            this.RemoveGold(creature, fee);

            Send.BankTransferInfo(creature, tabName, item);

            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Sends OpenBank to creature's client.
        /// </summary>
        /// <param name="creature"></param>
        /// <param name="bank"></param>
        /// <param name="race"></param>
        public static void OpenBank(Creature creature, BankInventory bank, BankTabRace race, string bankId, string bankTitle)
        {
            var packet = new Packet(Op.OpenBank, creature.EntityId);

            packet.PutByte(1);
            packet.PutByte((byte)race);
            packet.PutLong(DateTime.Now);
            packet.PutByte(0);
            packet.PutString(creature.Client.Account.Id);
            packet.PutString(bankId);
            packet.PutString(bankTitle);
            packet.PutInt(bank.Gold);

            var tabList = bank.GetTabList(race);
            packet.PutInt(tabList.Count);
            foreach (var tab in tabList)
            {
                packet.PutString(tab.Name);
                packet.PutByte((byte)tab.Race);

                // [190200, NA204 (2015-05-19)] ?
                // Haven't opened a bank in a while, could've been
                // added earlier. -- exec
                {
                    packet.PutInt(0);
                }

                packet.PutInt(tab.Width);
                packet.PutInt(tab.Height);

                var itemList = tab.GetItemList();
                packet.PutInt(itemList.Count);
                foreach (var item in itemList)
                {
                    packet.PutString(item.Bank);
                    packet.PutLong(item.BankTransferRemaining);
                    packet.PutLong(item.BankTransferStart);
                    packet.AddItemInfo(item, ItemPacketType.Private);
                }
            }

            creature.Client.Send(packet);
        }