greeduomacro / runuomondains

Automatically exported from code.google.com/p/runuomondains
0 stars 0 forks source link

ML-Quest-System #41

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Problems:
When adding/scripting custom quests which does not add objectives and rewards 
at Constrution, you will have serious serialization/deserialization problems.

Because Objectives and Rewards doesn't get properly serialized.

Please serialize the Members of your objectives and rewards properly:

Could look like this:

SlayObjective for example

        public override void Serialize( GenericWriter writer )
        {
            base.Serialize( writer );

            writer.WriteEncodedInt( (int) 0 ); // version
            QuestWriter.Type(writer,m_Creature);
            writer.Write(m_Name);
            if (m_Region == null)
                writer.Write("-null-");
            else
                writer.Write(m_Region.Name);
        }

        public override void Deserialize( GenericReader reader )
        {
            base.Deserialize( reader );

            int version = reader.ReadEncodedInt();
            m_Creature = QuestReader.Type(reader);
            m_Name = reader.ReadString();
            string region = reader.ReadString();
            if (region != "-null-")
            {
                Region reg = QuestHelper.FindRegion(region);
                if (reg != null)
                    m_Region = reg;
            }
        }   

BaseQuest.cs Serialize:

            writer.Write( (int)m_Objectives.Count );                
            for ( int i = 0; i < m_Objectives.Count; i ++ )
            {
                BaseObjective objective = m_Objectives[i];
                QuestWriter.Type(writer, objective.GetType());
                objective.Serialize( writer );
            }
            writer.Write((int)m_Rewards.Count);
            for ( int i = 0; i< m_Rewards.Count; i++ )
            {
                BaseReward reward = m_Rewards[i];
                QuestWriter.Type(writer,reward.GetType());
                reward.Serialize(writer);
            }

BaseQuest.cs Deserialize:
            int count = reader.ReadInt();
            for ( int i = 0; i < count; i ++ )
            {
                BaseObjective objective = QuestReader.Construct(reader) as BaseObjective;

                if (objective == null)
                    continue;
                objective.Deserialize( reader );
                AddObjective(objective);
            }
            count = reader.ReadInt();
            for (int i = 0; i < count; i++)
            {
                BaseReward reward = QuestReader.Construct(reader) as BaseReward;

                if (reward == null)
                    continue;
                reward.Deserialize(reader);
                AddReward(reward);
            }

Don't forget to add Constructors without parameters to rewards and objective. 
Or the QuestReader.Construct will not work. :)

Original issue reported on code.google.com by j.schulz...@gmail.com on 29 Mar 2011 at 10:25

GoogleCodeExporter commented 9 years ago
I did not code this part.  This is a part of Mondains Legacy by MalGanis.

Original comment by ShaiTanMalkier@gmail.com on 25 Aug 2011 at 2:13