コード例 #1
0
        /// <summary>Gets the fast travel info for a corresponding point on the map.</summary>
        /// <param name="point">The map point to check.</param>
        public static FastTravelPoint GetFastTravelPointForMapPoint(ClickableComponent point)
        {
            FastTravelPoint fastTravelPointResult = ModEntry.Config.FastTravelPoints.First(t => t.pointId == point.myID);

            fastTravelPointResult.MapName = point.name;

            return(fastTravelPointResult);
        }
コード例 #2
0
        private bool CheckValidationBeforeTeleport(FastTravelPoint targetPoint, out string errorMessage)
        {
            errorMessage = "";
            bool hasValidations = targetPoint.requires != null && targetPoint.requires?.mails.Length > 0;

            if (hasValidations)
            {
                var validateTargetPoint = FastTravelUtils.CheckPointRequiredMails(targetPoint.requires?.mails);
                if (!validateTargetPoint.isValid)
                {
                    errorMessage = translationHelper.Get($"mail.{validateTargetPoint.messageKeyId}");
                    return(false);
                }
            }
            return(true);
        }
コード例 #3
0
        private bool CheckBalancedTransition(FastTravelPoint targetPoint, out string errorMessage)
        {
            errorMessage = "";
            if (!Config.BalancedMode)
            {
                return(true);
            }

            // Block fast travel to calico entirely when balanced
            if (targetPoint.GameLocationIndex == Consts.GameLocationDesertCalico)
            {
                errorMessage = translationHelper.Get("DISABLED").ToString().Replace("{0}", targetPoint.MapName);
                return(false);
            }

            return(true);
        }
コード例 #4
0
        // TODO - Convert inline int/string declarations to a constant class
        private bool CheckBalancedTransition(FastTravelPoint targetPoint, out string errorMessage)
        {
            errorMessage = "";
            if (!Config.BalancedMode)
            {
                return(true);
            }

            // Block fast travel to calico entirely when balanced
            if (targetPoint.GameLocationIndex == 28)
            {
                errorMessage = "Fast-Travel to Calico Desert is disabled in balanced mode!";
                return(false);
            }

            // Block fast travel to the mines unless it has been unlocked.
            if (targetPoint.GameLocationIndex == 25 && !Game1.player.mailReceived.Contains("CF_Mines"))
            {
                errorMessage = "You must unlock the Mines before fast travel is available in balanced mode!";
                return(false);
            }

            return(true);
        }
コード例 #5
0
        /// <summary>Raised after the player presses a button on the keyboard, controller, or mouse.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void OnButtonPressed(object sender, ButtonPressedEventArgs e)
        {
            if (!Context.IsWorldReady)
            {
                return;
            }

            // toggle balanced mode
            if (e.Button == SButton.N)
            {
                Config.BalancedMode = !Config.BalancedMode;
                Game1.showGlobalMessage($"Balanced Mode: {Config.BalancedMode}");
                return;
            }

            // handle map click
            if (e.Button == SButton.MouseLeft && Game1.activeClickableMenu is GameMenu menu && menu.currentTab == GameMenu.mapTab)
            {
                // Get the map page from the menu.
                var mapPage = (Helper.Reflection.GetField <List <IClickableMenu> >(menu, "pages").GetValue()[3]) as MapPage;
                if (mapPage == null)                 // Gotta be safe
                {
                    return;
                }

                // Do balanced behavior.
                // (This is done after getting the map/menu to prevent spamming notifications when the player isn't in the menu)
                if (Config.BalancedMode && Game1.player.mount == null)
                {
                    Game1.showGlobalMessage("You can't fast travel without a horse!");
                    Game1.exitActiveMenu();
                    return;
                }

                int x = (int)e.Cursor.ScreenPixels.X;
                int y = (int)e.Cursor.ScreenPixels.Y;
                foreach (ClickableComponent point in mapPage.points)
                {
                    // If the player isn't hovering over this point, don't worry about anything.
                    if (!point.containsPoint(x, y))
                    {
                        continue;
                    }

                    // Lonely Stone is blocked because it's not an actual place
                    // TODO - Fix the visual bug with Quarry
                    if (point.name == "Lonely Stone")
                    {
                        continue;
                    }

                    // Make sure the location is valid
                    if (!FastTravelUtils.PointExistsInConfig(point))
                    {
                        Monitor.Log($"Failed to find a warp for point [{point.name}]!", LogLevel.Warn);

                        // Right now this closes the map and opens the players bag and doesn't give
                        // the player any information in game about what just happened
                        // so we tell them a warp point wasnt found and close the menu.
                        Game1.showGlobalMessage("No warp point found.");
                        Game1.exitActiveMenu();
                        continue;
                    }

                    // Get the location, and warp the player to it's first warp.
                    GameLocation    targetLocation = FastTravelUtils.GetLocationForMapPoint(point);
                    FastTravelPoint targetPoint    = FastTravelUtils.GetFastTravelPointForMapPoint(point);

                    if (!CheckBalancedTransition(targetPoint, out string errorMessage))
                    {
                        Game1.showGlobalMessage(errorMessage);
                        Game1.exitActiveMenu();
                        return;
                    }

                    // Dismount the player if they're going to calico desert, since the bus glitches with mounts.
                    if (targetPoint.GameLocationIndex == 28 && Game1.player.mount != null)
                    {
                        Game1.player.mount.dismount();
                    }

                    // Warp the player to their location, and exit the map.
                    Game1.warpFarmer(targetPoint.RerouteName ?? targetLocation.Name, targetPoint.SpawnPosition.X, targetPoint.SpawnPosition.Y, false);
                    Game1.exitActiveMenu();

                    // Lets check for warp status and give the player feed back on what happened to the warp.
                    // We are doing this check on a thread because we have to wait until the warp has finished
                    // to check its result.
                    var locationNames = new[] { targetPoint.RerouteName, targetLocation.Name };
                    var t1            = new Thread(CheckIfWarped);
                    t1.Start(locationNames);
                }
            }
        }
