private async Task HandleIncomingMessage(NetQuantum netQuantum) { switch (netQuantum.MessageType) { case AllMessages.NetEvent: await HandleNetEvent(netQuantum.Message <NetEvent>().Value); break; case AllMessages.NetPing: await HandleNetPing(netQuantum.Message <NetPing>().Value); break; case AllMessages.NetWorldView: await HandleNetWorldView(netQuantum.Message <NetWorldView>().Value); break; case AllMessages.NetLeaderboard: await HandleNetLeaderboard(netQuantum.Message <NetLeaderboard>().Value); break; default: //Console.WriteLine("Received other: " + netQuantum.MessageType.ToString()); break; } }
private async Task HandleIncomingMessage(NetQuantum quantum) { switch (quantum.MessageType) { case AllMessages.NetPing: var ping = quantum.Message <NetPing>().Value; await HandlePingAsync(ping); break; case AllMessages.NetSpawn: var spawn = quantum.Message <NetSpawn>().Value; var color = "red"; Sprites shipSprite = Sprites.ship_red; player.Connection = this; Logger.LogInformation($"Spawn: Name:\"{spawn.Name}\" Ship: {spawn.Ship} Score: {player.Score} Roles: {player.Roles}"); switch (spawn.Ship) { case "ship0": shipSprite = Sprites.ship0; color = "green"; break; case "ship_secret": if (player?.Roles?.Contains("Player") ?? false) { shipSprite = Sprites.ship_secret; color = "yellow"; } else { shipSprite = Sprites.ship_yellow; color = "yellow"; } break; /* * shipSprite = Sprites.ship_secret; * color = "yellow"; * break; */ case "ship_zed": if (player?.Roles?.Contains("Old Guard") ?? false) { shipSprite = Sprites.ship_zed; color = "red"; } else { shipSprite = Sprites.ship_red; color = "red"; } break; /* * shipSprite = Sprites.ship_zed; * color = "red"; * break; */ case "ship_green": shipSprite = Sprites.ship_green; color = "green"; break; case "ship_orange": shipSprite = Sprites.ship_orange; color = "orange"; break; case "ship_pink": shipSprite = Sprites.ship_pink; color = "pink"; break; case "ship_red": shipSprite = Sprites.ship_red; color = "red"; break; case "ship_cyan": shipSprite = Sprites.ship_cyan; color = "cyan"; break; case "ship_blue": shipSprite = Sprites.ship_blue; color = "blue"; break; case "ship_yellow": shipSprite = Sprites.ship_yellow; color = "yellow"; break; } player.Spawn(spawn.Name, shipSprite, color, spawn.Token); break; case AllMessages.NetControlInput: var input = quantum.Message <NetControlInput>().Value; player?.SetControl(new ControlInput { Position = new Vector2(input.X, input.Y), BoostRequested = input.Boost, ShootRequested = input.Shoot, CustomData = input.CustomData }); if (input.SpectateControl == "action:next") { var next = Player.GetWorldPlayers(world) .Where(p => p.IsAlive) .Where(p => p?.Fleet?.ID > (SpectatingFleet?.ID ?? 0)) .OrderBy(p => p?.Fleet?.ID) .FirstOrDefault()?.Fleet; if (next == null) { next = Player.GetWorldPlayers(world) .Where(p => p.IsAlive) .OrderBy(p => p?.Fleet?.ID) .FirstOrDefault()?.Fleet; } SpectatingFleet = next; IsSpectating = true; } else if (input.SpectateControl?.StartsWith("action:fleet:") ?? false) { var match = Regex.Match(input.SpectateControl, @"\d*$"); var fleetID = int.Parse(match.Value); var next = Player.GetWorldPlayers(world) .Where(p => p.IsAlive) .Where(p => p?.Fleet?.ID == fleetID) .FirstOrDefault()?.Fleet; SpectatingFleet = next; IsSpectating = true; } else if (input.SpectateControl == "spectating") { IsSpectating = true; } else { IsSpectating = false; } break; case AllMessages.NetExit: player.Exit(); break; case AllMessages.NetAuthenticate: var auth = quantum.Message <NetAuthenticate>().Value; if (player != null) { player.Token = auth.Token; player.AuthenticationStarted = false; } break; } }
private async Task HandleIncomingMessage(NetQuantum quantum) { switch (quantum.MessageType) { case AllMessages.NetPing: await SendPingAsync(); break; case AllMessages.NetSpawn: var spawn = quantum.Message <NetSpawn>().Value; Sprites shipSprite = Sprites.ship_red; switch (spawn.Color) { case "ship0": shipSprite = Sprites.ship0; break; case "green": shipSprite = Sprites.ship_green; break; case "orange": shipSprite = Sprites.ship_orange; break; case "pink": shipSprite = Sprites.ship_pink; break; case "red": shipSprite = Sprites.ship_red; break; case "cyan": shipSprite = Sprites.ship_cyan; break; case "yellow": shipSprite = Sprites.ship_yellow; break; } player.Spawn(spawn.Name, shipSprite, spawn.Color, spawn.Token); break; case AllMessages.NetControlInput: var input = quantum.Message <NetControlInput>().Value; player?.SetControl(new ControlInput { Position = new Vector2(input.X, input.Y), BoostRequested = input.Boost, ShootRequested = input.Shoot }); break; } /* * else if (message is Hook) * { * var hook = message as Hook; * world.Hook = hook; * }*/ }
private async Task HandleIncomingMessage(NetQuantum quantum) { switch (quantum.MessageType) { case AllMessages.NetPing: var ping = quantum.Message <NetPing>().Value; await HandlePingAsync(ping); break; case AllMessages.NetSpawn: var spawn = quantum.Message <NetSpawn>().Value; Sprites shipSprite = Sprites.ship_red; switch (spawn.Color) { case "ship0": shipSprite = Sprites.ship0; break; case "ship_secret": shipSprite = Sprites.ship_secret; break; case "ship_zed": shipSprite = Sprites.ship_zed; break; case "green": shipSprite = Sprites.ship_green; break; case "orange": shipSprite = Sprites.ship_orange; break; case "pink": shipSprite = Sprites.ship_pink; break; case "red": shipSprite = Sprites.ship_red; break; case "cyan": shipSprite = Sprites.ship_cyan; break; case "yellow": shipSprite = Sprites.ship_yellow; break; } player.Spawn(spawn.Name, shipSprite, spawn.Color, spawn.Token); break; case AllMessages.NetControlInput: var input = quantum.Message <NetControlInput>().Value; player?.SetControl(new ControlInput { Position = new Vector2(input.X, input.Y), BoostRequested = input.Boost, ShootRequested = input.Shoot }); switch (input.SpectateControl) { case "action:next": var next = Player.GetWorldPlayers(world) .Where(p => p.IsAlive) .Where(p => p?.Fleet?.ID > (SpectatingFleet?.ID ?? 0)) .OrderBy(p => p?.Fleet?.ID) .FirstOrDefault()?.Fleet; if (next == null) { next = Player.GetWorldPlayers(world) .Where(p => p.IsAlive) .OrderBy(p => p?.Fleet?.ID) .FirstOrDefault()?.Fleet; } SpectatingFleet = next; IsSpectating = true; break; case "spectating": IsSpectating = true; break; default: IsSpectating = false; break; } break; } }