Example #1
0
        ////////////////

        public override void PostDrawInInventory(Item item, SpriteBatch sb, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale)
        {
            if (item == null || item.IsAir)
            {
                return;
            }

            var mymod   = (NihilismMod)this.mod;
            var myworld = ModContent.GetInstance <NihilismWorld>();

            if (myworld.Logic == null)
            {
                LogLibraries.WarnOnce("Logic not loaded.");
                return;
            }

            if (!myworld.Logic.AreItemFiltersEnabled())
            {
                return;
            }

            bool _;

            if (!myworld.Logic.DataAccess.IsItemEnabled(item, out _, out _))
            {
                float posX  = position.X + (((float)frame.Width / 2f) * scale) - (((float)mymod.DisabledItemTex.Width / 2f) * scale);
                float posY  = position.Y + (((float)frame.Height / 2f) * scale) - (((float)mymod.DisabledItemTex.Height / 2f) * scale);
                var   pos   = new Vector2(posX, posY);
                var   rect  = new Rectangle(0, 0, mymod.DisabledItemTex.Width, mymod.DisabledItemTex.Height);
                var   color = Color.White * 0.625f;

                sb.Draw(mymod.DisabledItemTex, pos, rect, color, 0f, Vector2.Zero, scale, SpriteEffects.None, 0f);
            }
        }
        ////////////////

        /// <summary>
        /// Loads a binary custom data JSON file of a given mod.
        /// </summary>
        /// <typeparam name="T">Object type to deserialize from JSON into.</typeparam>
        /// <param name="mod"></param>
        /// <param name="fileNameWithExt"></param>
        /// <param name="jsonSettings"></param>
        /// <returns></returns>
        public static T LoadBinaryJson <T>(Mod mod, string fileNameWithExt, JsonSerializerSettings jsonSettings)
            where T : class
        {
            try {
                ModCustomDataFileLibraries.PrepareDir(mod);

                string fullPath  = ModCustomDataFileLibraries.GetFullPath(mod, fileNameWithExt);
                byte[] dataBytes = FileLibraries.LoadBinaryFile(fullPath, false);
                if (dataBytes == null)
                {
                    return(null);
                }

                string dataJson = System.Text.Encoding.UTF8.GetString(dataBytes);

                if (dataBytes != null)
                {
                    return(JsonConvert.DeserializeObject <T>(dataJson, jsonSettings));
                }
                else
                {
                    LogLibraries.Alert("No json file " + fileNameWithExt + ".");
                    return(null);
                }
            } catch (IOException e) {
                string fullDir = ModCustomDataFileLibraries.GetFullDirectoryPath(mod);
                LogLibraries.Warn("Failed to load binary file " + fileNameWithExt + " at " + fullDir + " - " + e.ToString());
                throw new IOException("Failed to load binary file " + fileNameWithExt + " at " + fullDir, e);
            } catch (Exception e) {
                throw new ModLibsException("From " + fileNameWithExt + " (" + typeof(T).Name + ")", e);
            }
        }
        /// <summary>
        /// Erases a given player file.
        /// </summary>
        /// <param name="data"></param>
        public static void ErasePlayer(PlayerFileData data)
        {
            try {
                FileUtilities.Delete(data.Path, data.IsCloudSave);
                FileUtilities.Delete(data.Path + ".bak", data.IsCloudSave);

                bool   cloudSave = data.IsCloudSave;
                string path      = Path.ChangeExtension(data.Path, ".tplr");

                FileUtilities.Delete(path, cloudSave);
                FileUtilities.Delete(path + ".bak", cloudSave);

                string dirPath = data.Path.Substring(0, data.Path.Length - 4);

                if (Directory.Exists(dirPath))
                {
                    Directory.Delete(dirPath, true);
                }

                Main.LoadPlayers();

                LogLibraries.Log("Player " + data.Name + " deleted.");
            } catch (Exception e) {
                LogLibraries.Log("PlayerFileLibraries.ErasePlayer - Path: " + data.Path + " - " + e.ToString());
            }
        }
        public override bool ConsumeItem(Player player)
        {
            int tileX = (int)player.Center.X >> 4;
            int tileY = (int)player.position.Y >> 4;

            ISet <(int, int)> _;
            bool canErect = HouseFramingKitItem.Validate(ref tileX, ref tileY, out _);

            if (canErect)
            {
                if (Main.netMode == NetmodeID.SinglePlayer)
                {
                    HouseFramingKitItem.MakeHouseFrame(tileX, tileY);
                }
                else if (Main.netMode == NetmodeID.MultiplayerClient)
                {
                    FramingKitProtocol.SendToServer(tileX, tileY);
                    return(true);
                }
                else if (Main.netMode == NetmodeID.Server)
                {
                    LogLibraries.Alert("Server?");
                }
            }
            else
            {
                Main.NewText("Not enough open space.", Color.Yellow);
            }

            return(canErect);
        }
        /// <summary>
        /// Gets table of npc types to their respective banner item types.
        /// </summary>
        /// <returns></returns>
        public static IDictionary <int, int> GetNpcToBannerItemTypes()
        {
            IDictionary <int, int> npcTypesToBannerItemTypes = new Dictionary <int, int>();

            for (int npcType = 0; npcType < Main.npcTexture.Length; npcType++)
            {
                int bannerType = Item.NPCtoBanner(npcType);
                if (bannerType == 0)
                {
                    continue;
                }

                int bannerItemType = Item.BannerToItem(bannerType);
                if (bannerItemType >= Main.itemTexture.Length || bannerItemType <= 0)
                {
                    continue;
                }

                try {
                    Item item = new Item();
                    item.SetDefaults(bannerItemType);
                } catch (Exception) {
                    LogLibraries.Log("Could not find banner of item id " + bannerItemType + " for npc id " + npcType);
                    continue;
                }

                npcTypesToBannerItemTypes[npcType] = bannerItemType;
            }

            return(npcTypesToBannerItemTypes);
        }
        /// <summary>
        /// Loads a custom data JSON file of a given mod.
        /// </summary>
        /// <typeparam name="T">Object type to deserialize from JSON into.</typeparam>
        /// <param name="mod"></param>
        /// <param name="fileNameNoExt"></param>
        /// <param name="jsonSettings"></param>
        /// <returns></returns>
        public static T LoadJson <T>(Mod mod, string fileNameNoExt, JsonSerializerSettings jsonSettings)
            where T : class
        {
            try {
                ModCustomDataFileLibraries.PrepareDir(mod);

                string fullPath = ModCustomDataFileLibraries.GetFullPath(mod, fileNameNoExt + ".json");
                string dataStr  = FileLibraries.LoadTextFile(fullPath, false);

                if (dataStr != null)
                {
                    return(JsonConvert.DeserializeObject <T>(dataStr, jsonSettings));
                }
                else
                {
                    LogLibraries.Alert("No json file " + fileNameNoExt + ".");
                    return(null);
                }
            } catch (IOException e) {
                string fullDir = ModCustomDataFileLibraries.GetFullDirectoryPath(mod);
                LogLibraries.Warn("Failed to load json file " + fileNameNoExt + " at " + fullDir + " - " + e.ToString());
                throw new IOException("Failed to load json file " + fileNameNoExt + " at " + fullDir, e);
            } catch (Exception e) {
                throw new ModLibsException("From " + fileNameNoExt + " (" + typeof(T).Name + ")", e);
            }
        }