コード例 #6
0
        /// <summary>Raised after the player presses a button on the keyboard, controller, or mouse.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void OnButtonPressed(object sender, ButtonPressedEventArgs e)
        {
            if (!Context.IsWorldReady)
            {
                return;
            }

            // toggle balanced mode
            if (e.Button == SButton.N)
            {
                Config.BalancedMode = !Config.BalancedMode;
                string message = translationHelper.Get("BALANCED_MODE");
                Game1.showGlobalMessage($"{message}: {Config.BalancedMode}");
                return;
            }

            // handle map click
            if (e.Button == SButton.MouseLeft && Game1.activeClickableMenu is GameMenu menu && menu.currentTab == GameMenu.mapTab)
            {
                // Get the map page from the menu.
                var mapPage = (Helper.Reflection.GetField <List <IClickableMenu> >(menu, "pages").GetValue()[3]) as MapPage;
                if (mapPage == null)                 // Gotta be safe
                {
                    return;
                }

                // Do balanced behavior.
                // (This is done after getting the map/menu to prevent spamming notifications when the player isn't in the menu)
                if (Config.BalancedMode && Game1.player.mount == null)
                {
                    Game1.showGlobalMessage(translationHelper.Get("BALANCED_MODE_NEED_HORSE"));
                    Game1.exitActiveMenu();
                    return;
                }

                int x = (int)e.Cursor.ScreenPixels.X;
                int y = (int)e.Cursor.ScreenPixels.Y;
                foreach (ClickableComponent point in mapPage.points)
                {
                    // If the player isn't hovering over this point, don't worry about anything.
                    if (!point.containsPoint(x, y))
                    {
                        continue;
                    }

                    if (Config.DebugMode)
                    {
                        StringBuilder reportDebug = new StringBuilder();
                        reportDebug.AppendLine("\n #### FastTravel Debug ####");
                        reportDebug.AppendLine($"   point.myID: {point.myID}");
                        reportDebug.AppendLine($"   point.name: {point.name}");
                        reportDebug.AppendLine($"   point.region: {point.region}");
                        reportDebug.AppendLine(" ###############");
                        this.Monitor.Log(reportDebug.ToString(), LogLevel.Warn);
                    }

                    // Make sure the location is valid
                    if (!FastTravelUtils.PointExistsInConfig(point))
                    {
                        string message = translationHelper.Get("WARP_FAILED").ToString().Replace("{0}", $"[{point.name}]");
                        Monitor.Log(message, LogLevel.Warn);

                        // Right now this closes the map and opens the players bag and doesn't give
                        // the player any information in game about what just happened
                        // so we tell them a warp point wasnt found and close the menu.
                        Game1.showGlobalMessage(translationHelper.Get("WARP_NOT_FOUND"));
                        Game1.exitActiveMenu();
                        continue;
                    }

                    // Get the location, and warp the player to it's first warp.
                    GameLocation    targetLocation = FastTravelUtils.GetLocationForMapPoint(point);
                    FastTravelPoint targetPoint    = FastTravelUtils.GetFastTravelPointForMapPoint(point);

                    if (!CheckBalancedTransition(targetPoint, out string errorMessage))
                    {
                        Game1.showGlobalMessage(errorMessage);
                        Game1.exitActiveMenu();
                        return;
                    }


                    if (!CheckValidationBeforeTeleport(targetPoint, out string errorValidationMessage))
                    {
                        Game1.showGlobalMessage(errorValidationMessage);
                        Game1.exitActiveMenu();
                        return;
                    }

                    // Dismount the player if they're going to calico desert, since the bus glitches with mounts.
                    if (targetPoint.GameLocationIndex == 28 && Game1.player.mount != null)
                    {
                        Game1.player.mount.dismount();
                    }

                    // Warp the player to their location, and exit the map.
                    Game1.warpFarmer(targetPoint.RerouteName ?? targetLocation.Name, targetPoint.SpawnPosition.X, targetPoint.SpawnPosition.Y, false);
                    Game1.exitActiveMenu();

                    // Lets check for warp status and give the player feed back on what happened to the warp.
                    // We are doing this check on a thread because we have to wait until the warp has finished
                    // to check its result.
                    var newThread = new Thread(CheckIfWarped);
                    newThread.Start(targetLocation.Name);
                }
            }
        }