public static Player CreateDefaultPlayer() { Player player = new Player(10, 10, 20, 0); player.Inventory.Add(new InventoryItem(World.ItemByID(World.ITEM_ID_RUSTY_SWORD), 1)); player.CurrentLocation = World.LocationById(World.LOCATION_ID_HOME); return(player); }
public Player(string name, int maximumHitPoint, int currentHitPoint, int maxExp, int gold = 0, int exp = 0, int level = 0, bool inCombat = false) : base(name, maximumHitPoint, currentHitPoint) { Gold = gold; CurrentEXP = exp; MaximumEXP = maxExp; CurrentLevel = level; Inventory = new List <InventoryItem>(); Quests = new List <PlayerQuest>(); CurrentLocation = World.LocationById(World.LOCATION_HOME); InCombat = inCombat; }
public static Player CreatePlayerFromXML(string xmlPlayerData) { try { XmlDocument playerData = new XmlDocument(); playerData.LoadXml(xmlPlayerData); int currentHP = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentHP").InnerText); int maxHP = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/MaxHP").InnerText); int gold = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/Gold").InnerText); int EXP = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/EXP").InnerText); Player player = new Player(currentHP, maxHP, gold, EXP); int currentLocationID = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentLocation").InnerText); player.CurrentLocation = World.LocationById(currentLocationID); if (playerData.SelectSingleNode("/Player/Stats/CurrentWeapon") != null) { int currentWeaponID = Convert.ToInt32(playerData.SelectSingleNode("/Player/Stats/CurrentWeapon").InnerText); player.CurrentWeapon = (Weapon)World.ItemByID(currentWeaponID); } foreach (XmlNode node in playerData.SelectNodes("/Player/Inventory/Item")) { int id = Convert.ToInt32(node.Attributes["ID"].Value); int quantity = Convert.ToInt32(node.Attributes["Quantity"].Value); for (int i = 0; i < quantity; i++) { player.AddItemToInventory(World.ItemByID(id)); } } foreach (XmlNode node in playerData.SelectNodes("/Player/PlayerQuests/Quest")) { int id = Convert.ToInt32(node.Attributes["ID"].Value); bool isCompleted = Convert.ToBoolean(node.Attributes["IsCompleted"].Value); PlayerQuest playerQuest = new PlayerQuest(World.QuestById(id)); playerQuest.IsCompleted = isCompleted; player.Quests.Add(playerQuest); } return(player); } catch { //if error with XML data, return default player return(Player.CreateDefaultPlayer()); } }
private void MoveHome() { MoveTo(World.LocationById(World.LOCATION_ID_HOME)); }