public void Deserialize(GenericReader reader) { int version = reader.ReadInt(); switch (version) { case 3: { LockWithdrawalAmount = reader.ReadBool(); goto case 2; } case 2: { Insured = reader.ReadBool(); goto case 1; } //case 1: added reference for loottype of parent object, as well as columns to display on gump case 1: { LootType = (LootType)reader.ReadInt(); DisplayColumns = reader.ReadInt(); goto case 0; } case 0: default: { Label = reader.ReadString(); Dynamic = reader.ReadBool(); OfferDeeds = reader.ReadBool(); WithdrawAmount = reader.ReadInt(); MinWithdrawAmount = reader.ReadInt(); int entrycount = reader.ReadInt(); //read in the active items if (entrycount > 0) { for (int i = 0; i < entrycount; i++) { //dynamically create store entries, ore derived ones, based on the type name stored in the serial data, then add it to the serial data reader //WARNING... this is very delicate!! if an improper type name was saved to the serial data (eg. if a tool or resource used to belong to a tool, and was removed from the shard) then an exception will be thrown here. //be sure to remove any and all tool types from keys, and cycle a world load/save before taking that class out StoreEntry entry = (StoreEntry)Activator.CreateInstance(ScriptCompiler.FindTypeByName(reader.ReadString()), new object[] { reader }); //register this store with the entry for refresh purposes entry.Store = this; StoreEntries.Add(entry); } } //read in the expelled items entrycount = reader.ReadInt(); if (entrycount > 0) { for (int i = 0; i < entrycount; i++) { StoreEntry entry = (StoreEntry)Activator.CreateInstance(ScriptCompiler.FindTypeByName(reader.ReadString()), new object[] { reader }); //register this store with the entry for refresh purposes entry.Store = this; ExpelStoreEntries.Add(entry); } } break; } } } //deserialize
//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(); }