예제 #1
0
        /// <summary>
        ///     The mod entry point, called after the mod is first loaded.
        /// </summary>
        /// <param name="helper">Provides simplified APIs for writing mods.</param>
        public override void Entry(IModHelper helper)
        {
            ClickToMoveHelper.Init(this.Monitor, this.Helper.Reflection);

            this.pathFindingManager = new PathFindingManager(helper);

            // Hook events.
            helper.Events.Display.RenderedWorld += this.OnRenderedWorld;

            // Add patches.
            HarmonyInstance.DEBUG = true;
            HarmonyInstance harmony = HarmonyInstance.Create(this.ModManifest.UniqueID);

            ClickToMovePatcher.Hook(harmony, helper, this.Monitor, this.pathFindingManager);

            // Log info
            this.Monitor.VerboseLog("Initialized.");
        }
        public AStarPath FindPathToNeighbourDiagonalWithBubbleCheck(AStarNode startNode, AStarNode endNode)
        {
            AStarPath pathWithBubbleCheck = this.FindPathWithBubbleCheck(startNode, endNode);

            if (pathWithBubbleCheck is not null)
            {
                return(pathWithBubbleCheck);
            }

            if (endNode.FakeTileClear)
            {
                int       minDistance = int.MaxValue;
                AStarNode nearestNode = null;
                foreach (WalkDirection walkDirection in WalkDirection.DiagonalDirections)
                {
                    AStarNode node = this.GetNode(endNode.X + walkDirection.X, endNode.Y + walkDirection.Y);

                    if (node is not null && node.TileClear)
                    {
                        int distance = ClickToMoveHelper.SquaredEuclideanDistance(
                            startNode.X,
                            startNode.Y,
                            node.X,
                            node.Y);

                        if (distance < minDistance)
                        {
                            nearestNode = node;
                            minDistance = distance;
                        }
                    }
                }

                if (nearestNode is not null)
                {
                    return(this.FindPathWithBubbleCheck(startNode, nearestNode));
                }
            }

            return(null);
        }