예제 #1
0
        private void ConvertCommodities()
        {
            var items = new List <Item>(Items);

            for (int i = 0; i < items.Count; i++)
            {
                var item = items[i];

                if (item is ICommodity && ((ICommodity)item).IsDeedable)
                {
                    var deed = new CommodityDeed();

                    if (deed.SetCommodity(item))
                    {
                        DropItem(deed);
                    }
                    else
                    {
                        deed.Delete();
                    }
                }
            }

            ColUtility.Free(items);
        }
예제 #2
0
        private bool GiveItems(Mobile from, Type type, int amt, StorageEntry entry)
        {
            int amount = amt;

            while (amount > 60000)
            {
                CommodityDeed deed = new CommodityDeed();
                Item          item = Loot.Construct(type);
                item.Amount = 60000;
                deed.SetCommodity(item);
                amount -= 60000;

                if (from.Backpack == null || !from.Backpack.TryDropItem(from, deed, false))
                {
                    deed.Delete();
                    return(false);
                }
                else
                {
                    entry.RemoveCommodity(type, 60000);
                }
            }

            CommodityDeed deed2 = new CommodityDeed();
            Item          item2 = Loot.Construct(type);

            item2.Amount = amount;
            deed2.SetCommodity(item2);

            if (from.Backpack == null || !from.Backpack.TryDropItem(from, deed2, false))
            {
                deed2.Delete();
                return(false);
            }
            else
            {
                entry.RemoveCommodity(type, amount);
            }

            return(true);
        }
예제 #3
0
            /// <summary>
            /// Core procedure of the donation system for stackable items.
            /// </summary>
            /// <param name="m">The player whose backpack the items will be taken</param>
            /// <param name="type">The type of the donation item.</param>
            /// <param name="ratio">Number of points per unit of the item.</param>
            /// <param name="amount">How much is he going to donate.</param>
            private void Donate(Mobile m, Type type, double ratio, int amount)
            {
                if (amount <= 0)
                {
                    // That is not a valid donation quantity.
                    m.SendLocalizedMessage(1073181);

                    return;
                }

                int sum    = GetTotalAmountByType(m, type);
                int points = (int)(amount * ratio);

                if (sum < amount)
                {
                    // You do not have enough to make a donation of that magnitude!
                    m.SendLocalizedMessage(1073182);
                }
                else if (points <= 0)
                {
                    // Your donation is too small to award any points.  Try giving a larger donation.
                    m.SendLocalizedMessage(1073166);
                }
                else
                {
                    List <Item> packItems = new List <Item>(m.Backpack.Items);

                    for (int i = 0; amount > 0 && i < packItems.Count; i++)
                    {
                        Item item = packItems[i];

                        CommodityDeed deed = null;

                        if (item is CommodityDeed)
                        {
                            deed = item as CommodityDeed;
                            item = deed.Commodity;
                        }

                        if (item != null && item.GetType() == type)
                        {
                            if (amount >= item.Amount)
                            {
                                amount -= item.Amount;
                                item.Delete();

                                if (deed != null)
                                {
                                    deed.Delete();
                                }
                            }
                            else
                            {
                                item.Amount -= amount;
                                amount       = 0;

                                if (deed != null)
                                {
                                    deed.InvalidateProperties();
                                }
                            }
                        }
                    }

                    m_Collection.Award(m, points);
                }
            }