Fixed teleporting
This commit is contained in:
parent
2a0bf9036a
commit
3312b769c4
6 changed files with 124 additions and 73 deletions
38
TShockAPI/Net/BaseMsg.cs
Normal file
38
TShockAPI/Net/BaseMsg.cs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using TerrariaAPI;
|
||||
using XNAHelpers;
|
||||
|
||||
namespace TShockAPI.Net
|
||||
{
|
||||
public class BaseMsg : IPackable
|
||||
{
|
||||
public virtual PacketTypes ID
|
||||
{
|
||||
get { throw new NotImplementedException("Msg ID not implemented"); }
|
||||
}
|
||||
public void PackFull(System.IO.Stream stream)
|
||||
{
|
||||
long start = stream.Position;
|
||||
stream.WriteInt32(1);
|
||||
stream.WriteInt8((byte)ID);
|
||||
Pack(stream);
|
||||
long end = stream.Position;
|
||||
stream.Position = start;
|
||||
stream.WriteInt32((int)(end - start) - 4);
|
||||
stream.Position = end;
|
||||
}
|
||||
|
||||
public virtual void Unpack(System.IO.Stream stream)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public virtual void Pack(System.IO.Stream stream)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
30
TShockAPI/Net/SpawnMsg.cs
Normal file
30
TShockAPI/Net/SpawnMsg.cs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using TerrariaAPI;
|
||||
using XNAHelpers;
|
||||
|
||||
namespace TShockAPI.Net
|
||||
{
|
||||
public class SpawnMsg : BaseMsg
|
||||
{
|
||||
public override PacketTypes ID
|
||||
{
|
||||
get
|
||||
{
|
||||
return PacketTypes.PlayerSpawn;
|
||||
}
|
||||
}
|
||||
|
||||
public int TileX { get; set; }
|
||||
public int TileY {get;set;}
|
||||
public byte PlayerIndex { get; set; }
|
||||
|
||||
public override void Pack(Stream stream)
|
||||
{
|
||||
stream.WriteInt8(PlayerIndex);
|
||||
stream.WriteInt32(TileX);
|
||||
stream.WriteInt32(TileY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -33,7 +33,7 @@ namespace TShockAPI.Net
|
|||
DownedBoss2 = 4,
|
||||
DownedBoss3 = 8,
|
||||
}
|
||||
public class WorldInfoMsg : IPackable
|
||||
public class WorldInfoMsg : BaseMsg
|
||||
{
|
||||
public int Time { get; set; }
|
||||
public bool DayTime { get; set; }
|
||||
|
|
@ -48,18 +48,14 @@ namespace TShockAPI.Net
|
|||
public int WorldID { get; set; }
|
||||
public WorldInfoFlag WorldFlags { get; set; }
|
||||
public string WorldName { get; set; }
|
||||
public void PackFull(Stream stream)
|
||||
public override PacketTypes ID
|
||||
{
|
||||
long start = stream.Position;
|
||||
stream.WriteInt32(1);
|
||||
stream.WriteInt8((byte)PacketTypes.WorldInfo);
|
||||
Pack(stream);
|
||||
long end = stream.Position;
|
||||
stream.Position = start;
|
||||
stream.WriteInt32((int)(end - start) - 4);
|
||||
stream.Position = end;
|
||||
get
|
||||
{
|
||||
return PacketTypes.WorldInfo;
|
||||
}
|
||||
}
|
||||
public void Pack(Stream stream)
|
||||
public override void Pack(Stream stream)
|
||||
{
|
||||
stream.WriteInt32(Time);
|
||||
stream.WriteBoolean(DayTime);
|
||||
|
|
@ -75,10 +71,5 @@ namespace TShockAPI.Net
|
|||
stream.WriteInt8((byte)WorldFlags);
|
||||
stream.WriteBytes(Encoding.ASCII.GetBytes(WorldName));
|
||||
}
|
||||
|
||||
public void Unpack(Stream stream)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,5 +36,5 @@ using System.Runtime.InteropServices;
|
|||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
|
||||
|
||||
[assembly: AssemblyVersion("3.2.5.0810")]
|
||||
[assembly: AssemblyFileVersion("3.2.5.0810")]
|
||||
[assembly: AssemblyVersion("3.2.6.0811")]
|
||||
[assembly: AssemblyFileVersion("3.2.6.0811")]
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ using Microsoft.Xna.Framework;
|
|||
using Terraria;
|
||||
using TerrariaAPI;
|
||||
using TShockAPI.Net;
|
||||
using XNAHelpers;
|
||||
|
||||
namespace TShockAPI
|
||||
{
|
||||
|
|
@ -157,31 +158,32 @@ namespace TShockAPI
|
|||
SendData(PacketTypes.Disconnect, reason);
|
||||
}
|
||||
|
||||
void SendTeleport(int tilex, int tiley)
|
||||
|
||||
void SendWorldInfo(int tilex, int tiley, bool fakeid)
|
||||
{
|
||||
var msg = new WorldInfoMsg
|
||||
{
|
||||
Time = (int)Main.time,
|
||||
DayTime = Main.dayTime,
|
||||
MoonPhase = (byte)Main.moonPhase,
|
||||
BloodMoon = Main.bloodMoon,
|
||||
MaxTilesX = Main.maxTilesX,
|
||||
MaxTilesY = Main.maxTilesY,
|
||||
SpawnX = tilex,
|
||||
SpawnY = tiley,
|
||||
WorldSurface = (int)Main.worldSurface,
|
||||
RockLayer = (int)Main.rockLayer,
|
||||
WorldID = Main.worldID,
|
||||
WorldFlags = (WorldGen.shadowOrbSmashed ? WorldInfoFlag.OrbSmashed : WorldInfoFlag.None) |
|
||||
(NPC.downedBoss1 ? WorldInfoFlag.DownedBoss1 : WorldInfoFlag.None) |
|
||||
(NPC.downedBoss2 ? WorldInfoFlag.DownedBoss2 : WorldInfoFlag.None) |
|
||||
(NPC.downedBoss3 ? WorldInfoFlag.DownedBoss3 : WorldInfoFlag.None),
|
||||
WorldName = Main.worldName
|
||||
};
|
||||
|
||||
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
var msg = new WorldInfoMsg
|
||||
{
|
||||
Time = (int)Main.time,
|
||||
DayTime = Main.dayTime,
|
||||
MoonPhase = (byte)Main.moonPhase,
|
||||
BloodMoon = Main.bloodMoon,
|
||||
MaxTilesX = Main.maxTilesX,
|
||||
MaxTilesY = Main.maxTilesY,
|
||||
SpawnX = tilex,
|
||||
SpawnY = tiley,
|
||||
WorldSurface = (int)Main.worldSurface,
|
||||
RockLayer = (int)Main.rockLayer,
|
||||
//Sending a fake world id causes the client to not be able to find a stored spawnx/y.
|
||||
//This fixes the bed spawn point bug. With a fake world id it wont be able to find the bed spawn.
|
||||
WorldID = !fakeid ? Main.worldID : -1,
|
||||
WorldFlags = (WorldGen.shadowOrbSmashed ? WorldInfoFlag.OrbSmashed : WorldInfoFlag.None) |
|
||||
(NPC.downedBoss1 ? WorldInfoFlag.DownedBoss1 : WorldInfoFlag.None) |
|
||||
(NPC.downedBoss2 ? WorldInfoFlag.DownedBoss2 : WorldInfoFlag.None) |
|
||||
(NPC.downedBoss3 ? WorldInfoFlag.DownedBoss3 : WorldInfoFlag.None),
|
||||
WorldName = Main.worldName
|
||||
};
|
||||
msg.PackFull(ms);
|
||||
SendRawData(ms.ToArray());
|
||||
}
|
||||
|
|
@ -191,7 +193,8 @@ namespace TShockAPI
|
|||
{
|
||||
InitSpawn = false;
|
||||
|
||||
SendTeleport(tilex, tiley);
|
||||
|
||||
SendWorldInfo(tilex, tiley, true);
|
||||
|
||||
//150 Should avoid all client crash errors
|
||||
//The error occurs when a tile trys to update which the client hasnt load yet, Clients only update tiles withen 150 blocks
|
||||
|
|
@ -202,44 +205,31 @@ namespace TShockAPI
|
|||
return false;
|
||||
}
|
||||
|
||||
if (TPlayer.SpawnX > 0 && TPlayer.SpawnY > 0)
|
||||
{
|
||||
int spX = TPlayer.SpawnX;
|
||||
int spY = TPlayer.SpawnY;
|
||||
Main.tile[spX, spY].active = false;
|
||||
SendTileSquare(spX, spY);
|
||||
Spawn();
|
||||
Main.tile[spX, spY].active = true;
|
||||
SendTileSquare(spX, spY);
|
||||
oldSpawn = new Vector2(spX, spY);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Checks if Player has spawn point set (Server may think player does not have spawn)
|
||||
if (oldSpawn != Vector2.Zero)
|
||||
{
|
||||
Main.tile[(int)oldSpawn.X, (int)oldSpawn.Y].active = false;
|
||||
SendTileSquare((int)oldSpawn.X, (int)oldSpawn.Y);
|
||||
Spawn();
|
||||
Main.tile[(int)oldSpawn.X, (int)oldSpawn.Y].active = true;
|
||||
SendTileSquare((int)oldSpawn.X, (int)oldSpawn.Y);
|
||||
NetMessage.syncPlayers();
|
||||
}
|
||||
//Player has no spawn point set
|
||||
else
|
||||
{
|
||||
Spawn();
|
||||
}
|
||||
}
|
||||
Spawn(-1, -1);
|
||||
|
||||
SendTeleport(Main.spawnTileX, Main.spawnTileY);
|
||||
SendWorldInfo(Main.spawnTileX, Main.spawnTileY, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Spawn()
|
||||
{
|
||||
SendData(PacketTypes.PlayerSpawn, "", Index, 0.0f, 0.0f, 0.0f);
|
||||
Spawn(TPlayer.SpawnX, TPlayer.SpawnY);
|
||||
}
|
||||
|
||||
public void Spawn(int tilex, int tiley)
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
var msg = new SpawnMsg()
|
||||
{
|
||||
PlayerIndex = (byte)Index,
|
||||
TileX = tilex,
|
||||
TileY = tiley
|
||||
};
|
||||
msg.PackFull(ms);
|
||||
SendRawData(ms.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool SendTileSquare(int x, int y, int size = 10)
|
||||
|
|
|
|||
|
|
@ -111,7 +111,9 @@
|
|||
<Compile Include="Group.cs" />
|
||||
<Compile Include="Extensions\LinqExt.cs" />
|
||||
<Compile Include="Log.cs" />
|
||||
<Compile Include="Net\BaseMsg.cs" />
|
||||
<Compile Include="Net\NetTile.cs" />
|
||||
<Compile Include="Net\SpawnMsg.cs" />
|
||||
<Compile Include="Net\WorldInfoMsg.cs" />
|
||||
<Compile Include="DB\RegionManager.cs" />
|
||||
<Compile Include="PacketBufferer.cs" />
|
||||
|
|
@ -178,7 +180,7 @@
|
|||
</PropertyGroup>
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
<UserProperties BuildVersion_UpdateAssemblyVersion="True" BuildVersion_UpdateFileVersion="True" BuildVersion_BuildAction="Both" BuildVersion_BuildVersioningStyle="None.None.None.MonthAndDayStamp" BuildVersion_StartDate="2011/6/17" BuildVersion_IncrementBeforeBuild="False" />
|
||||
<UserProperties BuildVersion_IncrementBeforeBuild="False" BuildVersion_StartDate="2011/6/17" BuildVersion_BuildVersioningStyle="None.None.None.MonthAndDayStamp" BuildVersion_BuildAction="Both" BuildVersion_UpdateFileVersion="True" BuildVersion_UpdateAssemblyVersion="True" />
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue