Esempio n. 1
0
        public static int GetTypes(PlayerMobile pm, CollectionItem colItem)
        {
            var  type    = colItem.Type;
            bool derives = type == typeof(RedScales) || type == typeof(Fish) || type == typeof(Crab) || type == typeof(Lobster);

            int count = 0;

            foreach (var item in pm.Backpack.Items)
            {
                if (CheckType(item, type, derives) && colItem.Validate(pm, GetActual(item)))
                {
                    if (type == typeof(BankCheck))
                    {
                        count += pm.Backpack.GetChecksWorth(true);
                    }
                    else if (item is CommodityDeed)
                    {
                        count += ((CommodityDeed)item).Commodity.Amount;
                    }
                    else
                    {
                        count += item.Amount;
                    }
                }
            }

            return(count);
        }
        public static int GetTypes(PlayerMobile pm, CollectionItem colItem)
        {
            Type type = colItem.Type;

            bool derives = type == typeof(BaseScales) || type == typeof(Fish) || type == typeof(Crab) || type == typeof(Lobster);

            int count = 0;

            for (var index = 0; index < pm.Backpack.Items.Count; index++)
            {
                Item item = pm.Backpack.Items[index];

                if (CheckType(item, type, derives) && colItem.Validate(pm, GetActual(item)))
                {
                    if (item is CommodityDeed deed)
                    {
                        count += deed.Commodity.Amount;
                    }
                    else
                    {
                        count += item.Amount;
                    }
                }
            }

            return(count);
        }
Esempio n. 3
0
        public static List <Item> FindTypes(PlayerMobile pm, CollectionItem colItem)
        {
            Type type    = colItem.Type;
            bool derives = type == typeof(RedScales) || type == typeof(Fish) || type == typeof(Crab) || type == typeof(Lobster);

            List <Item> list = new List <Item>();

            foreach (Item item in pm.Backpack.Items)
            {
                if (CheckType(item, type, derives) && colItem.Validate(pm, GetActual(item)))
                {
                    list.Add(item);
                }
            }

            return(list);
        }
        public static List <Item> FindTypes(PlayerMobile pm, CollectionItem colItem)
        {
            Type type = colItem.Type;

            bool derives = type == typeof(BaseScales) || type == typeof(Fish) || type == typeof(Crab) || type == typeof(Lobster);

            List <Item> list = new List <Item>();

            for (var index = 0; index < pm.Backpack.Items.Count; index++)
            {
                Item item = pm.Backpack.Items[index];

                if (CheckType(item, type, derives) && colItem.Validate(pm, GetActual(item)))
                {
                    list.Add(item);
                }
            }

            return(list);
        }
