From 08843714a32b7dc170b81fea210374565c16d7f8 Mon Sep 17 00:00:00 2001 From: Deathmax Date: Fri, 8 Jul 2011 19:27:18 +0800 Subject: [PATCH] /annoy (currently disabled) --- TShockAPI/Commands.cs | 24 ++++++++++++++++++++++++ TShockAPI/TSPlayer.cs | 27 +++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 520defb1..d8356e17 100755 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -167,6 +167,7 @@ namespace TShockAPI ChatCommands.Add(new Command("cfg", Broadcast, "broadcast", "bc")); ChatCommands.Add(new Command("whisper", Whisper, "whisper", "w", "tell")); ChatCommands.Add(new Command("whisper", Reply, "reply", "r")); + //ChatCommands.Add(new Command("annoy", Annoy, "annoy")); if (TShock.Config.DistributationAgent != "terraria-online") { ChatCommands.Add(new Command("kill", Kill, "kill")); @@ -1487,6 +1488,29 @@ namespace TShockAPI else args.Player.SendMessage("You haven't previously received any whispers. Please use /whisper to whisper to other people.", Color.Red); } + + private static void Annoy(CommandArgs args) + { + if (args.Parameters.Count != 2) + { + args.Player.SendMessage("Invalid syntax! Proper syntax: /annoy ", Color.Red); + return; + } + int annoy = 5; + int.TryParse(args.Parameters[1], out annoy); + + var players = Tools.FindPlayer(args.Parameters[0]); + if (players.Count == 0) + args.Player.SendMessage("Invalid player!", Color.Red); + else if (players.Count > 1) + args.Player.SendMessage("More than one player matched!", Color.Red); + else + { + var ply = players[0]; + args.Player.SendMessage("Annoying " + ply.Name + " for " + annoy.ToString() + " seconds."); + (new Thread(new ParameterizedThreadStart(ply.Whoopie))).Start(annoy); + } + } #endregion General Commands #region Cheat Commands diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 472a1513..f6507e50 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -259,6 +259,33 @@ namespace TShockAPI NetMessage.SendData((int)PacketTypes.TogglePVP, -1, -1, "", Index); } + public virtual void Whoopie(object time) + { + var time2 = (int)time; + var launch = DateTime.UtcNow; + var player = 0; + for (int i = 0; i < Main.maxPlayers; i++) + if (Main.player[i] != null & Main.player[i].active && i != Index) + player = i; + + var oriinv = Main.player[0].inventory[player]; + while ((DateTime.UtcNow - launch).TotalSeconds < time2) + { + Main.player[0].inventory[player].SetDefaults("Whoopie Cushion"); + SendData(TerrariaAPI.PacketTypes.PlayerSlot, "Whoopie Cushion", player, 0f); + Main.player[player].position = TPlayer.position; + Main.player[player].selectedItem = 0; + Main.player[player].controlUseItem = true; + SendData(TerrariaAPI.PacketTypes.PlayerUpdate, number: player); + Main.player[player].controlUseItem = false; + Main.player[player].controlJump = true; + SendData(TerrariaAPI.PacketTypes.PlayerUpdate, number: player); + System.Threading.Thread.Sleep(500); + } + Main.player[0].inventory[0] = oriinv; + SendData(TerrariaAPI.PacketTypes.PlayerSlot, oriinv.name, player, 0f); + } + //Todo: Separate this into a few functions. SendTo, SendToAll, etc public void SendData(PacketTypes msgType, string text = "", int number = 0, float number2 = 0f, float number3 = 0f, float number4 = 0f, int number5 = 0) {