Example #7
0
        /// <summary>
        /// Saves a custom mod data JSON file.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="mod"></param>
        /// <param name="fileNameNoExt"></param>
        /// <param name="jsonSettings"></param>
        /// <param name="overrides">Replaces any existing files.</param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static bool SaveAsJson <T>(
            Mod mod,
            string fileNameNoExt,
            JsonSerializerSettings jsonSettings,
            bool overrides, T data)
            where T : class
        {
            string relDir = ModCustomDataFileLibraries.GetRelativeDirectoryPath(mod);

            if (data == null)
            {
                LogLibraries.Warn("Failed to save json file " + fileNameNoExt + " at " + relDir + " - Data is null.");
                return(false);
            }

            try {
                ModCustomDataFileLibraries.PrepareDir(mod);

                string fullPath = ModCustomDataFileLibraries.GetFullPath(mod, fileNameNoExt + ".json");
                string dataJson = JsonConvert.SerializeObject(data, jsonSettings);

                return(FileLibraries.SaveTextFile(dataJson, fullPath, false, !overrides));
            } catch (IOException e) {
                LogLibraries.Warn("Failed to save json file " + fileNameNoExt + " at " + relDir + " - " + e.ToString());
                throw new IOException("Failed to save json file " + fileNameNoExt + " at " + relDir, e);
            }
        }
