diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 7364e6eb..f6c60839 100755 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -367,6 +367,9 @@ namespace TShockAPI get { return Index >= 0 && Index < Main.maxNetPlayers && Main.player[Index] != null; } } + /// + /// Checks if the player is active and not pending termination. + /// public bool ConnectionAlive { get @@ -377,13 +380,16 @@ namespace TShockAPI } /// - /// Gets the player's selected item. + /// Gets the item that the player is currently holding. /// public Item SelectedItem { get { return TPlayer.inventory[TPlayer.selectedItem]; } } + /// + /// Gets the player's Client State. + /// public int State { get { return Netplay.Clients[Index].State; } @@ -416,6 +422,9 @@ namespace TShockAPI } } + /// + /// Gets the player's accessories. + /// public IEnumerable Accessories { get @@ -477,43 +486,64 @@ namespace TShockAPI } /// - /// Terraria Player + /// Gets the Terraria Player object associated with the player. /// public Player TPlayer { get { return FakePlayer ?? Main.player[Index]; } } + /// + /// Gets the player's name. + /// public string Name { get { return TPlayer.name; } } + /// + /// Gets the player's active state. + /// public bool Active { get { return TPlayer != null && TPlayer.active; } } + /// + /// Gets the player's team. + /// public int Team { get { return TPlayer.team; } } + /// + /// Gets the player's X coordinate. + /// public float X { get { return RealPlayer ? TPlayer.position.X : Main.spawnTileX*16; } } + /// + /// Gets the player's Y coordinate. + /// public float Y { get { return RealPlayer ? TPlayer.position.Y : Main.spawnTileY*16; } } + /// + /// Gets the player's X tile coordinate. + /// public int TileX { get { return (int) (X/16); } } + /// + /// Gets the player's Y tile coordinate. + /// public int TileY { get { return (int) (Y/16); } @@ -521,6 +551,9 @@ namespace TShockAPI public bool TpLock; + /// + /// Checks if the player has any inventory slots available. + /// public bool InventorySlotAvailable { get @@ -617,11 +650,16 @@ namespace TShockAPI AwaitingResponse = new Dictionary>(); } + /// + /// Disconnects the player from the server. + /// + /// The reason why the player was disconnected. public virtual void Disconnect(string reason) { SendData(PacketTypes.Disconnect, reason); } + [Obsolete("This method is no longer used.")] public virtual void Flush() { var client = Netplay.Clients[Index]; @@ -631,7 +669,11 @@ namespace TShockAPI //TShock.PacketBuffer.Flush(client); } - + /// + /// Fired when the player's temporary group access expires. + /// + /// + /// public void TempGroupTimerElapsed(object sender, ElapsedEventArgs args) { SendWarningMessage("Your temporary group access has expired."); @@ -643,6 +685,13 @@ namespace TShockAPI } } + /// + /// Teleports a player to the given coordinates in the world. + /// + /// The X coordinate. + /// The Y coordinate. + /// The teleportation style. + /// True or false. public bool Teleport(float x, float y, byte style = 1) { if (x > Main.rightWorld - 992) @@ -668,11 +717,18 @@ namespace TShockAPI return true; } + /// + /// Heals the player. + /// + /// Heal health amount. public void Heal(int health = 600) { NetMessage.SendData((int)PacketTypes.PlayerHealOther, -1, -1, "", this.TPlayer.whoAmI, health); } + /// + /// Spawns the player at his spawn point. + /// public void Spawn() { if (this.sX > 0 && this.sY > 0) @@ -685,6 +741,11 @@ namespace TShockAPI } } + /// + /// Spawns the player at the given coordinates. + /// + /// The X coordinate. + /// The Y coordinate. public void Spawn(int tilex, int tiley) { using (var ms = new MemoryStream()) @@ -700,6 +761,11 @@ namespace TShockAPI } } + /// + /// Removes the projectile with the given index and owner. + /// + /// The projectile's index. + /// The projectile's owner. public void RemoveProjectile(int index, int owner) { using (var ms = new MemoryStream()) @@ -764,6 +830,16 @@ namespace TShockAPI return false; } + /// + /// Gives an item to the player. Includes banned item spawn prevention to check if the player can spawn the item. + /// + /// + /// + /// + /// + /// + /// + /// True or false, depending if the item passed the check or not. public bool GiveItemCheck(int type, string name, int width, int height, int stack, int prefix = 0) { if ((TShock.Itembans.ItemIsBanned(name) && TShock.Config.PreventBannedItemSpawn) && @@ -774,6 +850,15 @@ namespace TShockAPI return true; } + /// + /// Gives an item to the player. + /// + /// The item's netID. + /// The tiem's name. + /// The item's width. + /// The item's height. + /// The item's stack. + /// The item's prefix. public virtual void GiveItem(int type, string name, int width, int height, int stack, int prefix = 0) { int itemid = Item.NewItem((int) X, (int) Y, width, height, type, stack, true, prefix, true); @@ -792,52 +877,105 @@ namespace TShockAPI NetMessage.SendData((int)PacketTypes.ItemOwner, -1, -1, "", itemid, 0f, 0f, 0f); } + /// + /// Sends an information message to the player. + /// + /// The message. public virtual void SendInfoMessage(string msg) { SendMessage(msg, Color.Yellow); } + /// + /// Sends an information message to the player. + /// Replaces format items in the message with the string representation of a specified object. + /// + /// The message. + /// An array of objects to format. public void SendInfoMessage(string format, params object[] args) { SendInfoMessage(string.Format(format, args)); } + /// + /// Sends a success message to the player. + /// + /// The message. public virtual void SendSuccessMessage(string msg) { SendMessage(msg, Color.Green); } + /// + /// Sends a success message to the player. + /// Replaces format items in the message with the string representation of a specified object. + /// + /// The message. + /// An array of objects to format. public void SendSuccessMessage(string format, params object[] args) { SendSuccessMessage(string.Format(format, args)); } + /// + /// Sends a warning message to the player. + /// + /// The message. public virtual void SendWarningMessage(string msg) { SendMessage(msg, Color.OrangeRed); } + /// + /// Sends a warning message to the player. + /// Replaces format items in the message with the string representation of a specified object. + /// + /// The message. + /// An array of objects to format. public void SendWarningMessage(string format, params object[] args) { SendWarningMessage(string.Format(format, args)); } + /// + /// Sends an error message to the player. + /// + /// The message. public virtual void SendErrorMessage(string msg) { SendMessage(msg, Color.Red); } + /// + /// Sends an error message to the player. + /// Replaces format items in the message with the string representation of a specified object + /// + /// The message. + /// An array of objects to format. public void SendErrorMessage(string format, params object[] args) { SendErrorMessage(string.Format(format, args)); } + /// + /// Sends a message with the specified color. + /// + /// The message. + /// The message color. public virtual void SendMessage(string msg, Color color) { SendMessage(msg, color.R, color.G, color.B); } - public virtual void SendMessage(string msg, byte red, byte green, byte blue) + /// + /// Sends a message with the specified RGB color. + /// + /// The message. + /// The amount of red color to factor in. Max: 255. + /// The amount of green color to factor in. Max: 255 + /// The amount of blue color to factor in. Max: 255 + /// The number of pixels before the message splits lines. Defaults to -1, which is the client's screen width. + public virtual void SendMessage(string msg, byte red, byte green, byte blue, int messageLength = -1) { if (msg.Contains("\n")) { @@ -848,10 +986,19 @@ namespace TShockAPI } return; } - SendData(PacketTypes.ChatText, msg, 255, red, green, blue); + SendData(PacketTypes.SmartTextMessage, msg, 255, red, green, blue, messageLength); } - public virtual void SendMessageFromPlayer(string msg, byte red, byte green, byte blue, int ply) + /// + /// Sends a message to a player with the specified RGB color. + /// + /// The message. + /// The amount of red color to factor in. Max: 255. + /// The amount of green color to factor in. Max: 255. + /// The amount of blue color to factor in. Max: 255. + /// The player who receives the message. + /// The number of pixels before the message splits lines. Defaults to -1, which is the client's screen width. + public virtual void SendMessageFromPlayer(string msg, byte red, byte green, byte blue, int ply, int messageLength = -1) { if (msg.Contains("\n")) { @@ -862,15 +1009,23 @@ namespace TShockAPI } return; } - SendDataFromPlayer(PacketTypes.ChatText, ply, msg, red, green, blue, 0); + SendDataFromPlayer(PacketTypes.SmartTextMessage, ply, msg, red, green, blue, messageLength); } + /// + /// Wounds the player with the given damage. + /// + /// The amount of damage the player will take. public virtual void DamagePlayer(int damage) { NetMessage.SendData((int) PacketTypes.PlayerDamage, -1, -1, "", Index, ((new Random()).Next(-1, 1)), damage, (float) 0); } + /// + /// Sets the player's team. + /// + /// The team color index. public virtual void SetTeam(int team) { Main.player[Index].team = team; @@ -879,7 +1034,15 @@ namespace TShockAPI } private DateTime LastDisableNotification = DateTime.UtcNow; + + /// + /// Represents the ID of the chest that the player is viewing. + /// public int ActiveChest = -1; + + /// + /// Represents the current item the player is holding. + /// public Item ItemInHand = new Item(); /// @@ -968,6 +1131,12 @@ namespace TShockAPI } } + /// + /// Applies a buff to the player. + /// + /// The buff type. + /// The buff duration. + /// public virtual void SetBuff(int type, int time = 3600, bool bypass = false) { if ((DateTime.UtcNow - LastThreat).TotalMilliseconds < 5000 && !bypass) @@ -977,6 +1146,16 @@ namespace TShockAPI } //Todo: Separate this into a few functions. SendTo, SendToAll, etc + /// + /// Sends data to the player. + /// + /// The sent packet + /// The packet text. + /// + /// + /// + /// + /// public virtual void SendData(PacketTypes msgType, string text = "", int number = 0, float number2 = 0f, float number3 = 0f, float number4 = 0f, int number5 = 0) { @@ -986,6 +1165,16 @@ namespace TShockAPI NetMessage.SendData((int) msgType, Index, -1, text, number, number2, number3, number4, number5); } + /// + /// Sends data from the given player. + /// + /// The sent packet. + /// The packet sender. + /// The packet text. + /// + /// + /// + /// public virtual void SendDataFromPlayer(PacketTypes msgType, int ply, string text = "", float number2 = 0f, float number3 = 0f, float number4 = 0f, int number5 = 0) { @@ -995,6 +1184,10 @@ namespace TShockAPI NetMessage.SendData((int) msgType, Index, -1, text, ply, number2, number3, number4, number5); } + /// + /// Sends raw data to the player's socket object. + /// + /// The data to send. public virtual void SendRawData(byte[] data) { if (!RealPlayer || !ConnectionAlive) @@ -1053,7 +1246,7 @@ namespace TShockAPI SendMessage(msg, color.R, color.G, color.B); } - public override void SendMessage(string msg, byte red, byte green, byte blue) + public override void SendMessage(string msg, byte red, byte green, byte blue, int messageLength = -1) { this.CommandOutput.Add(msg); } diff --git a/TShockAPI/TSServerPlayer.cs b/TShockAPI/TSServerPlayer.cs index 7618e0ca..c658d9a1 100644 --- a/TShockAPI/TSServerPlayer.cs +++ b/TShockAPI/TSServerPlayer.cs @@ -50,7 +50,7 @@ namespace TShockAPI SendMessage(msg, color.R, color.G, color.B); } - public override void SendMessage(string msg, byte red, byte green, byte blue) + public override void SendMessage(string msg, byte red, byte green, byte blue, int messageLength = -1) { Console.WriteLine(msg); }