}; // Easier quest generating public static bool Fight(string sourceRequest, string sourceKey) // True = win; False = loss { bool myTurn = false; int myHP = PlayerHP(); int myDMG = PlayerAverageDamage(); int myCritChance = PlayerStats.PlayerTalentPoints["profileCritChanceButton"]; if (sourceRequest == "dungeon") { int enemyHP = PlayerStats.DungeonBosses[sourceKey].HealthPoints; int enemyDMG = PlayerStats.DungeonBosses[sourceKey].Damage; int enemyCritChance = PlayerStats.DungeonBosses[sourceKey].CritChance; while ((enemyHP > 0) && (myHP > 0)) { myTurn = !myTurn; if (myTurn) { if (PlayerStats.RandomNumber(1, 101) < myCritChance) { enemyHP -= (2 * myDMG); } else { enemyHP -= myDMG; } } else { if (PlayerStats.RandomNumber(1, 101) < enemyCritChance) { myHP -= (2 * enemyDMG); } else { myHP -= enemyDMG; } } } if (myTurn) //If you won { if ((PlayerStats.RandomNumber(1, 101) < PlayerStats.DungeonBosses[sourceKey].ItemLootChance) && (PlayerStats.PlayerInventorySpace > 0)) { GameCalculations.ItemFindSpaceAndPlace("dungeon", sourceKey); } } } else if (sourceRequest == "tavern") { int enemyHP = PlayerStats.TavernQuestsEnemy[sourceKey].HealthPoints; int enemyDMG = PlayerStats.TavernQuestsEnemy[sourceKey].Damage; int enemyCritChance = PlayerStats.TavernQuestsEnemy[sourceKey].CritChance; while ((enemyHP > 0) && (myHP > 0)) { myTurn = !myTurn; if (myTurn) { if (PlayerStats.RandomNumber(1, 101) < myCritChance) { enemyHP -= (2 * myDMG); } else { enemyHP -= myDMG; } } else { if (PlayerStats.RandomNumber(1, 101) < enemyCritChance) { myHP -= (2 * enemyDMG); } else { myHP -= enemyDMG; } } } if (myTurn) { if (PlayerStats.PlayerInventorySpace > 0) { GameCalculations.ItemFindSpaceAndPlace("tavern", sourceKey); } } } // Dung sources - dungeonSkeletonBossBtn dungeonFireBossBtn dungeonMountainBossBtn dungeonWoodBossBtn dungeonWaterBossBtn return(myTurn); }
public static void ImportGameData(string sourceFilePath) { XmlDocument xml = new XmlDocument(); string startupPath = System.IO.Path.GetFullPath(@"..\..\"); xml.Load(startupPath + @sourceFilePath); XmlNode player = xml.SelectSingleNode("//Player"); PlayerStats.Gold = int.Parse(player.SelectSingleNode("Gold").Attributes["value"].Value); PlayerStats.PlayerName = player.SelectSingleNode("PlayerName").Attributes["value"].Value; PlayerStats.PlayerProfileImgSource = player.SelectSingleNode("PlayerProfileImgSource").Attributes["value"].Value; PlayerStats.PlayerLevel = int.Parse(player.SelectSingleNode("PlayerLevel").Attributes["value"].Value); PlayerStats.PlayerCurrentXP = int.Parse(player.SelectSingleNode("PlayerCurrentXP").Attributes["value"].Value); PlayerStats.PlayerAvailableTalentPoints = int.Parse(player.SelectSingleNode("PlayerAvailableTalentPoints").Attributes["value"].Value); PlayerStats.PlayerInventorySpace = int.Parse(player.SelectSingleNode("PlayerInventorySpace").Attributes["value"].Value); foreach (XmlNode playerEquipItem in xml.SelectNodes("//PlayerEquip//PlayerEquipItem")) { string key = playerEquipItem.Attributes["value"].Value; PlayerStats.PlayerEquip[key].Type = playerEquipItem.SelectSingleNode("Type").Attributes["value"].Value; PlayerStats.PlayerEquip[key].WeaponType = playerEquipItem.SelectSingleNode("WeaponType").Attributes["value"].Value; PlayerStats.PlayerEquip[key].Enchanted = bool.Parse(playerEquipItem.SelectSingleNode("Enchanted").Attributes["value"].Value); PlayerStats.PlayerEquip[key].Damage = int.Parse(playerEquipItem.SelectSingleNode("Damage").Attributes["value"].Value); PlayerStats.PlayerEquip[key].GoldCost = int.Parse(playerEquipItem.SelectSingleNode("GoldCost").Attributes["value"].Value); PlayerStats.PlayerEquip[key].ImageSource = playerEquipItem.SelectSingleNode("ImageSource").Attributes["value"].Value; PlayerStats.PlayerEquip[key].ItemTooltip = playerEquipItem.SelectSingleNode("ItemTooltip").Attributes["value"].Value; PlayerStats.PlayerEquip[key].Intelligence = int.Parse(playerEquipItem.SelectSingleNode("Intelligence").Attributes["value"].Value); PlayerStats.PlayerEquip[key].Strength = int.Parse(playerEquipItem.SelectSingleNode("Strength").Attributes["value"].Value); PlayerStats.PlayerEquip[key].Stamina = int.Parse(playerEquipItem.SelectSingleNode("Stamina").Attributes["value"].Value); PlayerStats.PlayerEquip[key].CritChance = int.Parse(playerEquipItem.SelectSingleNode("CritChance").Attributes["value"].Value); } foreach (XmlNode playerInventoryItem in xml.SelectNodes("//PlayerInventory//PlayerInventoryItem")) { string key = playerInventoryItem.Attributes["value"].Value; PlayerStats.PlayerInventory[key].Type = playerInventoryItem.SelectSingleNode("Type").Attributes["value"].Value; PlayerStats.PlayerInventory[key].WeaponType = playerInventoryItem.SelectSingleNode("WeaponType").Attributes["value"].Value; PlayerStats.PlayerInventory[key].Enchanted = bool.Parse(playerInventoryItem.SelectSingleNode("Enchanted").Attributes["value"].Value); PlayerStats.PlayerInventory[key].Damage = int.Parse(playerInventoryItem.SelectSingleNode("Damage").Attributes["value"].Value); PlayerStats.PlayerInventory[key].GoldCost = int.Parse(playerInventoryItem.SelectSingleNode("GoldCost").Attributes["value"].Value); PlayerStats.PlayerInventory[key].ImageSource = playerInventoryItem.SelectSingleNode("ImageSource").Attributes["value"].Value; PlayerStats.PlayerInventory[key].ItemTooltip = playerInventoryItem.SelectSingleNode("ItemTooltip").Attributes["value"].Value; PlayerStats.PlayerInventory[key].Intelligence = int.Parse(playerInventoryItem.SelectSingleNode("Intelligence").Attributes["value"].Value); PlayerStats.PlayerInventory[key].Strength = int.Parse(playerInventoryItem.SelectSingleNode("Strength").Attributes["value"].Value); PlayerStats.PlayerInventory[key].Stamina = int.Parse(playerInventoryItem.SelectSingleNode("Stamina").Attributes["value"].Value); PlayerStats.PlayerInventory[key].CritChance = int.Parse(playerInventoryItem.SelectSingleNode("CritChance").Attributes["value"].Value); } XmlNode playerTalentPoints = xml.SelectSingleNode("//PlayerTalentPoints"); PlayerStats.PlayerTalentPoints["profileIntelligenceButton"] = int.Parse(playerTalentPoints.SelectSingleNode("profileIntelligenceButton").Attributes["value"].Value); PlayerStats.PlayerTalentPoints["profileStrengthButton"] = int.Parse(playerTalentPoints.SelectSingleNode("profileStrengthButton").Attributes["value"].Value); PlayerStats.PlayerTalentPoints["profileStaminaButton"] = int.Parse(playerTalentPoints.SelectSingleNode("profileStaminaButton").Attributes["value"].Value); PlayerStats.PlayerTalentPoints["profileCritChanceButton"] = int.Parse(playerTalentPoints.SelectSingleNode("profileCritChanceButton").Attributes["value"].Value); foreach (XmlNode vendorSuppliesItem in xml.SelectNodes("//VendorSupplies//VendorSuppliesItem")) { string key = vendorSuppliesItem.Attributes["value"].Value; PlayerStats.VendorSupplies[key].Type = vendorSuppliesItem.SelectSingleNode("Type").Attributes["value"].Value; PlayerStats.VendorSupplies[key].WeaponType = vendorSuppliesItem.SelectSingleNode("WeaponType").Attributes["value"].Value; PlayerStats.VendorSupplies[key].Enchanted = bool.Parse(vendorSuppliesItem.SelectSingleNode("Enchanted").Attributes["value"].Value); PlayerStats.VendorSupplies[key].Damage = int.Parse(vendorSuppliesItem.SelectSingleNode("Damage").Attributes["value"].Value); PlayerStats.VendorSupplies[key].GoldCost = int.Parse(vendorSuppliesItem.SelectSingleNode("GoldCost").Attributes["value"].Value); PlayerStats.VendorSupplies[key].ImageSource = vendorSuppliesItem.SelectSingleNode("ImageSource").Attributes["value"].Value; PlayerStats.VendorSupplies[key].ItemTooltip = vendorSuppliesItem.SelectSingleNode("ItemTooltip").Attributes["value"].Value; PlayerStats.VendorSupplies[key].Intelligence = int.Parse(vendorSuppliesItem.SelectSingleNode("Intelligence").Attributes["value"].Value); PlayerStats.VendorSupplies[key].Strength = int.Parse(vendorSuppliesItem.SelectSingleNode("Strength").Attributes["value"].Value); PlayerStats.VendorSupplies[key].Stamina = int.Parse(vendorSuppliesItem.SelectSingleNode("Stamina").Attributes["value"].Value); PlayerStats.VendorSupplies[key].CritChance = int.Parse(vendorSuppliesItem.SelectSingleNode("CritChance").Attributes["value"].Value); } foreach (XmlNode tavernQuestsEnemy in xml.SelectNodes("//Tavern//TavernQuestsEnemy")) { string key = tavernQuestsEnemy.Attributes["value"].Value; PlayerStats.TavernQuestsEnemy[key].Damage = int.Parse(tavernQuestsEnemy.SelectSingleNode("Damage").Attributes["value"].Value); PlayerStats.TavernQuestsEnemy[key].HealthPoints = int.Parse(tavernQuestsEnemy.SelectSingleNode("HealthPoints").Attributes["value"].Value); PlayerStats.TavernQuestsEnemy[key].CritChance = int.Parse(tavernQuestsEnemy.SelectSingleNode("CritChance").Attributes["value"].Value); PlayerStats.TavernQuestsEnemy[key].ExperienceGain = int.Parse(tavernQuestsEnemy.SelectSingleNode("ExperienceGain").Attributes["value"].Value); PlayerStats.TavernQuestsEnemy[key].GoldGain = int.Parse(tavernQuestsEnemy.SelectSingleNode("GoldGain").Attributes["value"].Value); PlayerStats.TavernQuestsEnemy[key].ItemLootChance = int.Parse(tavernQuestsEnemy.SelectSingleNode("ItemLootChance").Attributes["value"].Value); PlayerStats.TavernQuestsEnemy[key].ImageSource = tavernQuestsEnemy.SelectSingleNode("ImageSource").Attributes["value"].Value; } foreach (XmlNode tavernQuestItems in xml.SelectNodes("//Tavern//TavernQuestItems")) { string key = tavernQuestItems.Attributes["value"].Value; PlayerStats.TavernQuestItems[key].Type = tavernQuestItems.SelectSingleNode("Type").Attributes["value"].Value; PlayerStats.TavernQuestItems[key].WeaponType = tavernQuestItems.SelectSingleNode("WeaponType").Attributes["value"].Value; PlayerStats.TavernQuestItems[key].Enchanted = bool.Parse(tavernQuestItems.SelectSingleNode("Enchanted").Attributes["value"].Value); PlayerStats.TavernQuestItems[key].Damage = int.Parse(tavernQuestItems.SelectSingleNode("Damage").Attributes["value"].Value); PlayerStats.TavernQuestItems[key].GoldCost = int.Parse(tavernQuestItems.SelectSingleNode("GoldCost").Attributes["value"].Value); PlayerStats.TavernQuestItems[key].ImageSource = tavernQuestItems.SelectSingleNode("ImageSource").Attributes["value"].Value; PlayerStats.TavernQuestItems[key].ItemTooltip = tavernQuestItems.SelectSingleNode("ItemTooltip").Attributes["value"].Value; PlayerStats.TavernQuestItems[key].Intelligence = int.Parse(tavernQuestItems.SelectSingleNode("Intelligence").Attributes["value"].Value); PlayerStats.TavernQuestItems[key].Strength = int.Parse(tavernQuestItems.SelectSingleNode("Strength").Attributes["value"].Value); PlayerStats.TavernQuestItems[key].Stamina = int.Parse(tavernQuestItems.SelectSingleNode("Stamina").Attributes["value"].Value); PlayerStats.TavernQuestItems[key].CritChance = int.Parse(tavernQuestItems.SelectSingleNode("CritChance").Attributes["value"].Value); } XmlNode tavernQuestTimeTaken = xml.SelectSingleNode("//Tavern//TavernQuestTimeTaken"); PlayerStats.TavernQuestTimeTaken["tavernQuest0Label"] = int.Parse(tavernQuestTimeTaken.SelectSingleNode("tavernQuest0Label").Attributes["value"].Value); PlayerStats.TavernQuestTimeTaken["tavernQuest1Label"] = int.Parse(tavernQuestTimeTaken.SelectSingleNode("tavernQuest1Label").Attributes["value"].Value); PlayerStats.TavernQuestTimeTaken["tavernQuest2Label"] = int.Parse(tavernQuestTimeTaken.SelectSingleNode("tavernQuest2Label").Attributes["value"].Value); XmlNode timers = xml.SelectSingleNode("//Timers"); PlayerStats.VendorTimer = int.Parse(timers.SelectSingleNode("VendorTimer").Attributes["value"].Value); PlayerStats.VendorTimerRunning = bool.Parse(timers.SelectSingleNode("VendorTimerRunning").Attributes["value"].Value); PlayerStats.VendorFirstCall = bool.Parse(timers.SelectSingleNode("VendorFirstCall").Attributes["value"].Value); PlayerStats.DungeonTimer = int.Parse(timers.SelectSingleNode("DungeonTimer").Attributes["value"].Value); PlayerStats.DungeonTimerRunning = bool.Parse(timers.SelectSingleNode("DungeonTimerRunning").Attributes["value"].Value); PlayerStats.DungeonFirstCall = bool.Parse(timers.SelectSingleNode("DungeonFirstCall").Attributes["value"].Value); PlayerStats.TavernTimer = int.Parse(timers.SelectSingleNode("TavernTimer").Attributes["value"].Value); PlayerStats.TavernTimerRunning = bool.Parse(timers.SelectSingleNode("TavernTimerRunning").Attributes["value"].Value); PlayerStats.TavernFirstCall = bool.Parse(timers.SelectSingleNode("TavernFirstCall").Attributes["value"].Value); PlayerStats.TavernChoosenQuest = timers.SelectSingleNode("TavernChoosenQuest").Attributes["value"].Value; PlayerStats.StableMountActive = bool.Parse(timers.SelectSingleNode("StableMountActive").Attributes["value"].Value); PlayerStats.QuestTimerReduction = int.Parse(timers.SelectSingleNode("QuestTimerReduction").Attributes["value"].Value); PlayerStats.StableTimer = int.Parse(timers.SelectSingleNode("StableTimer").Attributes["value"].Value); PlayerStats.StableTimerRunning = bool.Parse(timers.SelectSingleNode("StableTimerRunning").Attributes["value"].Value); PlayerStats.StableFirstCall = bool.Parse(timers.SelectSingleNode("StableFirstCall").Attributes["value"].Value); XmlNode numberOfItemImages = xml.SelectSingleNode("//NumberOfItemImages"); foreach (XmlNode node in numberOfItemImages.ChildNodes) { string key = node.Name; PlayerStats.NumberOfItemImages[key] = int.Parse(numberOfItemImages.SelectSingleNode(key).Attributes["value"].Value); } GameCalculations.GeneratePlayerTooltip(); if (sourceFilePath != "\\firstInitData.xml") { DungeonInit("\\dungeonData.xml"); } }