diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 179bd6f4..6ddaffce 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -181,6 +181,7 @@ namespace TShockAPI add(Permissions.item, Item, "item", "i"); add(Permissions.item, Give, "give"); add(Permissions.heal, Heal, "heal"); + add(Permissions.buff, Buff, "buff"); } public static bool HandleCommand(TSPlayer player, string text) @@ -2395,6 +2396,38 @@ namespace TShockAPI } } + //TODO: Add player and time arguments + private static void Buff(CommandArgs args) + { + if (args.Parameters.Count != 1) + { + args.Player.SendMessage("Invalid syntax! Proper syntax: /buff ", Color.Red); + return; + } + int id = 0; + if (!int.TryParse(args.Parameters[0], out id)) + { + var found = Tools.GetBuffByName(args.Parameters[0]); + if (found.Count == 0) + { + args.Player.SendMessage("Invalid buff name!", Color.Red); + return; + } + else if (found.Count > 1) + { + args.Player.SendMessage(string.Format("More than one ({0}) buff matched!", found.Count), Color.Red); + return; + } + id = found[0]; + } + if (id > 0 && id < Main.maxBuffs) + { + //args.TPlayer.AddBuff(id, 60); + args.Player.SetBuff(id); + args.Player.SendMessage(string.Format("You have just buffed yourself with {0} - {1}!", + Tools.GetBuffName(id), Tools.GetBuffDescription(id)), Color.Green); + } + } #endregion Cheat Comamnds } } diff --git a/TShockAPI/Permissions.cs b/TShockAPI/Permissions.cs index b08515a3..f8744206 100644 --- a/TShockAPI/Permissions.cs +++ b/TShockAPI/Permissions.cs @@ -126,6 +126,9 @@ namespace TShockAPI [Description("")] public static readonly string heal; + [Description("User can buff players")] + public static readonly string buff; + static Permissions() { foreach (var field in typeof(Permissions).GetFields()) diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index e63b65bb..d5a7020e 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -337,6 +337,11 @@ namespace TShockAPI SendData(PacketTypes.PlayerSlot, oriinv.name, player, 0f); } + public virtual void SetBuff(int type, int time = 3600) + { + SendData(PacketTypes.PlayerAddBuff, number: Index, number2: (float)type, number3: (float)time); + } + //Todo: Separate this into a few functions. SendTo, SendToAll, etc public virtual void SendData(PacketTypes msgType, string text = "", int number = 0, float number2 = 0f, float number3 = 0f, float number4 = 0f, int number5 = 0) { diff --git a/TShockAPI/Tools.cs b/TShockAPI/Tools.cs index 7ac0d0b3..437ce6ff 100755 --- a/TShockAPI/Tools.cs +++ b/TShockAPI/Tools.cs @@ -306,6 +306,30 @@ namespace TShockAPI return found; } + public static string GetBuffName(int id) + { + return (id > 0 && id < Main.maxBuffs) ? Main.buffName[id] : "null"; + } + public static string GetBuffDescription(int id) + { + return (id > 0 && id < Main.maxBuffs) ? Main.buffTip[id] : "null"; + } + public static List GetBuffByName(string name) + { + for (int i = 1; i < Main.maxBuffs; i++) + { + if (Main.buffName[i].ToLower() == name) + return new List { i }; + } + var found = new List(); + for (int i = 1; i < Main.maxBuffs; i++) + { + if (Main.buffName[i].ToLower().StartsWith(name.ToLower())) + found.Add(i); + } + return found; + } + /// /// Kicks all player from the server without checking for immunetokick permission. ///