private void PrepareMove() { currentStep = MovementStep.Movement; checkNextStep = false; dodgeMover.Hide(); pushMover.Hide(); DestroyDices(); var attackerPosition = GameStateManager.Instance.GetActiveTile().GetUnitPosition(attackerRecieved.gameObject); var targetPosition = GameStateManager.Instance.GetActiveTile().GetUnitPosition(primaryTargetRecieved.gameObject); attackerOriginNode = attackerPosition; var nodeToMoveTo = DetermineTargetNode(attackerPosition, targetPosition); if (nodeToMoveTo != null) { var moveCommand = new UnitMovement() { MoveFrom = attackerPosition, MoveTo = nodeToMoveTo, Unit = attackerRecieved.gameObject, }; EventManager.RaiseEvent(ObjectEventType.UnitMoved, moveCommand); } currentStepCounter++; FinishCurrentStep(); }
protected override void OnMoveCursor(MovementStep step, int count, bool extend_selection) { base.OnMoveCursor(step, count, extend_selection); if (extension != null) { extension.CursorPositionChanged(); } }
private void PrepareEncounter() { dodgeRoll = 0; blockRoll = 0; currentStepCounter = 0; currentStep = MovementStep.None; checkNextStep = false; if (currentStepCounter == movementRecieved.MoveDistance) { currentStep = MovementStep.Resolved; } }
private void Update() { if (resolvingMovement) { if (currentStep == MovementStep.None) { PrepareInitialPush(); } else if (currentStep == MovementStep.InitialPush) { if (checkNextStep) { PrepareMove(); } else if (currentDefender == null) { ShowNextInitialPush(); } } else if (currentStep == MovementStep.Movement && checkNextStep) { PreparePushAway(); } else if (currentStep == MovementStep.PushAway) { if (checkNextStep) { currentStep = MovementStep.Resolved; } else if (currentDefender == null) { ShowNextPushAway(); } } else if (currentStep == MovementStep.Resolved) { if (currentStepCounter < movementRecieved.MoveDistance) { currentStep = MovementStep.None; } else { EventManager.RaiseEvent(ObjectEventType.EncountersResolved); FinalizeEncounter(); } } } }
private void InsertStepIntoList(MovementStep step, List <MovementStep> list) { int stepFScore = step.fScore(); int count = list.Count; int i; // Keep the list sorted by fscore for (i = 0; i < count; i++) { MovementStep currentStep = list[i]; if (stepFScore < currentStep.fScore()) { break; } } list.Insert(i, step); }
private void PreparePushAway() { currentStep = MovementStep.PushAway; checkNextStep = false; if (!movementRecieved.Push) { FinishCurrentStep(); return; } SetPushAwayVisibility(); unitToPushRemaining = GetUnitsToPush(); foreach (var unit in unitToPushRemaining) { unit.ShowTargetableBrillance(); } currentDefender = null; }
private void PrepareInitialPush() { currentStep = MovementStep.InitialPush; checkNextStep = false; DestroyDices(); if (!movementRecieved.Push) { FinishCurrentStep(); return; } SetInitialPushVisibility(); unitToPushRemaining = GetUnitsToPush(); foreach (var unit in unitToPushRemaining) { unit.ShowTargetableBrillance(); } currentDefender = null; attackerOriginNode = null; }
IEnumerator WalkAlongPath() { // currentPath could be replaced underneath us if the user // changes destination mid-walk. StopCoroutine("WalkToStep"); while (currentPath.Count > 0) { MovementStep step = currentPath[0]; currentPath.RemoveAt(0); animator.SetBool("Walking", true); Map.Direction newDirection = Map.CalculateDirectionTravelling(currentPosition, step.MapPoint); animator.SetInteger("Direction", (int)newDirection); MapPoint fromPoint = currentPosition; currentPosition = step.MapPoint; WalkingStep ws = new WalkingStep { fromPoint = fromPoint, step = step, direction = newDirection }; yield return(StartCoroutine("WalkToStep", ws)); } animator.SetBool("Walking", false); walking = false; if (currentCompletionHandler != null) { currentCompletionHandler(true); } }
protected override void OnMoveCursor (MovementStep step, int count, bool extend_selection) { base.OnMoveCursor (step, count, extend_selection); if (extension != null) extension.CursorPositionChanged (); }
public List <MovementStep> GeneratePath(MapPoint fromPoint, MapPoint toPoint) { Debug.Log("Generating path from " + fromPoint + " to " + toPoint); if (fromPoint == toPoint) { Debug.Log("Already at point"); // FIXME: is this the best way, or should I return an empty list? return(null); } List <MovementStep> openSteps = new List <MovementStep>(); List <MovementStep> closedSteps = new List <MovementStep>(); // Start by adding the from position to the open list MovementStep firstStep = new MovementStep(fromPoint); InsertStepIntoList(firstStep, openSteps); do { MovementStep currentStep = openSteps[0]; // Move the first step into the closedSteps list closedSteps.Add(currentStep); openSteps.RemoveAt(0); if (currentStep.MapPoint == toPoint) { List <MovementStep> shortestPath = new List <MovementStep>(); do { if (currentStep.parent != null) { shortestPath.Insert(0, currentStep); } currentStep = currentStep.parent; } while (currentStep != null); return(shortestPath); } List <MapPoint> walkableTiles = WalkableAdjacentTiles(currentStep.MapPoint); foreach (MapPoint mapPoint in walkableTiles) { MovementStep step = new MovementStep(mapPoint); if (closedSteps.Contains(step)) { continue; } // Compute the cost from the current step to that step int moveCost = CostToMove(currentStep, step); int idx = openSteps.IndexOf(step); if (idx == -1) { step.parent = currentStep; step.gScore = currentStep.gScore + moveCost; step.hScore = ComputeHScoreForMovement(step.MapPoint, toPoint); InsertStepIntoList(step, openSteps); } else { step = openSteps[idx]; if (currentStep.gScore + moveCost < step.gScore) { step.gScore = currentStep.gScore + moveCost; // As gscore has changed, fscore has changed too, so reinsert it into the list openSteps.RemoveAt(idx); InsertStepIntoList(step, openSteps); } } } } while (openSteps.Count > 0); Debug.Log("Cannot reach destination " + toPoint + " from " + fromPoint); return(null); }
private int CostToMove(MovementStep fromStep, MovementStep toStep) { // Because we can't move diagonally and because terrain is just walkable or unwalkable the cost is always the same. // But it can to be different if we can move diagonally and/or if there is swamps, hills, etc... return(1); }