Example #8
0
        ////////////////

        public override void ProcessTriggers(TriggersSet triggersSet)
        {
            var mymod = ModControlPanelMod.Instance;
            var cp    = ModContent.GetInstance <UIControlPanel>();

            try {
                if (mymod.ControlPanelHotkey != null && mymod.ControlPanelHotkey.JustPressed)
                {
                    if (cp != null)
                    {
                        if (cp.IsOpen)
                        {
                            ControlPanelTabs.CloseDialog();
                        }
                        else
                        {
                            ControlPanelTabs.OpenTab(UIControlPanel.DefaultTabName);
                        }
                    }
                }
            } catch (Exception e) {
                LogLibraries.Warn("(1) - " + e.ToString());
                return;
            }
        }
Example #9
0
        ////////////////

        private static void RemoveWingSlotProperty(ModPlayer mywingplayer, string propName)
        {
            object wingEquipSlot;

            if (ReflectionLibraries.Get(mywingplayer, propName, out wingEquipSlot) && wingEquipSlot != null)
            {
                Item wingItem;

                if (ReflectionLibraries.Get(wingEquipSlot, "Item", out wingItem))
                {
                    if (wingItem != null && !wingItem.IsAir)
                    {
                        ReflectionLibraries.Set(wingEquipSlot, "Item", new Item());
                        ReflectionLibraries.Set(mywingplayer, propName, wingEquipSlot);
                    }
                }
                else
                {
                    LogLibraries.Warn("Invalid Wing Mod item slot for " + propName);
                }
            }
            else
            {
                LogLibraries.Log("No Wing Mod item slot recognized for " + propName);
            }
        }
        ////////////////

        /// <summary>
        /// Makes a given town NPC leave, optionally alerting the world of their departure.
        /// </summary>
        /// <param name="npc"></param>
        /// <param name="announce"></param>
        public static void Leave(NPC npc, bool announce = true)
        {
            if (Main.netMode == NetmodeID.MultiplayerClient)
            {
                LogLibraries.Warn("NPCTownLibraries.Leave() called on client.");
            }

            int whoami = npc.whoAmI;

            if (announce)
            {
                string msg = Main.npc[whoami].GivenName + " the " + Main.npc[whoami].TypeName + " " + Lang.misc[35];

                if (Main.netMode == NetmodeID.SinglePlayer)
                {
                    Main.NewText(msg, 50, 125, 255, false);
                }
                else if (Main.netMode == NetmodeID.MultiplayerClient)
                {
                    //NetMessage.SendChatMessageFromClient( new ChatMessage( msg ) );
                }
                else if (Main.netMode == NetmodeID.Server)
                {
                    NetMessage.BroadcastChatMessage(NetworkText.FromLiteral(msg), new Color(255, 50, 125));
                    //NetMessage.SendData( MessageID.ChatText, -1, -1, NetworkText.FromLiteral( msg ), 255, 50f, 125f, 255f, 0, 0, 0 );
                }
            }
            Main.npc[whoami].active  = false;
            Main.npc[whoami].netSkip = -1;
            Main.npc[whoami].life    = 0;
            NetMessage.SendData(MessageID.SyncNPC, -1, -1, null, whoami, 0f, 0f, 0f, 0, 0, 0);
        }
