From 6d4682ed7e37722054b23c885cd6c85987605ccc Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Sun, 14 May 2023 09:11:18 +0700 Subject: [PATCH 01/12] Updated the `GodMode` field. * Changed the GodMode field to a property that is controlled by the journey mode. - Removed the call to godmode in `Commands.ToggleGodMode`. --- TShockAPI/Commands.cs | 4 ---- TShockAPI/TSPlayer.cs | 11 +++++++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 2214f252..3d1767ea 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -6740,10 +6740,6 @@ namespace TShockAPI playerToGod.GodMode = !playerToGod.GodMode; - var godPower = CreativePowerManager.Instance.GetPower(); - - godPower.SetEnabledState(playerToGod.Index, playerToGod.GodMode); - if (playerToGod != args.Player) { args.Player.SendSuccessMessage(playerToGod.GodMode diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index ef5c3c22..f6ece337 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -34,6 +34,7 @@ using TShockAPI.Hooks; using TShockAPI.Net; using Timer = System.Timers.Timer; using System.Linq; +using Terraria.GameContent.Creative; namespace TShockAPI { @@ -935,9 +936,15 @@ namespace TShockAPI public bool LoginHarassed = false; /// - /// Player cant die, unless onehit + /// Controls the journey godmode /// - public bool GodMode = false; + public bool GodMode + { + get => + CreativePowerManager.Instance.GetPower().IsEnabledForPlayer(Index); + set => + CreativePowerManager.Instance.GetPower().SetEnabledState(Index, value); + } /// /// Players controls are inverted if using SSC From c047b0e87d5309b503c9d0beb91797a81dafe38f Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Sun, 14 May 2023 09:14:43 +0700 Subject: [PATCH 02/12] Added the `Client` property. The `Client` property gets data from the array `Terraria.Netplay.Clients`. --- TShockAPI/TSPlayer.cs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index f6ece337..10b2e760 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -988,7 +988,7 @@ namespace TShockAPI get { return RealPlayer - && (Netplay.Clients[Index] != null && Netplay.Clients[Index].IsActive && !Netplay.Clients[Index].PendingTermination); + && (Client != null && Client.IsActive && !Client.PendingTermination); } } @@ -1005,8 +1005,8 @@ namespace TShockAPI /// public int State { - get { return Netplay.Clients[Index].State; } - set { Netplay.Clients[Index].State = value; } + get { return Client.State; } + set { Client.State = value; } } /// @@ -1014,7 +1014,7 @@ namespace TShockAPI /// public string UUID { - get { return RealPlayer ? Netplay.Clients[Index].ClientUUID : ""; } + get { return RealPlayer ? Client.ClientUUID : ""; } } /// @@ -1026,8 +1026,8 @@ namespace TShockAPI { if (string.IsNullOrEmpty(CacheIP)) return - CacheIP = RealPlayer ? (Netplay.Clients[Index].Socket.IsConnected() - ? TShock.Utils.GetRealIP(Netplay.Clients[Index].Socket.GetRemoteAddress().ToString()) + CacheIP = RealPlayer ? (Client.Socket.IsConnected() + ? TShock.Utils.GetRealIP(Client.Socket.GetRemoteAddress().ToString()) : "") : "127.0.0.1"; else @@ -1110,6 +1110,11 @@ namespace TShockAPI } + /// + /// Player RemoteClient. + /// + public RemoteClient Client => Netplay.Clients[Index]; + /// /// Gets the Terraria Player object associated with the player. /// @@ -2071,7 +2076,7 @@ namespace TShockAPI if (!RealPlayer || !ConnectionAlive) return; - Netplay.Clients[Index].Socket.AsyncSend(data, 0, data.Length, Netplay.Clients[Index].ServerWriteCallBack); + Client.Socket.AsyncSend(data, 0, data.Length, Client.ServerWriteCallBack); } /// From fa9e4419bd6ca6830a1b7684dfff168e549b0420 Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Sun, 14 May 2023 09:16:14 +0700 Subject: [PATCH 03/12] Added documentation to the `withMsg` parameter in the `SetPvP` method. --- TShockAPI/TSPlayer.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 10b2e760..f4cd0a3d 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -1852,6 +1852,7 @@ namespace TShockAPI /// Sets the player's pvp. /// /// The state of the pvp mode. + /// Whether a chat message about the change should be sent. public virtual void SetPvP(bool mode, bool withMsg = false) { Main.player[Index].hostile = mode; From 3647bbaf54d16ceead0a0ab96172d113f1d20d93 Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Sun, 14 May 2023 09:20:20 +0700 Subject: [PATCH 04/12] Added a reason for the `KillPlayer` and `DamagePlayer` methods. Added overloads that have a cause in the parameters (`PlayerDeathReason`) --- TShockAPI/TSPlayer.cs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index f4cd0a3d..6bfe0c44 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -1827,7 +1827,17 @@ namespace TShockAPI /// The amount of damage the player will take. public virtual void DamagePlayer(int damage) { - NetMessage.SendPlayerHurt(Index, PlayerDeathReason.LegacyDefault(), damage, (new Random()).Next(-1, 1), false, false, 0, -1, -1); + DamagePlayer(damage, PlayerDeathReason.LegacyDefault()); + } + + /// + /// Wounds the player with the given damage. + /// + /// The amount of damage the player will take. + /// The reason for causing damage to player. + public virtual void DamagePlayer(int damage, PlayerDeathReason reason) + { + NetMessage.SendPlayerHurt(Index, reason, damage, (new Random()).Next(-1, 1), false, false, 0, -1, -1); } /// @@ -1835,7 +1845,16 @@ namespace TShockAPI /// public virtual void KillPlayer() { - NetMessage.SendPlayerDeath(Index, PlayerDeathReason.LegacyDefault(), 99999, (new Random()).Next(-1, 1), false, -1, -1); + KillPlayer(PlayerDeathReason.LegacyDefault()); + } + + /// + /// Kills the player. + /// + /// Reason for killing a player. + public virtual void KillPlayer(PlayerDeathReason reason) + { + NetMessage.SendPlayerDeath(Index, reason, 99999, (new Random()).Next(-1, 1), false, -1, -1); } /// From d9352d690240ad34d142fae30b2e37c26e2e9b86 Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Sun, 14 May 2023 09:23:42 +0700 Subject: [PATCH 05/12] Added an exception that occurs when the developer changes team. --- TShockAPI/TSPlayer.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 6bfe0c44..284d9a31 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -1863,6 +1863,8 @@ namespace TShockAPI /// The team color index. public virtual void SetTeam(int team) { + if (team < 0 || team >= Main.teamColor.Length) + throw new ArgumentException("The player's team is not in the range of available."); Main.player[Index].team = team; NetMessage.SendData((int)PacketTypes.PlayerTeam, -1, -1, NetworkText.Empty, Index); } From 3d585d4d699d74c0f3f4cd569e00f7fae9f5324a Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Sun, 14 May 2023 09:38:35 +0700 Subject: [PATCH 06/12] Added the `UpdateSection` method. I described its action in the comments. --- TShockAPI/TSPlayer.cs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 284d9a31..79572412 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -1499,6 +1499,41 @@ namespace TShockAPI return false; } + /// + /// Changes the values of the array. + /// + /// The area of the sections you want to set a value to. + /// The minimum size should be set to 200x150. If null, then the entire map is specified. + /// Is the section loaded. + // The server does not send the player the whole world, it sends it in sections. To do this, it sets up visible and invisible sections. + // If the player was not in any section(Client.TileSections[x, y] == false) then the server will send the missing section of the world. + // This method allows you to simulate what the player has or has not seen these sections. + // For example, we can put some number of earths blocks in some vast area, for example, for the whole world, but the player will not see the changes, because some section is already loaded for him. At this point this method can come into effect! With it we will be able to select some zone and make it both visible and invisible to the player. + // The server will assume that the zone is not loaded on the player, and will resend the data, but with earth blocks. + public void UpdateSection(Rectangle? rectangle = null, bool isLoaded = false) + { + if (rectangle.HasValue) + { + for (int i = Netplay.GetSectionX(rectangle.Value.X); i < Netplay.GetSectionX(rectangle.Value.X + rectangle.Value.Width) && i < Main.maxSectionsX; i++) + { + for (int j = Netplay.GetSectionY(rectangle.Value.Y); j < Netplay.GetSectionY(rectangle.Value.Y + rectangle.Value.Height) && j < Main.maxSectionsY; j++) + { + Client.TileSections[i, j] = isLoaded; + } + } + } + else + { + for (int i = 0; i < Main.maxSectionsX; i++) + { + for (int j = 0; j < Main.maxSectionsY; j++) + { + Client.TileSections[i, j] = isLoaded; + } + } + } + } + /// /// Gives an item to the player. Includes banned item spawn prevention to check if the player can spawn the item. /// From 2f7514c0efc1c9411e7346bdb00852935c4a0533 Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Sun, 14 May 2023 09:43:18 +0700 Subject: [PATCH 07/12] Added an overload for `TSPlayer.GiveItem` Added `TShockAPI.NetItem` structure to the parameters. --- TShockAPI/TSPlayer.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 79572412..8aadacdf 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -1566,6 +1566,15 @@ namespace TShockAPI GiveItemByDrop(type, stack, prefix); } + /// + /// Gives an item to the player. + /// + /// Item with data to be given to the player. + public virtual void GiveItem(NetItem item) + { + GiveItem(item.NetId, item.Stack, item.PrefixId); + } + private Item EmptySentinelItem = new Item(); private bool Depleted(Item item) From 4d92f11cc805a52906abf974c6caf043035f5b4c Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Sun, 14 May 2023 09:56:47 +0700 Subject: [PATCH 08/12] Added the `TSPlayer.Hostile` property. It gets `TPlayer.hostile`. I also wanted to add the ability to change `TPlayer.hostile`, but noticed a property `TSPlayer.Team`. You can only use the `TSPlayer.SetTeam` method to change it. So it's exactly the same here: You can use the method `TSPlayer.SetPvP` (By the way, it should be renamed to `TSPlayer.SetHostile`) --- TShockAPI/TSPlayer.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 8aadacdf..c9194c36 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -1147,6 +1147,11 @@ namespace TShockAPI get { return TPlayer.team; } } + /// + /// Gets PvP player mode. + /// + public bool Hostile => TPlayer.hostile; + /// /// Gets the player's X coordinate. /// From b30a8cb6b2c4f1d5fff8b12e1ce58c01e70c57b9 Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Sun, 14 May 2023 10:03:55 +0700 Subject: [PATCH 09/12] Update changelog.md --- docs/changelog.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/changelog.md b/docs/changelog.md index 3f64f355..f02867f8 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -78,7 +78,16 @@ Use past tense when adding new entries; sign your name off when you add or chang * If there is no section called "Upcoming changes" below this line, please add one with `## Upcoming changes` as the first line, and then a bulleted item directly after with the first change. --> ## Upcoming changes -Your changes could be here! +* Updated `TSPlayer.GodMode`. (@AgaSpace) + * Previously the field was used as some kind of dataset changed by /godmode command, but now it is a property that receives/changes data in journey mode. +* Added the `TSPlayer.Client` property. It allows the developer to get the `RemoteClient` player, without an additional call to `Terraria.Netplay.Clients`. (@AgaSpace) +* Updated the documentation for the `TSPlayer.SetPvP` method. The `sendMsg` parameter, which is responsible for sending a pvp mode change message, was not documented earlier. (@AgaSpace) +* Added methods `TSPlayer.KillPlayer` and `TSPlayer.DamagePlayer` for which you can specify the cause (`PlayerDeathReason`) in parameters. +* Added an error when trying to change a `TSPlayer` team to, say, 9, when there are only 6. (@AgaSpace) +* Added an error when trying to call the `TSPlayer.SetTeam` method with an argument (team) greater than 5 or less than 0. (@AgaSpace) +* Added a method `TSPlayer.UpdateSection` with arguments `rectangle` and `isLoaded`, which will load some area from the server to the player. (@AgaSpace) +* Added a method `TSPlayer.GiveItem`, which has `TShockAPI.NetItem` structure in its arguments. (@AgaSpace) +* Added a property `TSPlayer.Hostile`, which gets pvp player mode. ## TShock 5.2 * An additional option `pvpwithnoteam` is added at `PvPMode` to enable PVP with no team. (@CelestialAnarchy, #2617, @ATFGK) From 72ecc472187dde708ea2a2d1176e3b9872cd27f7 Mon Sep 17 00:00:00 2001 From: James Puleo Date: Fri, 9 Jun 2023 05:52:19 -0400 Subject: [PATCH 10/12] Update `docs/changelog.md` (#2953) --- docs/changelog.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index f02867f8..89e4d39c 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -82,12 +82,12 @@ Use past tense when adding new entries; sign your name off when you add or chang * Previously the field was used as some kind of dataset changed by /godmode command, but now it is a property that receives/changes data in journey mode. * Added the `TSPlayer.Client` property. It allows the developer to get the `RemoteClient` player, without an additional call to `Terraria.Netplay.Clients`. (@AgaSpace) * Updated the documentation for the `TSPlayer.SetPvP` method. The `sendMsg` parameter, which is responsible for sending a pvp mode change message, was not documented earlier. (@AgaSpace) -* Added methods `TSPlayer.KillPlayer` and `TSPlayer.DamagePlayer` for which you can specify the cause (`PlayerDeathReason`) in parameters. +* Added methods `TSPlayer.KillPlayer` and `TSPlayer.DamagePlayer` for which you can specify the cause (`PlayerDeathReason`) in parameters. (@AgaSpace) * Added an error when trying to change a `TSPlayer` team to, say, 9, when there are only 6. (@AgaSpace) * Added an error when trying to call the `TSPlayer.SetTeam` method with an argument (team) greater than 5 or less than 0. (@AgaSpace) * Added a method `TSPlayer.UpdateSection` with arguments `rectangle` and `isLoaded`, which will load some area from the server to the player. (@AgaSpace) * Added a method `TSPlayer.GiveItem`, which has `TShockAPI.NetItem` structure in its arguments. (@AgaSpace) -* Added a property `TSPlayer.Hostile`, which gets pvp player mode. +* Added a property `TSPlayer.Hostile`, which gets pvp player mode. (@AgaSpace) ## TShock 5.2 * An additional option `pvpwithnoteam` is added at `PvPMode` to enable PVP with no team. (@CelestialAnarchy, #2617, @ATFGK) From 5bcde689d4262ae18ca639e4a9895d078ba31cc4 Mon Sep 17 00:00:00 2001 From: SGKoishi Date: Sun, 11 Jun 2023 22:11:20 -0700 Subject: [PATCH 11/12] Fix a typo in gbuff --- TShockAPI/Commands.cs | 2 +- docs/changelog.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 3d1767ea..a4669b04 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -6462,7 +6462,7 @@ namespace TShockAPI if (target == user) user.SendSuccessMessage(GetString($"You buffed yourself with {TShock.Utils.GetBuffName(id)} ({TShock.Utils.GetBuffDescription(id)}) for {time} seconds.")); else - target.SendSuccessMessage(GetString($"You have buffed {user.Name} with {TShock.Utils.GetBuffName(id)} ({TShock.Utils.GetBuffDescription(id)}) for {time} seconds!")); + user.SendSuccessMessage(GetString($"You have buffed {user.Name} with {TShock.Utils.GetBuffName(id)} ({TShock.Utils.GetBuffDescription(id)}) for {time} seconds!")); if (!args.Silent && target != user) target.SendSuccessMessage(GetString($"{user.Name} has buffed you with {TShock.Utils.GetBuffName(id)} ({TShock.Utils.GetBuffDescription(id)}) for {time} seconds!")); } diff --git a/docs/changelog.md b/docs/changelog.md index 89e4d39c..d4ab3cfe 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -88,6 +88,7 @@ Use past tense when adding new entries; sign your name off when you add or chang * Added a method `TSPlayer.UpdateSection` with arguments `rectangle` and `isLoaded`, which will load some area from the server to the player. (@AgaSpace) * Added a method `TSPlayer.GiveItem`, which has `TShockAPI.NetItem` structure in its arguments. (@AgaSpace) * Added a property `TSPlayer.Hostile`, which gets pvp player mode. (@AgaSpace) +* Fixed typo in `/gbuff`. (@sgkoishi, #2955) ## TShock 5.2 * An additional option `pvpwithnoteam` is added at `PvPMode` to enable PVP with no team. (@CelestialAnarchy, #2617, @ATFGK) From f66ad72e2caeec3de8c6a64cc007afdc83d1637a Mon Sep 17 00:00:00 2001 From: Stargazing Koishi Date: Sun, 11 Jun 2023 22:20:48 -0700 Subject: [PATCH 12/12] Update TShockAPI/Commands.cs Co-authored-by: punchready <22683812+punchready@users.noreply.github.com> --- TShockAPI/Commands.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index a4669b04..d39b84e0 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -6462,7 +6462,7 @@ namespace TShockAPI if (target == user) user.SendSuccessMessage(GetString($"You buffed yourself with {TShock.Utils.GetBuffName(id)} ({TShock.Utils.GetBuffDescription(id)}) for {time} seconds.")); else - user.SendSuccessMessage(GetString($"You have buffed {user.Name} with {TShock.Utils.GetBuffName(id)} ({TShock.Utils.GetBuffDescription(id)}) for {time} seconds!")); + user.SendSuccessMessage(GetString($"You have buffed {target.Name} with {TShock.Utils.GetBuffName(id)} ({TShock.Utils.GetBuffDescription(id)}) for {time} seconds!")); if (!args.Silent && target != user) target.SendSuccessMessage(GetString($"{user.Name} has buffed you with {TShock.Utils.GetBuffName(id)} ({TShock.Utils.GetBuffDescription(id)}) for {time} seconds!")); }