예제 #1
0
        private PositionBehavior DetermineTargetNode(PositionBehavior from, PositionBehavior to)
        {
            var currentPathLength = PathFinder.NodeWorldDistance(from, to);

            PositionBehavior bestNode;
            var distances = PathFinder.GetNodeDistances(to, from.GetAdjacentNodes());



            if (movementRecieved.Direction == MovementDirection.Forward)
            {
                bestNode = distances.OrderBy(e => e.Lengh).First().Node;
                if (PathFinder.NodeWorldDistance(bestNode, to) > PathFinder.NodeWorldDistance(from, to))
                {
                    return(null);
                }
            }
            else if (movementRecieved.Direction == MovementDirection.Backward)
            {
                bestNode = distances.OrderByDescending(e => e.Lengh).First().Node;
                if (PathFinder.NodeWorldDistance(bestNode, to) < PathFinder.NodeWorldDistance(from, to))
                {
                    return(null);
                }
            }
            else
            {
                throw new NotImplementedException();
            }



            return(bestNode);
        }
예제 #2
0
        private static List <PositionBehavior> GetPath(PositionBehavior start, PositionBehavior target, List <PositionBehavior> visited)
        {
            List <PositionBehavior> bestPath = null;

            foreach (var node in start.GetAdjacentNodes())
            {
                var currentPath = visited.ToList();
                if (target == node)
                {
                    currentPath.Add(node);
                    if (PathDistance(start, bestPath) > PathDistance(start, currentPath))
                    {
                        bestPath = currentPath;
                    }
                    return(bestPath);
                }
                else
                {
                    if (!currentPath.Contains(node) && node != start && CloserNode(node, start, target))
                    {
                        currentPath.Add(node);
                        var path = GetPath(node, target, currentPath);
                        if (path != null && (PathDistance(start, bestPath) > PathDistance(start, path)))
                        {
                            bestPath = path;
                        }
                    }
                }
            }

            return(bestPath);
        }
예제 #3
0
        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();
        }
예제 #4
0
 public static List <PositionBehavior> GetPath(PositionBehavior start, PositionBehavior target)
 {
     if (start == target)
     {
         return(new List <PositionBehavior>());
     }
     return(GetPath(start, target, new List <PositionBehavior>()));
 }
예제 #5
0
 private void DodgeMoveSelected(PositionBehavior _)
 {
     dodgeMover.Hide();
     blockButton.SetActive(false);
     dodgeButton.SetActive(false);
     rollType           = EncounterRollType.Dodge;
     diceResultRecieved = 0;
     ThrowDices();
 }
예제 #6
0
 private void PushMoveSelected(PositionBehavior position)
 {
     currentDefender.HideAttakedBrillance();
     if (currentStep == MovementStep.InitialPush)
     {
         currentDefender = null;
     }
     else if (currentStep == MovementStep.PushAway)
     {
         currentDefender = null;
     }
 }
예제 #7
0
        private void ShiftMoveSelected(PositionBehavior position)
        {
            if (shiftBeforeResolved < attackRecieved.ShiftBefore)
            {
                shiftBeforeResolved++;
            }
            else if (shiftAfterResolved < attackRecieved.ShiftAfter)
            {
                shiftAfterResolved++;
            }

            if (shiftBeforeResolved < attackRecieved.ShiftBefore || shiftAfterResolved < attackRecieved.ShiftAfter)
            {
                SetupForShift();
            }
        }
예제 #8
0
        private static float PathDistance(PositionBehavior start, List <PositionBehavior> path)
        {
            if (path == null)
            {
                return(float.MaxValue);
            }

            var completedPath = new List <PositionBehavior>()
            {
                start
            }.Concat(path).ToList();
            var distance = 0f;

            for (int i = 0; i < completedPath.Count() - 1; i++)
            {
                distance += NodeWorldDistance(completedPath[i], completedPath[i + 1]);
            }
            return(distance);
        }
예제 #9
0
        public static List <NodeDistance> GetNodeDistances(PositionBehavior to, IList <PositionBehavior> positions)
        {
            var result = new List <NodeDistance>();

            foreach (var position in positions)
            {
                var path = GetPath(position, to);

                result.Add(new NodeDistance()
                {
                    Node       = position,
                    DistanceTo = to,
                    PathLength = path.Count,
                    Lengh      = NodeWorldDistance(position, to),
                });
            }

            return(result);
        }
예제 #10
0
        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;
        }
예제 #11
0
 public static float NodeWorldDistance(PositionBehavior node1, PositionBehavior node2)
 {
     return((node2.transform.position - node1.transform.position).magnitude);
 }
예제 #12
0
 private static bool CloserNode(PositionBehavior nodeA, PositionBehavior nodeB, PositionBehavior target)
 {
     return(NodeWorldDistance(nodeA, target) <= NodeWorldDistance(nodeB, target));
 }
예제 #13
0
 private void PushMoveSelected(PositionBehavior position)
 {
     pushMover.Hide();
     ApplyResultFinalize();
 }