public static void SwapMateria(Armor before, Armor 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; } }
/// <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, ','); }
private static void Init() { _random = new Random(); InitializeLua(); Application.Init(); if (!GLib.Thread.Supported) { GLib.Thread.Init(); } Gdk.Threads.Init(); Gdk.Threads.Enter(); _window = new Gtk.Window(Globals.WINDOW_NAME); _window.SetDefaultSize(Globals.WIDTH, Globals.HEIGHT); _window.AppPaintable = true; _window.DoubleBuffered = false; _window.DeleteEvent += OnWinDelete; _window.KeyPressEvent += OnKeyPress; _window.KeyReleaseEvent += OnKeyRelease; //_window.ConfigureEvent += OnWindowConfigure; DrawingArea da = new DrawingArea(); da.ExposeEvent += OnExposed; Gdk.Color col = new Gdk.Color(0, 0, 0); _window.ModifyBg(StateType.Normal, col); da.ModifyBg(StateType.Normal, col); GLib.Timeout.Add(33, new GLib.TimeoutHandler(Graphics.TimedDraw)); _window.Add(da); _window.ShowAll(); Gdk.Threads.Leave(); Graphics.Init(); // depends on _window being initialized Item.Init(); Enemy.Init(); // depends on Globals ctor Weapon.Init(); // depends on Globals ctor Armor.Init(); // depends on Globals ctor Accessory.Init(); // depends on Globals ctor Materia.Init(); // depends on Globals ctor Character.Init(); // depends on [Weapons|Armor|Materia].Init() Globals.Init(); // depends on Character.Init() MenuScreen.Init(); // depends on Globals.Init() Inventory.Init(); // depends on a whole lot of things Spell.Init(); // depends on Globals ctor Materiatory.Init(); // depends on Materia.Init() int time = Int32.Parse(Globals.SaveGame.SelectSingleNode("//time").InnerText); _clock = new Clock(time); // depends on Globals ctor // Go to Main Menu _state = MainMenu; // Go to new Battle //GoToBattleState(); // Go to Post-Battle //List<IItem> i = new List<IItem>(); //i.Add(Item.ItemTable["powersource"]); //i.Add(Item.ItemTable["powersource"]); //i.Add(Item.ItemTable["potion"]); //PostBattle = new PostBattleState(234, 12, 1200, i); //_state = PostBattle; _state.Init(); if (Globals.Party[0] == null && Globals.Party[1] == null && Globals.Party[2] == null) { throw new GamedataException("No character in party!"); } // Level-up demo //using (StreamWriter w = new StreamWriter(@"c:\scripts\test.txt")) //{ // while (Character.Cloud.Level < 98) // { // Character.Cloud.GainExperience(Character.Cloud.ToNextLevel + 10); // w.WriteLine(Character.Cloud.ToString()); // } // w.Flush(); //} }
/// <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, ','); }