From 16df9bb16cc686fd1b06497d161da82bc5ff99db Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sun, 17 May 2020 22:44:10 -0700 Subject: [PATCH] Update "spawn boss invasion" get data handler This is really "spawn arbitrary stuff" and it can create invasions, pets, and bosses now. --- CHANGELOG.md | 1 + TShockAPI/GetDataHandlers.cs | 88 +++++++++++------------------------- TShockAPI/Permissions.cs | 5 +- 3 files changed, 32 insertions(+), 62 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8e2f20e..77d5c545 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -104,6 +104,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Multiple fields got slightly renamed. * Modifying ToggleExpert command. Main.expertMode is no longer settable. Using a Main.GameMode int property comparsion. * GameCulture no longer has static fields to get local language. Using methods to return/compare language. + * Added permission "tshock.npc.spawnpets" which restricts pet spawns. This can cause high network load, so it's restricted. (@hakusaro) ## TShock 4.3.26 * Removed the stat tracking system. (@hakusaro) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index bdc49a63..80b7048e 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -2821,6 +2821,9 @@ namespace TShockAPI return false; } + private static readonly int[] invasions = { -1, -2, -3, -4, -5, -6, -7, -8, -10, -11 }; + private static readonly int[] pets = { -12, -13, -14 }; + private static readonly int[] bosses = { 4, 13, 50, 125, 126, 134, 127, 128, 131, 129, 130, 222, 245, 266, 370, 657 }; private static bool HandleSpawnBoss(GetDataHandlerArgs args) { if (args.Player.IsBouncerThrottled()) @@ -2828,104 +2831,67 @@ namespace TShockAPI return true; } - var spawnboss = false; - var invasion = false; var plr = args.Data.ReadInt16(); - var Type = args.Data.ReadInt16(); + var thingType = args.Data.ReadInt16(); NPC npc = new NPC(); - npc.SetDefaults(Type); - spawnboss = npc.boss; - if (!spawnboss) - { - switch (Type) - { - case -1: - case -2: - case -3: - case -4: - case -5: - case -6: - case -7: - case -8: - invasion = true; - break; - case 4: - case 13: - case 50: - case 75: - case 125: - case 126: - case 127: - case 128: - case 129: - case 130: - case 131: - case 134: - case 222: - case 245: - case 266: - case 370: - case 398: - case 422: - case 439: - case 493: - case 507: - case 517: - spawnboss = true; - break; - } - } - if (spawnboss && !args.Player.HasPermission(Permissions.summonboss)) + npc.SetDefaults(thingType); + + if (bosses.Contains(thingType) && !args.Player.HasPermission(Permissions.summonboss)) { args.Player.SendErrorMessage("You don't have permission to summon a boss."); return true; } - if (invasion && !args.Player.HasPermission(Permissions.startinvasion)) + + if (invasions.Contains(thingType) && !args.Player.HasPermission(Permissions.startinvasion)) { args.Player.SendErrorMessage("You don't have permission to start an invasion."); return true; } - if (!spawnboss && !invasion) + + if (pets.Contains(thingType) && !args.Player.HasPermission(Permissions.spawnpets)) + { + args.Player.SendErrorMessage("You don't have permission to spawn pets."); return true; + } if (plr != args.Player.Index) return true; - string boss; - switch (Type) + string thing; + switch (thingType) { case -8: - boss = "a Moon Lord"; + thing = "a Moon Lord"; break; case -7: - boss = "a Martian invasion"; + thing = "a Martian invasion"; break; case -6: - boss = "an eclipse"; + thing = "an eclipse"; break; case -5: - boss = "a frost moon"; + thing = "a frost moon"; break; case -4: - boss = "a pumpkin moon"; + thing = "a pumpkin moon"; break; case -3: - boss = "the Pirates"; + thing = "the Pirates"; break; case -2: - boss = "the Snow Legion"; + thing = "the Snow Legion"; break; case -1: - boss = "a Goblin Invasion"; + thing = "a Goblin Invasion"; break; default: - boss = String.Format("the {0}", npc.FullName); + thing = String.Format("the {0}", npc.FullName); break; } if (TShock.Config.AnonymousBossInvasions) - TShock.Utils.SendLogs(string.Format("{0} summoned {1}!", args.Player.Name, boss), Color.PaleVioletRed, args.Player); + TShock.Utils.SendLogs(string.Format("{0} summoned {1}!", args.Player.Name, thing), Color.PaleVioletRed, args.Player); else - TShock.Utils.Broadcast(String.Format("{0} summoned {1}!", args.Player.Name, boss), 175, 75, 255); + TShock.Utils.Broadcast(String.Format("{0} summoned {1}!", args.Player.Name, thing), 175, 75, 255); return false; } diff --git a/TShockAPI/Permissions.cs b/TShockAPI/Permissions.cs index efd5062d..0aebd037 100644 --- a/TShockAPI/Permissions.cs +++ b/TShockAPI/Permissions.cs @@ -189,7 +189,7 @@ namespace TShockAPI [Description("User can edit the spawnrate.")] public static readonly string spawnrate = "tshock.npc.spawnrate"; - [Description("User can start an invasion.")] + [Description("User can start an invasion. Warning: high network use. Easy to abuse.")] public static readonly string invade = "tshock.npc.invade"; [Description("User can hurt town NPCs.")] @@ -198,6 +198,9 @@ namespace TShockAPI [Description("User can spawn bosses.")] public static readonly string spawnboss = "tshock.npc.spawnboss"; + [Description("User can spawn pets. Warning: high network use. Easy to abuse.")] + public static readonly string spawnpets = "tshock.npc.spawnpets"; + [Description("User can rename NPCs.")] public static readonly string renamenpc = "tshock.npc.rename";