Example #11
0
        public void OutputFormattedFilterData()
        {
            Main.NewText("Is nihilated: " + this.Filters.IsActive);
            Main.NewText("Items BL: "
                         + this.Filters.ItemBlacklist.Count + "+"
                         + this.Filters.ItemGroupBlacklist.Count + ", WL count: "
                         + this.Filters.ItemWhitelist.Count + "+"
                         + this.Filters.ItemGroupWhitelist.Count);
            Main.NewText("Recipes BL: "
                         + this.Filters.RecipeBlacklist.Count + "+"
                         + this.Filters.RecipeGroupBlacklist.Count + ", WL count: "
                         + this.Filters.RecipeWhitelist.Count + "+"
                         + this.Filters.RecipeGroupWhitelist.Count);
            Main.NewText("NPCs BL: "
                         + this.Filters.NpcBlacklist.Count + "+"
                         + this.Filters.NpcGroupBlacklist.Count + ", WL count: "
                         + this.Filters.NpcWhitelist.Count + "+"
                         + this.Filters.NpcGroupWhitelist.Count);
            Main.NewText("Loot BL: "
                         + this.Filters.NpcLootGroupBlacklist.Count + "+"
                         + this.Filters.NpcLootBlacklist.Count + ", WL count: "
                         + this.Filters.NpcLootGroupWhitelist.Count + "+"
                         + this.Filters.NpcLootWhitelist.Count);

            LogLibraries.Log(string.Join("\n", this.GetFormattedFilterData()));
        }
Example #12
0
        ////////////////

        /// <summary>
        /// Saves a custom mod data JSON file in binary form.
        /// </summary>
        /// <param name="mod"></param>
        /// <param name="fileNameWithExt"></param>
        /// <param name="overrides">Replaces any existing files.</param>
        /// <param name="data"></param>
        public static void SaveAsBinary(
            Mod mod,
            string fileNameWithExt,
            bool overrides,
            byte[] data)
        {
            if (data == null)
            {
                string fullPath = ModCustomDataFileLibraries.GetFullPath(mod, fileNameWithExt);
                LogLibraries.Warn("Failed to save binary file " + fullPath + " - Data is null.");
                return;
            }

            try {
                ModCustomDataFileLibraries.PrepareDir(mod);

                string fullPath = ModCustomDataFileLibraries.GetFullPath(mod, fileNameWithExt);

                FileLibraries.SaveBinaryFile(data, fullPath, false, !overrides);
            } catch (IOException e) {
                string fullDir = ModCustomDataFileLibraries.GetFullDirectoryPath(mod);
                LogLibraries.Warn("Failed to save binary file " + fileNameWithExt + " at " + fullDir + " - " + e.ToString());
                throw new IOException("Failed to save binary file " + fileNameWithExt + " at " + fullDir, e);
            }
        }
Example #13
0
        ////

        public override void ReceiveOnServer(int fromWho)
        {
            ISet <(ushort TileX, ushort TileY)> innerHouseSpace, fullHouseSpace;
            int floorX, floorY;

            HouseViabilityState state = HouseFurnishingKitItem.IsValidHouse(
                this.TileX,
                this.TileY,
                out innerHouseSpace,
                out fullHouseSpace,
                out floorX,
                out floorY
                );

            if (state == HouseViabilityState.Good)
            {
                bool aborted = HouseFurnishingKitItem.FurnishHouseFull(
                    Main.player[this.PlayerWho],
                    this.TileX,
                    this.TileY,
                    innerHouseSpace,
                    fullHouseSpace,
                    floorX,
                    floorY
                    );
            }
            else
            {
                LogLibraries.Alert("Could not furnish house");
            }
        }
