public static Player LoadPlayerInformationFromXml(string xmlPlayerData) { Player player; try { XmlDocument playerData = new XmlDocument(); playerData.LoadXml(xmlPlayerData); int currentHitPoints = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentHitPoints").InnerText); int maximumHitPoints = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/MaximumHitPoints").InnerText); int gold = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/Gold").InnerText); int experiencePoints = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/ExperiencePoints").InnerText); int level = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/Level").InnerText); int strength = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/Strength").InnerText); int dexterity = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/Dexterity").InnerText); int intelligent = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/Intelligent").InnerText); int currentMana = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentMana").InnerText); int maximumMana = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/MaximumMana").InnerText); Race race = World.RaceByID(Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/Race").InnerText)); Armour armourUsed = null; if (Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/ArmourUsed").InnerText) != 0) { armourUsed = (Armour)World.ItemByID(Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/ArmourUsed").InnerText)); } player = new Player(currentHitPoints, maximumHitPoints, gold, experiencePoints, level, strength, dexterity, intelligent, currentMana, maximumMana, race, armourUsed); player.CurrentLocation = World.LocationByID(Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentLocation").InnerText)); if (Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentWeapon").InnerText) != 0) { player.CurrentWeapon = (Weapon)World.ItemByID(Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentWeapon").InnerText)); } else { player.CurrentWeapon = null; } if (Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentPotion").InnerText) != 0) { player.CurrentPotion = (HealingPotion)World.ItemByID(Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentPotion").InnerText)); } else { player.CurrentPotion = null; } foreach (XmlNode node in playerData.SelectNodes("/Player/InventoryItems/InventoryItem")) { player.AddItem(World.ItemByID(Convert.ToInt32(node.Attributes["ID"].Value)), Convert.ToInt32(node.Attributes["Quantity"].Value)); } foreach (XmlNode node in playerData.SelectNodes("/Player/PlayerQuests/PlayerQuest")) { PlayerQuest playerQuest = new PlayerQuest(World.QuestByID(Convert.ToInt32(node.Attributes["ID"].Value))); playerQuest.IsCompleted = Convert.ToBoolean(node.Attributes["IsCompleted"].Value); player.Quests.Add(playerQuest); } } catch { player = new Player(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, World.RaceByID(World.RACE_ID_HUNMAN)); } return(player); }
public Player(int currentHitPoints, int maximumHitPoints, int gold, int experiencePoints, int level, int strength, int dexterity, int intelligent, int currentMana, int maximumMana, Race race, Armour armourUsed = null) : base(currentHitPoints, maximumHitPoints, level, strength, dexterity, intelligent, currentMana, maximumMana, race, armourUsed) { Gold = gold; ExperiencePoints = experiencePoints; Inventory = new BindingList <InventoryItem>(); Quests = new BindingList <PlayerQuest>(); }