Add /buff <buff id/name>

This commit is contained in:
Deathmax 2011-08-20 12:14:49 +08:00
parent 2cdb9dc953
commit 2c1c75db2b
4 changed files with 65 additions and 0 deletions

View file

@ -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 <buff id/name>", 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
}
}

View file

@ -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())

View file

@ -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)
{

View file

@ -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<int> GetBuffByName(string name)
{
for (int i = 1; i < Main.maxBuffs; i++)
{
if (Main.buffName[i].ToLower() == name)
return new List<int> { i };
}
var found = new List<int>();
for (int i = 1; i < Main.maxBuffs; i++)
{
if (Main.buffName[i].ToLower().StartsWith(name.ToLower()))
found.Add(i);
}
return found;
}
/// <summary>
/// Kicks all player from the server without checking for immunetokick permission.
/// </summary>