Example #14
0
        /// <summary>
        /// Gets the mod name of a mod-representing menu UI (sometimes needs the previous UI for context).
        /// </summary>
        /// <param name="prevUi"></param>
        /// <param name="currUi"></param>
        /// <returns></returns>
        public static string GetModName(UIState prevUi, UIState currUi)
        {
            // = uiType.GetField( "_localMod", BindingFlags.NonPublic | BindingFlags.Instance );
            object localmod;                    // <- is a LocalMod class

            if (!ReflectionLibraries.Get(currUi, "_localMod", out localmod))
            {
                LogLibraries.Warn("No '_localMod' field in " + currUi.GetType());
                return(null);
            }

            if (localmod != null)
            {
                return(ModMenuLibraries.GetLocalMod(localmod).name);
            }
            else
            {
                if (prevUi?.GetType().Name == "UIModBrowser")
                {
                    return(ModMenuLibraries.GetSelectedModBrowserModName(prevUi));
                }
            }

            LogLibraries.Alert("No mod loaded.");
            return(null);
        }
Example #15
0
        /// <summary>
        /// Gets the recommended element to add content to an "inner" container element of a given menu UI.
        /// </summary>
        /// <param name="uiInnerContainer"></param>
        /// <returns></returns>
        public static UIElement GetMenuContainerInsertPoint(UIElement uiInnerContainer)
        {
            List <UIElement> uiContainerElems;

            if (!ReflectionLibraries.Get(uiInnerContainer, "Elements", out uiContainerElems) ||
                uiContainerElems == null)
            {
                LogLibraries.AlertOnce("No Elements for " + uiInnerContainer?.GetType().Name);
                return(null);
            }

            //Type uiContainerType = uiInnerContainer.GetType();
            //FieldInfo uiContainerElemsField = uiContainerType.GetField( "Elements", BindingFlags.Instance | BindingFlags.NonPublic );
            //List<UIElement> uiContainerElems = (List<UIElement>)uiContainerElemsField.GetValue( uiInnerContainer );

            for (int i = 0; i < uiContainerElems.Count; i++)
            {
                if (uiContainerElems[i] is UIElement &&
                    !(uiContainerElems[i] is UIList) &&
                    !(uiContainerElems[i] is UIScrollbar))
                {
                    return(uiContainerElems[i]);
                }
            }

            LogLibraries.AlertOnce("Not found");
            return(null);
        }
Example #16
0
        public override void ModifyInterfaceLayers(List <GameInterfaceLayer> layers)
        {
            int idx = layers.FindIndex(layer => layer.Name.Equals("Vanilla: Mouse Text"));

            if (idx == -1)
            {
                return;
            }

            //

            GameInterfaceDrawMethod debugDrawCallback = () => {
                try {
                    ModContent.GetInstance <PlayerMessages>().Draw(Main.spriteBatch);
                } catch (Exception e) {
                    LogLibraries.Warn(e.ToString());
                }
                return(true);
            };

            //

            if (LoadLibraries.IsCurrentPlayerInGame())
            {
                var debugLayer = new LegacyGameInterfaceLayer("ModLibsGeneral: Debug Display",
                                                              debugDrawCallback,
                                                              InterfaceScaleType.UI);
                layers.Insert(idx, debugLayer);
            }
        }
Example #17
0
        ////////////////

        /// <summary>
        /// Saves a custom mod data JSON file in binary form.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="mod"></param>
        /// <param name="fileNameWithExt"></param>
        /// <param name="jsonSettings"></param>
        /// <param name="overrides">Replaces any existing files.</param>
        /// <param name="data"></param>
        public static void SaveAsBinaryJson <T>(
            Mod mod,
            string fileNameWithExt,
            JsonSerializerSettings jsonSettings,
            bool overrides,
            T data) where T : class
        {
            if (data == null)
            {
                string fullPath = ModCustomDataFileLibraries.GetFullPath(mod, fileNameWithExt);
                LogLibraries.Warn("Failed to save binary file " + fullPath + " - Data is null.");
                return;
            }

            try {
                ModCustomDataFileLibraries.PrepareDir(mod);

                string fullPath = ModCustomDataFileLibraries.GetFullPath(mod, fileNameWithExt);

                string dataJson  = JsonConvert.SerializeObject(data, jsonSettings);
                byte[] dataBytes = System.Text.Encoding.UTF8.GetBytes(dataJson);

                FileLibraries.SaveBinaryFile(dataBytes, fullPath, false, !overrides);
            } catch (IOException e) {
                string fullDir = ModCustomDataFileLibraries.GetFullDirectoryPath(mod);
                LogLibraries.Warn("Failed to save binary file " + fileNameWithExt + " at " + fullDir + " - " + e.ToString());
                throw new IOException("Failed to save binary file " + fileNameWithExt + " at " + fullDir, e);
            }
        }
