public ShipAbilityHandler(Ship me) : base(new Boost(me.MovementController, me.Controllable)) { _me = me; _me.OnOutOfBounds += Ability(Boost.NAME).Deactivate; }
public IdleManager(Ship me, NotificationManager notificationManager) { _lastActive = DateTime.UtcNow; _notificationManager = notificationManager; _me = me; Idle = false; }
public void AddShipToGame(Ship ship) { if (ship != null) { _shipManager.Add(ship); _collisionManager.Monitor(ship); } }
public void RemoveShipFromGame(Ship ship) { if (ship != null) { _shipManager.Remove(ship.Host.ConnectionID); _collisionManager.UnMonitor(ship); } }
public ShipWeaponController(Ship ship, BulletManager bm) { _bulletManager = bm; _me = ship; Energy = 1; DamageModifier = 1; LastFired = DateTime.UtcNow; AutoFire = false; }
public Bullet(Vector2 position, Vector2 direction, Ship firedBy, double damageModifier) : base(WIDTH, HEIGHT, new BulletMovementController(position, direction, firedBy.MovementController.Rotation), new LifeController(LIFE), new DamageController(BASE_DAMAGE)) { ID = Interlocked.Increment(ref _bulletGUID);// Reverse bullet GUID's to go below 0 _spawnedAt = DateTime.UtcNow; FiredBy = firedBy; DamageController.MultiplyDamage(damageModifier); }
/// <summary> /// Adds a ship and returns the added ship. Used to chain methods together. /// </summary> /// <param name="s">The ship to add</param> public void Add(Ship s) { // Only enable respawn if it hasn't been enabled yet if (!s.RespawnEnabled) { s.RespawnEnabled = true; s.OnDeath += new DeathEventHandler(_respawnManager.StartRespawnCountdown); } Ships.TryAdd(s.Host.ConnectionID, s); }
public ShipLevelManager(Ship me) { Level = 1; Experience = 0; _me = me; _levelCalculator = new LevelCalculator(); ExperienceToNextLevel = Convert.ToInt32(_levelCalculator.NextLevelExperience(Level)); _me.OnKill += Killed; _me.OnDeath += Died; OnLevel += _me.LifeController.LeveledUp; OnLevel += _me.WeaponController.LeveledUp; }
public object[] Compress(Ship ship) { object[] result = new object[23]; SetCollidableContractMembers(result, ship); result[ShipCompressionContract.RotatingLeft] = Convert.ToInt32(ship.MovementController.Moving.RotatingLeft); result[ShipCompressionContract.RotatingRight] = Convert.ToInt32(ship.MovementController.Moving.RotatingRight); result[ShipCompressionContract.Forward] = Convert.ToInt32(ship.MovementController.Moving.Forward); result[ShipCompressionContract.Backward] = Convert.ToInt32(ship.MovementController.Moving.Backward); result[ShipCompressionContract.Name] = ship.Name; result[ShipCompressionContract.MaxLife] = ship.LifeController.MaxLife; result[ShipCompressionContract.Level] = ship.LevelManager.Level; result[ShipCompressionContract.Boost] = Convert.ToInt32(ship.AbilityHandler.Ability(Boost.NAME).Active); return result; }
public User(string connectionID, Ship ship, RegisteredClient rc) { RegistrationTicket = rc; ConnectionID = connectionID; MyShip = ship; ReadyForPayloads = false; Viewport = new Size(0, 0); // Initialize the viewport to 0 by 0 RemoteControllers = new List<User>(); NotificationManager = new NotificationManager(); IdleManager = new IdleManager(ship, NotificationManager); Connected = true; if (ship != null) { ship.Host = this; } }
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 ShipSnapShotManager(Ship ship) { _snapShotLifetime = TimeSpan.FromMilliseconds(Game.Instance.Configuration.gameConfig.DRAW_INTERVAL * 1.5); _snapShotTail = new BoundsSnapShot { Position = ship.MovementController.Position, At = GameTime.Now, Next = null }; _snapShotHead = new BoundsSnapShot { Position = ship.MovementController.Position, At = GameTime.Now, Next = _snapShotTail }; _ship = ship; _bounds = new Rectangle(Convert.ToInt32(_ship.MovementController.Position.X), Convert.ToInt32(_ship.MovementController.Position.Y), _ship.Width(), _ship.Height()); _updateLock = new object(); }
/// <summary> /// Retrieves the game's configuration /// </summary> /// <returns>The game's configuration</returns> public object initializeClient(string connectionId, RegisteredClient rc) { if (!UserHandler.UserExistsAndReady(connectionId)) { try { lock (_locker) { User user = UserHandler.FindUserByIdentity(rc.Identity); Ship ship; if (user == null) { if (UserHandler.TotalActiveUsers >= RuntimeConfiguration.MaxServerUsers) { return new { ServerFull = true }; } else { ship = new Ship(RespawnManager.GetRandomStartPosition(), GameHandler.BulletManager); ship.Name = rc.DisplayName; user = new User(connectionId, ship, rc) { Controller = false }; UserHandler.AddUser(user); } } else { string previousConnectionID = user.ConnectionID; UserHandler.ReassignUser(connectionId, user); ship = user.MyShip; if (user.Connected) // Check if it's a duplicate login { GetContext().Clients.Client(previousConnectionID).controlTransferred(); user.NotificationManager.Notify("Transfering control to this browser. You were already logged in."); } else { ship.Disposed = false; ship.LifeController.HealFull(); user.Connected = true; } user.IdleManager.RecordActivity(); user.IdleManager.Idle = false; } 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 (Exception e) { ErrorLog.Instance.Log(e); } } return null; }
public ShipStatRecorder(Ship me) { _me = me; }
public const int MIN_EXPERIENCE = 40; // Cannot gain less than 5 experience per kill public int CalculateKillExperience(Ship Killer, Ship Killed) { var levelDiff = Killed.LevelManager.Level - Killer.LevelManager.Level; return Convert.ToInt32(Math.Max(Math.Round(BASE_EXPERIENCE_GAIN + BASE_EXPERIENCE_GAIN * levelDiff * LEVEL_DIFFERENCE_MULTIPLIER), MIN_EXPERIENCE)); }
/// <summary> /// Retrieves the game's configuration /// </summary> /// <returns>The game's configuration</returns> public object initializeClient(string connectionId, RegisteredClient rc) { if (!UserHandler.UserExistsAndReady(connectionId)) { try { lock (_locker) { User user = UserHandler.FindUserByIdentity(rc.Identity); Ship ship; if (user == null) { if (UserHandler.TotalActiveUsers >= RuntimeConfiguration.MaxServerUsers) { return(new { ServerFull = true }); } else { ship = new Ship(RespawnManager.GetRandomStartPosition(), GameHandler.BulletManager); ship.Name = rc.DisplayName; user = new User(connectionId, ship, rc) { Controller = false }; UserHandler.AddUser(user); } } else { string previousConnectionID = user.ConnectionID; UserHandler.ReassignUser(connectionId, user); ship = user.MyShip; if (user.Connected) // Check if it's a duplicate login { GetContext().Clients.Client(previousConnectionID).controlTransferred(); user.NotificationManager.Notify("Transfering control to this browser. You were already logged in."); } else { ship.Disposed = false; ship.LifeController.HealFull(); user.Connected = true; } user.IdleManager.RecordActivity(); user.IdleManager.Idle = false; } GameHandler.AddShipToGame(ship); } return(new { Configuration = Configuration, CompressionContracts = new { ServerFull = false, 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 (Exception e) { ErrorLog.Instance.Log(e); } } return(null); }