Example #1
0
        public static int Redeploy(int fromPlayerWho)
        {
            var kitSingleton = ModContent.GetInstance <TrackDeploymentKitItem>();

            (int x, int y, int dir)resume = kitSingleton.ResumeDeploymentAt;

            kitSingleton.ResumeDeploymentAt = (0, 0, 0);

            if (Main.tile[resume.x, resume.y]?.active() == true)
            {
                Main.NewText("Track kit auto-deploy obstructed.", Color.Yellow);
                return(0);
            }

/*int blah=120;
 * Timers.SetTimer( "blah_"+resume.x+"_"+resume.y, 3, false, () => {
 *      Dust.QuickDust( new Point(resume.x,resume.y), Color.Red );
 *      return blah-- > 0;
 * } );*/

            if (Main.netMode == 0)
            {
                return(TrackDeploymentKitItem.Deploy(fromPlayerWho, resume.x, resume.y, resume.dir > 0));
            }
            else
            {
                TrackKitDeployProtocol.SendToServer(resume.dir > 0, resume.x, resume.y, true);
                return(0);
            }
        }
Example #2
0
        ////////////////

        public static int Deploy(int fromPlayerWho, int tileX, int tileY, bool isAimedRight)
        {
            int tracks          = PrefabKitsConfig.Instance.Get <int>(nameof(PrefabKitsConfig.TrackDeploymentKitTracks));
            int tracksScanRange = tracks + (tracks / 2);

            int dir = isAimedRight ? 1 : -1;

            IList <(int, int)> path = TrackDeploymentKitItem.TracePath(tileX, tileY, dir, tracksScanRange);

            if (path.Count > 0)
            {
                TrackDeploymentKitItem.DeployRunner(fromPlayerWho, path, isAimedRight, tracks, 0);
            }

            return(Math.Max(tracks - path.Count, 0));
        }
        ////////////////

        private static IList <(int, int)> TracePath(
            int tileX,
            int tileY,
            int dir,
            int tracks)
        {
            if (Main.tile[tileX, tileY]?.active() == true)
            {
                return(new List <(int, int)>());
            }

            IDictionary <(int, int), PathTree> pathMap = new Dictionary <(int, int), PathTree>();
            PathTree pathTree = TrackDeploymentKitItem.TracePathTree(tileX, tileY, dir, 0, tracks, pathMap);

            IList <(int, int)> path = new List <(int, int)> {
                (tileX, tileY)
            };

            TrackDeploymentKitItem.TraceTreeForLongestPath(pathTree, path);

            TrackDeploymentKitItem.SmoothPath(path);

            return(path);
        }