//Serialize public override void Serialize(GenericWriter writer) { base.Serialize(writer); Console.WriteLine("Serialize LoggedQuestSystem"); writer.WriteEncodedInt((int)0); // version //To Serialize a hashtable, we have work to do... //So to serialize a hashtable of hashtables... Imagine ;-) //Loop through all items of the Player Hashtable IDictionaryEnumerator en = QuestsTable.GetEnumerator(); //First get number of entries int cnt = QuestsTable.Count; //Write number of entries writer.WriteEncodedInt((int)cnt); Console.WriteLine("LoggedQuestCenter cnt : " + cnt); //Now write them while (en.MoveNext()) { Console.WriteLine("LoggedQuestCenter Key : " + en.Key); //Write the key of this element writer.Write((Mobile)en.Key); //Now we handle all the elements of the value hashtable //Get the hashtable entry Hashtable questname = (Hashtable)en.Value; //Get second enumerator IDictionaryEnumerator secen = questname.GetEnumerator(); //First get number of entries cnt = questname.Count; Console.WriteLine("LoggedQuestCenter Player cnt : " + cnt); //Write number of entries writer.WriteEncodedInt((int)cnt); //Now write them while (secen.MoveNext()) { Console.WriteLine("LoggedQuestCenter Player Hash Key : " + secen.Key); Console.WriteLine("LoggedQuestCenter Player Hash Value : " + secen.Value); LoggedQuestInfo lqi = (LoggedQuestInfo)secen.Value; //Write key writer.Write((string)secen.Key); //Write Value LoggedQuestInfoSerializer.Serialize(lqi, writer); } } }
//Deserialize public override void Deserialize(GenericReader reader) { base.Deserialize(reader); //Init the static side of the class //Initialize(); Console.WriteLine("Deserialize LoggedQuestCenter"); int version = reader.ReadEncodedInt(); //To deserialize the hashtable of hashtables... //Note the constructor creates the hashtable so no need of creating it //First we get the number of entries int cnt = reader.ReadEncodedInt(), i, j; Console.WriteLine("Deser LoggedQuestCenter Cnt : " + cnt); //Next read each entry for (i = 0; i < cnt; i++) { //Get player key Mobile playerkey = reader.ReadMobile(); Console.WriteLine("Deser LoggedQuestCenter Player : " + playerkey); //Get player hash table //If not yet in hashtable Hashtable playerquests = null; if (!QuestsTable.ContainsKey(playerkey)) { Console.WriteLine("LoggedQuestCenter here3"); //Create an entry playerquests = new Hashtable(); QuestsTable[playerkey] = playerquests; } else { Console.WriteLine("LoggedQuestCenter here2"); //Otherwise just get it playerquests = (Hashtable)QuestsTable[playerkey]; } Console.WriteLine("LoggedQuestCenter here"); //Get number of quest entries for this player int nbrquests = reader.ReadEncodedInt(); //Get quest entries Console.WriteLine("Deser LoggedQuestCenter Player Hash Count : " + nbrquests); for (j = 0; j < nbrquests; j++) { //Get hash key (string name) string key = reader.ReadString(); //Get hash value (LoggedQuestInfo) LoggedQuestInfo value = LoggedQuestInfoSerializer.Deserialize(reader); Console.WriteLine("Deser LoggedQuestCenter Player Hash Key : " + key); //Add entry playerquests[key] = value; } } }