コード例 #1
0
 private void StartDialogDebounced(object sender, EventArgs args)
 {
     RateLimiting.Debounce(nameof(StartDialogDebounced), 1000, () => {
         var tile = Game1.currentLocation?.currentEvent?.getActorByName("Lewis")?.getTileLocation();
         if (tile != null)
         {
             Vector2 mousePosition = tile.Value.ConvertTileToMouseCoords();
             var mouseState        = new MouseState(Convert.ToInt32(mousePosition.X), Convert.ToInt32(mousePosition.Y), 0, ButtonState.Released, ButtonState.Released, ButtonState.Pressed, ButtonState.Released, ButtonState.Released);
             Game1.setMousePosition(new Point(Convert.ToInt32(mousePosition.X), Convert.ToInt32(mousePosition.Y)));
             Game1.pressActionButton(new KeyboardState(), mouseState, new GamePadState());
             ViewportChanged -= StartDialogDebounced;
         }
     });
 }
コード例 #2
0
        //todo: factor out this logic from main and add wentToFestival to mod state
        //TODO: add trace log
        public void AFKHostingRoutine()
        {
            //TODO: need to cancel waiting for player dialog if other players have quit
            //should be able to ignore events and cutscenes since that should be handled by Context.PlayerCanMove
            //TODO: cancel cutscenens when they occur
            //TODO: move player outside house in morning to trigger any cutscenes that might occur

            //TODO: pause game if no players are online
#if DEBUG
            if (!(IsThisPlayerFree && Context.IsMultiplayer))
            {
                return;
            }
#else
            if (!(IsThisPlayerFree && RemotePlayersAreOnline && Context.IsMultiplayer))
            {
                return;
            }
#endif
            //teleport player to festival when its ready if they have not been yet
            if (IsFestivalDay && IsFestivalReady && !IsThisPlayerAtFestival && !State.WentToTodaysFestival)
            {
                var festivalLocation = WhereIsFestival();
                if (festivalLocation != Location.None)
                {
                    void DebouncedTeleportToNPC(object sender, EventArgs args)
                    {
                        RateLimiting.Debounce(nameof(DebouncedTeleportToNPC), 1000, () =>
                        {
                            ViewportChanged -= DebouncedTeleportToNPC;
                            var testDialog   = new NPCDialogAutomater("Lewis", true, Monitor, Helper,
                                                                      new DialogAction[] {
                                new DialogAction {
                                    DialogActionType = DialogActionType.Start
                                },
                                new DialogAction {
                                    DialogActionType = DialogActionType.Next
                                },
                                new DialogAction {
                                    DialogActionType = DialogActionType.Next
                                },
                                new DialogAction {
                                    DialogActionType = DialogActionType.Start
                                },
                                new DialogAction {
                                    DialogActionType = DialogActionType.Answer,
                                    AnswerIndex      = 0
                                }
                            });

                            ViewportChanged += DebouncedRunActions;
                            testDialog.TeleportToNPC();

                            void DebouncedRunActions(object s, EventArgs e)
                            {
                                RateLimiting.Debounce(nameof(DebouncedRunActions), 1000, () =>
                                {
                                    ViewportChanged -= DebouncedRunActions;
                                    testDialog.RunActions();
                                });
                            }
                        });
                    }

                    ViewportChanged += DebouncedTeleportToNPC;
                    TeleportThisPlayer(festivalLocation, 0, 0);
                    return;
                }
            }

            //should not have to handle where player is waiting for other players to enter festival
            //as that should be taken care of by StardewAPI.IsThisPlayerFree
            if (IsFestivalDay && IsThisPlayerAtFestival && !State.WentToTodaysFestival)
            {
                //var tile = Game1.currentLocation?.currentEvent?.getActorByName("Lewis")?.getTileLocation();
                //if (!tile.HasValue) return;
                //Game1.player.setTileLocation(new Vector2(tile.Value.X, tile.Value.Y+1));

                State.With(s => s.WentToTodaysFestival, true);
                //Game1.player.team.SetLocalReady("festivalEnd", true);
                //Game1.activeClickableMenu = (IClickableMenu)new ReadyCheckDialog("festivalEnd", true, new ConfirmationDialog.behavior(Game1.currentLocation.currentEvent.forceEndFestival), (ConfirmationDialog.behavior)null);
            }

            //this should run once to trigger the festival leave waiting screen which should teleport to farm
            //(or just start here if there is no festival) then it will run again to move player to bed if they are not in it
            //and one more time to trigger wait for sleep
            //TODO: test how this is affected by time change when festival ends
            if (!IsFestivalDay || (IsFestivalDay && !IsThisPlayerAtFestival && State.WentToTodaysFestival))
            {
                //TODO: this doesnt work when at a festival, tries to tele repeatedly but nothing happens
                //test if this waits until the teleport is finished
                if (!IsThisPlayerInBed)
                {
                    TeleportThisPlayerToBed();
                }
                else
                {
                    StartSleepForThisPlayer(Helper);
                }
            }

            //reset festival status on next day
            //TODO: will this work for night market?
            if (!IsFestivalDay && State.WentToTodaysFestival)
            {
                State.With(s => s.WentToTodaysFestival, false);
            }

            //if (Game1.activeClickableMenu is DialogueBox dialogueBox)
            //{
            //    var isQuestion = Helper.Reflection.GetField<bool>(dialogueBox, "isQuestion").GetValue();
            //    if(isQuestion)
            //    {
            //        //TODO: auto answer questions based on a json event/dialog/person configuration file
            //        return;
            //    }
            //    CloseDialogOrMenu();
            //}
        }