Exemplo n.º 1
0
        /// <summary>
        /// Loads a saved character.
        /// </summary>
        /// <param name="savexmlstring"></param>
        /// <param name="dataxmlstring"></param>
        private Character(string savexmlstring, string dataxmlstring)
        {
            _halve = new List<Element>();
            _void = new List<Element>();
            _absorb = new List<Element>();
            _immune = new List<Status>();

            XmlDocument savexml = new XmlDocument();
            XmlDocument dataxml = new XmlDocument();
            savexml.Load(new MemoryStream(Encoding.UTF8.GetBytes(savexmlstring)));
            dataxml.Load(new MemoryStream(Encoding.UTF8.GetBytes(dataxmlstring)));

            _name = savexml.FirstChild.Name;

            // Old Way : xml.SelectSingleNode("/" + _name + "/stats/lvl").InnerText

            // Stats
            _strength_base = Int32.Parse(savexml.SelectSingleNode("//str").InnerText);
            _dexterity_base = Int32.Parse(savexml.SelectSingleNode("//dex").InnerText);
            _vitality_base = Int32.Parse(savexml.SelectSingleNode("//vit").InnerText);
            _magic_base = Int32.Parse(savexml.SelectSingleNode("//mag").InnerText);
            _spirit_base = Int32.Parse(savexml.SelectSingleNode("//spi").InnerText);
            _luck_base = Int32.Parse(savexml.SelectSingleNode("//lck").InnerText);

            // Experience and Level
            _exp = Int32.Parse(savexml.SelectSingleNode("//exp").InnerText);
            _level = Int32.Parse(savexml.SelectSingleNode("//lvl").InnerText);
            _limitlvl = Int32.Parse(savexml.SelectSingleNode("//limitlvl").InnerText);

            // HP
            _hp = Int32.Parse(savexml.SelectSingleNode("//hp").InnerText);
            _maxhp = Int32.Parse(savexml.SelectSingleNode("//maxhp").InnerText);
            if (_hp > _maxhp) throw new SavegameException("HP > MAXHP for " + _name);
            _death = (_hp == 0);

            // MP
            _mp = Int32.Parse(savexml.SelectSingleNode("//mp").InnerText);
            _maxmp = Int32.Parse(savexml.SelectSingleNode("//maxmp").InnerText);
            if (_mp > _maxmp) throw new SavegameException("MP > MAXMP for " + _name);

            // Fury/Sadness
            _sadness = Boolean.Parse(savexml.SelectSingleNode("//sadness").InnerText);
            _fury = Boolean.Parse(savexml.SelectSingleNode("//fury").InnerText);
            if (_sadness && _fury) throw new SavegameException("Can't be both sad and furious");

            // Sex
            _sex = (Sex)Enum.Parse(typeof(Sex), dataxml.SelectSingleNode("//sex").InnerText);

            // Equipment
            _weaponType = (WeaponType)Enum.Parse(typeof(WeaponType), _name.Replace(" ", ""));

            _weapon = new Weapon(savexml.SelectSingleNode("//weapon/name").InnerText);
            foreach (XmlNode orb in savexml.SelectNodes("//weapon/materia/orb"))
            {
                string id = orb.Attributes["id"].Value;
                MateriaType type = (MateriaType)Enum.Parse(typeof(MateriaType), orb.Attributes["type"].Value);
                int ap = Int32.Parse(orb.Attributes["ap"].Value);
                int slot = Int32.Parse(orb.Attributes["slot"].Value);
                if (slot >= _weapon.Slots.Length)
                    throw new SavegameException("Materia orb assigned to slot that doesnt exist on weapon.");

                _weapon.Slots[slot] = Atmosphere.BattleSimulator.Materia.Create(id, ap, type);
            }

            _armor = new Armor(savexml.SelectSingleNode("//armor/name").InnerText);
            foreach (XmlNode orb in savexml.SelectNodes("//armor/materia/orb"))
            {
                string id = orb.Attributes["id"].Value;
                MateriaType type = (MateriaType)Enum.Parse(typeof(MateriaType), orb.Attributes["type"].Value);
                int ap = Int32.Parse(orb.Attributes["ap"].Value);
                int slot = Int32.Parse(orb.Attributes["slot"].Value);
                if (slot >= _weapon.Slots.Length)
                    throw new SavegameException("Materia orb assigned to slot that doesnt exist on armor.");

                _armor.Slots[slot] = Atmosphere.BattleSimulator.Materia.Create(id, ap, type);
            }

            string acc = savexml.SelectSingleNode("//accessory").InnerText;
            _accessory = String.IsNullOrEmpty(acc) ? new Accessory() : Accessory.AccessoryTable[acc];

            // Q-Values
            InitTable(ref _qvals, dataxml.SelectSingleNode("//qvals").InnerText, ',');

            // Luck base/gradient tables
            InitTable(ref _lck_base, dataxml.SelectSingleNode("//lbvals").InnerText, ',');
            InitTable(ref _lck_gradient, dataxml.SelectSingleNode("//lgvals").InnerText, ',');

            // HP base/gradient tables
            InitTable(ref _hp_base, dataxml.SelectSingleNode("//hpbvals").InnerText, ',');
            InitTable(ref _hp_gradient, dataxml.SelectSingleNode("//hpgvals").InnerText, ',');

            // MP base/gradient tables
            InitTable(ref _mp_base, dataxml.SelectSingleNode("//mpbvals").InnerText, ',');
            InitTable(ref _mp_gradient, dataxml.SelectSingleNode("//mpgvals").InnerText, ',');

            // Stat ranks
            InitTable(ref _stat_ranks, dataxml.SelectSingleNode("//ranks").InnerText, ',');
        }
Exemplo n.º 2
0
 public static void SwapMateria(Weapon before, Weapon after, Character c)
 {
     for (int i = 0; i < before.Slots.Length; i++)
     {
         Materia m = before.Slots[i];
         if (m != null)
             if (i > after.Slots.Length)
             {
                 m.Detach(c);
                 Materiatory.Put(m);
             }
             else
             {
                 after.Slots[i] = m;
             }
         before.Slots[i] = null;
     }
 }