Example #18
0
        ////

        public override void Unload()
        {
            try {
                LogLibraries.Alert("Unloading mod...");
            } catch { }

            ModLibsGeneralMod.Instance = null;
        }
Example #19
0
        /// <summary>
        /// Clears mod data for a player.
        /// </summary>
        /// <param name="player"></param>
        /// <param name="exemptMods">Names of mods to skip (internal names).</param>
        public static void ModdedExtensionsReset(Player player, ISet <string> exemptMods)
        {
            foreach (Mod mod in ModLoader.Mods)
            {
                if (exemptMods.Contains(mod.Name))
                {
                    continue;
                }

                try {
                    mod.Call("ResetPlayerModData", player);
                } catch (Exception e) {
                    LogLibraries.Warn("Mod.Call failed for " + mod.Name + ": " + e.ToString());
                }
            }

            var wingSlotMod      = ModLoader.GetMod("WingSlot");
            var thoriumMod       = ModLoader.GetMod("ThoriumMod");
            var weaponOutMod     = ModLoader.GetMod("WeaponOut");
            var weaponOutLiteMod = ModLoader.GetMod("WeaponOutLite");

            if (wingSlotMod != null && !exemptMods.Contains("WingSlot"))
            {
                ModPlayer modplayer = player.GetModPlayer(wingSlotMod, "WingSlotPlayer");

                PlayerModLibraries.RemoveWingSlotProperty(modplayer, "EquipSlot");
                PlayerModLibraries.RemoveWingSlotProperty(modplayer, "VanitySlot");
                PlayerModLibraries.RemoveWingSlotProperty(modplayer, "DyeSlot");
            }

            if (thoriumMod != null && !exemptMods.Contains("ThoriumMod"))
            {
                ModPlayer modplayer = player.GetModPlayer(thoriumMod, "ThoriumPlayer");

                // "Inspiration" resets to the recommended default:
                ReflectionLibraries.Set(modplayer, "bardResource", 8);
            }

            if (weaponOutMod != null && !exemptMods.Contains("WeaponOut"))
            {
                ModPlayer modplayer = player.GetModPlayer(weaponOutMod, "PlayerFX");

                // "Frenzy Heart" resets:
                ReflectionLibraries.Set(modplayer, "demonBlood", false);
            }

            if (weaponOutLiteMod != null && !exemptMods.Contains("WeaponOutLite"))
            {
                ModPlayer modplayer = player.GetModPlayer(weaponOutLiteMod, "PlayerFX");

                // "Frenzy Heart" resets:
                ReflectionLibraries.Set(modplayer, "demonBlood", false);
            }
        }
Example #20
0
        ////////////////

        public override void Initialize()
        {
            var mymod = NihilismMod.Instance;

            this.Logic = new WorldLogic();

            if (NihilismConfig.Instance.DebugModeInfo)
            {
                LogLibraries.Alert("World initialized.");
            }
        }
        public override void ReceiveOnClient()
        {
            Player player = Main.player[this.PlayerWho];

            if (player == null || !player.active)
            {
                LogLibraries.Alert("Inactive player indexed as " + this.PlayerWho);
                return;
            }

            PlayerLibraries.ApplyPermaDeathState(player, this.Msg);
        }
