Server.Mobiles.Banker.Withdraw C# (CSharp) Méthode

Withdraw() public static méthode

public static Withdraw ( Mobile from, int amount ) : bool
from Mobile
amount int
Résultat bool
        public static bool Withdraw(Mobile from, int amount)
        {
            // If for whatever reason the TOL checks fail, we should still try old methods for withdrawing currency.
            if (AccountGold.Enabled && from.Account != null && from.Account.WithdrawGold(amount))
            {
                return true;
            }

            Item[] gold, checks;
            var balance = GetBalance(from, out gold, out checks);

            if (balance < amount)
            {
                return false;
            }

            for (var i = 0; amount > 0 && i < gold.Length; ++i)
            {
                if (gold[i].Amount <= amount)
                {
                    amount -= gold[i].Amount;
                    gold[i].Delete();
                }
                else
                {
                    gold[i].Amount -= amount;
                    amount = 0;
                }
            }

            for (var i = 0; amount > 0 && i < checks.Length; ++i)
            {
                var check = (BankCheck)checks[i];

                if (check.Worth <= amount)
                {
                    amount -= check.Worth;
                    check.Delete();
                }
                else
                {
                    check.Worth -= amount;
                    amount = 0;
                }
            }

            return true;
        }

Usage Example

Exemple #1
0
        public override void OnResponse(NetState sender, RelayInfo info)
        {
            if (info.ButtonID == 1)
            {
                int[] switches = info.Switches;

                if (switches.Length > 0)
                {
                    int index  = switches[0] % m_Entries.Length;
                    int offset = switches[0] / m_Entries.Length;

                    if (index >= 0 && index < m_Entries.Length)
                    {
                        if (offset >= 0 && offset < m_Entries[index].Hues.Length)
                        {
                            if (m_Hair && m_From.HairItemID > 0 || m_FacialHair && m_From.FacialHairItemID > 0)
                            {
                                if (!Banker.Withdraw(m_From, m_Vendor.TypeOfCurrency, m_Price))
                                {
                                    // You cannot afford my services for that style.
                                    m_Vendor.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 1042293, m_From.NetState);
                                    return;
                                }

                                int hue = m_Entries[index].Hues[offset];

                                if (m_Hair)
                                {
                                    m_From.HairHue = hue;
                                }

                                if (m_FacialHair)
                                {
                                    m_From.FacialHairHue = hue;
                                }
                            }
                            else
                            {
                                // You have no hair to dye and you cannot use this.
                                m_Vendor.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 502623, m_From.NetState);
                            }
                        }
                    }
                }
                else
                {
                    // You decide not to change your hairstyle.
                    m_Vendor.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 1013009, m_From.NetState);
                }
            }
            else
            {
                // You decide not to change your hairstyle.
                m_Vendor.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 1013009, m_From.NetState);
            }
        }
All Usage Examples Of Server.Mobiles.Banker::Withdraw