/// <summary> /// Performs a character action given an ActionBase and a target position. /// </summary> /// <param name="action">The action being performed.</param> /// <param name="targetPosition">The position the action will target.</param> private void StartAIAction(ActionBase action, int targetPosition) { var targetPositions = AITargets.GetModifiedSelection(action, targetPosition); _actionController.StartAction(CombatStateHandler.CurrentRoundOrder[0], action, targetPositions); EndTurn(); }
/// <summary> /// Called to start an AI's turn. /// <para>Throws an exception if the AI returns a null ActionBase.</para> /// </summary> private void StartAITurn() { var aiDecision = _combatAI.GetAIDecision(CombatStateHandler.CurrentRoundOrder[0], CombatStateHandler.EnemyCharacters, CombatStateHandler.PlayerCharacters); if (aiDecision.ActionChoice == null) { throw new Exception("AI action choice cannot be null."); } // Invoke AIChoseTarget event once the AI has come to a decision. if (AIChoseTarget != null) { var eventArgs = new AIChoseTargetEventArgs() { AICharacter = CombatStateHandler.CurrentRoundOrder[0], CenterOfTarget = aiDecision.TargetPosition, TargetPositions = AITargets.GetModifiedSelection(aiDecision.ActionChoice, aiDecision.TargetPosition) }; AIChoseTarget(this, eventArgs); } StartAIAction(aiDecision.ActionChoice, aiDecision.TargetPosition); // todo: Create class to handle consumables if (aiDecision.ConsumableUsed != null) { _consumablesHandler.UseConsumable(aiDecision.ConsumableUsed, CombatStateHandler.CurrentRoundOrder[0]); } }
public void GetModifiedCenter_WithDisplacedCenter_ReturnsCorrect() { // Target positions: 1, 2, 3, 6 // Center of Targets Position: 1 var testAction = _actions.FirstOrDefault(action => action.Id == 1); int expected = 18; var actual = AITargets.GetModifiedCenter(testAction.CenterOfTargetsPosition); Assert.AreEqual(expected, actual); }
public void GetModifiedTargets_WithLShape_ReturnsCorrectTargets() { // Target positions: 1, 2, 3, 6 // Center of Targets Position: 1 var testAction = _actions.FirstOrDefault(action => action.Id == 1); var expected = new List <int>() { 18, 17, 16, 13 }; var actual = AITargets.GetModifiedTargets(testAction).ToList(); CollectionAssert.AreEquivalent(expected, actual); }
public void GetModifiedSelection_WithLShapeInEnemy_ReturnsLine() { // Target positions: 1, 2, 3, 6 // Center of Targets Position: 1 var testAction = _actions.FirstOrDefault(action => action.Id == 1); int selectionTarget = 3; var expected = new List <int>() { 1, 2, 3 }; var actual = new List <int>(AITargets.GetModifiedSelection(testAction, selectionTarget)); CollectionAssert.AreEquivalent(expected, actual); }