Exemple #1
0
        public override void GetProperties(ObjectPropertyList list)
        {
            base.GetProperties(list);

            using (var eopl = new ExtendedOPL(list))
            {
                if (!Trading)
                {
                    eopl.Add("Not Trading".WrapUOHtmlColor(Color.OrangeRed));
                    return;
                }

                if (!ShowCashName)
                {
                    return;
                }

                var name = CashName.GetString();

                if (!String.IsNullOrWhiteSpace(name))
                {
                    eopl.Add("Trades For {0}".WrapUOHtmlColor(Color.SkyBlue), name);
                }

                var races = RequiredRaces;

                if (races != null && races.Length > 0)
                {
                    foreach (var r in races)
                    {
                        eopl.Add("Trades With {0}".WrapUOHtmlColor(Color.LawnGreen), r.PluralName);
                    }
                }
            }
        }
Exemple #2
0
        public override void GetProperties(ObjectPropertyList list)
        {
            base.GetProperties(list);

            if (!Trading)
            {
                list.Add("Not Trading".WrapUOHtmlColor(Color.OrangeRed));
                return;
            }

            if (!ShowCashName)
            {
                return;
            }

            var name = CashName.GetString();

            if (!String.IsNullOrWhiteSpace(name))
            {
                list.Add("Trades For {0}".WrapUOHtmlColor(Color.SkyBlue), name);
            }
        }
        public override bool OnSellItems(Mobile seller, List <SellItemResponse> list)
        {
            if (!Trading || CashType == null || !CashType.IsNotNull)
            {
                return(false);
            }

            if (!IsActiveBuyer)
            {
                return(false);
            }

            if (!seller.CheckAlive())
            {
                return(false);
            }

            if (!CheckVendorAccess(seller))
            {
                Say("I can't serve you! Company policy.");
                //Say(501522); // I shall not treat with scum like thee!
                return(false);
            }

            seller.PlaySound(0x32);

            var       info         = GetSellInfo();
            var       buyInfo      = GetBuyInfo();
            var       giveCurrency = 0;
            Container cont;

            var finalList = list.Where(resp => CanSell(seller, info, resp)).ToArray();

            if (finalList.Length > 500)
            {
                SayTo(seller, true, "You may only sell 500 items at a time!");
                return(false);
            }

            if (finalList.Length == 0)
            {
                return(true);
            }

            foreach (var resp in finalList)
            {
                foreach (var ssi in info)
                {
                    if (!ssi.IsSellable(resp.Item))
                    {
                        continue;
                    }

                    var amount = resp.Amount;

                    if (amount > resp.Item.Amount)
                    {
                        amount = resp.Item.Amount;
                    }

                    var worth = GetSellPrice(seller, ssi, resp) * amount;

                    if (ssi.IsResellable(resp.Item))
                    {
                        var found = false;

                        if (buyInfo.Any(bii => bii.Restock(resp.Item, amount)))
                        {
                            resp.Item.Consume(amount);
                            found = true;
                        }

                        if (!found)
                        {
                            cont = BuyPack;

                            if (amount < resp.Item.Amount)
                            {
                                var item = LiftItemDupe(resp.Item, resp.Item.Amount - amount);

                                if (item != null)
                                {
                                    item.SetLastMoved();

                                    if (!cont.TryDropItem(this, resp.Item, false))
                                    {
                                        resp.Item.Delete();
                                    }
                                }
                                else
                                {
                                    resp.Item.SetLastMoved();

                                    if (!cont.TryDropItem(this, resp.Item, false))
                                    {
                                        resp.Item.Delete();
                                    }
                                }
                            }
                            else
                            {
                                resp.Item.SetLastMoved();

                                if (!cont.TryDropItem(this, resp.Item, false))
                                {
                                    resp.Item.Delete();
                                }
                            }
                        }
                    }
                    else
                    {
                        if (amount < resp.Item.Amount)
                        {
                            resp.Item.Amount -= amount;
                        }
                        else
                        {
                            resp.Item.Delete();
                        }
                    }

                    giveCurrency += worth;
                    break;
                }
            }

            if (giveCurrency <= 0)
            {
                return(false);
            }

            while (giveCurrency > 0)
            {
                Item c = null;

                if (CashType.TypeEquals <ObjectProperty>())
                {
                    var cashSource = GetCashObject(seller) ?? seller;

                    if (!CashProperty.Add(cashSource, giveCurrency))
                    {
                        c = new Static(0x14F0, 1)
                        {
                            Name       = String.Format("Staff I.O.U [{0} {1}]", giveCurrency.ToString("#,0"), CashName.GetString(seller)),
                            Hue        = 85,
                            Movable    = true,
                            BlessedFor = seller,
                            LootType   = LootType.Blessed
                        };
                    }

                    giveCurrency = 0;
                }

                if (c == null && giveCurrency > 0)
                {
                    c = CashType.CreateInstance <Item>();

                    if (c == null)
                    {
                        c = new Static(0x14F0, 1)
                        {
                            Name       = String.Format("Staff I.O.U [{0} {1}]", giveCurrency.ToString("#,0"), CashName.GetString(seller)),
                            Hue        = 85,
                            Movable    = true,
                            BlessedFor = seller,
                            LootType   = LootType.Blessed
                        };
                        giveCurrency = 0;
                    }
                    else
                    {
                        if (giveCurrency >= 60000)
                        {
                            c.Amount      = 60000;
                            giveCurrency -= 60000;
                        }
                        else
                        {
                            c.Amount     = giveCurrency;
                            giveCurrency = 0;
                        }
                    }
                }

                c.GiveTo(seller);
            }

            seller.PlaySound(0x0037);             //Gold dropping sound

            if (SupportsBulkOrders(seller))
            {
                var bulkOrder = CreateBulkOrder(seller, false);

                if (bulkOrder is LargeBOD)
                {
                    seller.SendGump(new LargeBODAcceptGump(seller, (LargeBOD)bulkOrder));
                }
                else if (bulkOrder is SmallBOD)
                {
                    seller.SendGump(new SmallBODAcceptGump(seller, (SmallBOD)bulkOrder));
                }
            }

            return(true);
        }
        public override bool OnBuyItems(Mobile buyer, List <BuyItemResponse> list)
        {
            if (!Trading || !IsActiveSeller || CashType == null || !CashType.IsNotNull)
            {
                return(false);
            }

            if (!buyer.CheckAlive())
            {
                return(false);
            }

            if (!CheckVendorAccess(buyer))
            {
                Say("I can't serve you! Company policy.");
                //Say(501522); // I shall not treat with scum like thee!
                return(false);
            }

            UpdateBuyInfo();

            var info         = GetSellInfo();
            var totalCost    = 0;
            var validBuy     = new List <BuyItemResponse>(list.Count);
            var fromBank     = false;
            var fullPurchase = true;
            var controlSlots = buyer.FollowersMax - buyer.Followers;

            foreach (var buy in list)
            {
                var ser    = buy.Serial;
                var amount = buy.Amount;

                if (ser.IsItem)
                {
                    var item = World.FindItem(ser);

                    if (item == null)
                    {
                        continue;
                    }

                    var gbi = LookupDisplayObject(item);

                    if (gbi != null)
                    {
                        ProcessSinglePurchase(buy, gbi, validBuy, ref controlSlots, ref fullPurchase, ref totalCost);
                    }
                    else if (item != BuyPack && item.IsChildOf(BuyPack))
                    {
                        if (amount > item.Amount)
                        {
                            amount = item.Amount;
                        }

                        if (amount <= 0)
                        {
                            continue;
                        }

                        foreach (var ssi in info.Where(ssi => ssi.IsSellable(item) && ssi.IsResellable(item)))
                        {
                            totalCost += ssi.GetBuyPriceFor(item) * amount;
                            validBuy.Add(buy);
                            break;
                        }
                    }
                }
                else if (ser.IsMobile)
                {
                    var mob = World.FindMobile(ser);

                    if (mob == null)
                    {
                        continue;
                    }

                    var gbi = LookupDisplayObject(mob);

                    if (gbi != null)
                    {
                        ProcessSinglePurchase(buy, gbi, validBuy, ref controlSlots, ref fullPurchase, ref totalCost);
                    }
                }
            }

            if (fullPurchase && validBuy.Count == 0)
            {
                // Thou hast bought nothing!
                SayTo(buyer, 500190);
            }
            else if (validBuy.Count == 0)
            {
                // Your order cannot be fulfilled, please try again.
                SayTo(buyer, 500187);
            }

            if (validBuy.Count == 0)
            {
                return(false);
            }

            var bought = buyer.AccessLevel >= AccessLevel.GameMaster;

            if (!bought && CashType.TypeEquals <ObjectProperty>())
            {
                var cashSource = GetCashObject(buyer) ?? buyer;

                bought = CashProperty.Consume(cashSource, totalCost);

                if (!bought)
                {
                    // Begging thy pardon, but thou cant afford that.
                    SayTo(buyer, 500192);
                    return(false);
                }

                SayTo(buyer, "{0:#,0} {1} has been deducted from your total.", totalCost, CashName.GetString(buyer));
            }

            var isGold = CashType.TypeEquals <Gold>();

            var cont = buyer.Backpack;

            if (!bought && cont != null && isGold)
            {
                VitaNexCore.TryCatch(
                    () =>
                {
                    var lt = ScriptCompiler.FindTypeByName("GoldLedger") ?? Type.GetType("GoldLedger");

                    if (lt == null)
                    {
                        return;
                    }

                    var ledger = cont.FindItemByType(lt);

                    if (ledger == null || ledger.Deleted)
                    {
                        return;
                    }

                    var lp = lt.GetProperty("Gold");

                    if (lp == null)
                    {
                        return;
                    }

                    if (lp.PropertyType.IsEqual <Int64>())
                    {
                        var lg = (long)lp.GetValue(ledger, null);

                        if (lg < totalCost)
                        {
                            return;
                        }

                        lp.SetValue(ledger, lg - totalCost, null);
                        bought = true;
                    }
                    else if (lp.PropertyType.IsEqual <Int32>())
                    {
                        var lg = (int)lp.GetValue(ledger, null);

                        if (lg < totalCost)
                        {
                            return;
                        }

                        lp.SetValue(ledger, lg - totalCost, null);
                        bought = true;
                    }

                    if (bought)
                    {
                        buyer.SendMessage(2125, "{0:#,0} gold has been withdrawn from your ledger.", totalCost);
                    }
                });
            }

            if (!bought)
            {
                ConsumeCurrency(buyer, ref totalCost, ref bought);
            }

            if (!bought && cont != null)
            {
                if (cont.ConsumeTotal(CashType, totalCost))
                {
                    bought = true;
                }
            }

            if (!bought && isGold && Banker.Withdraw(buyer, totalCost))
            {
                bought   = true;
                fromBank = true;
            }

            if (!bought && !isGold)
            {
                cont = buyer.FindBankNoCreate();

                if (cont != null && cont.ConsumeTotal(CashType, totalCost))
                {
                    bought   = true;
                    fromBank = true;
                }
            }

            if (!bought)
            {
                // Begging thy pardon, but thou cant afford that.
                SayTo(buyer, 500192);
                return(false);
            }

            buyer.PlaySound(0x32);

            cont = buyer.Backpack ?? buyer.BankBox;

            foreach (var buy in validBuy)
            {
                var ser    = buy.Serial;
                var amount = buy.Amount;

                if (amount < 1)
                {
                    continue;
                }

                if (ser.IsItem)
                {
                    var item = World.FindItem(ser);

                    if (item == null)
                    {
                        continue;
                    }

                    var gbi = LookupDisplayObject(item);

                    if (gbi != null)
                    {
                        ProcessValidPurchase(amount, gbi, buyer, cont);
                    }
                    else
                    {
                        if (amount > item.Amount)
                        {
                            amount = item.Amount;
                        }

                        if (info.Where(ssi => ssi.IsSellable(item)).Any(ssi => ssi.IsResellable(item)))
                        {
                            Item buyItem;

                            if (amount >= item.Amount)
                            {
                                buyItem = item;
                            }
                            else
                            {
                                buyItem = LiftItemDupe(item, item.Amount - amount) ?? item;
                            }

                            if (cont == null || !cont.TryDropItem(buyer, buyItem, false))
                            {
                                buyItem.MoveToWorld(buyer.Location, buyer.Map);
                            }
                        }
                    }
                }
                else if (ser.IsMobile)
                {
                    var mob = World.FindMobile(ser);

                    if (mob == null)
                    {
                        continue;
                    }

                    var gbi = LookupDisplayObject(mob);

                    if (gbi != null)
                    {
                        ProcessValidPurchase(amount, gbi, buyer, cont);
                    }
                }
            }

            if (fullPurchase)
            {
                if (buyer.AccessLevel >= AccessLevel.GameMaster)
                {
                    SayTo(buyer, true, "I would not presume to charge thee anything.  Here are the goods you requested.");
                }
                else if (fromBank)
                {
                    SayTo(
                        buyer,
                        true,
                        "The total of thy purchase is {0:#,0} {1}, which has been withdrawn from your bank account.  My thanks for the patronage.",
                        totalCost,
                        CashName.GetString(buyer));
                }
                else
                {
                    SayTo(
                        buyer,
                        true,
                        "The total of thy purchase is {0:#,0} {1}.  My thanks for the patronage.",
                        totalCost,
                        CashName.GetString(buyer));
                }
            }
            else
            {
                if (buyer.AccessLevel >= AccessLevel.GameMaster)
                {
                    SayTo(
                        buyer,
                        true,
                        "I would not presume to charge thee anything.  Unfortunately, I could not sell you all the goods you requested.");
                }
                else if (fromBank)
                {
                    SayTo(
                        buyer,
                        true,
                        "The total of thy purchase is {0:#,0} {1}, which has been withdrawn from your bank account.  My thanks for the patronage.  Unfortunately, I could not sell you all the goods you requested.",
                        totalCost,
                        CashName.GetString(buyer));
                }
                else
                {
                    SayTo(
                        buyer,
                        true,
                        "The total of thy purchase is {0:#,0} {1}.  My thanks for the patronage.  Unfortunately, I could not sell you all the goods you requested.",
                        totalCost,
                        CashName.GetString(buyer));
                }
            }

            return(true);
        }
