예제 #1
0
        //withdraw action by type - this one will be used from the craft system
        public void WithdrawItem(Mobile from, int amount, Type type)
        {
            int entryindex = StoreEntry.IndexOfType(_StoreEntries, type);

            if (entryindex > 0)
            {
                WithdrawItem(from, amount, entryindex, false, false);
            }
        }
예제 #2
0
        public StoreEntry FindConsumableEntry(Type[] types, int amount)
        {
            //find a match in this key's store
            int index = StoreEntry.IndexOfType(_Store.StoreEntries, types, true);

            //check if there was a match, and there is a sufficient amount
            if (index > -1 && _Store.StoreEntries[index].Amount >= amount)
            {
                //return a reference to this
                return(_Store.StoreEntries[index]);
            }

            //nothing suitable found, return null
            return(null);
        }
예제 #3
0
        //scans thru the contents for requested consumables and returns a list of all usable candidates.  The foundentries boolean
        //array holds recod of previously found resources from other IItemStoreObjects previously scanned, and thus are ignored
        public List <StoreEntry> FindConsumableEntries(Type[] types, int[] amounts, ref bool[] foundentries)
        {
            List <StoreEntry> stores = new List <StoreEntry>();

            for (int i = 0; i < types.Length; i++)
            {
                //ignore it if this has already been found in another storage
                if (foundentries[i])
                {
                    continue;
                }

                //find a match in this key's store
                foreach (ItemStore store in _Stores)
                {
                    int index = StoreEntry.IndexOfType(store.StoreEntries, types[i], true);

                    //check if there was a match, and there is a sufficient amount
                    if (index > -1 && store.StoreEntries[index].Amount >= amounts[i])
                    {
                        //add to the list to return
                        stores.Add(store.StoreEntries[index]);

                        //record the amount to consume, so if the operation is a success, the store entry will perform the consumption
                        store.StoreEntries[index].ToConsume = amounts[i];

                        //flag this entry as found
                        foundentries[i] = true;

                        //go on to the next type
                        break;
                    }
                }
            }



            return(stores);
        }
예제 #4
0
        //this synchronizes the item store with a specified list of item entries.  this is done to allow a scripter to on-the-fly
        //modify the contents of any object containing an item store without having to manually reorganize the data entries of all
        //instanced objects in the world save data
        public void SynchronizeStore(List <StoreEntry> synchentries)
        {
            //Idea: stick current active store entry list in a temporary location, and rebuild the list using the
            //synchentries list data.  Pull amount info from the temporary list (if it exists there) and remove that entry
            //from the temporary list.  Finally, put any leftover entries in the temporary list into the expel list, to
            //be claimed externally the next time the device implementing this list is used.

            //store the current world loaded list into a temporary list
            List <StoreEntry> templist = StoreEntry.CloneList(_StoreEntries);

            //clear the current list so it's ready to be written to
            _StoreEntries = new List <StoreEntry>();

            //begin generating new list based on synch entries parameter
            foreach (StoreEntry entry in synchentries)
            {
                //use clone constructor
                StoreEntry newentry = entry.Clone();

                //find a matching item entry in the temporary list
                int matchingindex = StoreEntry.IndexOfType(templist, entry.Type);

                if (matchingindex > -1)
                {
                    //special treatment: if the entry is a list entry, then transfer the contained list too
                    if (entry is ListEntry && templist[matchingindex] is ListEntry)
                    {
                        //transfer over a clone copy of all item list entries
                        ((ListEntry)entry).CloneItemListEntries((ListEntry)templist[matchingindex]);
                    }
                    //special treatment: if the entry is a stash entry, then transfer the contained list too
                    else if (entry is StashEntry && templist[matchingindex] is StashEntry)
                    {
                        //transfer over a clone copy of all the item stash entries
                        ((StashEntry)entry).CloneStashListEntries((StashEntry)templist[matchingindex]);
                    }
                    else
                    {
                        //transfer over the amount into the new listing
                        entry.Amount = templist[matchingindex].Amount;
                    }



                    templist.RemoveAt(matchingindex);
                }
                else
                {
                }

                //add this to the finished product list
                _StoreEntries.Add(entry);
                //register entry with this store for refresh purposes
                entry.Store = this;
            }

            //finally, store the leftovers in the expel list
            foreach (StoreEntry entry in templist)
            {
                if (entry.Amount > 0)                           //note, this will automatically ignore all column separators
                {
                    int matchingindex = StoreEntry.IndexOfType(ExpelStoreEntries, entry.Type);
                    if (matchingindex > -1)
                    {
                        //append amount to existing entry in expel list
                        ExpelStoreEntries[matchingindex].Amount += entry.Amount;
                    }
                    else
                    {
                        //add new entry to the expel list
                        ExpelStoreEntries.Add(entry);
                    }
                }
            }

            RefreshEntryHeight();
        }