Upgrade version and make team work good

This commit is contained in:
Sofia 2020-08-14 16:21:37 +03:00
parent ad83a09db8
commit 0b8e06e9d0
7 changed files with 39 additions and 18 deletions

View File

@ -26,13 +26,13 @@ namespace NeonTea.Quakeball.Game {
Team team = Team.FreeForAll; Team team = Team.FreeForAll;
if (GameMode == GameMode.TeamPlay) { if (GameMode == GameMode.TeamPlay) {
if (Players[Team.Sun].Count > Players[Team.Moon].Count) { if (Players[Team.Sun].Count > Players[Team.Moon].Count) {
team = Team.Sun;
} else {
team = Team.Moon; team = Team.Moon;
} else {
team = Team.Sun;
} }
} }
Players[Team.Sun].Add(player.Id);
player.Team = team; player.Team = team;
Players[player.Team].Add(player.Id);
Terminal.Singleton.Println($"Put {player.Nick} to Team {player.Team}"); Terminal.Singleton.Println($"Put {player.Nick} to Team {player.Team}");
} }

View File

@ -23,7 +23,7 @@ namespace NeonTea.Quakeball.Networking.Instances {
public Client() { public Client() {
Net = GameObject.FindGameObjectWithTag("Net").GetComponent<NetChaperone>(); Net = GameObject.FindGameObjectWithTag("Net").GetComponent<NetChaperone>();
LocalPlayer = new NetPlayer(ulong.MaxValue - 1); LocalPlayer = new NetPlayer(ulong.MaxValue - 1, false);
LocalPlayer.Controlled = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>(); LocalPlayer.Controlled = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>();
} }
@ -87,6 +87,7 @@ namespace NeonTea.Quakeball.Networking.Instances {
LocalPlayer.Controlled.NetId = LocalPlayer.Id; LocalPlayer.Controlled.NetId = LocalPlayer.Id;
AddPlayer(LocalPlayer); AddPlayer(LocalPlayer);
SelfIdentified = true; SelfIdentified = true;
LocalPlayer.Ready = true;
NicknamePckt nickpckt = new NicknamePckt(LocalPlayer.Nick); NicknamePckt nickpckt = new NicknamePckt(LocalPlayer.Nick);
Peer.SendReliableLater(Server.uid, nickpckt); Peer.SendReliableLater(Server.uid, nickpckt);
@ -114,15 +115,16 @@ namespace NeonTea.Quakeball.Networking.Instances {
} }
} else if (packet is PlayerInitPckt) { } else if (packet is PlayerInitPckt) {
PlayerInitPckt init = (PlayerInitPckt)packet; PlayerInitPckt init = (PlayerInitPckt)packet;
if (Players.ContainsKey(conn.uid)) { if (Players.ContainsKey(init.PlayerId)) {
return; // Got the same init twice return; // Got the same init twice
} }
NetPlayer player = new NetPlayer(init.PlayerId); NetPlayer player = new NetPlayer(init.PlayerId, true);
player.Nick = init.NicknamePckt.Nick; player.Nick = init.NicknamePckt.Nick;
player.Team = init.Team; player.Team = init.Team;
Player obj = Net.SpawnPlayer(init.SpawnPckt.Location).GetComponent<Player>(); Player obj = Net.SpawnPlayer(init.SpawnPckt.Location).GetComponent<Player>();
player.Controlled = obj; player.Controlled = obj;
AddPlayer(player); AddPlayer(player);
Debug.Log("Added player" + player.Nick);
} else if (packet is DeadPckt) { } else if (packet is DeadPckt) {
DeadPckt dead = (DeadPckt)packet; DeadPckt dead = (DeadPckt)packet;
if (Players.ContainsKey(dead.DeadPlayerId)) { if (Players.ContainsKey(dead.DeadPlayerId)) {
@ -173,14 +175,14 @@ namespace NeonTea.Quakeball.Networking.Instances {
} }
private void HandleUpdatePlayer(PlayerUpdatePckt pckt) { private void HandleUpdatePlayer(PlayerUpdatePckt pckt) {
if (pckt.PlayerId == LocalPlayer.Id && Players[pckt.PlayerId] != null) { if (pckt.PlayerId == LocalPlayer.Id || !Players.ContainsKey(pckt.PlayerId)) {
return; // Ignore, again. return; // Ignore, again.
} }
Players[pckt.PlayerId].Controlled.ProcessUpdatePacket(pckt); Players[pckt.PlayerId].Controlled.ProcessUpdatePacket(pckt);
} }
private void HandleSyncPckt(PlayerSyncPacket syncPckt) { private void HandleSyncPckt(PlayerSyncPacket syncPckt) {
if (Players[syncPckt.PlayerId] != null && (syncPckt.Unsynced || syncPckt.PlayerId != LocalPlayer.Id)) { if (Players.ContainsKey(syncPckt.PlayerId) && (syncPckt.Unsynced || syncPckt.PlayerId != LocalPlayer.Id)) {
Players[syncPckt.PlayerId].Controlled.ProcessSyncPacket(syncPckt); Players[syncPckt.PlayerId].Controlled.ProcessSyncPacket(syncPckt);
} }
} }

View File

@ -22,7 +22,7 @@ namespace NeonTea.Quakeball.Networking.Instances {
public GameMaster GameMaster; public GameMaster GameMaster;
public Server() { public Server() {
LocalPlayer = new NetPlayer(ulong.MaxValue); LocalPlayer = new NetPlayer(ulong.MaxValue, true);
} }
public override void Start(string address, int port, string nick, PeerMessageListener listener) { public override void Start(string address, int port, string nick, PeerMessageListener listener) {
@ -63,7 +63,7 @@ namespace NeonTea.Quakeball.Networking.Instances {
Terminal.Singleton.Println($"{conn.uid} Connected"); Terminal.Singleton.Println($"{conn.uid} Connected");
foreach (NetPlayer p in Players.Values) { foreach (NetPlayer p in Players.Values) {
if (p.Controlled == null) { // Not yet initialized, sending later. if (!IsReady(p.Id)) { // Not yet ready, sending later.
continue; continue;
} }
@ -72,7 +72,7 @@ namespace NeonTea.Quakeball.Networking.Instances {
PlayerInitPckt init = new PlayerInitPckt(p.Id, p.Team, nick, spawn); PlayerInitPckt init = new PlayerInitPckt(p.Id, p.Team, nick, spawn);
Peer.SendReliableLater(conn.uid, init); Peer.SendReliableLater(conn.uid, init);
} }
NetPlayer RemotePlayer = new NetPlayer(PlayerIdCounter++); NetPlayer RemotePlayer = new NetPlayer(PlayerIdCounter++, false);
GameMaster.PlayerJoined(RemotePlayer); GameMaster.PlayerJoined(RemotePlayer);
AddPlayer(RemotePlayer); AddPlayer(RemotePlayer);
@ -91,15 +91,17 @@ namespace NeonTea.Quakeball.Networking.Instances {
} }
public void PlayerJoined(NetPlayer player) { public void PlayerJoined(NetPlayer player) {
player.Ready = true;
NicknamePckt nick = new NicknamePckt(player.Nick, player.Id); NicknamePckt nick = new NicknamePckt(player.Nick, player.Id);
SpawnPckt spawn = new SpawnPckt(player.Controlled.transform.position, player.Id); SpawnPckt spawn = new SpawnPckt(player.Controlled.transform.position, player.Id);
PlayerInitPckt init = new PlayerInitPckt(player.Id, player.Team, nick, spawn); PlayerInitPckt init = new PlayerInitPckt(player.Id, player.Team, nick, spawn);
SendReliableToAll(init, except: spawn.PlayerId); Debug.Log("Sending init: " + player.Id);
SendReliableToAll(init, except: player.Id);
} }
public override void Handle(Connection conn, Packet packet) { public override void Handle(Connection conn, Packet packet) {
if (packet is ReadyPckt) { if (packet is ReadyPckt) {
if (Players[conn.uid].Controlled == null) { if (!IsReady(conn.uid)) {
NetPlayer player = Players[conn.uid]; NetPlayer player = Players[conn.uid];
Player obj = Net.SpawnPlayer(GameMaster.GetSpawn(player)).GetComponent<Player>(); Player obj = Net.SpawnPlayer(GameMaster.GetSpawn(player)).GetComponent<Player>();
player.Controlled = obj; player.Controlled = obj;
@ -113,7 +115,9 @@ namespace NeonTea.Quakeball.Networking.Instances {
NicknamePckt nick = (NicknamePckt)packet; NicknamePckt nick = (NicknamePckt)packet;
Players[conn.uid].Nick = nick.Nick; Players[conn.uid].Nick = nick.Nick;
nick.PlayerId = conn.uid; nick.PlayerId = conn.uid;
if (IsReady(conn.uid)) {
SendReliableToAll(nick); SendReliableToAll(nick);
}
} else if (packet is PlayerUpdatePckt) { } else if (packet is PlayerUpdatePckt) {
PlayerUpdatePckt updatePckt = (PlayerUpdatePckt)packet; PlayerUpdatePckt updatePckt = (PlayerUpdatePckt)packet;
HandleUpdatePckt(conn.uid, updatePckt); HandleUpdatePckt(conn.uid, updatePckt);
@ -211,6 +215,10 @@ namespace NeonTea.Quakeball.Networking.Instances {
} }
} }
public bool IsReady(ulong uid) {
return Players.ContainsKey(uid) && Players[uid].ReadyAndSpawned;
}
public override void UpdateLocalPlayer() { public override void UpdateLocalPlayer() {
MultiplePlayerUpdatesPckt pckt = new MultiplePlayerUpdatesPckt(PlayerList); MultiplePlayerUpdatesPckt pckt = new MultiplePlayerUpdatesPckt(PlayerList);
SendUnreliableToAll(pckt); SendUnreliableToAll(pckt);

View File

@ -27,12 +27,17 @@ namespace NeonTea.Quakeball.Networking {
} }
public string Nick; public string Nick;
public Team Team = Team.FreeForAll; public Team Team = Team.FreeForAll;
public bool Ready;
public bool ReadyAndSpawned => Ready && _Controlled != null;
public bool Unsynced = false; public bool Unsynced = false;
public float Ping = 0; public float Ping = 0;
public NetPlayer(ulong id, Player obj = null) { public NetPlayer(ulong id, bool ready, Player obj = null) {
Id = id; Id = id;
Controlled = obj; Controlled = obj;
Ready = ready;
Nick = id.ToString(); Nick = id.ToString();
} }
} }

View File

@ -96,7 +96,8 @@
"depth": 0, "depth": 0,
"source": "builtin", "source": "builtin",
"dependencies": { "dependencies": {
"com.unity.modules.ui": "1.0.0" "com.unity.modules.ui": "1.0.0",
"com.unity.modules.imgui": "1.0.0"
} }
}, },
"com.unity.modules.ai": { "com.unity.modules.ai": {

View File

@ -115,6 +115,8 @@ PlayerSettings:
switchNVNShaderPoolsGranularity: 33554432 switchNVNShaderPoolsGranularity: 33554432
switchNVNDefaultPoolsGranularity: 16777216 switchNVNDefaultPoolsGranularity: 16777216
switchNVNOtherPoolsGranularity: 16777216 switchNVNOtherPoolsGranularity: 16777216
switchNVNMaxPublicTextureIDCount: 0
switchNVNMaxPublicSamplerIDCount: 0
stadiaPresentMode: 0 stadiaPresentMode: 0
stadiaTargetFramerate: 0 stadiaTargetFramerate: 0
vulkanNumSwapchainBuffers: 3 vulkanNumSwapchainBuffers: 3
@ -517,6 +519,7 @@ PlayerSettings:
ps4ShareFilePath: ps4ShareFilePath:
ps4ShareOverlayImagePath: ps4ShareOverlayImagePath:
ps4PrivacyGuardImagePath: ps4PrivacyGuardImagePath:
ps4ExtraSceSysFile:
ps4NPtitleDatPath: ps4NPtitleDatPath:
ps4RemotePlayKeyAssignment: -1 ps4RemotePlayKeyAssignment: -1
ps4RemotePlayKeyMappingDir: ps4RemotePlayKeyMappingDir:
@ -559,6 +562,8 @@ PlayerSettings:
ps4disableAutoHideSplash: 0 ps4disableAutoHideSplash: 0
ps4videoRecordingFeaturesUsed: 0 ps4videoRecordingFeaturesUsed: 0
ps4contentSearchFeaturesUsed: 0 ps4contentSearchFeaturesUsed: 0
ps4CompatibilityPS5: 0
ps4GPU800MHz: 1
ps4attribEyeToEyeDistanceSettingVR: 0 ps4attribEyeToEyeDistanceSettingVR: 0
ps4IncludedModules: [] ps4IncludedModules: []
ps4attribVROutputEnabled: 0 ps4attribVROutputEnabled: 0

View File

@ -1,2 +1,2 @@
m_EditorVersion: 2020.1.0f1 m_EditorVersion: 2020.1.2f1
m_EditorVersionWithRevision: 2020.1.0f1 (2ab9c4179772) m_EditorVersionWithRevision: 2020.1.2f1 (7b32bc54ba47)