/// <summary> /// Handles all the logic for the human player input stages /// </summary> public override void Think() { if (endTurnRequested) { endTurnRequested = false; NextDecision = new Decision() { Type = DecisionType.EndTurn }; } if (mouseClicked) { mouseClicked = false; var ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out RaycastHit hit)) { if (hit.collider.CompareTag("Unit")) { var unit = hit.collider.gameObject.GetComponentInParent <Unit>(); if (unit.Faction == FactionManager.FactionIndex) { if (unit == SelectedUnit) { deselectUnit(); } else { deselectUnit(); SelectedUnit = unit; MatchManager.ActivateUIForUnit(SelectedUnit); SelectedUnit.gameObject.AddComponent <SelectedUnit>(); } } else { if (SelectedUnit != null) { NextDecision = CreateAttackDecision(SelectedUnit, unit); } } } else if (hit.collider.CompareTag("Map") && SelectedUnit) { var cell = MatchManager.MapManager.GetCell(hit.point); if (MapManager.IsFree(cell)) { NextDecision = CreateMoveDecision(SelectedUnit, cell); } } } else { deselectUnit(); } } }
/// <summary> /// Applies an already validated decision /// </summary> /// <param name="decision">An already validated decision</param> /// <returns></returns> private IEnumerator applyDecision(Decision decision) { if (decision.Type != DecisionType.EndTurn && currentPlayer.FactionManager.IsHuman) { m_matchManager.DeactivateUIForUnit(decision.SourceUnit); } if (decision.Type == DecisionType.Move) { yield return(applyMove(decision)); } if (decision.Type == DecisionType.Attack) { yield return(applyAttack(decision)); } if (decision.Type != DecisionType.EndTurn && currentPlayer.FactionManager.IsHuman) { m_matchManager.ActivateUIForUnit(decision.SourceUnit); } }