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;
if (GameMode == GameMode.TeamPlay) {
if (Players[Team.Sun].Count > Players[Team.Moon].Count) {
team = Team.Sun;
} else {
team = Team.Moon;
} else {
team = Team.Sun;
}
}
Players[Team.Sun].Add(player.Id);
player.Team = team;
Players[player.Team].Add(player.Id);
Terminal.Singleton.Println($"Put {player.Nick} to Team {player.Team}");
}

View File

@ -23,7 +23,7 @@ namespace NeonTea.Quakeball.Networking.Instances {
public Client() {
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>();
}
@ -87,6 +87,7 @@ namespace NeonTea.Quakeball.Networking.Instances {
LocalPlayer.Controlled.NetId = LocalPlayer.Id;
AddPlayer(LocalPlayer);
SelfIdentified = true;
LocalPlayer.Ready = true;
NicknamePckt nickpckt = new NicknamePckt(LocalPlayer.Nick);
Peer.SendReliableLater(Server.uid, nickpckt);
@ -114,15 +115,16 @@ namespace NeonTea.Quakeball.Networking.Instances {
}
} else if (packet is PlayerInitPckt) {
PlayerInitPckt init = (PlayerInitPckt)packet;
if (Players.ContainsKey(conn.uid)) {
if (Players.ContainsKey(init.PlayerId)) {
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.Team = init.Team;
Player obj = Net.SpawnPlayer(init.SpawnPckt.Location).GetComponent<Player>();
player.Controlled = obj;
AddPlayer(player);
Debug.Log("Added player" + player.Nick);
} else if (packet is DeadPckt) {
DeadPckt dead = (DeadPckt)packet;
if (Players.ContainsKey(dead.DeadPlayerId)) {
@ -173,14 +175,14 @@ namespace NeonTea.Quakeball.Networking.Instances {
}
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.
}
Players[pckt.PlayerId].Controlled.ProcessUpdatePacket(pckt);
}
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);
}
}

View File

@ -22,7 +22,7 @@ namespace NeonTea.Quakeball.Networking.Instances {
public GameMaster GameMaster;
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) {
@ -63,7 +63,7 @@ namespace NeonTea.Quakeball.Networking.Instances {
Terminal.Singleton.Println($"{conn.uid} Connected");
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;
}
@ -72,7 +72,7 @@ namespace NeonTea.Quakeball.Networking.Instances {
PlayerInitPckt init = new PlayerInitPckt(p.Id, p.Team, nick, spawn);
Peer.SendReliableLater(conn.uid, init);
}
NetPlayer RemotePlayer = new NetPlayer(PlayerIdCounter++);
NetPlayer RemotePlayer = new NetPlayer(PlayerIdCounter++, false);
GameMaster.PlayerJoined(RemotePlayer);
AddPlayer(RemotePlayer);
@ -91,15 +91,17 @@ namespace NeonTea.Quakeball.Networking.Instances {
}
public void PlayerJoined(NetPlayer player) {
player.Ready = true;
NicknamePckt nick = new NicknamePckt(player.Nick, player.Id);
SpawnPckt spawn = new SpawnPckt(player.Controlled.transform.position, player.Id);
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) {
if (packet is ReadyPckt) {
if (Players[conn.uid].Controlled == null) {
if (!IsReady(conn.uid)) {
NetPlayer player = Players[conn.uid];
Player obj = Net.SpawnPlayer(GameMaster.GetSpawn(player)).GetComponent<Player>();
player.Controlled = obj;
@ -113,7 +115,9 @@ namespace NeonTea.Quakeball.Networking.Instances {
NicknamePckt nick = (NicknamePckt)packet;
Players[conn.uid].Nick = nick.Nick;
nick.PlayerId = conn.uid;
if (IsReady(conn.uid)) {
SendReliableToAll(nick);
}
} else if (packet is PlayerUpdatePckt) {
PlayerUpdatePckt updatePckt = (PlayerUpdatePckt)packet;
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() {
MultiplePlayerUpdatesPckt pckt = new MultiplePlayerUpdatesPckt(PlayerList);
SendUnreliableToAll(pckt);

View File

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

View File

@ -96,7 +96,8 @@
"depth": 0,
"source": "builtin",
"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": {

View File

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

View File

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