public void TurnEngine_GetRandomMonsterItemDrops_1_Roll_Level_3_Good_ItemList_Should_Return_List() { MockForms.Init(); // Turn off random numbers // Set random to 1, and to hit to 1 GameGlobals.SetForcedRandomNumbers(2, 1); var myTurnEngine = new TurnEngine(); var roundCount = 2; // Make Sure Items List exists and is loaded... ItemsViewModel.Instance.ForceDataRefresh(); // Don't init itemlist so exit with empty list... var Actual = myTurnEngine.GetRandomMonsterItemDrops(roundCount); // Should roll for 1 item, and return it... var Expected = 2; // Reset GameGlobals.ToggleRandomState(); Assert.AreEqual(Expected, Actual.Count(), "Item Count " + TestContext.CurrentContext.Test.Name); Assert.AreEqual(roundCount, Actual.FirstOrDefault().Value, "Item Level " + TestContext.CurrentContext.Test.Name); }
public void BattleEngine_AutoBattle_With_No_Initial_Characters_Should_Pass() { MockForms.Init(); // Can create a new battle engine... var myBattleEngine = new BattleEngine(); // Add new myCharacters in automaticaly // Characters are Level 1 // Monsters are Level 1 // Monsters will kill Characters in round 1. // Turn off random numbers // For a hit on everything... GameGlobals.SetForcedRandomNumbers(1, 20); // Needs to be 20 so monsters always score a hit... MasterDataStore.ForceDataRestoreAll(); myBattleEngine.AutoBattle(); // Reset GameGlobals.ToggleRandomState(); var Actual = myBattleEngine.BattleScore; Assert.AreNotEqual(1, Actual.RoundCount, "Round Count " + TestContext.CurrentContext.Test.Name); Assert.AreNotEqual(null, Actual, "Score Object " + TestContext.CurrentContext.Test.Name); Assert.AreNotEqual(0, Actual.ExperienceGainedTotal, "Experience " + TestContext.CurrentContext.Test.Name); Assert.AreNotEqual(0, Actual.TurnCount, "Turn Count " + TestContext.CurrentContext.Test.Name); Assert.AreNotEqual(0, Actual.ScoreTotal, "Score Total " + TestContext.CurrentContext.Test.Name); Assert.AreNotEqual(string.Empty, Actual.ItemsDroppedList, "Items Dropped " + TestContext.CurrentContext.Test.Name); Assert.AreNotEqual(string.Empty, Actual.MonstersKilledList, "Monsters Killed " + TestContext.CurrentContext.Test.Name); Assert.AreNotEqual(string.Empty, Actual.CharacterAtDeathList, "Character List " + TestContext.CurrentContext.Test.Name); }
public void TurnEngine_DetermineCriticalMissProblem_Attacker_Sword_Roll_1_Should_Return_Sword_Broke() { MockForms.Init(); // Turn off random numbers // Set random to 1, and to hit to 1 GameGlobals.SetForcedRandomNumbers(1, 1); GameGlobals.ForcedRandomValue = 1; var myTurnEngine = new TurnEngine(); var myCharacter = new Character(DefaultModels.CharacterDefault()); var itemGuid = ItemHelper.AddItemForAttribute(AttributeEnum.Attack, ItemLocationEnum.PrimaryHand, 1000).Guid; var myItem = ItemsViewModel.Instance.GetItem(itemGuid); myCharacter.PrimaryHand = itemGuid; // Nothing in the hand, so nothing to drop... var Actual = myTurnEngine.DetermineCriticalMissProblem(myCharacter); var Expected = " Item " + myItem.Name + " from " + ItemLocationEnum.PrimaryHand + " Broke, and lost forever"; // Reset GameGlobals.ToggleRandomState(); Assert.AreEqual(Expected, Actual, TestContext.CurrentContext.Test.Name); }
public void TurnEngine_TurnAsAttack_Monster_Attack_DefenderList_CriticalMiss_Should_Pass() { // Turn off random numbers GameGlobals.SetForcedRandomNumbers(1, 20); var Attacker = DefaultModels.MonsterDefault(); Attacker.Name = "Rat"; var myDefaultCharacter = DefaultModels.CharacterDefault(); myDefaultCharacter.Name = "Fighter"; var myTurnEngine = new TurnEngine(); myTurnEngine.CharacterList.Add(myDefaultCharacter); GameGlobals.ForceToHitValue = 1; // Force a miss var AttackScore = Attacker.Level + Attacker.GetAttack(); var DefenseScore = myDefaultCharacter.GetDefense() + myDefaultCharacter.Level; var Status = myTurnEngine.TurnAsAttack(Attacker, AttackScore, myDefaultCharacter, DefenseScore); var Actual = Status; bool Expected = true; var ActualString = myTurnEngine.TurnMessage; var ActualResult = myTurnEngine.HitStatus; var ActualDamage = myTurnEngine.DamageAmount; // Reset GameGlobals.ToggleRandomState(); Assert.AreEqual(Expected, Actual, TestContext.CurrentContext.Test.Name); }
public void TurnEngine_GetRandomMonsterItemDrops_1_Roll_Level_3_Empty_ItemList_Should_Skip() { MockForms.Init(); // Turn off random numbers // Set random to 1, and to hit to 1 GameGlobals.SetForcedRandomNumbers(1, 1); var myTurnEngine = new TurnEngine(); // Make Sure Items List exists and is loaded... ItemsViewModel.Instance.ForceDataRefresh(); // Clear the items MockDataStore.Instance.DeleteTables(); var roundCount = 3; // Don't init itemlist so exit with empty list... var Actual = myTurnEngine.GetRandomMonsterItemDrops(roundCount); // Should roll for 1 item, and return it... var Expected = 1; // Reset GameGlobals.ToggleRandomState(); // Restor the database MockDataStore.Instance.InitializeDatabaseNewTables(); Assert.AreEqual(Expected, Actual.Count(), "Item Count " + TestContext.CurrentContext.Test.Name); }
public void TurnEngine_DetermineCriticalMissProblem_Attacker_Null_Roll_1_Should_Return_Nothing_Broke() { MockForms.Init(); // Turn off random numbers // Set random to 1, and to hit to 1 GameGlobals.SetForcedRandomNumbers(1, 1); GameGlobals.ForcedRandomValue = 1; var myTurnEngine = new TurnEngine(); var myCharacter = new Character(DefaultModels.CharacterDefault()); myCharacter.PrimaryHand = null; // Nothing in the hand, so nothing to drop... var Actual = myTurnEngine.DetermineCriticalMissProblem(myCharacter); // Should roll for 1 item, and return it... var Expected = " Luckly, nothing to drop from PrimaryHand"; // Reset GameGlobals.ToggleRandomState(); Assert.AreEqual(Expected, Actual, TestContext.CurrentContext.Test.Name); }
public void BattleEngine_AutoBattle_With_Six_Characters_Should_Pass() { MockForms.Init(); // Can create a new battle engine... var myBattleEngine = new BattleEngine(); var myCharacter = new Character(DefaultModels.CharacterDefault()); myCharacter.Name = "Fighter 1"; myCharacter.ScaleLevel(1); myBattleEngine.CharacterList.Add(myCharacter); myCharacter = new Character(DefaultModels.CharacterDefault()); myCharacter.Name = "Fighter 2"; myCharacter.ScaleLevel(2); myBattleEngine.CharacterList.Add(myCharacter); myCharacter = new Character(DefaultModels.CharacterDefault()); myCharacter.Name = "Fighter 3"; myCharacter.ScaleLevel(3); myBattleEngine.CharacterList.Add(myCharacter); myCharacter = new Character(DefaultModels.CharacterDefault()); myCharacter.Name = "Fighter 4"; myCharacter.ScaleLevel(4); myBattleEngine.CharacterList.Add(myCharacter); myCharacter = new Character(DefaultModels.CharacterDefault()); myCharacter.Name = "Fighter 5"; myCharacter.ScaleLevel(5); myBattleEngine.CharacterList.Add(myCharacter); myCharacter = new Character(DefaultModels.CharacterDefault()); myCharacter.Name = "Fighter 6"; myCharacter.ScaleLevel(6); myBattleEngine.CharacterList.Add(myCharacter); // Turn off random numbers // For a hit on everything... GameGlobals.SetForcedRandomNumbers(1, 20); myBattleEngine.AutoBattle(); // Reset GameGlobals.ToggleRandomState(); var Actual = myBattleEngine.BattleScore; Assert.AreNotEqual(null, Actual, "Score Object " + TestContext.CurrentContext.Test.Name); Assert.AreNotEqual(0, Actual.ExperienceGainedTotal, "Experience " + TestContext.CurrentContext.Test.Name); Assert.AreNotEqual(0, Actual.RoundCount, "Round Count " + TestContext.CurrentContext.Test.Name); Assert.AreNotEqual(0, Actual.TurnCount, "Turn Count " + TestContext.CurrentContext.Test.Name); Assert.AreNotEqual(0, Actual.ScoreTotal, "Score Total " + TestContext.CurrentContext.Test.Name); Assert.AreNotEqual(string.Empty, Actual.ItemsDroppedList, "Items Dropped " + TestContext.CurrentContext.Test.Name); Assert.AreNotEqual(string.Empty, Actual.MonstersKilledList, "Monsters Killed " + TestContext.CurrentContext.Test.Name); Assert.AreNotEqual(string.Empty, Actual.CharacterAtDeathList, "Character List " + TestContext.CurrentContext.Test.Name); }
public void BattleEngine_AutoBattle_With_Characters_Level_2_Should_Level_Up_Pass() { MockForms.Init(); // Can create a new battle engine... var myBattleEngine = new BattleEngine(); // Turn off random numbers // For a hit on everything... GameGlobals.SetForcedRandomNumbers(1, 20); // Needs to be 20 so monsters always score a hit... MasterDataStore.ForceDataRestoreAll(); // Add new Characters in automaticaly // Characters are Level 2 // Monsters are Level 1 // Characters have weapons... // Use 6 existing Characters. This will go for a few rounds. var myLevel = 3; var myCharacter = myBattleEngine.GetRandomCharacter(myLevel, myLevel); myCharacter.Attribute.MaxHealth = 100; myCharacter.Attribute.CurrentHealth = 100; // Set them just below the next level, so they level up... myCharacter.ExperienceTotal = LevelTable.Instance.LevelDetailsList[myLevel + 1].Experience - 1; for (var count = 1; count < 7; count++) { var myNewCharacter = new Character(myCharacter); myNewCharacter.Name = "Fighter " + count; myBattleEngine.CharacterList.Add(myNewCharacter); } var TempDamageBonusValue = GameGlobals.ForceCharacterDamangeBonusValue; // Make myCharacter s hit really really hard... GameGlobals.ForceCharacterDamangeBonusValue = 100; myBattleEngine.AutoBattle(); // Reset GameGlobals.ToggleRandomState(); GameGlobals.ForceCharacterDamangeBonusValue = TempDamageBonusValue; var Actual = myBattleEngine.BattleScore; Assert.AreNotEqual(1, Actual.RoundCount, "Round Count " + TestContext.CurrentContext.Test.Name); Assert.AreNotEqual(null, Actual, "Score Object " + TestContext.CurrentContext.Test.Name); Assert.AreNotEqual(0, Actual.ExperienceGainedTotal, "Experience " + TestContext.CurrentContext.Test.Name); Assert.AreNotEqual(0, Actual.TurnCount, "Turn Count " + TestContext.CurrentContext.Test.Name); Assert.AreNotEqual(0, Actual.ScoreTotal, "Score Total " + TestContext.CurrentContext.Test.Name); Assert.AreNotEqual(string.Empty, Actual.ItemsDroppedList, "Items Dropped " + TestContext.CurrentContext.Test.Name); Assert.AreNotEqual(string.Empty, Actual.MonstersKilledList, "Monsters Killed " + TestContext.CurrentContext.Test.Name); Assert.AreNotEqual(string.Empty, Actual.CharacterAtDeathList, "Character List " + TestContext.CurrentContext.Test.Name); }
public void RoundEngine_RoundNextTurn_2Characters_1Monster_Should_Take_3_Rounds() { MockForms.Init(); // No characters, so return should be game over... // Can create a new Round engine... var myRoundEngine = new RoundEngine(); // Start myRoundEngine.StartRound(); // Add moderate monsters // First monster var myMonsterWeak = new Monster(DefaultModels.MonsterDefault()); myMonsterWeak.ScaleLevel(2); myMonsterWeak.Attribute.CurrentHealth = 10; // need to set to enough to last 2 rounds... myRoundEngine.MonsterList.Clear(); // start fresh, because it was loaded already with 6... myRoundEngine.MonsterList.Add(myMonsterWeak); // Add weak character for first... var myCharacterStrong = new Character(DefaultModels.CharacterDefault()); myCharacterStrong.ScaleLevel(10); myRoundEngine.CharacterList.Add(myCharacterStrong); // Add strong character for second myCharacterStrong = new Character(DefaultModels.CharacterDefault()); myCharacterStrong.ScaleLevel(20); myRoundEngine.CharacterList.Add(myCharacterStrong); // Should be Character 20, Character 10, Monster 5 // Force rolls to 18 for to hit... // Turn off random numbers GameGlobals.SetForcedRandomNumbers(1, 18); // Character, should kill the monster in the first round. // So the check for the second round will say Round over... var FirstRound = myRoundEngine.RoundNextTurn(); // Character 20 var SecondRound = myRoundEngine.RoundNextTurn(); // Character 10 goes var ThirdRound = myRoundEngine.RoundNextTurn(); // Monster goes var FourthRound = myRoundEngine.RoundNextTurn(); // Character 20 goes, kills monster... var Actual = myRoundEngine.RoundNextTurn(); // over... // Reset GameGlobals.ToggleRandomState(); var Expected = RoundEnum.NewRound; Assert.AreEqual(Expected, Actual, "Status " + TestContext.CurrentContext.Test.Name); Assert.AreEqual(4, myRoundEngine.BattleScore.TurnCount, "TurnCount " + TestContext.CurrentContext.Test.Name); Assert.AreEqual(1, myRoundEngine.BattleScore.RoundCount, "RoundCount " + TestContext.CurrentContext.Test.Name); }
public void TurnEngine_TurnAsAttack_Monster_Attack_Defender_Die_With_Item_Should_Drop() { MockForms.Init(); // Turn off random numbers GameGlobals.SetForcedRandomNumbers(1, 20); var Attacker = DefaultModels.MonsterDefault(); Attacker.Name = "Rat"; Attacker.ScaleLevel(20); var myDefaultCharacter = new Character(DefaultModels.CharacterDefault()); myDefaultCharacter.Name = "Fighter"; myDefaultCharacter.ScaleLevel(1); // Add Uniqueitem var myItem = new Item { Attribute = AttributeEnum.Attack, Location = ItemLocationEnum.Feet, Value = 1 }; ItemsViewModel.Instance.AddAsync(myItem).GetAwaiter().GetResult(); // Register Item to DataSet myDefaultCharacter.PrimaryHand = myItem.Guid; var myTurnEngine = new TurnEngine(); myTurnEngine.CharacterList.Add(myDefaultCharacter); // Get Score, and remember item. var BeforeItemDropList = myTurnEngine.BattleScore.ItemsDroppedList; GameGlobals.ForceToHitValue = 20; // Force a hit // Should Kill because level 20 hit on level 1 Character for Critical is more damage than health... var AttackScore = Attacker.Level + Attacker.GetAttack(); var DefenseScore = myDefaultCharacter.GetDefense() + myDefaultCharacter.Level; var Status = myTurnEngine.TurnAsAttack(Attacker, AttackScore, myDefaultCharacter, DefenseScore); // Item should drop... // Reset GameGlobals.ToggleRandomState(); // Need to get Score // See if Item is now in the score list... var AfterItemDropList = myTurnEngine.BattleScore.ItemsDroppedList; Assert.AreNotEqual(BeforeItemDropList, AfterItemDropList, TestContext.CurrentContext.Test.Name); }
public void GameEngine_Helper_Random_For_UnitTests_Roll1_DiceNeg_Should_Have_Known_Values() { // Turn off random numbers GameGlobals.SetForcedRandomNumbers(1, 20); var Expected = 0; var Actual = HelperEngine.RollDice(1, -1); // Reset GameGlobals.ToggleRandomState(); Assert.AreEqual(Expected, Actual, TestContext.CurrentContext.Test.Name); }
public void TurnEngine_TakeTurn_Attack_Valid_Defender_Valid_Defender_Should_Die() { MockForms.Init(); // Turn off random numbers GameGlobals.SetForcedRandomNumbers(1, 20); var Attacker = DefaultModels.CharacterDefault(); Attacker.Name = "Fighter"; Attacker.ScaleLevel(20); var myDefaultMonster = new Monster(DefaultModels.MonsterDefault()); myDefaultMonster.Name = "Rat"; myDefaultMonster.ScaleLevel(1); // Add Uniqueitem var myItem = new Item { Attribute = AttributeEnum.Attack, Location = ItemLocationEnum.Feet, Value = 1 }; ItemsViewModel.Instance.AddAsync(myItem).GetAwaiter().GetResult(); // Register Item to DataSet myDefaultMonster.UniqueItem = myItem.Guid; var myTurnEngine = new TurnEngine(); myTurnEngine.MonsterList.Add(myDefaultMonster); // Get Score, and remember item. var BeforeItemDropList = myTurnEngine.BattleScore.ItemsDroppedList; GameGlobals.ForceToHitValue = 20; // Force a hit var BeforeMonsterList = myTurnEngine.MonsterList.Count(); // Instead of calling TurnAsAttack, call TakeTurn... var Status = myTurnEngine.TakeTurn(Attacker); var AfterMonsterList = myTurnEngine.MonsterList.Count(); // Item should drop... // Reset GameGlobals.ToggleRandomState(); Assert.AreEqual(BeforeMonsterList - 1, AfterMonsterList, TestContext.CurrentContext.Test.Name); }
public void GameEngine_Helper_Random_For_Dice_Should_Have_Known_Range() { // Turn off random numbers GameGlobals.SetForcedRandomNumbers(1, 20); var ExpectedMin = 6; var ExpectedMax = 6 * 18; var Actual = HelperEngine.RollDice(6, 6); // Reset GameGlobals.ToggleRandomState(); Assert.GreaterOrEqual(Actual, ExpectedMin, "Min " + TestContext.CurrentContext.Test.Name); Assert.LessOrEqual(Actual, ExpectedMax, "Max " + TestContext.CurrentContext.Test.Name); }
public void TurnEngine_TurnAsAttack_Monster_Attack_Null_Should_Skip() { // Turn off random numbers GameGlobals.SetForcedRandomNumbers(1, 20); var myDefaultMonster = new Character(); var myTurnEngine = new TurnEngine(); var Status = myTurnEngine.TurnAsAttack((Monster)null, 1, myDefaultMonster, 1); var Actual = Status; bool Expected = false; // Reset GameGlobals.ToggleRandomState(); Assert.AreEqual(Expected, Actual, TestContext.CurrentContext.Test.Name); }
public void TurnEngine_TurnAsAttack_Monster_Attack_Defender_CriticalHit_PowerfullHit_Should_Kill() { MockForms.Init(); // Turn off random numbers GameGlobals.SetForcedRandomNumbers(1, 20); var Attacker = DefaultModels.MonsterDefault(); Attacker.Name = "Rat"; Attacker.ScaleLevel(20); var myDefaultCharacter = new Character(DefaultModels.CharacterDefault()); myDefaultCharacter.Name = "Fighter"; myDefaultCharacter.ScaleLevel(1); var myTurnEngine = new TurnEngine(); myTurnEngine.CharacterList.Add(myDefaultCharacter); GameGlobals.ForceToHitValue = 20; // Force a hit // Should Kill because level 20 hit on level 1 Character for Critical is more damage than health... var AttackScore = Attacker.Level + Attacker.GetAttack(); var DefenseScore = myDefaultCharacter.GetDefense() + myDefaultCharacter.Level; var Status = myTurnEngine.TurnAsAttack(Attacker, AttackScore, myDefaultCharacter, DefenseScore); var Actual = Status; bool Expected = true; var ActualString = myTurnEngine.TurnMessage; var ActualResult = myTurnEngine.HitStatus; var ActualDamage = myTurnEngine.DamageAmount; var LifeStatus = myDefaultCharacter.Alive; // Reset GameGlobals.ToggleRandomState(); Assert.AreEqual(Expected, Actual, TestContext.CurrentContext.Test.Name); Assert.AreEqual(false, myDefaultCharacter.Alive, TestContext.CurrentContext.Test.Name); }
public void RoundEngine_RoundNextTurn_Characters_MonstersDead_Should_Return_NewRound() { MockForms.Init(); // No characters, so return should be game over... // Can create a new Round engine... var myRoundEngine = new RoundEngine(); // Turn off random numbers GameGlobals.SetForcedRandomNumbers(1, 20); // Start myRoundEngine.StartRound(); // Clear the monster list // Add weak monsters var myMonsterWeak = new Monster(DefaultModels.MonsterDefault()); myMonsterWeak.ScaleLevel(1); myRoundEngine.MonsterList.Clear(); // start fresh, because it was loaded already with 6... myRoundEngine.MonsterList.Add(myMonsterWeak); // Add strong character var myCharacterStrong = new Character(DefaultModels.CharacterDefault()); myCharacterStrong.ScaleLevel(20); myRoundEngine.CharacterList.Add(myCharacterStrong); // Character, should kill the monster in the first round. // So the check for the second round will say Round over... var FirstRound = myRoundEngine.RoundNextTurn(); var Actual = myRoundEngine.RoundNextTurn(); var Expected = RoundEnum.NewRound; // Reset GameGlobals.ToggleRandomState(); Assert.AreEqual(RoundEnum.NextTurn, FirstRound, TestContext.CurrentContext.Test.Name); Assert.AreEqual(Expected, Actual, TestContext.CurrentContext.Test.Name); }
public void TurnEngine_RollToHitTarget_Attacker_Lower_Than_Defender_Roll_1_Should_CriticalMiss() { MockForms.Init(); // Turn off random numbers // Set random to 1, and to hit to 1 GameGlobals.SetForcedRandomNumbers(1, 1); var myTurnEngine = new TurnEngine(); var Attacker = 1; var Defender = 10; var Actual = myTurnEngine.RollToHitTarget(Attacker, Defender); var Expected = HitStatusEnum.CriticalMiss; // Reset GameGlobals.ToggleRandomState(); Assert.AreEqual(Expected, Actual, TestContext.CurrentContext.Test.Name); }
public void TurnEngine_DetermineCriticalMissProblem_Attacker_Null_Should_Return_Invalid() { MockForms.Init(); // Turn off random numbers // Set random to 1, and to hit to 1 GameGlobals.SetForcedRandomNumbers(1, 1); GameGlobals.ForcedRandomValue = 1; var myTurnEngine = new TurnEngine(); var Actual = myTurnEngine.DetermineCriticalMissProblem(null); // Should roll for 1 item, and return it... var Expected = " Invalid Character "; // Reset GameGlobals.ToggleRandomState(); Assert.AreEqual(Expected, Actual, TestContext.CurrentContext.Test.Name); }
public void Model_Item_ScaleLevel_With_NoRandom_Values_Should_Pass() { MockForms.Init(); // Turn off random numbers // Set random to 1, and to hit to 1 GameGlobals.SetForcedRandomNumbers(3, 1); var myItem = new Item(); myItem.ScaleLevel(2); var Actual = myItem.Value; // Should roll for 1 item, and return it... var Expected = 2; // Reset GameGlobals.ToggleRandomState(); Assert.AreEqual(Expected, Actual, TestContext.CurrentContext.Test.Name); }
public void TurnEngine_GetRandomMonsterItemDrops_3_Roll_Should_Return_List() { MockForms.Init(); // Turn off random numbers // Set random to 1, and to hit to 1 GameGlobals.SetForcedRandomNumbers(1, 1); GameGlobals.ForcedRandomValue = 3; var myTurnEngine = new TurnEngine(); var roundCount = 1; var Actual = myTurnEngine.GetRandomMonsterItemDrops(roundCount); // Should roll for 1 item, and return it... var Expected = 3; // Reset GameGlobals.ToggleRandomState(); Assert.AreEqual(Expected, Actual.Count(), TestContext.CurrentContext.Test.Name); }