fix player spawn stuff

This commit is contained in:
鱼鱼 2020-05-20 21:27:49 +08:00
parent 208afe9a7e
commit 946d54b69e
6 changed files with 53 additions and 38 deletions

View file

@ -164,7 +164,7 @@ namespace TShockAPI
var lastTileY = args.Player.LastNetPosition.Y - 48;
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);
args.Handled = true;

View file

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

View file

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

View file

@ -1,4 +1,4 @@
/*
/*
TShock, a server mod for Terraria
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.Streams;
using Terraria;
namespace TShockAPI.Net
{
@ -28,15 +29,21 @@ namespace TShockAPI.Net
get { return PacketTypes.PlayerSpawn; }
}
public byte PlayerIndex { get; set; }
public short TileX { 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)
{
stream.WriteInt8(PlayerIndex);
stream.WriteInt32(TileX);
stream.WriteInt32(TileY);
// stream.WriteInt16(TileX);
// stream.WriteInt16(TileY);
// stream.WriteInt32(RespawnTimer);
// stream.WriteByte((byte) PlayerSpawnContext);
}
}
}

View file

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

View file

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