コード例 #1
0
ファイル: ModEntry.cs プロジェクト: somnomania/smapi-mod-dump
        public static bool passOutFromTired_Prefix(SObject __instance, Farmer who)
        {
            try
            {
                if (ModEntry.config.reduceEnergyWhenPassingOut)
                {
                    if (!who.IsLocalPlayer)
                    {
                        modEntry.Monitor.Log($"{who.displayName} is not local player. Stop.", LogLevel.Trace);
                        return(true);
                    }

                    modEntry.Monitor.Log($"Energy loss on passout is enabled.", LogLevel.Trace);

                    int percentToTake = ModEntry.config.percentEnergyLostWhenPassingOut;

                    float currentStamina = who.Stamina;

                    int staminaToTake = (int)Math.Floor(who.Stamina * (100 / percentToTake));

                    if (currentStamina - staminaToTake < 2.0)
                    {
                        staminaToTake = (int)currentStamina - 2;
                    }

                    modEntry.Monitor.Log($"Remove {staminaToTake} energy.", LogLevel.Trace);

                    who.Stamina -= staminaToTake;
                }

                GameLocation passOutLocation = Game1.currentLocation;
                modEntry.Monitor.Log($"Game Location for {who.displayName} is {passOutLocation.Name}", LogLevel.Trace);
                //turn this into a configurable list of locations.
                if (letModHandlePassout(who, passOutLocation))
                {
                    modEntry.Monitor.Log($"{who.displayName} in mod controlled location. Game Location is {passOutLocation.Name}", LogLevel.Trace);
                    //we need to handle most of the passing out logic again here so we can deal with the money and messaging
                    //stuff in the middle. Sad sad panda.
                    if (!who.IsLocalPlayer)
                    {
                        modEntry.Monitor.Log($"{who.displayName} is not local player. Stop.", LogLevel.Trace);
                        return(true);
                    }

                    modEntry.Monitor.Log($"{who.displayName} is mounted. Dismount.", LogLevel.Trace);

                    if (who.isRidingHorse())
                    {
                        who.mount.dismount(false);
                    }

                    if (Game1.activeClickableMenu != null)
                    {
                        Game1.activeClickableMenu.emergencyShutDown();
                        Game1.exitActiveMenu();
                    }

                    who.completelyStopAnimatingOrDoingAction();
                    if ((bool)((NetFieldBase <bool, NetBool>)who.bathingClothes))
                    {
                        who.changeOutOfSwimSuit();
                    }

                    who.swimming.Value = false;
                    who.CanMove        = false;
                    if (who == Game1.player && (FarmerTeam.SleepAnnounceModes)((NetFieldBase <FarmerTeam.SleepAnnounceModes, NetEnum <FarmerTeam.SleepAnnounceModes> >)Game1.player.team.sleepAnnounceMode) != FarmerTeam.SleepAnnounceModes.Off)
                    {
                        string str = "PassedOut";
                        int    num = 0;
                        for (int index = 0; index < 2; ++index)
                        {
                            if (Game1.random.NextDouble() < 0.25)
                            {
                                ++num;
                            }
                        }

                        if (mHelper != null)
                        {
                            String message = who.displayName + " has passed out.";
                            if (Game1.IsMultiplayer)
                            {
                                mHelper.Multiplayer.SendMessage <String>(message, "PassoutMessage");
                            }
                        }
                    }

                    Vector2 bed = Utility.PointToVector2(Utility.getHomeOfFarmer(Game1.player).getBedSpot()) * 64f;
                    bed.X -= 64f;

                    LocationRequest.Callback callback = (LocationRequest.Callback)(() =>
                    {
                        who.Position = bed;
                        who.currentLocation.lastTouchActionLocation = bed;
                        if (!Game1.IsMultiplayer || Game1.timeOfDay >= 2600)
                        {
                            Game1.PassOutNewDay();
                        }
                        Game1.changeMusicTrack("none", false, Game1.MusicContext.Default);

                        if (ModEntry.config.enableRobberyOnFarm || ModEntry.config.enableRobberyOnNonFarmSafeLocations)
                        {
                            modEntry.Monitor.Log($"Robbery enabled. Check for robbery.", LogLevel.Trace);
                            if ((ModEntry.config.enableRobberyOnFarm && isFarmLocation(passOutLocation)) ||
                                (ModEntry.config.enableRobberyOnNonFarmSafeLocations && !isFarmLocation(passOutLocation)))
                            {
                                //eligible to be robbed
                                Random random1 = new Random((int)Game1.uniqueIDForThisGame + (int)Game1.stats.DaysPlayed + (int)Game1.player.UniqueMultiplayerID);

                                int robbedRoll = random1.Next(100);

                                modEntry.Monitor.Log($"Robbery roll:. {robbedRoll}", LogLevel.Trace);

                                if (robbedRoll < ModEntry.config.percentRobberyChance)
                                {
                                    //we got robbed, sad sad panda.
                                    int percentTaken = random1.Next(ModEntry.config.percentFundsLostMinimumInRobbery, ModEntry.config.percentFundsLostMaximumInRobbery);
                                    int amountTaken  = who.Money * (percentTaken / 100);

                                    List <int> list = new List <int>();
                                    list.Add(2); //the willy letter.
                                    list.Add(4); //the marlon letter.

                                    int letterNumber = Utility.GetRandom <int>(list, random1);

                                    string letter = "passedOut" + (object)letterNumber + " " + (object)amountTaken;
                                    modEntry.Monitor.Log($"Got robbed send letter: {letter}", LogLevel.Trace);
                                    if (amountTaken > 0)
                                    {
                                        who.Money -= amountTaken;
                                        who.mailForTomorrow.Add(letter);
                                    }
                                }
                            }
                        }
                    });

                    if (!(bool)((NetFieldBase <bool, NetBool>)who.isInBed) || who.currentLocation != null && !who.currentLocation.Equals((object)who.homeLocation.Value))
                    {
                        modEntry.Monitor.Log($"{who.displayName} is not in bed. Send home.", LogLevel.Trace);
                        LocationRequest locationRequest = Game1.getLocationRequest(who.homeLocation.Value, false);
                        Game1.warpFarmer(locationRequest, (int)bed.X / 64, (int)bed.Y / 64, 2);
                        locationRequest.OnWarp += callback;
                        who.FarmerSprite.setCurrentSingleFrame(5, (short)3000, false, false);
                        who.FarmerSprite.PauseForSingleAnimation = true;
                    }
                    else
                    {
                        callback();
                    }

                    modEntry.Monitor.Log($"Skip regular passout behavior.", LogLevel.Trace);
                    return(false);
                }

                modEntry.Monitor.Log($"Execute standard passout behavior.", LogLevel.Trace);
                return(true);
            }
            catch (Exception ex)
            {
                modEntry.Monitor.Log($"Failed in {nameof(passOutFromTired_Prefix)}:\n{ex}", LogLevel.Error);
                return(true); // run original logic
            }
        }
