public void Load(XmlReader reader)
{
// System.Diagnostics.Debug.WriteLine(reader.Name);
_newItems = 0;
_inventory.Clear();
if (reader.GetAttribute("name") != null) _name = reader.GetAttribute("name");
if (reader.GetAttribute("maxhp") != null) _maxhealth = Convert.ToInt32(reader.GetAttribute("maxhp"));
if (reader.GetAttribute("id") != null) _id = Convert.ToInt32(reader.GetAttribute("id"));
if (reader.GetAttribute("maxMana") != null) _maxMana = Convert.ToInt32(reader.GetAttribute("maxMana"));
if (reader.GetAttribute("file") != null) _animationFile = Convert.ToString(reader.GetAttribute("file"));
if (reader.GetAttribute("viewRange") != null) _viewRange = Convert.ToInt32(reader.GetAttribute("viewRange"));
if (reader.GetAttribute("online") != null) _online = Convert.ToBoolean(reader.GetAttribute("online"));
if (reader.GetAttribute("hp") != null) _health = Convert.ToInt32(reader.GetAttribute("hp")); else _health = _maxhealth;
if (reader.GetAttribute("level") != null) _level = Convert.ToInt32(reader.GetAttribute("level"));
if (reader.GetAttribute("mana") != null) _mana = Convert.ToInt32(reader.GetAttribute("mana")); else _mana = maxMana;
if (reader.GetAttribute("evade") != null) _evade = Convert.ToInt32(reader.GetAttribute("evade"));
if (reader.GetAttribute("block") != null) _block = Convert.ToInt32(reader.GetAttribute("block"));
if (reader.GetAttribute("penetrate") != null) _penetrate = Convert.ToInt32(reader.GetAttribute("penetrate"));
if (reader.GetAttribute("healthReg") != null) _healthReg = Convert.ToInt32(reader.GetAttribute("healthReg"));
if (reader.GetAttribute("skills") != null) _skills = Convert.ToInt32(reader.GetAttribute("skills"));
if (reader.GetAttribute("abilityPoints") != null) _abilityPoints = Convert.ToInt32(reader.GetAttribute("abilityPoints"));
if (reader.GetAttribute("armor") != null) _armor = Convert.ToInt32(reader.GetAttribute("armor"));
if (reader.GetAttribute("stealHealth") != null) _stealHealth = Convert.ToInt32(reader.GetAttribute("stealHealth"));
if (reader.GetAttribute("stealMana") != null) _stealMana = Convert.ToInt32(reader.GetAttribute("stealMana"));
if (reader.GetAttribute("fireDamage") != null) _fireDamage = Convert.ToInt32(reader.GetAttribute("fireDamage"));
if (reader.GetAttribute("iceDamage") != null) _iceDamage = Convert.ToInt32(reader.GetAttribute("iceDamage"));
if (reader.GetAttribute("fireDefense") != null) _fireDefense = Convert.ToInt32(reader.GetAttribute("fireDefense"));
if (reader.GetAttribute("iceDefense") != null) _iceDefense = Convert.ToInt32(reader.GetAttribute("iceDefense"));
if (reader.GetAttribute("expNeeded") != null) _expNeeded = Convert.ToInt32(reader.GetAttribute("expNeeded"));
if (reader.GetAttribute("exp") != null) _exp = Convert.ToInt32(reader.GetAttribute("exp"));
if (reader.GetAttribute("resist") != null) _resist = Convert.ToInt32(reader.GetAttribute("resist"));
if (reader.GetAttribute("damage") != null) _damage = Convert.ToInt32(reader.GetAttribute("damage"));
if (reader.GetAttribute("level") != null) _level = Convert.ToInt32(reader.GetAttribute("level"));
if (reader.GetAttribute("gold") != null) _gold = Convert.ToInt32(reader.GetAttribute("gold"));
if (reader.GetAttribute("manaReg") != null) _manaReg = Convert.ToInt32(reader.GetAttribute("manaReg"));
if (reader.GetAttribute("destroyWeapon") != null) _destroyWeapon = Convert.ToInt32(reader.GetAttribute("destroyWeapon"));
if (reader.GetAttribute("destroyArmor") != null) _destroyArmor = Convert.ToInt32(reader.GetAttribute("destroyArmor"));
if (reader.GetAttribute("direction") != null)
_direction = (Direction)Enum.Parse(typeof(Direction), reader.GetAttribute("direction"));
if (_direction == Direction.None) _direction = Direction.Up;
if (!(this is Player))
{
if (reader.GetAttribute("crazy") != null) _crazy = Convert.ToBoolean(reader.GetAttribute("crazy"));
if (reader.GetAttribute("ranged") != null) _ranged = Convert.ToBoolean(reader.GetAttribute("ranged"));
if (reader.GetAttribute("aggro") != null) _aggro = Convert.ToBoolean(reader.GetAttribute("aggro"));
if (reader.GetAttribute("friendly") != null) _friendly = Convert.ToBoolean(reader.GetAttribute("friendly"));
}
else
{
if (reader.GetAttribute("lives") != null) _lives = Convert.ToInt32(reader.GetAttribute("lives"));
if (reader.GetAttribute("GUID") != null) _GUID = reader.GetAttribute("GUID");
if (reader.GetAttribute("lastCheckpoint") != null)
{
_lastCheckpoint = Convert.ToInt32(reader.GetAttribute("lastCheckpoint"));
_checkPointCoords = new Coords(Convert.ToInt32(reader.GetAttribute("cpX")), Convert.ToInt32(reader.GetAttribute("cpY")));
}
}
if (reader.GetAttribute("stunned") != null)
_stunned = Convert.ToInt32(reader.GetAttribute("stunned"));
if (reader.GetAttribute("charmed") != null)
_charmed = Convert.ToInt32(reader.GetAttribute("charmed"));
if (reader.GetAttribute("scared") != null)
_scared = Convert.ToInt32(reader.GetAttribute("scared"));
bool hasQuests = false;
switch (_actorType)
{
case ActorType.NPC:
NPC n = this as NPC;
if (n != null)
{
if (reader.GetAttribute("love") != null) n.love = Convert.ToInt32(reader.GetAttribute("love"));
if (reader.GetAttribute("hasShop") != null) n.hasShop = Convert.ToBoolean(reader.GetAttribute("hasShop"));
if (reader.GetAttribute("hasDialogue") != null) n.hasDialog = Convert.ToBoolean(reader.GetAttribute("hasDialogue"));
if (reader.GetAttribute("hasQuests") != null) hasQuests = true;
n.ClearQuests();
}
break;
case ActorType.Player:
(this as Player).ClearQuests();
if (reader.GetAttribute("hasQuests") != null) hasQuests = true;
break;
}
reader.Read();
if (reader.IsEmptyElement)
{
reader.Read();
}
else
{
reader.Read();
while (reader.NodeType != XmlNodeType.EndElement)
{
Item item = new Item();
item.Load(reader);
item.owner = this;
_inventory.Add(item);
if (item.isNew)
_newItems += 1;
reader.Read();
}
reader.ReadEndElement();
}
// System.Diagnostics.Debug.WriteLine(reader.Name);
if (reader.Name == "Abilities")
{
// System.Diagnostics.Debug.WriteLine("Abilities");
if (reader.IsEmptyElement)
{
reader.Read();
}
else
{
reader.Read();
while (reader.NodeType != XmlNodeType.EndElement)
{
Ability ability = new Ability();
ability.Load(reader);
_abilities.Add(ability);
reader.Read();
}
reader.ReadEndElement();
}
if (hasQuests)
{
if (reader.IsEmptyElement)
{
reader.Read();
}
else
{
reader.Read();
while (reader.NodeType != XmlNodeType.EndElement)
{
/* Quest.QuestType q1 = (Quest.QuestType)Enum.Parse(typeof(Quest.QuestType), reader.GetAttribute("type"));
string text = Convert.ToString(reader.GetAttribute("text"));
int xp = Convert.ToInt32(reader.GetAttribute("xp"));
List<Item> itemList = new List<Item>();
int goal = Convert.ToInt32(reader.GetAttribute("goal"));
reader.Read();
if (reader.IsEmptyElement)
{
reader.Read();
}
else
{
reader.Read();
while (reader.NodeType != XmlNodeType.EndElement)
{
Item item = new Item();
item.Load(reader);
item.owner = null;
item.tile = null;
itemList.Add(item);
reader.Read();
}
reader.ReadEndElement();
}
Quest q = new Quest(q1, text, xp, itemList, goal);
(this as Player).AddQuest(q);
reader.Read();*/
}
reader.ReadEndElement();
}
}
// Read Quickbar / Common attacks (ranked by frequency)
if (reader.IsEmptyElement)
{
reader.Read();
}
else
{
// System.Diagnostics.Debug.WriteLine("Quickbar");
int id = 0;
reader.Read();
while (reader.NodeType != XmlNodeType.EndElement)
{
// System.Diagnostics.Debug.WriteLine(reader.Name);
if (reader.HasAttributes)
{
_quicklist[id] = Convert.ToInt32(reader.GetAttribute(0));
// System.Diagnostics.Debug.WriteLine(reader.GetAttribute(0));
++id;
}
reader.Read();
}
reader.ReadEndElement();
}
reader.ReadEndElement();
// System.Diagnostics.Debug.WriteLine(reader.Name);
}
else return;
}