/// <summary> /// End the combat /// </summary> /// <param name="combatEndState"></param> private void EndCombat(CombatEndingState combatEndingState) { // go back to the non-combat music // AudioManager.PopMusic(); switch (combatEndingState) { case CombatEndingState.Victory: int experienceReward = 0; int goldReward = 0; List<Gear> gearRewards = new List<Gear>(); List<string> gearRewardNames = new List<string>(); // calculate the rewards from the monsters foreach (CombatantMonster combatantMonster in monsters) { Monster monster = combatantMonster.Monster; Session.Party.AddMonsterKill(monster); experienceReward += monster.CalculateExperienceReward(Session.Random); goldReward += monster.CalculateGoldReward(Session.Random); gearRewardNames.AddRange( monster.CalculateGearDrop(Session.Random)); } foreach (string gearRewardName in gearRewardNames) { gearRewards.Add(Session.ScreenManager.Game.Content.Load<Gear>( Path.Combine(@"Gear", gearRewardName))); } // add the reward screen Session.ScreenManager.AddScreen(new RewardsScreen( RewardsScreen.RewardScreenMode.Combat, experienceReward, goldReward, gearRewards)); // remove the fixed combat entry, if this wasn't a random fight if (FixedCombatEntry != null) { Session.RemoveFixedCombat(FixedCombatEntry); } break; case CombatEndingState.Loss: // game over ScreenManager screenManager = Session.ScreenManager; // end the session Session.EndSession(); // add the game-over screen screenManager.AddScreen(new GameOverScreen()); break; case CombatEndingState.Fled: break; } // clear the singleton singleton = null; }
/// <summary> /// Ensure that there is no combat happening right now. /// </summary> public static void ClearCombat() { // clear the singleton if (singleton != null) { singleton = null; } }
/// <summary> /// Start a new combat between the party and a group of monsters. /// </summary> /// <param name="players">The player combatants.</param> /// <param name="monsters">The monster combatants.</param> /// <param name="fleeThreshold">The odds of success when fleeing.</param> private static void StartNewCombat(List<CombatantPlayer> players, List<CombatantMonster> monsters, int fleeThreshold) { // check if we are already in combat if (singleton != null) { throw new InvalidOperationException( "There can only be one combat at a time."); } // create the new CombatEngine object singleton = new CombatEngine(players, monsters, fleeThreshold); }