Add HitPckg
This commit is contained in:
parent
10fe5bfd3a
commit
a60b7707b6
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
||||
|
20
Assets/Scripts/Networking/Packets/HitPckt.cs
Normal file
20
Assets/Scripts/Networking/Packets/HitPckt.cs
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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 {
|
||||
/// <summary>The central glue class for players (both local and remote).</summary>
|
||||
@ -62,6 +63,9 @@ namespace NeonTea.Quakeball.Players {
|
||||
/// <summary>The timestamp of when the player was last on the ground.</summary>
|
||||
public float GroundedTime;
|
||||
|
||||
/// <summary> The possible networked Id of this Player instance </summary>
|
||||
public ulong NetId;
|
||||
|
||||
public float LatestGroundedY;
|
||||
|
||||
[Header("Misc. technical knobs")]
|
||||
@ -153,6 +157,10 @@ namespace NeonTea.Quakeball.Players {
|
||||
Player Player = Hit.rigidbody.GetComponent<Player>();
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user