static void Main(string[] args) { var server = new GameStateServer(); GameStateFrame oldFrame = null; server.RegisterGameStateCallback(frame => { Console.WriteLine("Received gamestate"); var player = frame.GetComponent <PlayerComponent>(); Console.WriteLine("New game state"); if (player != null) { Console.WriteLine(player.Name); var weapons = player.GetComponent <PlayerWeaponsComponent>(); if (weapons != null) { Console.WriteLine("Number of weapons: " + weapons.Weapons.Count); // Get the active weapon from the oldFrame if (oldFrame != null) { var oldPlayer = oldFrame.GetComponent <PlayerComponent>(); if (oldPlayer != null) { var oldWeapons = oldPlayer.GetComponent <PlayerWeaponsComponent>(); if (oldWeapons != null) { var oldActiveWeapon = oldWeapons.Weapons.FirstOrDefault(w => w.State == WeaponState.Active); if (oldActiveWeapon != null) { Console.WriteLine("Old active weapon: " + oldActiveWeapon.Name); } } } } var activeWeapon = weapons.Weapons.FirstOrDefault(w => w.State == WeaponState.Active); if (activeWeapon != null) { Console.WriteLine("Active weapon: " + activeWeapon.Name); if (activeWeapon.AmmoClip.HasValue && activeWeapon.AmmoClipMax.HasValue) { Console.WriteLine(activeWeapon.AmmoClip <= 0.25 * activeWeapon.AmmoClipMax ? "WARNING: LOW AMMO" : ""); } } } } Console.WriteLine(""); oldFrame = frame; }); server.Start(); Console.WriteLine("Server started"); while (server.IsListening) { Thread.Sleep(500); } }
private void GameStateCallback(GameStateFrame frame) { try { var provider = frame.GetComponent <ProviderComponent>(); if (provider != null) { ProviderComponentIsActive = true; ProviderName = provider.Name; } var player = frame.GetComponent <PlayerComponent>(); if (player != null) { PlayerComponentIsActive = true; PlayerName = player.Name; var weapons = player.GetComponent <PlayerWeaponsComponent>(); if (weapons != null) { ActiveWeapon = weapons.Weapons.FirstOrDefault(w => w.State == WeaponState.Active || w.State == WeaponState.Reloading); WeaponComponentIsActive = ActiveWeapon != null && ActiveWeapon.AmmoClip.HasValue && ActiveWeapon.AmmoClipMax.HasValue; RaisePropertyChangedOnUiThread(() => LowAmmo); } var state = player.GetComponent <PlayerStateComponent>(); if (state != null) { PlayerStateComponentIsActive = true; PlayerStateComponent = state; } } var round = frame.GetComponent <RoundComponent>(); if (round != null) { switch (round.Bomb) { case BombStatus.Planted: if (!bombPlantedTime.HasValue) { lock (bombPlantedTimeMutex) { bombPlantedTime = DateTime.Now; Task.Run((Action)UpdateBombTimer); } } bombIsPlanted = true; RaisePropertyChangedOnUiThread(() => BombIsPlanted); break; default: lock (bombPlantedTimeMutex) { bombPlantedTime = null; } bombIsPlanted = false; RaisePropertyChangedOnUiThread(() => BombIsPlanted); UpdateUiThread(); break; } } } catch (Exception e) { } }