From 1d6263f143a06bd5d805c25ff670dfc6e426beaa Mon Sep 17 00:00:00 2001 From: goldenapple3 Date: Sun, 25 Jun 2017 18:47:38 +0300 Subject: [PATCH] v2.6 update, lots of stuff --- BossExpertise.cs | 120 +++++++++++++++++++-------------------- BossExpertise.csproj | 4 +- CheatSheetIntegration.cs | 32 ----------- Config.cs | 46 +++++++-------- ExpertCommand.cs | 53 +++++++++++++++++ ExpertGlobalItem.cs | 3 +- ExpertGlobalNPC.cs | 19 +------ ExpertNPCInfo.cs | 17 ------ ModIntegration.cs | 48 ++++++++++++++++ OldConfig.cs | 4 ++ build.txt | 4 +- description.txt | 1 + 12 files changed, 191 insertions(+), 160 deletions(-) delete mode 100644 CheatSheetIntegration.cs create mode 100644 ExpertCommand.cs delete mode 100644 ExpertNPCInfo.cs create mode 100644 ModIntegration.cs diff --git a/BossExpertise.cs b/BossExpertise.cs index afe69ec..2540e32 100644 --- a/BossExpertise.cs +++ b/BossExpertise.cs @@ -3,75 +3,68 @@ using System.IO; using Microsoft.Xna.Framework; using Terraria; +using Terraria.ID; using Terraria.IO; +using Terraria.Localization; using Terraria.ModLoader; namespace BossExpertise { public class BossExpertise : Mod - { - public BossExpertise() - { - Properties = new ModProperties - { - Autoload = true, - AutoloadGores = true, - AutoloadSounds = true - }; - } - + { public override void Load() { OldConfig.Load(); Config.Load(); + if(Config.AddExpertCommand) + { + AddCommand("expert", new ExpertCommand()); + } + /* Translation Start */ + var text = CreateTranslation("NowNormalMode"); + text.SetDefault("The world is now in Normal Mode."); + text.AddTranslation(GameCulture.Russian, "Этот мир теперь в Нормальном режиме."); + AddTranslation(text); + text = CreateTranslation("NowExpertMode"); + text.SetDefault("The world is now in Expert Mode!"); + text.AddTranslation(GameCulture.Russian, "Этот мир теперь в Режиме эксперта!"); + AddTranslation(text); + text = CreateTranslation("AlreadyNormalMode"); + text.SetDefault("The world is already in Normal Mode."); + text.AddTranslation(GameCulture.Russian, "Этот мир уже в Нормальном режиме."); + AddTranslation(text); + text = CreateTranslation("AlreadyExpertMode"); + text.SetDefault("The world is already in Expert Mode!"); + text.AddTranslation(GameCulture.Russian, "Этот мир уже в Режиме эксперта!"); + AddTranslation(text); + text = CreateTranslation("ToggleModePermission"); + text.SetDefault("Toggle Expert Mode"); + text.AddTranslation(GameCulture.Russian, "Включать/выключать Режим эксперта"); + AddTranslation(text); + text = CreateTranslation("SwitchToNormal"); + text.SetDefault("Switch to Normal Mode"); + text.AddTranslation(GameCulture.Russian, "Перейти в Нормальный режим"); + AddTranslation(text); + text = CreateTranslation("SwitchToExpert"); + text.SetDefault("Switch to Expert Mode"); + text.AddTranslation(GameCulture.Russian, "Перейти в Режим эксперта"); + AddTranslation(text); + text = CreateTranslation("ExpertCommandUsage"); + text.SetDefault("Usage: /expert OR /expert "); + text.AddTranslation(GameCulture.Russian, "Использование: /expert или /expert "); + AddTranslation(text); + text = CreateTranslation("RightClickToUse"); + text.SetDefault(" to use!"); + text.AddTranslation(GameCulture.Russian, "Нажмите <ПКМ>, чтобы использовать!"); + AddTranslation(text); + /* Tranlsation End */ } public override void PostSetupContent() { if(Config.AddCheatSheetButton) - CheatSheetIntegration.Load(this); - } - - public override void ChatInput(string text, ref bool broadcast) - { - //argument split code from ExampleMod - if (text[0] != '/') - return; - int index = text.IndexOf(' '); - string command; - string[] args; - if (index < 0) { - command = text.Substring(1); - args = new string[0]; - } - else - { - command = text.Substring(1, index - 1); - args = text.Substring(index).Split(new []{' '}, StringSplitOptions.RemoveEmptyEntries); - } - - switch(command) - { - case "expert": - if(Config.AddExpertCommand) - { - if(args.Length == 0) - SetExpertMode(!Main.expertMode); - else if(args.Length == 1) - { - if(args[0].Equals("true", StringComparison.OrdinalIgnoreCase)) - SetExpertMode(true); - else if(args[0].Equals("false", StringComparison.OrdinalIgnoreCase)) - SetExpertMode(false); - else - Main.NewText("Usage: /expert OR /expert "); - } - else - Main.NewText("Usage: /expert OR /expert "); - broadcast = false; - } - return; + ModIntegration.Load(this); } } @@ -82,7 +75,12 @@ public override void HandlePacket(BinaryReader reader, int whoAmI) switch(msgType) { case ExpertMessageType.SyncExpert: - Main.expertMode = reader.ReadBoolean(); + bool expert = reader.ReadBoolean(); + Main.expertMode = expert; + if(Main.netMode == NetmodeID.Server) + { + SyncExpertMode(expert, whoAmI); + } return; case ExpertMessageType.SyncDemonHeart: var player = Main.player[reader.ReadInt32()]; @@ -91,15 +89,15 @@ public override void HandlePacket(BinaryReader reader, int whoAmI) } } - public void SyncExpertMode(bool expert) + public void SyncExpertMode(bool expert, int ignoreClient = -1) { Main.expertMode = expert; - if(Main.netMode == 1 || Main.netMode == 2) //Multiplayer + if(Main.netMode != NetmodeID.SinglePlayer) { var msg = GetPacket(); msg.Write((byte)ExpertMessageType.SyncExpert); msg.Write(expert); - msg.Send(); + msg.Send(ignoreClient: ignoreClient); } } @@ -108,20 +106,20 @@ public void SetExpertMode(bool expert) if(Main.expertMode && !expert) { SyncExpertMode(false); - Main.NewText("This world is now in Normal Mode"); + Main.NewText(Language.GetTextValue("Mods.BossExpertise.NowNormalMode")); } else if(!Main.expertMode && expert) { SyncExpertMode(true); - Main.NewText("This world is now in Expert Mode!", 255, 50, 50); + Main.NewText(Language.GetTextValue("Mods.BossExpertise.NowExpertMode"), 255, 50, 50); } else if(!Main.expertMode && !expert) { - Main.NewText("This world is already in Normal Mode"); + Main.NewText(Language.GetTextValue("Mods.BossExpertise.AlreadyNormalMode")); } else { - Main.NewText("This world is already in Expert Mode!", 255, 50, 50); + Main.NewText(Language.GetTextValue("Mods.BossExpertise.AlreadyExpertMode"), 255, 50, 50); } } diff --git a/BossExpertise.csproj b/BossExpertise.csproj index baa63e2..92a46f2 100644 --- a/BossExpertise.csproj +++ b/BossExpertise.csproj @@ -54,14 +54,14 @@ - + + - \ No newline at end of file diff --git a/CheatSheetIntegration.cs b/CheatSheetIntegration.cs deleted file mode 100644 index c093fbc..0000000 --- a/CheatSheetIntegration.cs +++ /dev/null @@ -1,32 +0,0 @@ - -using System; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; - -namespace BossExpertise -{ - public static class CheatSheetIntegration - { - static BossExpertise mod; - - public static void Load(BossExpertise bossExpertiseMod) - { - mod = bossExpertiseMod; - var cheatSheetMod = ModLoader.GetMod("CheatSheet"); - if(cheatSheetMod != null && !Main.dedServ) - cheatSheetMod.Call("AddButton_Test", mod.GetTexture("ExpertModeButton"), (Action)ExpertModeButtonPressed, (Func)ExpertModeButtonTooltip); - } - - public static string ExpertModeButtonTooltip() - { - return Main.expertMode ? "Switch to Normal Mode" : "Switch to Expert Mode"; - } - - public static void ExpertModeButtonPressed() - { -// Main.PlaySound(10); - mod.SetExpertMode(!Main.expertMode); - } - } -} diff --git a/Config.cs b/Config.cs index 91fae93..6cc7d2e 100644 --- a/Config.cs +++ b/Config.cs @@ -15,49 +15,41 @@ public static class Config public static bool DemonHeartHack; public static bool TransformMatrix; - static int ConfigVersion; - const int LatestVersion = 1; - static string ConfigFolderPath = Path.Combine(Main.SavePath, "Mod Configs", "Boss Expertise"); - static string ConfigPath = Path.Combine(ConfigFolderPath, "config.json"); - static string ConfigVersionPath = Path.Combine(ConfigFolderPath, "config.version"); + static string ConfigPath = Path.Combine(Main.SavePath, "Mod Configs", "Boss Expertise.json"); + + static string OldConfigFolderPath = Path.Combine(Main.SavePath, "Mod Configs", "Boss Expertise"); + static string OldConfigPath = Path.Combine(OldConfigFolderPath, "config.json"); + static string OldConfigVersionPath = Path.Combine(OldConfigFolderPath, "config.version"); static Preferences Configuration = new Preferences(ConfigPath); public static void Load() { - if(File.Exists(ConfigVersionPath)) + if(Directory.Exists(OldConfigFolderPath)) { - try + if(File.Exists(OldConfigPath)) + { + BossExpertise.Log("Found config file in old folder! Moving config..."); + File.Move(OldConfigPath, ConfigPath); + } + if(File.Exists(OldConfigVersionPath)) + { + File.Delete(OldConfigVersionPath); + } + if(Directory.GetFiles(OldConfigFolderPath).Length == 0 && Directory.GetDirectories(OldConfigFolderPath).Length == 0) { - int.TryParse(File.ReadAllText(ConfigVersionPath), out ConfigVersion); + Directory.Delete(OldConfigFolderPath); } - catch(Exception e) + else { - BossExpertise.Log("Unable to read config version!"); - BossExpertise.Log(e.ToString()); - ConfigVersion = 0; + BossExpertise.Log("Old config folder still cotains some files/directories. They will not get deleted."); } } - else - ConfigVersion = 0; - - if(ConfigVersion < LatestVersion) - BossExpertise.Log("Config is outdated! Current version: {0} Latest version: {1}", ConfigVersion, LatestVersion); - if(ConfigVersion > LatestVersion) - BossExpertise.Log("Config is from the future?! Current version: {0} Latest version: {1}", ConfigVersion, LatestVersion); - -// BossExpertise.Log("Reading config..."); if(!ReadConfig()) { BossExpertise.Log("Failed to read config file! Recreating config..."); SaveConfig(); } - else if(ConfigVersion != LatestVersion) - { - BossExpertise.Log("Replacing config with newest version..."); - File.WriteAllText(ConfigVersionPath, LatestVersion.ToString()); - SaveConfig(); - } } static bool ReadConfig() diff --git a/ExpertCommand.cs b/ExpertCommand.cs new file mode 100644 index 0000000..72cc2c5 --- /dev/null +++ b/ExpertCommand.cs @@ -0,0 +1,53 @@ + +using System; +using Terraria; +using Terraria.Localization; +using Terraria.ModLoader; + +namespace BossExpertise +{ + public class ExpertCommand : ModCommand + { + public override bool Autoload(ref string name) + { + return false; + } + + public override void Action(CommandCaller caller, string input, string[] args) + { + if(args.Length == 0) + { + (mod as BossExpertise).SetExpertMode(!Main.expertMode); + } + else if(args.Length == 1) + { + if(args[0].Equals("true", StringComparison.OrdinalIgnoreCase)) + { + (mod as BossExpertise).SetExpertMode(true); + } + else if(args[0].Equals("false", StringComparison.OrdinalIgnoreCase)) + { + (mod as BossExpertise).SetExpertMode(false); + } + else + { + Main.NewText(Language.GetTextValue("Mods.BossExpertise.ExpertCommandUsage")); + } + } + else + { + Main.NewText(Language.GetTextValue("Mods.BossExpertise.ExpertCommandUsage")); + } + } + + public override string Command + { + get { return "expert"; } + } + + public override CommandType Type + { + get { return CommandType.World; } + } + } +} diff --git a/ExpertGlobalItem.cs b/ExpertGlobalItem.cs index 08e18ff..7884731 100644 --- a/ExpertGlobalItem.cs +++ b/ExpertGlobalItem.cs @@ -4,6 +4,7 @@ using Microsoft.Xna.Framework; using Terraria; using Terraria.ID; +using Terraria.Localization; using Terraria.ModLoader; namespace BossExpertise @@ -20,7 +21,7 @@ public override void ModifyTooltips(Item item, List tooltips) { if(Config.DemonHeartHack && item.type == ItemID.DemonHeart && !Main.expertMode) { - var line = new TooltipLine(mod, "DemonHeart", "Right Click to use!"); + var line = new TooltipLine(mod, "DemonHeart", Language.GetTextValue("Mods.BossExpertise.RightClickToUse")); line.overrideColor = Colors.RarityRed; tooltips.Insert(2, line); } diff --git a/ExpertGlobalNPC.cs b/ExpertGlobalNPC.cs index 9430d86..66d7529 100644 --- a/ExpertGlobalNPC.cs +++ b/ExpertGlobalNPC.cs @@ -9,12 +9,10 @@ namespace BossExpertise { public class ExpertGlobalNPC : GlobalNPC { - public bool FakeExpert; + public static bool FakeExpert; public override void ResetEffects(NPC npc) { -// if(npc.GetModInfo(mod).FakeExpertMode) -// SetFakeExpert(npc, false); if(FakeExpert) { (mod as BossExpertise).SyncExpertMode(false); @@ -24,9 +22,6 @@ public override void ResetEffects(NPC npc) public override bool PreAI(NPC npc) { -// if(npc.boss && Config.ChangeBossAI && !Main.expertMode) -// SetFakeExpert(npc, true); -// return true; if(npc.boss && Config.ChangeBossAI && !Main.expertMode) { FakeExpert = true; @@ -45,9 +40,6 @@ public override void PostAI(NPC npc) public override bool PreNPCLoot(NPC npc) { -// if(npc.boss && Config.DropBags && !Main.expertMode) -// SetFakeExpert(npc, true); -// return true; if(npc.boss && Config.DropBags && !Main.expertMode) { FakeExpert = true; @@ -58,8 +50,6 @@ public override bool PreNPCLoot(NPC npc) public override void NPCLoot(NPC npc) { -// if(npc.GetModInfo(mod).FakeExpertMode) -// SetFakeExpert(npc, false); if(FakeExpert) { FakeExpert = false; @@ -85,12 +75,5 @@ public override void PostDraw(NPC npc, SpriteBatch spriteBatch, Color drawColor) Main.expertMode = false; } } - -// void SetFakeExpert(NPC npc, bool expert) -// { -// var info = npc.GetModInfo(mod); -// ((BossExpertise)mod).SyncExpertMode(expert); -// info.FakeExpertMode = expert; -// } } } diff --git a/ExpertNPCInfo.cs b/ExpertNPCInfo.cs deleted file mode 100644 index 1f448e3..0000000 --- a/ExpertNPCInfo.cs +++ /dev/null @@ -1,17 +0,0 @@ - -using System; -using Terraria; -using Terraria.ModLoader; - -namespace BossExpertise -{ - public class ExpertNPCInfo : NPCInfo - { - public override bool Autoload(ref string name) - { - return false; - } - - internal bool FakeExpertMode; - } -} diff --git a/ModIntegration.cs b/ModIntegration.cs new file mode 100644 index 0000000..effc081 --- /dev/null +++ b/ModIntegration.cs @@ -0,0 +1,48 @@ + +using System; +using Terraria; +using Terraria.ID; +using Terraria.Localization; +using Terraria.ModLoader; + +namespace BossExpertise +{ + public static class ModIntegration + { + static BossExpertise mod; + + public static void Load(BossExpertise bossExpertiseMod) + { + mod = bossExpertiseMod; + var cheatSheetMod = ModLoader.GetMod("CheatSheet"); + if(cheatSheetMod != null && !Main.dedServ) + { + cheatSheetMod.Call("AddButton_Test", Main.buffTexture[BuffID.Horrified], (Action)OnButtonPressed, (Func)GetButtonTooltip); + } + var herosMod = ModLoader.GetMod("HEROsMod"); + if(herosMod != null) + { + herosMod.Call("AddPermission", "ToggleExpertMode", Language.GetTextValue("Mods.BossExpertise.ToggleModePermission")); + if(!Main.dedServ) + { + herosMod.Call("AddSimpleButton", "ToggleExpertMode", Main.buffTexture[BuffID.Horrified], (Action)OnButtonPressed, (Action)OnPermissionChanged, (Func)GetButtonTooltip); + } + } + } + + public static string GetButtonTooltip() + { + return Language.GetTextValue(Main.expertMode ? "Mods.BossExpertise.SwitchToNormal" : "Mods.BossExpertise.SwitchToExpert"); + } + + public static void OnButtonPressed() + { + mod.SetExpertMode(!Main.expertMode); + } + + public static void OnPermissionChanged(bool hasPermission) + { + //do nothing + } + } +} diff --git a/OldConfig.cs b/OldConfig.cs index 8474a07..a063a71 100644 --- a/OldConfig.cs +++ b/OldConfig.cs @@ -51,9 +51,13 @@ public static void Load() File.Delete(ConfigPath); File.Delete(ConfigVersionPath); if(Directory.GetFiles(ConfigFolderPath).Length == 0 && Directory.GetDirectories(ConfigFolderPath).Length == 0) + { Directory.Delete(ConfigFolderPath); + } else + { BossExpertise.Log("Outdated config folder still cotains some files/directories. They will not get deleted."); + } } catch(Exception e) { diff --git a/build.txt b/build.txt index 4013fa5..852a530 100644 --- a/build.txt +++ b/build.txt @@ -1,7 +1,7 @@ displayName = Boss Expertise author = goldenapple -version = 2.5.1 -homepage = http://forums.terraria.org/index.php?threads/boss-expertise.41243/ +version = 2.6 +homepage = http://forums.terraria.org/index.php?threads/vanilla-tweaks-other-little-tweak-mods.37443/#BossExpertise hideCode = false includeSource = true buildIgnore = obj\*, bin\*, *.csproj, .git\*, .gitattributes, .gitignore \ No newline at end of file diff --git a/description.txt b/description.txt index 787b1f1..d1a153c 100644 --- a/description.txt +++ b/description.txt @@ -1,4 +1,5 @@ Do you think that Expert Mode is too hard but still want a challenge? Are Normal Mode bosses too boring? Then this mod is probably for you! Boss Expertise makes bosses behave like they're in Expert Mode, even though their stats don't change. BossExpertise also adds some optional features (like bosses dropping Treasure Bags in Normal Mode), which are disabled by default. +Also allows you to toggle Expert Mode via chat command (/expert), Cheat Sheet or HERO's Mod. Visit the Forum Thread for info about how to enable/disable optional features. \ No newline at end of file