Esempio n. 5
0
            private void HandleResponse(Mobile from, string text)
            {
                int amount = Utility.ToInt32(text);

                if (amount <= 0)
                {
                    from.SendLocalizedMessage(1073181); // That is not a valid donation quantity.
                    return;
                }

                if (from.Backpack == null)
                {
                    return;
                }

                if (m_Selected.Type == typeof(Gold))
                {
                    if (amount * m_Selected.Points < 1)
                    {
                        from.SendLocalizedMessage(1073167); // You do not have enough of that item to make a donation!
                        from.SendGump(new CommunityCollectionGump((PlayerMobile)from, m_Collection, m_Location));
                        return;
                    }

                    Item[]  items = from.Backpack.FindItemsByType(m_Selected.Type, true);
                    Account acct  = from.Account as Account;

                    int goldcount    = 0;
                    int accountcount = acct == null ? 0 : acct.TotalGold;

                    foreach (Item item in items)
                    {
                        goldcount += item.Amount;
                    }

                    if (goldcount >= amount)
                    {
                        foreach (Item item in items)
                        {
                            if (item.Amount <= amount)
                            {
                                item.Delete();
                                amount -= item.Amount;
                            }
                            else
                            {
                                item.Amount -= amount;
                                amount       = 0;
                            }

                            if (amount == 0)
                            {
                                break;
                            }
                        }
                    }
                    else if (goldcount + accountcount >= amount)
                    {
                        foreach (Item item in items)
                        {
                            amount -= item.Amount;
                            item.Delete();
                        }

                        Banker.Withdraw(from, amount);
                    }
                    else
                    {
                        from.SendLocalizedMessage(1073182); // You do not have enough to make a donation of that magnitude!
                        from.SendGump(new CommunityCollectionGump((PlayerMobile)from, m_Collection, m_Location));
                        return;
                    }

                    m_Collection.Donate((PlayerMobile)from, m_Selected, amount);
                    return;
                }
                else if (m_Selected.Type == typeof(Fish) || m_Selected.Type == typeof(Crab) || m_Selected.Type == typeof(Lobster) || m_Selected.Type == typeof(RedScales))
                {
                    if (amount * m_Selected.Points < 1)
                    {
                        from.SendLocalizedMessage(1073167); // You do not have enough of that item to make a donation!
                        from.SendGump(new CommunityCollectionGump((PlayerMobile)from, m_Collection, m_Location));
                        return;
                    }

                    Item[] items;

                    if (m_Selected.Type == typeof(Fish))
                    {
                        items = CommunityCollectionGump.FindFishyItems(from.Backpack);
                    }
                    else if (m_Selected.Type == typeof(RedScales))
                    {
                        items = CommunityCollectionGump.FindScales(from.Backpack);
                    }
                    else
                    {
                        items = CommunityCollectionGump.FindCrabsAndLobsters(from.Backpack);
                    }

                    if (items != null)
                    {
                        // count items
                        int count = 0;

                        for (int i = 0; i < items.Length; i++)
                        {
                            if (m_Selected.Validate((PlayerMobile)from, items[i]) && !items[i].Deleted)
                            {
                                count += items[i].Amount;
                            }
                        }

                        // check
                        if (amount > count)
                        {
                            from.SendLocalizedMessage(1073182); // You do not have enough to make a donation of that magnitude!
                            from.SendGump(new CommunityCollectionGump((PlayerMobile)from, m_Collection, m_Location));
                            return;
                        }
                        else if (amount * m_Selected.Points < 1)
                        {
                            from.SendLocalizedMessage(1073167); // You do not have enough of that item to make a donation!
                            from.SendGump(new CommunityCollectionGump((PlayerMobile)from, m_Collection, m_Location));
                            return;
                        }

                        // donate
                        int deleted = 0;

                        for (int i = 0; i < items.Length && deleted < amount; i++)
                        {
                            if (m_Selected.Validate((PlayerMobile)from, items[i]) && items[i].Stackable && items[i].Amount + deleted > amount && !items[i].Deleted)
                            {
                                items[i].Amount -= amount - deleted;
                                deleted         += amount - deleted;
                            }
                            else if (m_Selected.Validate((PlayerMobile)from, items[i]) && !items[i].Deleted)
                            {
                                deleted += items[i].Amount;
                                items[i].Delete();
                            }
                        }

                        m_Collection.Donate((PlayerMobile)from, m_Selected, amount);
                        return;
                    }
                    else
                    {
                        from.SendLocalizedMessage(1073182); // You do not have enough to make a donation of that magnitude!
                    }
                }
                if (m_Selected.Type == typeof(BankCheck))
                {
                    int count = from.Backpack.GetChecksWorth(true);
                    if (count < amount)
                    {
                        from.SendLocalizedMessage(1073182); // You do not have enough to make a donation of that magnitude!
                        return;
                    }
                }
                else
                {
                    int count = from.Backpack.GetAmount(m_Selected.Type, true, true);
                    if (count < amount)
                    {
                        if (m_Selected.Type == typeof(Gold))
                        {
                            from.SendLocalizedMessage(1073182); // You do not have enough to make a donation of that magnitude!
                        }
                        else
                        {
                            from.SendLocalizedMessage(1073167); // You do not have enough of that item to make a donation!
                        }
                        return;
                    }
                }

                // Donate
                if (m_Selected.Type == typeof(BankCheck))
                {
                    from.Backpack.TakeFromChecks(amount, true);
                }
                else
                {
                    from.Backpack.ConsumeTotal(m_Selected.Type, amount, true, true);
                }

                m_Collection.Donate((PlayerMobile)from, m_Selected, amount);
            }
            public override void OnResponse(Mobile from, string text)
            {
                if (!from.InRange(m_Location, 2) || !(from is PlayerMobile))
                {
                    return;
                }

                from.SendGump(new ComunityCollectionGump((PlayerMobile)from, m_Collection, m_Location));

                int amount = Utility.ToInt32(text);

                if (amount <= 0)
                {
                    from.SendLocalizedMessage(1073181);                       // That is not a valid donation quantity.
                    return;
                }

                Item[] items = from.Backpack != null?from.Backpack.FindItemsByType(m_Selected.Type, true) : null;

                if (items != null)
                {
                    // count items
                    int count = 0;

                    for (int i = 0; i < items.Length; i++)
                    {
                        if (items[i] is BankCheck && !items[i].Deleted)
                        {
                            count += ((BankCheck)items[i]).Worth;
                        }
                        else if (m_Selected.Validate((PlayerMobile)from, items[i]) && !items[i].Deleted)
                        {
                            count += items[i].Amount;
                        }
                    }

                    // check
                    if (amount > count)
                    {
                        from.SendLocalizedMessage(1073182);                           // You do not have enough to make a donation of that magnitude!
                        return;
                    }
                    else if (amount * m_Selected.Points < 1)
                    {
                        from.SendLocalizedMessage(1073167);                           // You do not have enough of that item to make a donation!
                        return;
                    }

                    // donate
                    int deleted = 0;

                    for (int i = 0; i < items.Length && deleted < amount; i++)
                    {
                        if (items[i] is BankCheck && !items[i].Deleted)
                        {
                            BankCheck check = (BankCheck)items[i];

                            if (check.Worth + deleted > amount)
                            {
                                check.Worth -= amount - deleted;
                                deleted     += amount - deleted;
                            }
                            else
                            {
                                deleted += check.Worth;
                                check.Delete();
                            }
                        }
                        else if (m_Selected.Validate((PlayerMobile)from, items[i]) && items[i].Stackable && items[i].Amount + deleted > amount && !items[i].Deleted)
                        {
                            items[i].Amount -= amount - deleted;
                            deleted         += amount - deleted;
                        }
                        else if (m_Selected.Validate((PlayerMobile)from, items[i]) && !items[i].Deleted)
                        {
                            deleted += items[i].Amount;
                            items[i].Delete();
                        }
                    }

                    m_Collection.Donate((PlayerMobile)from, m_Selected, amount);
                }
                else
                {
                    from.SendLocalizedMessage(1073182);                       // You do not have enough to make a donation of that magnitude!
                }
            }