Merge pull request #1812 from AxeelAnder/spawn

Fix player spawn stuff
This commit is contained in:
Axeel 2020-05-20 22:44:02 +08:00 committed by GitHub
commit 53d211bd8e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 56 additions and 40 deletions

View file

@ -2,6 +2,9 @@
This is the rolling changelog for TShock for Terraria. Use past tense when adding new entries; sign your name off when you add or change something. This should primarily be things like user changes, not necessarily codebase changes unless it's really relevant or large. This is the rolling changelog for TShock for Terraria. Use past tense when adding new entries; sign your name off when you add or change something. This should primarily be things like user changes, not necessarily codebase changes unless it's really relevant or large.
## Upcoming changes
* Update player spawn related things to 1.4. `Terraria.Player.Spawn` method now has a required argument, `PlayerSpawnContext context`. (@AxeelAnder)
## TShock 4.4.0 (Pre-release 4) ## TShock 4.4.0 (Pre-release 4)
* Debug logging now provides ConsoleDebug and ILog has been updated to support the concept of debug logs. Debug logs are now controlled by `config.json` instead of by preprocessor debug flag. (@hakusaro) * Debug logging now provides ConsoleDebug and ILog has been updated to support the concept of debug logs. Debug logs are now controlled by `config.json` instead of by preprocessor debug flag. (@hakusaro)
* Removed `/confuse` command and Terraria player data resync from @Zidonuke. (@hakusaro) * Removed `/confuse` command and Terraria player data resync from @Zidonuke. (@hakusaro)

View file

@ -164,7 +164,7 @@ namespace TShockAPI
var lastTileY = args.Player.LastNetPosition.Y - 48; var lastTileY = args.Player.LastNetPosition.Y - 48;
if (!args.Player.Teleport(lastTileX, lastTileY)) if (!args.Player.Teleport(lastTileX, lastTileY))
{ {
args.Player.Spawn(); args.Player.Spawn(PlayerSpawnContext.RecallFromItem);
} }
TShock.Log.ConsoleDebug("Bouncer / OnPlayerUpdate rejected from (??) {0}", args.Player.Name); TShock.Log.ConsoleDebug("Bouncer / OnPlayerUpdate rejected from (??) {0}", args.Player.Name);
args.Handled = true; args.Handled = true;

View file

@ -2565,7 +2565,7 @@ namespace TShockAPI
private static void Home(CommandArgs args) private static void Home(CommandArgs args)
{ {
args.Player.Spawn(); args.Player.Spawn(PlayerSpawnContext.RecallFromItem);
args.Player.SendSuccessMessage("Teleported to your spawnpoint."); args.Player.SendSuccessMessage("Teleported to your spawnpoint.");
} }

View file

@ -2662,7 +2662,7 @@ namespace TShockAPI
if (type == 1 && TShock.Config.DisableDungeonGuardian) if (type == 1 && TShock.Config.DisableDungeonGuardian)
{ {
args.Player.SendMessage("The Dungeon Guardian returned you to your spawn point", Color.Purple); args.Player.SendMessage("The Dungeon Guardian returned you to your spawn point", Color.Purple);
args.Player.Spawn(); args.Player.Spawn(PlayerSpawnContext.RecallFromItem);
return true; return true;
} }

View file

@ -1,4 +1,4 @@
/* /*
TShock, a server mod for Terraria TShock, a server mod for Terraria
Copyright (C) 2011-2019 Pryaxis & TShock Contributors Copyright (C) 2011-2019 Pryaxis & TShock Contributors
@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
using System.IO; using System.IO;
using System.IO.Streams; using System.IO.Streams;
using Terraria;
namespace TShockAPI.Net namespace TShockAPI.Net
{ {
@ -28,15 +29,19 @@ namespace TShockAPI.Net
get { return PacketTypes.PlayerSpawn; } get { return PacketTypes.PlayerSpawn; }
} }
public byte PlayerIndex { get; set; }
public short TileX { get; set; } public short TileX { get; set; }
public short TileY { get; set; } public short TileY { get; set; }
public byte PlayerIndex { get; set; } public int RespawnTimer { get; set; }
public PlayerSpawnContext PlayerSpawnContext { get; set; }
public override void Pack(Stream stream) public override void Pack(Stream stream)
{ {
stream.WriteInt8(PlayerIndex); stream.WriteInt8(PlayerIndex);
stream.WriteInt32(TileX); stream.WriteInt16(TileX);
stream.WriteInt32(TileY); stream.WriteInt16(TileY);
stream.WriteInt32(RespawnTimer);
stream.WriteByte((byte) PlayerSpawnContext);
} }
} }
} }

View file

@ -297,7 +297,11 @@ namespace TShockAPI
/// <summary> /// <summary>
/// The player's respawn timer. /// The player's respawn timer.
/// </summary> /// </summary>
public int RespawnTimer; public int RespawnTimer
{
get => TPlayer.respawnTimer;
set => TPlayer.respawnTimer = value;
}
/// <summary> /// <summary>
/// Whether the player is dead or not. /// Whether the player is dead or not.
@ -1164,15 +1168,15 @@ namespace TShockAPI
/// <summary> /// <summary>
/// Spawns the player at his spawn point. /// Spawns the player at his spawn point.
/// </summary> /// </summary>
public void Spawn() public void Spawn(PlayerSpawnContext context, int? respawnTimer = null)
{ {
if (this.sX > 0 && this.sY > 0) if (this.sX > 0 && this.sY > 0)
{ {
Spawn(this.sX, this.sY); Spawn(this.sX, this.sY, context, respawnTimer);
} }
else else
{ {
Spawn(TPlayer.SpawnX, TPlayer.SpawnY); Spawn(TPlayer.SpawnX, TPlayer.SpawnY, context, respawnTimer);
} }
} }
@ -1181,7 +1185,9 @@ namespace TShockAPI
/// </summary> /// </summary>
/// <param name="tilex">The X coordinate.</param> /// <param name="tilex">The X coordinate.</param>
/// <param name="tiley">The Y coordinate.</param> /// <param name="tiley">The Y coordinate.</param>
public void Spawn(int tilex, int tiley) /// <param name="context">The PlayerSpawnContext.</param>
/// <param name="respawnTimer">The respawn timer, will be Player.respawnTimer if parameter is null.</param>
public void Spawn(int tilex, int tiley, PlayerSpawnContext context, int? respawnTimer = null)
{ {
using (var ms = new MemoryStream()) using (var ms = new MemoryStream())
{ {
@ -1189,7 +1195,9 @@ namespace TShockAPI
{ {
PlayerIndex = (byte)Index, PlayerIndex = (byte)Index,
TileX = (short)tilex, TileX = (short)tilex,
TileY = (short)tiley TileY = (short)tiley,
RespawnTimer = respawnTimer ?? TShock.Players[Index].TPlayer.respawnTimer,
PlayerSpawnContext = context,
}; };
msg.PackFull(ms); msg.PackFull(ms);
SendRawData(ms.ToArray()); SendRawData(ms.ToArray());

View file

@ -1047,7 +1047,7 @@ namespace TShockAPI
if (player.RespawnTimer > 0 && --player.RespawnTimer == 0 && player.Difficulty != 2) if (player.RespawnTimer > 0 && --player.RespawnTimer == 0 && player.Difficulty != 2)
{ {
player.Spawn(); player.Spawn(PlayerSpawnContext.ReviveFromDeath);
} }
if (!Main.ServerSideCharacter || (Main.ServerSideCharacter && player.IsLoggedIn)) if (!Main.ServerSideCharacter || (Main.ServerSideCharacter && player.IsLoggedIn))