public static LoggedQuestInfo Deserialize(GenericReader reader)
        {
            int encoding = reader.ReadEncodedInt();

            switch (encoding)
            {
            default:
            case 0x00:                     // null
            {
                return(null);
            }

            case 0x01:
            {
                Type type = ReadType(LoggedQuestInfo.InfoTypes, reader);

                LoggedQuestInfo lqi = Construct(type) as LoggedQuestInfo;

                if (lqi != null)
                {
                    lqi.BaseDeserialize(reader);
                }

                return(lqi);
            }
            }
        }
Ejemplo n.º 2
0
        //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);
                }
            }
        }
        public static void Serialize(LoggedQuestInfo lqi, GenericWriter writer)
        {
            if (lqi == null)
            {
                writer.WriteEncodedInt(0x00);
            }
            else
            {
                writer.WriteEncodedInt(0x01);

                Write(lqi.GetType(), LoggedQuestInfo.InfoTypes, writer);

                lqi.BaseSerialize(writer);
            }
        }
        public static void updateQuestState(Hashtable playerquests, string questname, LoggedQuestState state)
        {
            LoggedQuestInfo lqi;

            //Is the quest in the hashtable
            if (playerquests.ContainsKey(questname))
            {
                lqi = (LoggedQuestInfo)playerquests[questname];
            }
            else
            {
                lqi = new LoggedQuestInfo();
                playerquests[questname] = lqi;
            }

            Console.WriteLine("LoggedQuestSystem, updating : " + questname + " with : " + (int)state);
            //Update quest state
            lqi.State = state;
        }
        //Returns QuestState
        public static LoggedQuestState getQuestState(Mobile from, string questname)
        {
            Console.WriteLine("Here");
            //If we have an entry for the player
            if (QuestsTable.Contains(from))
            {
                Console.WriteLine("Here 2");
                Hashtable playerquests = getPlayerEntry(from);

                //If we have an entry for the quest
                if (playerquests.ContainsKey(questname))
                {
                    //Return state
                    LoggedQuestInfo lqi = (LoggedQuestInfo)playerquests[questname];
                    return(lqi.State);
                }
            }
            //Otherwise the player is not involved with this quest
            return(LoggedQuestState.NOTINVOLVED);
        }
Ejemplo n.º 6
0
        //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;
                }
            }
        }