public void ExecuteTurn_WhenDoesNotHaveObjectsInCurrentRoundAndGroupRandomReturns0AndFirstGroupIsEmpty_ShouldReturnObjectFromSecondGroup( [Frozen] IBattleRandom battleRandom, BattleOrder battleOrder) { // 999 controls order to be defense // 0 is the to always return first obj and first group battleRandom.Next(Arg.Any <int>()).Returns(999, 0); ICombatObject outCombatObject; ICombatGroup outCombatGroup; BattleManager.BattleSide foundInGroup; var attackerObject = CreateCombatObject(round: 1); var attackerGroup = CreateGroup(attackerObject); var attackerList = CreateList(upkeepNotParticipated: 1, combatGroups: attackerGroup); var defenderGroup1 = CreateGroup(); var defenderObject2 = CreateCombatObject(round: 1); var defenderGroup2 = CreateGroup(defenderObject2); var defenderList = CreateList(upkeepNotParticipated: 999, combatGroups: new [] { defenderGroup1, defenderGroup2 }); var result = battleOrder.NextObject(0, attackerList, defenderList, out outCombatObject, out outCombatGroup, out foundInGroup); result.Should().Be(false); outCombatObject.Should().Be(defenderObject2); ((object)outCombatGroup).Should().Be(defenderGroup2); foundInGroup.Should().Be(BattleManager.BattleSide.Defense); }
public void ExecuteTurn_WhenGroupRandomReturns1AndGroupHasNoObjectsLeft_ShouldReturnFirstObjectFromFirstGroup( [Frozen] IBattleRandom battleRandom, BattleOrder battleOrder) { // 999 controls order to be defense // 1 is the second group idx // 0 is the first combat obj idx battleRandom.Next(Arg.Any <int>()).Returns(999, 1, 0); ICombatObject outCombatObject; ICombatGroup outCombatGroup; BattleManager.BattleSide foundInGroup; var attackerObject = CreateCombatObject(round: 0); var attackerGroup = CreateGroup(attackerObject); var attackerList = CreateList(upkeepNotParticipated: 1, combatGroups: attackerGroup); var defenderObject1 = CreateCombatObject(round: 0); var defenderGroup1 = CreateGroup(defenderObject1); var defenderObject2 = CreateCombatObject(round: 1); var defenderGroup2 = CreateGroup(defenderObject2); var defenderList = CreateList(upkeepNotParticipated: 999, combatGroups: new [] { defenderGroup1, defenderGroup2 }); var result = battleOrder.NextObject(0, attackerList, defenderList, out outCombatObject, out outCombatGroup, out foundInGroup); result.Should().Be(true); outCombatObject.Should().Be(defenderObject1); ((object)outCombatGroup).Should().Be(defenderGroup1); foundInGroup.Should().Be(BattleManager.BattleSide.Defense); }
public void ExecuteTurn_WhenDoesNotHaveObjectsInCurrentRoundAndGroupRandomReturns0AndObjectRandomReturns1_ShouldReturnSecondObjectFromFirstGroup( [Frozen] IBattleRandom battleRandom, BattleOrder battleOrder) { // 999 controls order to be defense // 0 is the first group idx // 1 is the second combat obj idx // 1 is the random obj after we've found no objects are in the current round // 0 is going to be when looking into the attacker list (for group and obj) after it didnt find a defense battleRandom.Next(Arg.Any <int>()).Returns(999, 0, 1, 1, 0); ICombatObject outCombatObject; ICombatGroup outCombatGroup; BattleManager.BattleSide foundInGroup; var attackerObject = CreateCombatObject(round: 1); var attackerGroup = CreateGroup(attackerObject); var attackerList = CreateList(upkeepNotParticipated: 1, combatGroups: attackerGroup); var defenderObject1 = CreateCombatObject(round: 1); var defenderObject2 = CreateCombatObject(round: 1); var defenderGroup = CreateGroup(defenderObject1, defenderObject2); var defenderList = CreateList(upkeepNotParticipated: 999, combatGroups: defenderGroup); var result = battleOrder.NextObject(0, attackerList, defenderList, out outCombatObject, out outCombatGroup, out foundInGroup); result.Should().Be(false); outCombatObject.Should().Be(defenderObject2); ((object)outCombatGroup).Should().Be(defenderGroup); foundInGroup.Should().Be(BattleManager.BattleSide.Defense); }
/// <summary> /// Returns the next object from the primary group that should attack. /// If primary group has no one able to attack, it will look into the secondary group instead. /// </summary> /// <returns>True if got an object from the current round. False if had to look into next round.</returns> public bool NextObject(uint round, ICombatList attacker, ICombatList defender, out ICombatObject outCombatObject, out ICombatGroup outCombatGroup, out BattleManager.BattleSide foundInGroup) { var attackerUpkeep = attacker.UpkeepNotParticipatedInRound(round); var defenderUpkeep = defender.UpkeepNotParticipatedInRound(round); if (attackerUpkeep == 0 && defenderUpkeep == 0) { attackerUpkeep = attacker.UpkeepNotParticipatedInRound(round + 1); defenderUpkeep = defender.UpkeepNotParticipatedInRound(round + 1); } BattleManager.BattleSide sideAttack = random.Next(attackerUpkeep + defenderUpkeep) < attackerUpkeep ? BattleManager.BattleSide.Attack : BattleManager.BattleSide.Defense; var offensiveCombatList = sideAttack == BattleManager.BattleSide.Attack ? attacker : defender; var defensiveCombatList = sideAttack == BattleManager.BattleSide.Attack ? defender : attacker; var offensiveSide = sideAttack; var defensiveSide = sideAttack == BattleManager.BattleSide.Attack ? BattleManager.BattleSide.Defense : BattleManager.BattleSide.Attack; // Look into offenside combat list first ICombatObject outCombatObjectAttacker; ICombatGroup outCombatGroupAttacker; if (NextObjectFromList(round, offensiveCombatList, out outCombatObjectAttacker, out outCombatGroupAttacker)) { foundInGroup = offensiveSide; outCombatGroup = outCombatGroupAttacker; outCombatObject = outCombatObjectAttacker; return(true); } // Couldnt find in the attacker so look in defense ICombatObject outCombatObjectDefender; ICombatGroup outCombatGroupDefender; if (NextObjectFromList(round, defensiveCombatList, out outCombatObjectDefender, out outCombatGroupDefender)) { foundInGroup = defensiveSide; outCombatGroup = outCombatGroupDefender; outCombatObject = outCombatObjectDefender; return(true); } // Okay looks like both sides are done for this round. If we had an attacker // then we return that, otherwise go to the defender if (outCombatObjectAttacker != null) { foundInGroup = offensiveSide; outCombatGroup = outCombatGroupAttacker; outCombatObject = outCombatObjectAttacker; } else if (outCombatObjectDefender != null) { foundInGroup = defensiveSide; outCombatGroup = outCombatGroupDefender; outCombatObject = outCombatObjectDefender; } // If this happens then it means there is no one in the battle or the battle is prolly over else { outCombatGroup = null; outCombatObject = null; foundInGroup = offensiveSide; return(true); } return(false); }