Change JumpPckt to generic ActionPckt
This commit is contained in:
parent
fc2e737c8a
commit
d33028047e
@ -22,7 +22,7 @@ namespace NeonTea.Quakeball.Networking {
|
||||
RegisterPacket(typeof(SpawnPckt));
|
||||
RegisterPacket(typeof(SelfIdentPckt));
|
||||
RegisterPacket(typeof(PlayerUpdatePckt));
|
||||
RegisterPacket(typeof(PlayerJumpPckt));
|
||||
RegisterPacket(typeof(PlayerActionPckt));
|
||||
RegisterPacket(typeof(PlayerSyncPacket));
|
||||
RegisterPacket(typeof(MultiplePlayerUpdatesPckt));
|
||||
RegisterPacket(typeof(MultipleSyncsPckt));
|
||||
|
@ -103,9 +103,9 @@ namespace NeonTea.Quakeball.Networking.Instances {
|
||||
foreach (PlayerSyncPacket pckt in multiple.Syncs) {
|
||||
HandleSyncPckt(pckt);
|
||||
}
|
||||
} else if (packet is PlayerJumpPckt) {
|
||||
PlayerJumpPckt jump = (PlayerJumpPckt)packet;
|
||||
Players[jump.PlayerId].Controlled.Jump();
|
||||
} else if (packet is PlayerActionPckt) {
|
||||
PlayerActionPckt action = (PlayerActionPckt)packet;
|
||||
HandleAction(action);
|
||||
} else if (packet is PingPckt) {
|
||||
PingPckt ping = (PingPckt)packet;
|
||||
ping.ClientReceived = true;
|
||||
@ -136,6 +136,14 @@ namespace NeonTea.Quakeball.Networking.Instances {
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleAction(PlayerActionPckt action) {
|
||||
switch (action.Action) {
|
||||
case PlayerAction.Jump:
|
||||
Players[action.PlayerId].Controlled.Jump();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateLocalPlayer() {
|
||||
if (SelfIdentified && Server != null) {
|
||||
PlayerUpdatePckt pckt = LocalPlayer.Controlled.CreateUpdatePacket();
|
||||
@ -145,7 +153,7 @@ namespace NeonTea.Quakeball.Networking.Instances {
|
||||
|
||||
public override void LocalPlayerJump() {
|
||||
if (SelfIdentified && Server != null) {
|
||||
PlayerJumpPckt jump = new PlayerJumpPckt();
|
||||
PlayerActionPckt jump = new PlayerActionPckt();
|
||||
Peer.SendReliable(Server.uid, jump);
|
||||
}
|
||||
}
|
||||
|
@ -95,14 +95,6 @@ namespace NeonTea.Quakeball.Networking.Instances {
|
||||
updatePckt.PlayerId = conn.uid;
|
||||
Players[conn.uid].Controlled.ProcessUpdatePacket(updatePckt);
|
||||
}
|
||||
} else if (packet is PlayerJumpPckt) {
|
||||
PlayerJumpPckt jump = (PlayerJumpPckt)packet;
|
||||
if (Players[conn.uid].Controlled != null) {
|
||||
if (Players[conn.uid].Controlled.Jump()) {
|
||||
jump.PlayerId = conn.uid;
|
||||
SendReliableToAll(jump);
|
||||
}
|
||||
}
|
||||
} else if (packet is PlayerSyncPacket) {
|
||||
PlayerSyncPacket syncPckt = (PlayerSyncPacket)packet;
|
||||
if (Players[conn.uid].Controlled != null) {
|
||||
@ -111,6 +103,11 @@ namespace NeonTea.Quakeball.Networking.Instances {
|
||||
Players[conn.uid].Unsynced = true;
|
||||
}
|
||||
}
|
||||
} else if (packet is PlayerActionPckt) {
|
||||
PlayerActionPckt action = (PlayerActionPckt)packet;
|
||||
if (Players[conn.uid].Controlled != null) {
|
||||
HandleAction(conn.uid, action);
|
||||
}
|
||||
} else if (packet is PingPckt) {
|
||||
PingPckt ping = (PingPckt)packet;
|
||||
if (!ping.ServerReceived) {
|
||||
@ -144,6 +141,17 @@ namespace NeonTea.Quakeball.Networking.Instances {
|
||||
PlayerList.Remove(player);
|
||||
}
|
||||
|
||||
private void HandleAction(ulong uid, PlayerActionPckt action) {
|
||||
switch (action.Action) {
|
||||
case PlayerAction.Jump:
|
||||
if (Players[uid].Controlled.Jump()) {
|
||||
action.PlayerId = uid;
|
||||
SendReliableToAll(action);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void SendReliableToAll(Packet packet, ulong except = ulong.MaxValue) {
|
||||
foreach (NetPlayer p in Players.Values) {
|
||||
if (p.Id == ulong.MaxValue || p.Id == except) {
|
||||
@ -168,7 +176,7 @@ namespace NeonTea.Quakeball.Networking.Instances {
|
||||
}
|
||||
|
||||
public override void LocalPlayerJump() {
|
||||
PlayerJumpPckt jump = new PlayerJumpPckt(LocalPlayer.Id);
|
||||
PlayerActionPckt jump = new PlayerActionPckt(PlayerAction.Jump, LocalPlayer.Id);
|
||||
SendReliableToAll(jump);
|
||||
}
|
||||
|
||||
|
35
Assets/Scripts/Networking/Packets/PlayerActionPckt.cs
Normal file
35
Assets/Scripts/Networking/Packets/PlayerActionPckt.cs
Normal file
@ -0,0 +1,35 @@
|
||||
|
||||
using NeonTea.Quakeball.TeaNet.Packets;
|
||||
|
||||
namespace NeonTea.Quakeball.Networking.Packets {
|
||||
public class PlayerActionPckt : Packet {
|
||||
public ulong PlayerId;
|
||||
|
||||
public PlayerAction Action;
|
||||
|
||||
public PlayerActionPckt() { }
|
||||
public PlayerActionPckt(PlayerAction action, ulong id = 0) {
|
||||
Action = action;
|
||||
PlayerId = id;
|
||||
}
|
||||
|
||||
public override void Read(ByteBuffer buffer) {
|
||||
PlayerId = buffer.ReadULong();
|
||||
switch (buffer.Read()) {
|
||||
case 0:
|
||||
Action = PlayerAction.Jump;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Write(ByteBuffer buffer) {
|
||||
buffer.Write(PlayerId);
|
||||
buffer.Write((byte)Action);
|
||||
}
|
||||
}
|
||||
|
||||
public enum PlayerAction {
|
||||
Null = byte.MaxValue,
|
||||
Jump = 0,
|
||||
}
|
||||
}
|
@ -38,21 +38,6 @@ namespace NeonTea.Quakeball.Networking.Packets {
|
||||
}
|
||||
}
|
||||
|
||||
public class PlayerJumpPckt : Packet {
|
||||
public ulong PlayerId;
|
||||
|
||||
public PlayerJumpPckt() { }
|
||||
public PlayerJumpPckt(ulong id) { PlayerId = id; }
|
||||
|
||||
public override void Read(ByteBuffer buffer) {
|
||||
PlayerId = buffer.ReadULong();
|
||||
}
|
||||
|
||||
public override void Write(ByteBuffer buffer) {
|
||||
buffer.Write(PlayerId);
|
||||
}
|
||||
}
|
||||
|
||||
public class PlayerSyncPacket : Packet {
|
||||
public ulong PlayerId;
|
||||
public bool Unsynced;
|
||||
|
Loading…
Reference in New Issue
Block a user