public static bool Update(IPEndPoint endPoint, UpdateRequest state) { try { lastUpdated[endPoint] = DateTime.Now; LightPlayer player = players[endPoint]; int id = player.ID; if (id != state.PlayerID) { return(false); } UpdatePlayer(endPoint, state.Players[0]); if (state.Shots != null) { LightShot shot = state.Shots[0]; if (shots.Any((x) => x.ID == shot.ID)) { return(true); } Vector2i mousePos = new Vector2i(shot.Dest.X, shot.Dest.Y); Vector2i hit = new Player(player).HitScan(level, mousePos, players.Values); shot.Dest = new LightVect2(hit); shots.Add(shot); LightPlayer target = FindTarget(shot, id); if (target != null) { target.ReSpawn = true; target.Deaths += 1; player.Score += 1; } } return(true); } catch (KeyNotFoundException) { if (endPoint != lastUnkownEP) { PrintErr($"update request: unknown player from {endPoint}"); lastUnkownEP = endPoint; } return(false); } }
private static LightPlayer FindTarget(LightShot shot, int id) { foreach (var lightPlayer in players.Values) { if (freePlayerIDs[lightPlayer.ID] || lightPlayer.ID == id) { continue; } Player player = new Player(lightPlayer); //player.MakeRect(); //player.Rect.Left = lightPlayer.Pos.X; //player.Rect.Top = lightPlayer.Pos.Y; if (Geometry.ScaleRect(player.Rect, 120, 120).Contains(shot.Dest.X, shot.Dest.Y)) { return(lightPlayer); } } return(null); }