Exemple #5
0
        public virtual void ConsumeCurrency(Mobile buyer, ref double totalCost, ref bool bought, ref bool fromBank)
        {
            if (!bought && CashType.TypeEquals <ObjectProperty>())
            {
                var cashSource = GetCashObject(buyer) ?? buyer;

                bought = CashProperty.Consume(cashSource, totalCost);

                if (bought)
                {
                    SayTo(buyer, "{0:#,0} {1} has been deducted from your total.", totalCost, CashName.GetString(buyer));
                }
                else
                {
                    // Begging thy pardon, but thou cant afford that.
                    SayTo(buyer, 500192);
                }

                return;
            }

            var isGold = CashType.TypeEquals <Gold>();

            var cont = buyer.Backpack;

            if (!bought && cont != null && isGold)
            {
                try
                {
                    var lt = ScriptCompiler.FindTypeByName("GoldLedger") ?? Type.GetType("GoldLedger");

                    if (lt != null)
                    {
                        var ledger = cont.FindItemByType(lt);

                        if (ledger != null && !ledger.Deleted)
                        {
                            var lp = lt.GetProperty("Gold");

                            if (lp != null)
                            {
                                if (lp.PropertyType.IsEqual <Int64>())
                                {
                                    var lg = (long)lp.GetValue(ledger, null);

                                    if (lg >= totalCost)
                                    {
                                        lp.SetValue(ledger, lg - (long)totalCost, null);
                                        bought = true;
                                    }
                                }
                                else if (lp.PropertyType.IsEqual <Int32>())
                                {
                                    var lg = (int)lp.GetValue(ledger, null);

                                    if (lg >= totalCost)
                                    {
                                        lp.SetValue(ledger, lg - (int)totalCost, null);
                                        bought = true;
                                    }
                                }

                                if (bought)
                                {
                                    buyer.SendMessage(2125, "{0:#,0} gold has been withdrawn from your ledger.", totalCost);
                                    return;
                                }
                            }
                        }
                    }
                }
                catch
                { }
            }

            if (!bought && cont != null && ConsumeCash(CashType, cont, totalCost))
            {
                bought = true;
            }

            if (!bought && isGold)
            {
                if (totalCost <= Int32.MaxValue)
                {
                    if (Banker.Withdraw(buyer, (int)totalCost))
                    {
                        bought   = true;
                        fromBank = true;
                    }
                }
                else if (buyer.Account != null && AccountGold.Enabled)
                {
                    if (buyer.Account.WithdrawCurrency(totalCost / AccountGold.CurrencyThreshold))
                    {
                        bought   = true;
                        fromBank = true;
                    }
                }
            }

            if (!bought && !isGold)
            {
                cont = buyer.FindBankNoCreate();

                if (cont != null && ConsumeCash(CashType, cont, totalCost))
                {
                    bought   = true;
                    fromBank = true;
                }
            }
        }