Example #22
0
        private static TmodFile GetLocalMod(object localmod)
        {
            object rawModFile;

            if (!ReflectionLibraries.Get(localmod, "modFile", out rawModFile) || rawModFile == null)
            {
                LogLibraries.Warn("Empty 'modFile' field");
                return(null);
            }

            return((TmodFile)rawModFile);
        }
Example #23
0
        ////////////////

        public override void PostWorldGen()
        {
            var config     = BossReignsConfig.Instance;
            int addedTicks = config.Get <int>(nameof(config.AddedTicksUntilFirstReign));

            if (addedTicks > 0)
            {
                this.ElapsedReignBuildupTicks = -addedTicks;

                LogLibraries.Log("Added " + addedTicks + " ticks to timer for initial boss reign.");
            }
        }
        ////////////////

        private static UIState GetMainMenuUI(string menuFieldName)
        {
            UIState menuUI;

            if (!ReflectionLibraries.Get(typeof(Main), null, menuFieldName, out menuUI))
            {
                LogLibraries.Warn("Could not find Main." + menuFieldName);
                return(null);
            }

            return(menuUI);
        }
Example #25
0
        ////

        public override void Unload()
        {
            try {
                LogLibraries.Alert("Unloading mod...");

                this.ControlPanelHotkey = null;
            } catch (Exception e) {
                this.Logger.Warn("!ModControlPanel.ModControlPanelMod.UnloadFull - " + e.ToString());                   //was Error(...)
            }

            ModControlPanelMod.Instance = null;
        }
        public override void ReceiveOnClient()
        {
            NPC npc = Main.npc[this.NpcWho];

            if (npc?.active != true || npc.type != ModContent.NPCType <BanditNPC>())
            {
                LogLibraries.Alert("Mismatched npc.");
            }

            var mynpc = npc.modNPC as BanditNPC;

            mynpc?.BeginRetreat();
        }
Example #27
0
        ////////////////

        /// <summary>
        /// Creates a mod's data directory, if needed.
        /// </summary>
        /// <param name="mod"></param>
        public static void PrepareDir(Mod mod)
        {
            string fullDir = ModCustomDataFileLibraries.GetFullDirectoryPath(mod);

            try {
                Directory.CreateDirectory(Main.SavePath);
                Directory.CreateDirectory(Main.SavePath + Path.DirectorySeparatorChar + ModCustomDataFileLibraries.BaseFolder);
                Directory.CreateDirectory(fullDir);
            } catch (IOException e) {
                LogLibraries.Warn("Failed to prepare directory: " + fullDir + " - " + e.ToString());
                throw new IOException("Failed to prepare directory: " + fullDir, e);
            }
        }
        ////

        public override void ReceiveOnServer(int fromWho)
        {
            ISet <(int TileX, int TileY)> houseTiles;
            bool isValid = HouseFramingKitItem.Validate(ref this.TileX, ref this.TileY, out houseTiles);

            if (isValid)
            {
                HouseFramingKitItem.MakeHouseFrame(this.TileX, this.TileY);
            }
            else
            {
                LogLibraries.Alert("Could not place house frame");
            }
        }
Example #29
0
        public static void SetReignBuildupPause(bool isPaused)
        {
            var myworld = ModContent.GetInstance <BossReignsWorld>();

            myworld.IsPaused = isPaused;

            if (Main.netMode == NetmodeID.Server)
            {
                ReignBuildupPauseProtocol.SendToAllClients(isPaused);
            }
            else
            {
                LogLibraries.Warn("Not server.");
            }
        }
        private void ModsUnloading()
        {
            try {
                Main.OnPostDraw -= MenuContextServiceManager._Update;
                this.HideAllForCurrentMenuUI();

                foreach (MenuContext context in this.Contexts.Values.SafeSelectMany(kv => kv.Values))
                {
                    context.ModsUnloading();
                }

                this.Contexts.Clear();
            } catch (Exception e) {
                LogLibraries.Warn("Could not finish unloading menu contexts: " + e.ToString());
            }
        }