public void SpawnAIShips(int number) { for (int i = 0; i < number; i++) { string connectionidAI = Guid.NewGuid().ToString(); ShipAI shipAI = new ShipAI(RespawnManager.GetRandomStartPosition(), GameHandler.BulletManager); UserAI userAI = new UserAI(connectionidAI, shipAI) { Controller = false }; UserHandler.AddUser(userAI); GameHandler.AddShipToGame(shipAI); } }
/// <summary> /// Retrieves the game's configuration /// </summary> /// <returns>The game's configuration</returns> public object initializeClient(string connectionId, RegisteredClient rc) { if (!UserHandler.UserExistsAndReady(connectionId)) { _gameLock.Wait(); try { User user = null;//UserHandler.FindUserByIdentity(rc.Identity); Ship ship = null; if (user == null) { if (UserHandler.TotalActiveUsers >= 50 /*RuntimeConfiguration.MaxServerUsers*/) { return(new { ServerFull = true }); } else { ship = new Ship(this, RespawnManager.GetRandomStartPosition(), GameHandler.BulletManager); ship.Name = rc.DisplayName; user = new User(connectionId, ship, rc) { Controller = false }; UserHandler.AddUser(user); } } GameHandler.AddShipToGame(ship); return(new { Configuration = Configuration, ServerFull = false, CompressionContracts = new { PayloadContract = _payloadManager.Compressor.PayloadCompressionContract, CollidableContract = _payloadManager.Compressor.CollidableCompressionContract, ShipContract = _payloadManager.Compressor.ShipCompressionContract, BulletContract = _payloadManager.Compressor.BulletCompressionContract, LeaderboardEntryContract = _payloadManager.Compressor.LeaderboardEntryCompressionContract, PowerupContract = _payloadManager.Compressor.PowerupCompressionContract }, ShipID = UserHandler.GetUserShip(connectionId).ID, ShipName = UserHandler.GetUserShip(connectionId).Name }); } catch { } finally { _gameLock.Release(); } } return(null); }
public bool TryRespawn(Ship ship, DateTime startedAt) { // We should respawn // We also check the ships host to ensure that we did not remove the user if ((DateTime.UtcNow - startedAt).TotalSeconds >= RESPAWN_TIMER && ship.Host != null) { ship.LifeController.HealFull(); ship.MovementController.Position = GetRandomStartPosition(); ship.Disposed = false; ship.Controllable.Value = true; _gameHandler.AddShipToGame(ship); Game.Instance.Leaderboard.StopRequestingLeaderboard(ship.Host.ConnectionID); return(true); } else { return(false); } }
public async Task <bool> TryRespawn(Ship ship, DateTime startedAt) { // We should respawn // We also check the ships host to ensure that we did not remove the user if ((DateTime.UtcNow - startedAt).TotalSeconds >= RESPAWN_TIMER && ship.Host != null) { ship.LifeController.HealFull(); ship.MovementController.Position = GetRandomStartPosition(); ship.MovementController.Velocity = Vector2.Zero; ship.MovementController.Rotation = _gen.Next(0, 360); ship.MovementController.StopMovement(); ship.Disposed = false; ship.Controllable.Value = true; _gameHandler.AddShipToGame(ship); await _game.Leaderboard.StopRequestingLeaderboardAsync(ship.Host.ConnectionID); return(true); } else { return(false); } }