Add respawning and "death"
This commit is contained in:
parent
edd6e1def3
commit
e127e253d1
@ -38,7 +38,7 @@ RenderSettings:
|
|||||||
m_ReflectionIntensity: 1
|
m_ReflectionIntensity: 1
|
||||||
m_CustomReflection: {fileID: 0}
|
m_CustomReflection: {fileID: 0}
|
||||||
m_Sun: {fileID: 0}
|
m_Sun: {fileID: 0}
|
||||||
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
|
m_IndirectSpecularColor: {r: 0.17393494, g: 0.2174847, b: 0.299652, a: 1}
|
||||||
m_UseRadianceAmbientProbe: 0
|
m_UseRadianceAmbientProbe: 0
|
||||||
--- !u!157 &3
|
--- !u!157 &3
|
||||||
LightmapSettings:
|
LightmapSettings:
|
||||||
@ -11623,6 +11623,36 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: ef9117cc11410da479d1af23fbe77b23, type: 3}
|
m_Script: {fileID: 11500000, guid: ef9117cc11410da479d1af23fbe77b23, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
|
--- !u!1 &1280423820
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 1280423821}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: SpawnPoint
|
||||||
|
m_TagString: Respawn
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!4 &1280423821
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1280423820}
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: 0.02, z: 0}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 0}
|
||||||
|
m_RootOrder: 11
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
--- !u!1 &1349294154
|
--- !u!1 &1349294154
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -83,17 +83,23 @@ namespace NeonTea.Quakeball.Networking.Instances {
|
|||||||
Players.Add(LocalPlayer.Id, LocalPlayer);
|
Players.Add(LocalPlayer.Id, LocalPlayer);
|
||||||
SelfIdentified = true;
|
SelfIdentified = true;
|
||||||
|
|
||||||
SpawnPckt spawn = new SpawnPckt();
|
SpawnPckt spawn = new SpawnPckt(LocalPlayer.Controlled.transform.position);
|
||||||
spawn.Location = LocalPlayer.Controlled.transform.position;
|
spawn.Location = LocalPlayer.Controlled.transform.position;
|
||||||
Peer.SendReliable(Server.uid, spawn);
|
Peer.SendReliable(Server.uid, spawn);
|
||||||
} else if (packet is SpawnPckt) {
|
} else if (packet is SpawnPckt) {
|
||||||
SpawnPckt spawn = (SpawnPckt)packet;
|
SpawnPckt spawn = (SpawnPckt)packet;
|
||||||
if (spawn.PlayerId == LocalPlayer.Id) {
|
if (spawn.PlayerId == LocalPlayer.Id && spawn.IsInitial) {
|
||||||
return; // Ignore, it's their own.
|
return; // Ignore, it's their own.
|
||||||
}
|
}
|
||||||
Player obj = Net.SpawnPlayer(spawn.Location).GetComponent<Player>();
|
if (spawn.IsInitial) {
|
||||||
NetPlayer player = new NetPlayer(spawn.PlayerId, obj);
|
Player obj = Net.SpawnPlayer(spawn.Location).GetComponent<Player>();
|
||||||
Players.Add(spawn.PlayerId, player);
|
NetPlayer player = new NetPlayer(spawn.PlayerId, obj);
|
||||||
|
Players.Add(spawn.PlayerId, player);
|
||||||
|
} else {
|
||||||
|
if (Players.ContainsKey(spawn.PlayerId)) {
|
||||||
|
HandlePlayerDeath(spawn.PlayerId, spawn.Location);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (packet is MultiplePlayerUpdatesPckt) {
|
} else if (packet is MultiplePlayerUpdatesPckt) {
|
||||||
MultiplePlayerUpdatesPckt multiple = (MultiplePlayerUpdatesPckt)packet;
|
MultiplePlayerUpdatesPckt multiple = (MultiplePlayerUpdatesPckt)packet;
|
||||||
foreach (PlayerUpdatePckt pckt in multiple.Updates) {
|
foreach (PlayerUpdatePckt pckt in multiple.Updates) {
|
||||||
@ -185,5 +191,11 @@ namespace NeonTea.Quakeball.Networking.Instances {
|
|||||||
Peer.SendUnreliable(Server.uid, packet);
|
Peer.SendUnreliable(Server.uid, packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void HandlePlayerDeath(ulong uid, Vector3 respawn) {
|
||||||
|
if (Players[uid].Controlled != null) {
|
||||||
|
Players[uid].Controlled.transform.position = respawn;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -57,9 +57,7 @@ namespace NeonTea.Quakeball.Networking.Instances {
|
|||||||
if (p.Controlled == null) { // Not yet initialized, sending later.
|
if (p.Controlled == null) { // Not yet initialized, sending later.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
SpawnPckt spawn = new SpawnPckt();
|
SpawnPckt spawn = new SpawnPckt(p.Controlled.transform.position, p.Id);
|
||||||
spawn.PlayerId = p.Id;
|
|
||||||
spawn.Location = p.Controlled.transform.position;
|
|
||||||
Peer.SendReliableLater(conn.uid, spawn);
|
Peer.SendReliableLater(conn.uid, spawn);
|
||||||
}
|
}
|
||||||
NetPlayer RemotePlayer = new NetPlayer(PlayerIdCounter++);
|
NetPlayer RemotePlayer = new NetPlayer(PlayerIdCounter++);
|
||||||
@ -80,13 +78,11 @@ namespace NeonTea.Quakeball.Networking.Instances {
|
|||||||
public override void Handle(Connection conn, Packet packet) {
|
public override void Handle(Connection conn, Packet packet) {
|
||||||
if (packet is SpawnPckt) {
|
if (packet is SpawnPckt) {
|
||||||
SpawnPckt spawn = (SpawnPckt)packet;
|
SpawnPckt spawn = (SpawnPckt)packet;
|
||||||
if (Players[conn.uid].Controlled == null) {
|
if (Players[conn.uid].Controlled == null && spawn.IsInitial) {
|
||||||
Player obj = Net.SpawnPlayer(spawn.Location).GetComponent<Player>();
|
Player obj = Net.SpawnPlayer(spawn.Location).GetComponent<Player>();
|
||||||
Players[conn.uid].Controlled = obj;
|
Players[conn.uid].Controlled = obj;
|
||||||
|
|
||||||
spawn = new SpawnPckt();
|
spawn = new SpawnPckt(obj.transform.position, conn.uid);
|
||||||
spawn.PlayerId = conn.uid;
|
|
||||||
spawn.Location = obj.transform.position;
|
|
||||||
SendReliableToAll(spawn, except: spawn.PlayerId);
|
SendReliableToAll(spawn, except: spawn.PlayerId);
|
||||||
}
|
}
|
||||||
} else if (packet is PlayerUpdatePckt) {
|
} else if (packet is PlayerUpdatePckt) {
|
||||||
@ -208,5 +204,13 @@ namespace NeonTea.Quakeball.Networking.Instances {
|
|||||||
HitPckt hit = new HitPckt(id);
|
HitPckt hit = new HitPckt(id);
|
||||||
SendReliableToAll(hit);
|
SendReliableToAll(hit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void HandlePlayerDeath(ulong uid) {
|
||||||
|
Vector3 point = GameObject.FindGameObjectWithTag("Respawn").transform.position;
|
||||||
|
Player player = Players[uid].Controlled;
|
||||||
|
player.transform.position = point;
|
||||||
|
SpawnPckt spawn = new SpawnPckt(point, uid, false);
|
||||||
|
SendReliableToAll(spawn);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,6 +6,13 @@ namespace NeonTea.Quakeball.Networking.Packets {
|
|||||||
|
|
||||||
public ulong PlayerId;
|
public ulong PlayerId;
|
||||||
public Vector3 Location;
|
public Vector3 Location;
|
||||||
|
public bool IsInitial;
|
||||||
|
|
||||||
|
public SpawnPckt(Vector3 location, ulong id = 0, bool isinitial = true) {
|
||||||
|
PlayerId = id;
|
||||||
|
Location = location;
|
||||||
|
IsInitial = isinitial;
|
||||||
|
}
|
||||||
|
|
||||||
public override void Read(ByteBuffer buffer) {
|
public override void Read(ByteBuffer buffer) {
|
||||||
float x = buffer.ReadFloat();
|
float x = buffer.ReadFloat();
|
||||||
@ -13,6 +20,7 @@ namespace NeonTea.Quakeball.Networking.Packets {
|
|||||||
float z = buffer.ReadFloat();
|
float z = buffer.ReadFloat();
|
||||||
Location = new Vector3(x, y, z);
|
Location = new Vector3(x, y, z);
|
||||||
PlayerId = buffer.ReadULong();
|
PlayerId = buffer.ReadULong();
|
||||||
|
IsInitial = buffer.ReadBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Write(ByteBuffer buffer) {
|
public override void Write(ByteBuffer buffer) {
|
||||||
@ -20,6 +28,7 @@ namespace NeonTea.Quakeball.Networking.Packets {
|
|||||||
buffer.Write(Location.y);
|
buffer.Write(Location.y);
|
||||||
buffer.Write(Location.z);
|
buffer.Write(Location.z);
|
||||||
buffer.Write(PlayerId);
|
buffer.Write(PlayerId);
|
||||||
|
buffer.Write(IsInitial);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,6 +195,9 @@ namespace NeonTea.Quakeball.Players {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void Hit() {
|
public void Hit() {
|
||||||
|
if (Net.Singleton.Instance is Server) {
|
||||||
|
((Server)Net.Singleton.Instance).HandlePlayerDeath(NetId);
|
||||||
|
}
|
||||||
Debug.Log("I was hit! Aaagh!");
|
Debug.Log("I was hit! Aaagh!");
|
||||||
Splatter.Play();
|
Splatter.Play();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user