public void DamageBehavior()
 {
     if (type == 1)
     {
         if (!Raycaster.AreWallsBlockView(targetPosition, position, Game.Walls))
         {
             if (Component.CoolDown(ref shootCoolDown, maxReloadBuffer, true))
             {
                 Game.Bullets.Add(new Bullet(false, position, Game.Player.position, "Textures/EnemyBullet.png", damage));
             }
         }
     }
     else if (type == 3)
     {
         if (Component.DistanceOfPointsLessThan(position, Game.Player.position, Game.Player.radius + radius))
         {
             Game.Player.Hit(damage);
             Death();
         }
     }
     else if (type == 2)
     {
         if (!Raycaster.AreWallsBlockView(targetPosition, position, Game.Walls))
         {
             if (Component.CoolDown(ref shootCoolDown, maxReloadBuffer, true))
             {
                 double r  = (degrees * Math.PI) / 180;
                 double pX = Math.Sin(r);
                 double pY = Math.Cos(r);
                 Game.Bullets.Add(new Bullet(false, position + new Vector(pX * 27, pY * 27), Game.Player.position, "Textures/EnemyBullet.png", damage));
                 Game.Bullets.Add(new Bullet(false, position + new Vector(pX * -27, pY * -27), Game.Player.position, "Textures/EnemyBullet.png", damage));
             }
         }
     }
 }
        private void RetracePath(Node startNode, Node targetNode, double distFromTarget)
        {
            nodePath = new List <Node>();
            Node currentNode = targetNode;

            while (currentNode != startNode)
            {
                nodePath.Add(currentNode);
                currentNode = currentNode.parent;
            }

            nodePath.Reverse();

            //Evaluate path and cutting off range.
            for (int i = 0; i < nodePath.Count; i++)
            {
                if (Component.DistanceOfPointsLessThan(nodePath[i].worldPosition, nodePath[nodePath.Count - 1].worldPosition, distFromTarget) &&
                    !Raycaster.AreWallsBlockView(nodePath[i].worldPosition, nodePath[nodePath.Count - 1].worldPosition, Game.Walls)
                    )
                {
                    nodePath.RemoveRange(i + 1, nodePath.Count - 1 - i);
                    break;
                }
            }

            //If a previous node was marked as endpoint, cut off. Unlikely safe catch.

            /*
             * for (int j = 0; j < nodePath.Count - 2; j++)
             * {
             *  if (nodePath[j].rLevel == 3)
             *  {
             *      nodePath.RemoveRange(j + 1, nodePath.Count - 1 - j);
             *      break;
             *  }
             * }
             */
        }
        public void Update()
        {
            //finding new path
            if (healthBar <= 0)
            {
                Death();
            }
            else
            {
                if (Component.CoolDown(ref searchPlayerCoolDown, 20, false) && targetPosition != Game.Player.position &&
                    Game.Grid.NodeFromWorld(Game.Player.position).walkable&& Game.Grid.NodeFromWorld(Game.Player.position).rLevel == 0)
                {
                    targetPosition = Game.Player.position;

                    if (Component.DistanceOfPointsLessThan(targetPosition, position, ACTIVATE_RANGE) || path != null)
                    {
                        if (!pathPending &&
                            (!Component.DistanceOfPointsLessThan(targetPosition, position, SHOOTING_RANGE) ||
                             Raycaster.AreWallsBlockView(targetPosition, position, Game.Walls)))
                        {
                            searchPlayerCoolDown = 50;

                            if (path != null)
                            {
                                for (int i = currentTargetIndex - 1; i < path.Count; i++)
                                {
                                    if (i >= 0)
                                    {
                                        Game.Grid.SetLevelGroupNodes(path[i], 0, RADIUS_IN_NODES);
                                    }
                                }
                                Game.Grid.SetLevelGroupNodes(Game.Grid.NodeFromWorld(position), 3, 2);
                            }
                            Game.Pathmanager.RequestPath(position, targetPosition, SHOOTING_RANGE, OnPathFound);
                            pathPending = true;
                        }
                    }
                }

                if (path != null)
                {
                    if (currentTargetIndex < path.Count)
                    {
                        position = LocateNextPosition();
                        degrees  = Math.Atan2(direction.Y, direction.X) * 180 / Math.PI;

                        if (type == 3 && Component.DistanceOfPointsLessThan(position, Game.Player.position, Game.Player.radius + radius))
                        {
                            Game.Player.healthBar -= damage;
                            Death();
                        }
                    }
                    else
                    {
                        if (currentTargetIndex >= 0)
                        {
                            //Game.Grid.SetLevelGroupNodes(path[currentTargetIndex - 1], 0, RADIUS_IN_NODES, 1);
                            Game.Grid.SetLevelGroupNodes(path[currentTargetIndex - 1], 3, RADIUS_IN_NODES, 1);
                        }
                        degrees = (Math.Atan2(Game.Player.position.Y - position.Y, Game.Player.position.X - position.X) * 180) / Math.PI;
                        DamageBehavior();
                    }
                }
            }
        }