Example #1
0
        //this is used to withdraw based on a particular store entry, and specified parameters
        public static Item WithdrawByEntryType(Container pack, Type entrytype, int amount, object[] parameters)
        {
            //check if there are any BaseStoreKey or MasterItemStoreKey objects in the caster's backpack
            Item[] keysources = pack.FindItemsByType(new Type[] { typeof(BaseStoreKey), typeof(MasterItemStoreKey) });

            if (keysources == null || amount == 0)
            {
                return(null);
            }

            //go thru the list of found objects
            foreach (Item key in keysources)
            {
                //utilizes IItemStoreObject interface function, defined by keys
                if (key is IItemStoreObject)
                {
                    //scan this object for any usable candidates to withdraw from
                    StoreEntry entry = ((IItemStoreObject)key).FindEntryByEntryType(entrytype, amount, parameters);

                    if (entry != null)
                    {
                        Item item = entry.Withdraw(ref amount, true);

                        entry.RefreshParentGump();

                        pack.AddItem(_LastWithdrawn);

                        return(item);
                    }
                }
            }

            return(null);
        }
Example #2
0
        public static bool CraftWithdraw(Container pack, Type[] types, int amount, bool getamountonly)
        {
            //check if there are any BaseStoreKey or MasterItemStoreKey objects in the caster's backpack
            Item[] keysources = pack.FindItemsByType(new Type[] { typeof(BaseStoreKey), typeof(MasterItemStoreKey) });

            if (keysources == null || types == null || amount == 0)
            {
                return(false);
            }

            //go thru the list of found objects
            foreach (Item key in keysources)
            {
                //utilizes IItemStoreObject interface function, defined by keys
                if (key is IItemStoreObject)
                {
                    //scan this object for any usable candidates to withdraw from
                    StoreEntry entry = ((IItemStoreObject)key).FindConsumableEntry(types, amount);

                    if (entry != null)
                    {
                        if (getamountonly)
                        {
                            _LastAmountCount = entry.Amount;
                        }
                        else if (entry.Amount < amount)
                        {
                            //don't do anything if there's not enough to work from
                            return(false);
                        }
                        else
                        {
                            //if a valid entry was found, withdraw it to the container

                            Console.WriteLine("trying to withdraw " + amount.ToString());
                            //doesn't work properly with unstackable items

                            //store the amount that needs to be withdrawn, and reset the amount that has been withdrawn
                            int amounttowithdraw = amount;
                            int amountwithdrawn  = 0;

                            //keep withdrawing until the desired amount has been taken out
                            while (amountwithdrawn < amounttowithdraw)
                            {
                                amount = amounttowithdraw - amountwithdrawn;

                                _LastWithdrawn = entry.Withdraw(ref amount);

                                amountwithdrawn += amount;

                                //if for some reason none was taken out, then exit
                                if (amount == 0)
                                {
                                    return(false);
                                }
                                pack.AddItem(_LastWithdrawn);
                            }
                            entry.RefreshParentGump();
                        }
                        return(true);
                    }
                }
            }

            //if nothing was found, return false
            return(false);
        }        //static CraftWithdraw