Exemple #1
0
        /// <summary>
        /// Deserializes a bestiary from an XML string.
        /// </summary>
        /// <param name="xml">The XML content.</param>
        /// <param name="powerBook">The PowerBook containing the creatures' powers.</param>
        /// <returns>The bestiary from the string data.</returns>
        public static Bestiary Deserialize(string xml, PowerBook powerBook)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Bestiary));

            StringReader reader = new StringReader(xml);
            Bestiary bst =  (Bestiary)serializer.Deserialize(reader);

            Debug.Log("Loaded " + bst.Prototypes.Count + " creatures into Bestiary.");

            //Initialize the creature powers.
            int referenced = 0;
            foreach (CreaturePrototype c in bst.Prototypes) {
                referenced += c.LoadPowersFromNames(powerBook);
            }
            Debug.Log("Successfully referenced " + referenced + " creature powers.");

            return bst;
        }
    // Use this for initialization
    public void Start()
    {
        //These kind of have to be deserialized in this order to make any sense.
        this.powerBook = PowerBook.Deserialize(this.PowerBookXML.text);
        this.bestiary = Bestiary.Deserialize(this.BestiaryXML.text, this.powerBook);
        this.scenario = Scenario.Deserialize(this.ScenarioXML.text, this.bestiary);

        #region Temp Bestiary...
        //Bestiary bst = new Bestiary();
        //bst.Creatures.Add(new Creature("Player Character Alpha"));
        //bst.Creatures.Add(new Creature("Player Character Bravo"));

        //string[] p1 = new string[] { "Acid Arrow", "Tectonic Shift" };
        //string[] p2 = new string[] { "Flame Burst", "Force Orb" };
        //bst.Creatures[0].AtWillPowerNames = new List<string>(p1);
        //bst.Creatures[1].AtWillPowerNames = new List<string>(p2);

        //bst.Creatures.Add(new Creature("Monster Yankee"));
        //bst.Creatures.Add(new Creature("Monster Zulu"));

        //string[] m = new string[] { "Strike" };
        //bst.Creatures[2].AtWillPowerNames = new List<string>(m);
        //bst.Creatures[3].AtWillPowerNames = new List<string>(m);

        //string bXML = bst.Serialize();
        //StreamWriter writer = new StreamWriter("ThisIsWhereOutputGoes.txt");
        //writer.Write("Nothing to see here.");
        //writer.Close();
        #endregion

        #region Temp Scenario...
        //Scenario scen = new Scenario();

        //Battle a = new Battle();
        //a.FriendlyNames.Add("Player Character Alpha");
        //a.FriendlyNames.Add("Player Character Bravo");
        //a.HostileNames.Add("Monster Zulu");

        //Battle b = new Battle();
        //b.FriendlyNames.Add("Player Character Alpha");
        //b.HostileNames.Add("Monster Yankee");
        //b.HostileNames.Add("Monster Zulu");

        //scen.Battles.Add(a);
        //scen.Battles.Add(b);

        //string sXML = scen.Serialize();
        //StreamWriter writer = new StreamWriter("Assets/Data/scenario.xml");
        //writer.Write(sXML);
        //writer.Close();
        #endregion

        //Make sure there's at least one battle, creature, and power.
        if (this.scenario.Battles.Count == 0 || this.bestiary.Prototypes.Count == 0 || this.powerBook.Powers.Count == 0) {
            Debug.LogError("Data files do not contain sufficient information to play a scenario.");
            Application.Quit();
        }

        this.battleReports = new List<BattleReport>();
        this.surveyReports = new List<SurveyReport>();
    }
 /// <summary>
 /// Loads a creature's powers from a powerbook.
 /// </summary>
 /// <param name="pb">The powerbook containing the referenced powers.</param>
 /// <returns>The number of loaded powers.</returns>
 public int LoadPowersFromNames(PowerBook pb)
 {
     this.AtWillPowers = new List<Power>();
     foreach (string name in this.AtWillPowerNames) {
         Power power = pb.GetPower(name);
         if (power == null) {
             Debug.LogWarning("Creature Power not found in PowerBook. (" + name + ")");
         } else {
             this.AtWillPowers.Add(power);
         }
     }
     return this.AtWillPowers.Count;
 }