public void OnInitialize() { if (!Keys.TryParse(IniAPI.ReadIni("PortableCraftingGuide", "ToggleKey", "C", writeIt: true), out pcgKey)) { pcgKey = Keys.C; } Loader.RegisterHotkey(() => { pcg = !pcg; if (!pcg) { Main.InGuideCraftMenu = false; Main.player[Main.myPlayer].talkNPC = -1; } }, pcgKey); Keys invKey; Keys.TryParse(Main.cInv, out invKey); Loader.RegisterHotkey(() => { pcg = false; }, invKey); }
public static Hotkey ParseHotkey(string hotkey) { var key = Keys.None; var control = false; var shift = false; var alt = false; bool hotkeyParseFailed = false; foreach (var keyStr in hotkey.Split(',')) { switch (keyStr.ToLower()) { case "control": control = true; break; case "shift": shift = true; break; case "alt": alt = true; break; default: if (key != Keys.None || !Keys.TryParse(keyStr, true, out key)) { hotkeyParseFailed = true; } break; } } if (hotkeyParseFailed || key == Keys.None) { return(null); } return(new Hotkey() { Key = key, Control = control, Alt = alt, Shift = shift }); }
public Events() { var worldGen = Assembly.GetEntryAssembly().GetType("Terraria.WorldGen"); triggerLunarApocalypse = worldGen.GetMethod("TriggerLunarApocalypse"); spawnMeteor = worldGen.GetField("spawnMeteor"); dropMeteor = worldGen.GetMethod("dropMeteor"); if (!Keys.TryParse(IniAPI.ReadIni("Events", "Meteor", "NumPad0", writeIt: true), out meteor)) { meteor = Keys.NumPad0; } if (!Keys.TryParse(IniAPI.ReadIni("Events", "BloodMoon", "NumPad1", writeIt: true), out bloodMoon)) { bloodMoon = Keys.NumPad1; } if (!Keys.TryParse(IniAPI.ReadIni("Events", "GoblinArmy", "NumPad2", writeIt: true), out goblin)) { goblin = Keys.NumPad2; } if (!Keys.TryParse(IniAPI.ReadIni("Events", "FrostLegion", "NumPad3", writeIt: true), out frost)) { frost = Keys.NumPad3; } if (!Keys.TryParse(IniAPI.ReadIni("Events", "PirateInvasion", "NumPad4", writeIt: true), out pirates)) { pirates = Keys.NumPad4; } if (!Keys.TryParse(IniAPI.ReadIni("Events", "SolarEclipse", "NumPad5", writeIt: true), out eclipse)) { eclipse = Keys.NumPad5; } if (!Keys.TryParse(IniAPI.ReadIni("Events", "PumpkinMoon", "NumPad6", writeIt: true), out pumpkinMoon)) { pumpkinMoon = Keys.NumPad6; } if (!Keys.TryParse(IniAPI.ReadIni("Events", "FrostMoon", "NumPad7", writeIt: true), out frostMoon)) { frostMoon = Keys.NumPad7; } if (!Keys.TryParse(IniAPI.ReadIni("Events", "MartianMadness", "NumPad8", writeIt: true), out martians)) { martians = Keys.NumPad8; } if (!Keys.TryParse(IniAPI.ReadIni("Events", "LunarApocalypse", "NumPad9", writeIt: true), out lunarApocalypse)) { lunarApocalypse = Keys.NumPad9; } if (!Keys.TryParse(IniAPI.ReadIni("Events", "Moon Lord", "Add", writeIt: true), out moonLord)) { moonLord = Keys.Add; } Loader.RegisterHotkey(() => { if (Main.invasionType > 0) { Main.invasionSize = 0; } else { Main.StartInvasion(1); } }, goblin); Loader.RegisterHotkey(() => { if (Main.invasionType > 0) { Main.invasionSize = 0; } else { Main.StartInvasion(2); } }, frost); Loader.RegisterHotkey(() => { if (Main.invasionType > 0) { Main.invasionSize = 0; } else { Main.StartInvasion(3); } }, pirates); Loader.RegisterHotkey(() => { if (Main.invasionType > 0) { Main.invasionSize = 0; } else { Main.StartInvasion(4); } }, martians); Loader.RegisterHotkey(() => { if (Main.pumpkinMoon) { Main.stopMoonEvent(); } else { Main.startPumpkinMoon(); } }, pumpkinMoon); Loader.RegisterHotkey(() => { if (Main.snowMoon) { Main.stopMoonEvent(); } else { Main.startSnowMoon(); } }, frostMoon); Loader.RegisterHotkey(() => { if (Terraria.NPC.LunarApocalypseIsUp || Terraria.NPC.AnyNPCs(398)) { StopLunarEvent(); } else { TriggerLunarApocalypse(); } }, lunarApocalypse); Loader.RegisterHotkey(() => { if (Terraria.NPC.LunarApocalypseIsUp || Terraria.NPC.AnyNPCs(398)) { StopLunarEvent(); } else { SpawnMoonLord(); } }, moonLord); Loader.RegisterHotkey(() => { if (Main.bloodMoon) { Main.bloodMoon = false; } else { TriggerBloodMoon(); } }, bloodMoon); Loader.RegisterHotkey(() => { if (Main.eclipse) { Main.eclipse = false; } else { TriggerEclipse(); } }, eclipse); Loader.RegisterHotkey(() => { SpawnMeteor = false; DropMeteor(); }, meteor); }
public NPC() { var npc = Assembly.GetEntryAssembly().GetType("Terraria.NPC"); defaultMaxSpawns = npc.GetField("defaultMaxSpawns", BindingFlags.Static | BindingFlags.NonPublic); defaultSpawnRate = npc.GetField("defaultSpawnRate", BindingFlags.Static | BindingFlags.NonPublic); DefaultMaxSpawns = int.Parse(IniAPI.ReadIni("Spawning", "SpawnLimit", "5", writeIt: true)); DefaultSpawnRate = int.Parse(IniAPI.ReadIni("Spawning", "SpawnRate", "100", writeIt: true)); if (!Keys.TryParse(IniAPI.ReadIni("NPC", "Toggle", "N", writeIt: true), out toggleKey)) { toggleKey = Keys.N; } if (!Keys.TryParse(IniAPI.ReadIni("NPC", "Increase", "OemPlus", writeIt: true), out increaseKey)) { increaseKey = Keys.OemPlus; } if (!Keys.TryParse(IniAPI.ReadIni("NPC", "Decrease", "OemMinus", writeIt: true), out decreaseKey)) { decreaseKey = Keys.OemMinus; } Color purple = Color.Purple; Loader.RegisterHotkey(() => { ModifySpawnLimit(-1); Main.NewText("Spawn limit: " + DefaultMaxSpawns, purple.R, purple.G, purple.B, false); }, decreaseKey, control: true); Loader.RegisterHotkey(() => { ModifySpawnRate(-20); Main.NewText("Spawn rate: " + DefaultSpawnRate + "%", purple.R, purple.G, purple.B, false); }, decreaseKey, control: false); Loader.RegisterHotkey(() => { ModifySpawnLimit(1); Main.NewText("Spawn limit: " + DefaultMaxSpawns, purple.R, purple.G, purple.B, false); }, increaseKey, control: true); Loader.RegisterHotkey(() => { ModifySpawnRate(20); Main.NewText("Spawn rate: " + DefaultSpawnRate + "%", purple.R, purple.G, purple.B, false); }, increaseKey, control: false); Loader.RegisterHotkey(() => { if (DefaultMaxSpawns > 0) { previousMaxSpawns = DefaultMaxSpawns; previousSpawnRate = DefaultSpawnRate; DefaultMaxSpawns = 0; DefaultSpawnRate = 0; KillAllNPCs(); } else { DefaultMaxSpawns = previousMaxSpawns; DefaultSpawnRate = previousSpawnRate; } Main.NewText("Spawn rate: " + DefaultSpawnRate + "%", purple.R, purple.G, purple.B, false); Main.NewText("Spawn limit: " + DefaultMaxSpawns, purple.R, purple.G, purple.B, false); }, toggleKey); }