void Restart() { //Debug.Log("*AI* Restarting Steps"); currentStep = AIStep.SelectUnit; selectedUnit = null; target = null; path = null; }
public void Control() { if (!stopped && stepTime > stepDelay) { stepTime -= stepDelay; //Debug.Log("*AI* Loop"); switch (currentStep) { case AIStep.SelectUnit: //Debug.Log("*AI* Selection"); if (!SelectUnit()) { stopped = true; //Debug.Log("*AI* Stopped!"); } else if (selectedUnit != null) { currentStep = AIStep.FindPath; unitController.SelectedInstance = selectedUnit; //Debug.Log("*AI* Unit Selected"); } break; case AIStep.FindPath: //Debug.Log("*AI* Pathing"); //path = GGAStar.GetPath(selectedUnit.Head.Cell, target, true, false); path = RegenPath(); // GOTO Move currentStep = AIStep.Move; unitController.CurrentAction = UnitController.SelectedAction.Move; pathIndexer = 1; break; case AIStep.Move: //Debug.Log("*AI* Moving"); int pathMinus = 0; if (path.LastOrDefault() != null) { UnitBody body = path.LastOrDefault().Objects.Select(ggo => ggo.GetComponent<UnitBody>()).FirstOrDefault(b => b != null); if (path.LastOrDefault().IsOccupied && body != null && body.UnitInstance != selectedUnit) { pathMinus = 1; } } if (unitController.RemainingMoves > 0 && pathIndexer < path.Count - pathMinus) { //Debug.Log("*AI* Move"); unitController.MoveSelectedUnit(path[pathIndexer]); pathIndexer++; } else { //Debug.Log("*AI* Destination"); //unitController.CompleteTurnActions(); //Restart(); currentStep = AIStep.SelectTarget; } break; case AIStep.SelectTarget: //Debug.Log("*AI* Targeting"); target = GetNearestOfEnemy(); if (target != null && target.GetTypesInCell<UnitBody>().FirstOrDefault()) { currentStep = AIStep.Attack; unitController.CurrentAction = UnitController.SelectedAction.Action_1; } break; case AIStep.Attack: //Debug.Log("*AI* Attack"); //target if (UnitInstance.GetDistanceBetweenCells(selectedUnit.Head.Cell, target) <= selectedUnit.Definition.GetActionModuleInclusive((int)unitController.CurrentAction).RangeValue) { unitController.CommitSelectedActionTo(target); //unitController.CompleteTurnActions(); } else { unitController.CompleteTurnActions(); } Restart(); //stopped = true; break; } /*if (selectedUnit.IsExausted) { Restart(); }*/ } stepTime += Time.deltaTime; }