Exemple #6
0
        public override bool OnBuyItems(Mobile buyer, List <BuyItemResponse> list)
        {
            if (!Trading || !IsActiveSeller || CashType == null || !CashType.IsNotNull)
            {
                return(false);
            }

            if (!buyer.CheckAlive())
            {
                return(false);
            }

            if (!CheckVendorAccess(buyer))
            {
                Say("I can't serve you! Company policy.");
                //Say(501522); // I shall not treat with scum like thee!
                return(false);
            }

            UpdateBuyInfo();

            var info         = GetSellInfo();
            var totalCost    = 0.0;
            var validBuy     = new List <BuyItemResponse>(list.Count);
            var fromBank     = false;
            var fullPurchase = true;
            var controlSlots = buyer.FollowersMax - buyer.Followers;

            foreach (var buy in list)
            {
                var ser    = buy.Serial;
                var amount = buy.Amount;

                if (ser.IsItem)
                {
                    var item = World.FindItem(ser);

                    if (item == null)
                    {
                        continue;
                    }

                    var gbi = LookupDisplayObject(item);

                    if (gbi != null)
                    {
                        ProcessSinglePurchase(buy, gbi, validBuy, ref controlSlots, ref fullPurchase, ref totalCost);
                    }
                    else if (item != BuyPack && item.IsChildOf(BuyPack))
                    {
                        if (amount > item.Amount)
                        {
                            amount = item.Amount;
                        }

                        if (amount <= 0)
                        {
                            continue;
                        }

                        foreach (var ssi in info.Where(ssi => ssi.IsSellable(item) && ssi.IsResellable(item)))
                        {
                            totalCost += (double)ssi.GetBuyPriceFor(item) * amount;
                            validBuy.Add(buy);
                            break;
                        }
                    }
                }
                else if (ser.IsMobile)
                {
                    var mob = World.FindMobile(ser);

                    if (mob == null)
                    {
                        continue;
                    }

                    var gbi = LookupDisplayObject(mob);

                    if (gbi != null)
                    {
                        ProcessSinglePurchase(buy, gbi, validBuy, ref controlSlots, ref fullPurchase, ref totalCost);
                    }
                }
            }

            if (fullPurchase && validBuy.Count == 0)
            {
                // Thou hast bought nothing!
                SayTo(buyer, 500190);
            }
            else if (validBuy.Count == 0)
            {
                // Your order cannot be fulfilled, please try again.
                SayTo(buyer, 500187);
            }

            if (validBuy.Count == 0)
            {
                return(false);
            }

            var bought = buyer.AccessLevel >= AccessLevel.GameMaster;

            ConsumeCurrency(buyer, ref totalCost, ref bought, ref fromBank);

            if (!bought)
            {
                // Begging thy pardon, but thou cant afford that.
                SayTo(buyer, 500192);
                return(false);
            }

            buyer.PlaySound(0x32);

            var cont = buyer.Backpack ?? buyer.BankBox;

            foreach (var buy in validBuy)
            {
                var ser    = buy.Serial;
                var amount = buy.Amount;

                if (amount < 1)
                {
                    continue;
                }

                if (ser.IsItem)
                {
                    var item = World.FindItem(ser);

                    if (item == null)
                    {
                        continue;
                    }

                    var gbi = LookupDisplayObject(item);

                    if (gbi != null)
                    {
                        ProcessValidPurchase(amount, gbi, buyer, cont);
                    }
                    else
                    {
                        if (amount > item.Amount)
                        {
                            amount = item.Amount;
                        }

                        if (info.Where(ssi => ssi.IsSellable(item)).Any(ssi => ssi.IsResellable(item)))
                        {
                            Item buyItem;

                            if (amount >= item.Amount)
                            {
                                buyItem = item;
                            }
                            else
                            {
                                buyItem = LiftItemDupe(item, item.Amount - amount) ?? item;
                            }

                            if (cont != null)
                            {
                                cont.DropItem(buyItem);
                            }
                            else
                            {
                                buyItem.MoveToWorld(buyer.Location, buyer.Map);
                            }

                            OnItemReceived(buyer, buyItem, null);

                            if (cont != null && !buyItem.Deleted && buyItem.Stackable)
                            {
                                cont.MergeStacks(buyItem.GetType(), buyer);
                            }
                        }
                    }
                }
                else if (ser.IsMobile)
                {
                    var mob = World.FindMobile(ser);

                    if (mob == null)
                    {
                        continue;
                    }

                    var gbi = LookupDisplayObject(mob);

                    if (gbi != null)
                    {
                        ProcessValidPurchase(amount, gbi, buyer, cont);
                    }
                }
            }

            if (fullPurchase)
            {
                if (buyer.AccessLevel >= AccessLevel.GameMaster)
                {
                    SayTo(buyer, true, "I would not presume to charge thee anything.  Here are the goods you requested.");
                }
                else if (fromBank)
                {
                    SayTo(
                        buyer,
                        true,
                        "The total of thy purchase is {0:#,0} {1}, which has been withdrawn from your bank account.  My thanks for the patronage.",
                        totalCost,
                        CashName.GetString(buyer));
                }
                else
                {
                    SayTo(
                        buyer,
                        true,
                        "The total of thy purchase is {0:#,0} {1}.  My thanks for the patronage.",
                        totalCost,
                        CashName.GetString(buyer));
                }
            }
            else
            {
                if (buyer.AccessLevel >= AccessLevel.GameMaster)
                {
                    SayTo(
                        buyer,
                        true,
                        "I would not presume to charge thee anything.  Unfortunately, I could not sell you all the goods you requested.");
                }
                else if (fromBank)
                {
                    SayTo(
                        buyer,
                        true,
                        "The total of thy purchase is {0:#,0} {1}, which has been withdrawn from your bank account.  My thanks for the patronage.  Unfortunately, I could not sell you all the goods you requested.",
                        totalCost,
                        CashName.GetString(buyer));
                }
                else
                {
                    SayTo(
                        buyer,
                        true,
                        "The total of thy purchase is {0:#,0} {1}.  My thanks for the patronage.  Unfortunately, I could not sell you all the goods you requested.",
                        totalCost,
                        CashName.GetString(buyer));
                }
            }

            return(true);
        }