diff --git a/Assets/Scripts/Networking/Instances/Client.cs b/Assets/Scripts/Networking/Instances/Client.cs
index ba5fe6f..ddcca3b 100644
--- a/Assets/Scripts/Networking/Instances/Client.cs
+++ b/Assets/Scripts/Networking/Instances/Client.cs
@@ -121,6 +121,11 @@ namespace NeonTea.Quakeball.Networking.Instances {
}
UpdatePingBias();
}
+ } else if (packet is HitPckt) {
+ HitPckt hit = (HitPckt)packet;
+ if (Players[hit.Target].Controlled != null) {
+ Players[hit.Target].Controlled.Hit();
+ }
}
}
diff --git a/Assets/Scripts/Networking/Instances/Server.cs b/Assets/Scripts/Networking/Instances/Server.cs
index 416a0c6..666779e 100644
--- a/Assets/Scripts/Networking/Instances/Server.cs
+++ b/Assets/Scripts/Networking/Instances/Server.cs
@@ -203,5 +203,10 @@ namespace NeonTea.Quakeball.Networking.Instances {
MultipleSyncsPckt pckt = new MultipleSyncsPckt(PlayerList);
SendUnreliableToAll(pckt);
}
+
+ public void SendHit(ulong id) {
+ HitPckt hit = new HitPckt(id);
+ SendReliableToAll(hit);
+ }
}
}
\ No newline at end of file
diff --git a/Assets/Scripts/Networking/NetPlayer.cs b/Assets/Scripts/Networking/NetPlayer.cs
index 9df32df..81b5d3b 100644
--- a/Assets/Scripts/Networking/NetPlayer.cs
+++ b/Assets/Scripts/Networking/NetPlayer.cs
@@ -3,8 +3,22 @@ using NeonTea.Quakeball.Players;
namespace NeonTea.Quakeball.Networking {
public class NetPlayer {
- public ulong Id;
- public Player Controlled;
+ public ulong Id {
+ get { return Id; }
+ set {
+ Id = value;
+ if (Controlled != null) {
+ Controlled.NetId = Id;
+ }
+ }
+ }
+ public Player Controlled {
+ get { return Controlled; }
+ set {
+ Controlled = value;
+ Controlled.NetId = Id;
+ }
+ }
public bool Unsynced = false;
public float Ping = 0;
diff --git a/Assets/Scripts/Networking/Packets/HitPckt.cs b/Assets/Scripts/Networking/Packets/HitPckt.cs
new file mode 100644
index 0000000..997587a
--- /dev/null
+++ b/Assets/Scripts/Networking/Packets/HitPckt.cs
@@ -0,0 +1,20 @@
+
+using NeonTea.Quakeball.TeaNet.Packets;
+
+namespace NeonTea.Quakeball.Networking.Packets {
+ public class HitPckt : Packet {
+
+ public ulong Target;
+
+ public HitPckt() { }
+ public HitPckt(ulong id) { Target = id; }
+
+ public override void Read(ByteBuffer buffer) {
+ Target = buffer.ReadULong();
+ }
+
+ public override void Write(ByteBuffer buffer) {
+ buffer.Write(Target);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assets/Scripts/Players/Player.cs b/Assets/Scripts/Players/Player.cs
index 52560b4..148cb82 100644
--- a/Assets/Scripts/Players/Player.cs
+++ b/Assets/Scripts/Players/Player.cs
@@ -1,7 +1,8 @@
using UnityEngine;
using NeonTea.Quakeball.Networking.Packets;
using NeonTea.Quakeball.Util;
-using NeonTea.Quakeball.Interface;
+using NeonTea.Quakeball.Networking;
+using NeonTea.Quakeball.Networking.Instances;
namespace NeonTea.Quakeball.Players {
/// The central glue class for players (both local and remote).
@@ -62,6 +63,9 @@ namespace NeonTea.Quakeball.Players {
/// The timestamp of when the player was last on the ground.
public float GroundedTime;
+ /// The possible networked Id of this Player instance
+ public ulong NetId;
+
public float LatestGroundedY;
[Header("Misc. technical knobs")]
@@ -153,6 +157,10 @@ namespace NeonTea.Quakeball.Players {
Player Player = Hit.rigidbody.GetComponent();
if (Player != null) {
Debug.DrawLine(GunPoint, To, Color.red, 5f);
+ if (Net.Singleton.Instance is Server) {
+ ((Server)Net.Singleton.Instance).SendHit(Player.NetId);
+ Player.Hit();
+ }
}
} else {
Debug.DrawLine(GunPoint, To, Color.yellow, 5f);
@@ -160,6 +168,10 @@ namespace NeonTea.Quakeball.Players {
}
}
+ public void Hit() {
+ Debug.Log("I was hit! Aaagh!");
+ }
+
public bool IsGrounded() {
return CharacterController.isGrounded && Vector3.Dot(GravitationalVelocity, Vector3.down) >= 0;
}