Skip to content

Commit

Permalink
More config options + Cheat Sheet integration!
Browse files Browse the repository at this point in the history
  • Loading branch information
gardenappl committed Apr 10, 2016
1 parent df6f65f commit 81ba5bd
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 17 deletions.
6 changes: 5 additions & 1 deletion BossExpertise.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public BossExpertise()

public override void ChatInput(string text)
{
if(!Config.AddCommand)
return;

if(text.Equals("/expert"))
{
if(Main.expertMode)
Expand Down Expand Up @@ -64,7 +67,8 @@ public override void Load()

public override void PostSetupContent()
{
//CheatSheetIntegration.Load(this);
if(Config.AddCheatSheetButton)
CheatSheetIntegration.Load(this);
}

public static void Log(string message, params object[] formatData)
Expand Down
52 changes: 41 additions & 11 deletions Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ namespace BossExpertise
public static class Config
{
public static bool DropBags;
public static bool AddCheatSheetButton = true;
public static bool ChangeBossAI = true;
public static bool AddCommand = true;

static int ConfigVersion;
const int LatestVersion = 2;
const int LatestVersion = 3;
static string ConfigFolderPath = Path.Combine(Main.SavePath, "Mod Configs", "BossExpertise");
static string ConfigPath = Path.Combine(ConfigFolderPath, "config.txt");
static string ConfigVersionFilePath = Path.Combine(ConfigFolderPath, "configVersion.txt");
Expand All @@ -23,7 +26,7 @@ public static void Load()
{
CreateConfig();
WriteConfigVersion(LatestVersion);
ErrorLogger.Log("Creating new config");
ErrorLogger.Log("Creating new config...");
}

ConfigVersion = ReadConfigVersion();
Expand All @@ -38,25 +41,43 @@ public static void Load()
{
CreateConfig();
WriteConfigVersion(LatestVersion);
ErrorLogger.Log("Recreating config");
ErrorLogger.Log("Recreating config...");
}

//Debug
BossExpertise.Log("Drop bags: {0}", DropBags);
BossExpertise.Log("Change boss AI: {0}", ChangeBossAI);
BossExpertise.Log("Add Cheat Sheet button: {0}", AddCheatSheetButton);
BossExpertise.Log("Add /expert command: {0}", AddCommand);
}


internal static bool ReadConfig()
static bool ReadConfig()
{
var file = new StreamReader(ConfigPath);
try
{
file.ReadLine(); //Skip the comment
DropBags = Boolean.Parse(file.ReadLine().Split(':')[1]); //Read the actual value

file.ReadLine();
ChangeBossAI = Boolean.Parse(file.ReadLine().Split(':')[1]);

file.ReadLine();
AddCheatSheetButton = Boolean.Parse(file.ReadLine().Split(':')[1]);

file.ReadLine();
DropBags = Boolean.Parse(file.ReadLine().Split(':')[1]);
BossExpertise.Log("Drop bags: {0}", DropBags);
AddCommand = Boolean.Parse(file.ReadLine().Split(':')[1]);

return true;
}
catch(Exception e)
{
BossExpertise.Log("Couldn't properly read config file! Using default values...");
BossExpertise.Log(e.ToString());
if(ConfigVersion == LatestVersion)
{
BossExpertise.Log("Couldn't properly read config file! Using default values...");
BossExpertise.Log(e.ToString());
}
}
finally
{
Expand All @@ -65,7 +86,7 @@ internal static bool ReadConfig()
return false;
}

internal static int ReadConfigVersion()
static int ReadConfigVersion()
{
string[] versionFile = File.ReadAllLines(ConfigVersionFilePath);
try
Expand All @@ -81,17 +102,26 @@ internal static int ReadConfigVersion()
}


internal static void CreateConfig()
static void CreateConfig()
{
Directory.CreateDirectory(ConfigFolderPath);
using(var file = File.CreateText(ConfigPath))
{
file.WriteLine("This value can either be True or False");
file.WriteLine("Drop Treasure Bags: {0}", DropBags);

file.WriteLine("This value can either be True or False");
file.WriteLine("Change boss AI: {0}", ChangeBossAI);

file.WriteLine("This value can either be True or False (requires the Cheat Sheet mod)");
file.WriteLine("Add Cheat Sheet button: {0}", AddCheatSheetButton);

file.WriteLine("This value can either be True or False");
file.WriteLine("Add /expert command: {0}", AddCommand);
}
}

internal static void WriteConfigVersion(int version)
static void WriteConfigVersion(int version)
{
using(var file = File.CreateText(ConfigVersionFilePath))
{
Expand Down
2 changes: 1 addition & 1 deletion NPC/ExpertGlobalNPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class ExpertGlobalNPC : GlobalNPC
{
public override bool PreAI(NPC npc)
{
if(npc.boss && !Main.expertMode)
if(npc.boss && Config.ChangeBossAI && !Main.expertMode)
SetFakeExpert(npc, true);
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion build.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
displayName = Boss Expertise
author = goldenapple
version = 2.1
version = 2.2
homepage = http://forums.terraria.org/index.php?threads/boss-expertise.41243/
hideCode = false
includeSource = true
Expand Down
5 changes: 2 additions & 3 deletions description.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
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.
Optional feature:
-Bosses drop Treasure Bags
This is disabled by default: visit the Forum Thread for info about how to enable it.
BossExpertise also adds some optional features (like bosses dropping Treasure Bags in Normal Mode), which are disabled by default.
Visit the Forum Thread for info about how to enable/disable optional features.

0 comments on commit 81ba5bd

Please sign in to comment.