Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
                }
            }
        }
Ejemplo n.º 3
0
        private void ControlEvents_MouseChanged(object sender, EventArgsMouseStateChanged e)
        {
            // If the world isn't ready, or the player didn't left click, we have nothing to work with.
            if (!Context.IsWorldReady || e.NewState.LeftButton != ButtonState.Pressed)
            {
                return;
            }

            // Create a reference to the current menu, and make sure it isn't null.
            var menu = (Game1.activeClickableMenu as GameMenu);

            if (menu == null || menu.currentTab != GameMenu.mapTab) // Also make sure it's on the right tab(Map)
            {
                return;
            }

            // 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 = Game1.getMouseX();
            int y = Game1.getMouseY();

            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
                // Quarry is blocked because it's broken currently.
                // 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.
                var location        = FastTravelUtils.GetLocationForMapPoint(point);
                var fastTravelPoint = FastTravelUtils.GetFastTravelPointForMapPoint(point);

                // If the player is in balanced mode, block warping to calico altogether.
                if (Config.BalancedMode && fastTravelPoint.GameLocationIndex == 28)
                {
                    Game1.showGlobalMessage("Fast-Travel to Calico Desert is disabled in balanced mode!");
                    Game1.exitActiveMenu();
                    return;
                }

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

                // Warp the player to their location, and exit the map.
                Game1.warpFarmer(fastTravelPoint.RerouteName == null ? location.Name : fastTravelPoint.RerouteName, fastTravelPoint.SpawnPosition.X, fastTravelPoint.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 untill the warp has finished
                // to check its result.
                var locationNames = new String[] { fastTravelPoint.RerouteName, location.Name };
                var t1            = new Thread(new ParameterizedThreadStart(CheckIfWarped));
                t1.Start(locationNames);
            }
        }
Ejemplo n.º 4
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);
                }
            }
        }