Skip to content

Commit

Permalink
v2.6 update, lots of stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
gardenappl committed Jun 25, 2017
1 parent b711b4e commit 1d6263f
Show file tree
Hide file tree
Showing 12 changed files with 191 additions and 160 deletions.
120 changes: 59 additions & 61 deletions BossExpertise.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <true|false>");
text.AddTranslation(GameCulture.Russian, "Использование: /expert или /expert <true|false>");
AddTranslation(text);
text = CreateTranslation("RightClickToUse");
text.SetDefault("<right> 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 <true|false>");
}
else
Main.NewText("Usage: /expert OR /expert <true|false>");
broadcast = false;
}
return;
ModIntegration.Load(this);
}
}

Expand All @@ -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()];
Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions BossExpertise.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@
</ItemGroup>
<ItemGroup>
<Compile Include="BossExpertise.cs" />
<Compile Include="CheatSheetIntegration.cs" />
<Compile Include="ModIntegration.cs" />
<Compile Include="Config.cs" />
<Compile Include="ExpertCommand.cs" />
<Compile Include="ExpertGlobalItem.cs" />
<Compile Include="ExpertMessageType.cs" />
<Compile Include="OldConfig.cs" />
<Compile Include="ExpertGlobalNPC.cs" />
<Compile Include="ExpertPlayer.cs" />
<Compile Include="ExpertNPCInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
32 changes: 0 additions & 32 deletions CheatSheetIntegration.cs

This file was deleted.

46 changes: 19 additions & 27 deletions Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
53 changes: 53 additions & 0 deletions ExpertCommand.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
}
3 changes: 2 additions & 1 deletion ExpertGlobalItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.Localization;
using Terraria.ModLoader;

namespace BossExpertise
Expand All @@ -20,7 +21,7 @@ public override void ModifyTooltips(Item item, List<TooltipLine> 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);
}
Expand Down
Loading

0 comments on commit 1d6263f

Please sign in to comment.