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

            StringReader reader = new StringReader(xml);
            Scenario scen = (Scenario)serializer.Deserialize(reader);

            Debug.Log("Loaded " + scen.Battles.Count + " battles into Scenario.");

            //Initialize the creature powers.
            int referenced = 0;
            foreach (Battle battle in scen.Battles) {
                referenced += battle.LoadCreaturesFromNames(bestiary);
            }
            Debug.Log("Successfully referenced " + referenced + " battle creatures.");

            return scen;
        }
Exemple #2
0
        /// <summary>
        /// Loads battle teams from a bestiary.
        /// </summary>
        /// <param name="bst">The bestiary containing the referenced creatures.</param>
        /// <returns>The number of loaded creatures.</returns>
        public int LoadCreaturesFromNames(Bestiary bst)
        {
            //Create lists.
            this.FriendlyTeam = new List<Creature>();
            this.HostileTeam = new List<Creature>();

            int referenced = 0;
            //Lookup friendly creatures.
            foreach (string name in this.FriendlyNames) {
                CreaturePrototype prototype = bst.GetCreature(name);
                if (prototype == null) {
                    Debug.LogWarning("Battle Creature not found in Bestiary. (" + name + ")");
                } else {
                    this.FriendlyTeam.Add(new Creature(prototype));
                    referenced++;
                }
            }

            //Lookup hostile creatures.
            foreach (string name in this.HostileNames) {
                CreaturePrototype prototype = bst.GetCreature(name);
                if (prototype == null) {
                    Debug.LogWarning("Battle Creature not found in Bestiary. (" + name + ")");
                } else {
                    this.HostileTeam.Add(new Creature(prototype));
                    referenced++;
                }
            }
            return referenced;
        }