Example #1
0
        /// <summary>
        /// Indicates if a given world is being played at present (at least 1 active player).
        /// </summary>
        /// <returns></returns>
        public static bool IsWorldBeingPlayed()
        {
            var mymod = ModHelpersMod.Instance;

            if (Main.netMode != 2 && !Main.dedServ)
            {
                if (!mymod.LoadHelpers.IsClientPlaying_Hackish)
                {
                    return(false);
                }

                var myplayer = (ModHelpersPlayer)TmlHelpers.SafelyGetModPlayer(Main.LocalPlayer, ModHelpersMod.Instance, "ModHelpersPlayer");
                return(myplayer.Logic.IsSynced);
            }
            else
            {
                if (!LoadHelpers.IsWorldLoaded())
                {
                    return(false);
                }
                if (!mymod.LoadHelpers.HasServerBegunHavingPlayers_Hackish)
                {
                    return(false);
                }

                return(true);
            }
        }
Example #2
0
        /// <summary>
        /// Indicates if a given world is being played (at least 1 active player), and that player has finished all of their
        /// own in-game "loading" stuff (attempts to account for any Terraria/mod hidden loading behaviors).
        /// </summary>
        /// <returns></returns>
        public static bool IsWorldSafelyBeingPlayed()
        {
            var mymod = ModHelpersMod.Instance;

            if (mymod.LoadHelpers == null)
            {
                return(false);
            }

            bool notSafelyPlayed = mymod.LoadHelpers.WorldStartupDelay >= (60 * 2);

            if (ModHelpersMod.Config.DebugModeHelpersInfo && !notSafelyPlayed)
            {
                if (Main.netMode != 2 && !Main.dedServ)
                {
                    var myplayer = (ModHelpersPlayer)TmlHelpers.SafelyGetModPlayer(Main.LocalPlayer, mymod, "ModHelpersPlayer");

                    LogHelpers.LogOnce(DebugHelpers.GetCurrentContext(2) + " - IsWorldSafelyBeingPlayed - "
                                       + "StartupDelay: " + !(mymod.LoadHelpers.WorldStartupDelay < (60 * 2))
                                       + ", IsClientPlaying_Hackish: " + mymod.LoadHelpers.IsClientPlaying_Hackish + " (true?)"
                                       + ", IsSynced: " + (myplayer?.Logic.IsSynced.ToString() ?? "null") + " (true?)");
                }
                else
                {
                    var myworld = ModContent.GetInstance <ModHelpersWorld>();
                    LogHelpers.LogOnce(DebugHelpers.GetCurrentContext(2) + " - IsWorldSafelyBeingPlayed - "
                                       + "StartupDelay: " + !(mymod.LoadHelpers.WorldStartupDelay < (60 * 2))
                                       + ", IsModLoaded(): " + LoadHelpers.IsModLoaded() + " (true?)"
                                       + ", HasObsoleteId: " + myworld.HasObsoleteId + " (false?)"
                                       + ", HasServerBegunHavingPlayers_Hackish: " + mymod.LoadHelpers.HasServerBegunHavingPlayers_Hackish + " (true?)"
                                       + ", HasSetupContent: " + mymod.HasSetupContent + " (true?)"
                                       + ", HasAddedRecipeGroups: " + mymod.HasAddedRecipeGroups + " (true?)"
                                       + ", HasAddedRecipes: " + mymod.HasAddedRecipes + " (true?)");
                }
            }
            return(notSafelyPlayed);
        }
Example #3
0
 /// <summary>
 /// Provides an alternative to `Player.GetModPlayer(...)` to ensure the given player is properly loaded. Addresses some
 /// confusing types of errors.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="player"></param>
 /// <returns></returns>
 public static T SafelyGetModPlayer <T>(Player player) where T : ModPlayer
 {
     TmlHelpers.ForceSetupPlayer(player);
     return(player.GetModPlayer <T>());
 }
Example #4
0
        ////

        /// <summary>
        /// Provides an alternative to `Player.GetModPlayer(...)` to ensure the given player is properly loaded. Addresses some
        /// confusing types of errors.
        /// </summary>
        /// <param name="player"></param>
        /// <param name="mod"></param>
        /// <param name="modPlayerName"></param>
        /// <returns></returns>
        public static ModPlayer SafelyGetModPlayer(Player player, Mod mod, string modPlayerName)                // Solely for Main.LocalPlayer?
        {
            TmlHelpers.ForceSetupPlayer(player);
            return(player.GetModPlayer(mod, modPlayerName));
        }