//this produces a clone of the specified ItemStore public static ItemStore Clone(ItemStore store) { //create a new itemstore and populate its store entry list with a clone of the store entry list belonging to the source store ItemStore newstore = new ItemStore(StoreEntry.CloneList(store.StoreEntries)); newstore.ExpelStoreEntries = StoreEntry.CloneList(store.ExpelStoreEntries); newstore.Label = store.Label; newstore.Dynamic = store.Dynamic; newstore.OfferDeeds = store.OfferDeeds; newstore.WithdrawAmount = store.WithdrawAmount; newstore.MinWithdrawAmount = store.MinWithdrawAmount; newstore.LootType = store.LootType; newstore.Insured = store.Insured; newstore.LockWithdrawalAmount = store.LockWithdrawalAmount; newstore.DisplayColumns = store.DisplayColumns; //this is reset to the new containing object after the cloning process is complete. newstore.Owner = store.Owner; foreach (StoreEntry entry in store.StoreEntries) { entry.Store = newstore; } return(newstore); }
//the basic initialization of the item store protected virtual ItemStore GenerateItemStore() { //load the item entry structure. Note that contents is specific because EntryStructure can be //overloaded in child entities ItemStore newstore = new ItemStore(StoreEntry.CloneList(EntryStructure)); //write the new display column number to the store newstore.DisplayColumns = DisplayColumns; newstore.RegisterEntries(); return(newstore); }
//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(); }