コード例 #2
0
        /// <summary>
        /// Used to patch
        /// </summary>
        /// <returns></returns>
        private static bool Prefix(Farmer who)
        {
            if (!who.IsLocalPlayer)
            {
                return(false);
            }
            if (who.isRidingHorse())
            {
                who.mount.dismount();
            }
            if (Game1.activeClickableMenu != null)
            {
                Game1.activeClickableMenu.emergencyShutDown();
                Game1.exitActiveMenu();
            }
            who.completelyStopAnimatingOrDoingAction();
            if (who.bathingClothes.Value)
            {
                who.changeOutOfSwimSuit();
            }
            who.swimming.Value = false;
            who.CanMove        = false;
            GameLocation passOutLocation = Game1.currentLocation;
            Vector2      bed             = Utility.PointToVector2(Utility.getHomeOfFarmer(Game1.player).getBedSpot()) * 64f;

            bed.X -= 64f;
            LocationRequest.Callback callback = (LocationRequest.Callback)(() =>
            {
                who.Position = bed;
                who.currentLocation.lastTouchActionLocation = bed;
                if (!Game1.IsMultiplayer || Game1.timeOfDay >= 2600)
                {
                    Game1.PassOutNewDay();
                }
                Game1.changeMusicTrack("none");
                if (passOutLocation is FarmHouse || passOutLocation is Cellar)
                {
                    return;
                }

                // Check if an NPC has piked up the player or if the game should handle the passout
                if (!ModEntry.HasPassoutBeenHandled)
                {
                    int num = Math.Min(1000, who.Money / 10);
                    who.Money -= num;
                    who.mailForTomorrow.Add("passedOut " + (object)num);
                }
            });
            if (!who.isInBed.Value)
            {
                LocationRequest locationRequest = Game1.getLocationRequest(who.homeLocation.Value, false);
                Game1.warpFarmer(locationRequest, (int)bed.X / 64, (int)bed.Y / 64, 2);
                locationRequest.OnWarp += callback;
                who.FarmerSprite.setCurrentSingleFrame(5, (short)3000, false, false);
                who.FarmerSprite.PauseForSingleAnimation = true;
            }
            else
            {
                callback();
            }

            return(false);
        }