public void Reloading_MicroWarpDrive_Test() { var server = EnvironmentGlobal.CreateGameServer("Reloading"); var gameSession = EnvironmentGlobal.GetSession(server); var spaceship = gameSession.GetPlayerSpaceShip(); var module = spaceship.GetPropulsionModules().First(); Assert.AreEqual(2.0f, module.Reloading); server.Command(server.SessionId, ModuleCommand.ToJson(gameSession, module.Braking)); Assert.AreEqual(1, server.Commands.Count); Assert.AreEqual(7, gameSession.GetCelestialObject(spaceship.Id).Speed); server.TurnCalculation(1); gameSession = EnvironmentGlobal.GetSession(server); spaceship = gameSession.GetPlayerSpaceShip(); module = spaceship.GetPropulsionModules().First(); Assert.AreEqual(0.05, module.Reloading); server.TurnCalculation(5); module = EnvironmentGlobal.GetSessionServerSide(server).GetPlayerSpaceShip().GetPropulsionModules().First(); Assert.AreEqual(0.3, module.Reloading); }
public void AddCommandsGeneral_Test() { var server = EnvironmentGlobal.CreateGameServer("CommandsTests"); var gameSession = EnvironmentGlobal.GetSession(server); var spaceship = gameSession.GetPlayerSpaceShip(); var module = spaceship.GetPropulsionModules().First(); server.Command(server.SessionId, ModuleCommand.ToJson(gameSession, module.Braking)); Assert.AreEqual(1, server.Commands.Count); server.TurnCalculation(1); server.Command(server.SessionId, ModuleCommand.ToJson(gameSession, module.Braking)); Assert.AreEqual(0, server.Commands.Count); server.TurnCalculation(5); Assert.AreEqual(0, server.Commands.Count); server.TurnCalculation(1); server.Wait(5); server.Command(server.SessionId, ModuleCommand.ToJson(gameSession, module.Braking)); Assert.AreEqual(1, server.Commands.Count); server.TurnCalculation(1); }
private void Window_KeyDown(object sender, KeyEventArgs e) { Logger.Debug($"Window_KeyDown - Handle the KeyDown event {e.KeyCode} "); var spacecraft = _environment.Session.GetPlayerSpaceShip(); string commandBody; switch (e.KeyCode) { case Keys.S: if (_environment.Session.IsPause) { return; } commandBody = ModuleCommand.ToJson(_environment.Session, spacecraft.GetPropulsionModules()[0].Braking); Global.Game.ExecuteCommand(new EngineCore.Command(commandBody)); break; case Keys.D: if (_environment.Session.IsPause) { return; } commandBody = ModuleCommand.ToJson(_environment.Session, spacecraft.GetPropulsionModules()[0].TurnRight); Global.Game.ExecuteCommand(new EngineCore.Command(commandBody)); break; case Keys.A: if (_environment.Session.IsPause) { return; } commandBody = ModuleCommand.ToJson(_environment.Session, spacecraft.GetPropulsionModules()[0].TurnLeft); Global.Game.ExecuteCommand(new EngineCore.Command(commandBody)); break; case Keys.W: if (_environment.Session.IsPause) { return; } commandBody = ModuleCommand.ToJson(_environment.Session, spacecraft.GetPropulsionModules()[0].Acceleration); Global.Game.ExecuteCommand(new EngineCore.Command(commandBody)); break; case Keys.Escape: _environment.CancelAction(); if (_environment.Session.IsPause) { Global.Game.SessionResume(); } break; } }
public void PropulsionModule_Braking_Test() { var server = EnvironmentGlobal.CreateGameServer("CommandsTests"); var gameSession = EnvironmentGlobal.GetSession(server); var spaceship = gameSession.GetPlayerSpaceShip(); var module = spaceship.GetPropulsionModules().First(); server.Command(server.SessionId, ModuleCommand.ToJson(gameSession, module.Braking)); Assert.AreEqual(1, server.Commands.Count); Assert.AreEqual(7, gameSession.GetCelestialObject(spaceship.Id).Speed); server.TurnCalculation(1); gameSession = EnvironmentGlobal.GetSession(server); Assert.AreEqual(6.975, Math.Round(gameSession.GetCelestialObject(spaceship.Id).Speed, 3)); Assert.AreEqual(0, server.Commands.Count); Assert.AreEqual(1, server.GetHistoryCommands(server.SessionId, spaceship.Id).Count); server.TurnCalculation(1); // Add command for not reloaded module server.Command(server.SessionId, ModuleCommand.ToJson(gameSession, module.Braking)); server.TurnCalculation(1); Assert.AreEqual(0, server.Commands.Count); server.Wait(5); server.Command(server.SessionId, ModuleCommand.ToJson(gameSession, module.Braking)); Assert.AreEqual(1, server.Commands.Count); server.Wait(5); Assert.AreEqual(0, server.Commands.Count); Assert.AreEqual(2, server.GetHistoryCommands(server.SessionId, spaceship.Id).Count); Assert.AreEqual(CommandTypes.StopShip, server.GetHistoryCommands(server.SessionId, spaceship.Id)[0].Type); }
public void Explosive_Integration_Test() { var settings = new EngineSettings { DebugProperties = new DebugProperties(true, true) }; var server = EnvironmentGlobal.CreateGameServer("CommandsTests_Weapon", settings); server.EnableDebugMode(); var gameSession = EnvironmentGlobal.GetSession(server); var spaceship = gameSession.GetPlayerSpaceShip(); var targetSpacecraft = gameSession.GetCelestialObject(1000348945).ToSpaceship(); var module = spaceship.GetWeaponModules().First(); server.Command(server.SessionId, ModuleCommand.ToJson(gameSession, module.Shot, 1000348945, ((IModule)module).Id, 1)); Assert.AreEqual(1, server.Commands.Count); Assert.AreEqual(200, targetSpacecraft.Shields); Assert.AreEqual(false, targetSpacecraft.IsDestroyed); server.TurnCalculation(1); gameSession = EnvironmentGlobal.GetSession(server); var explosives = gameSession.CelestialObjects.Where(obj => obj.OwnerId == 5005 && obj is Explosion).ToList(); Assert.AreEqual(1, explosives.Count); server.TurnCalculation(1); explosives = gameSession.CelestialObjects.Where(obj => obj.OwnerId == 5005 && obj is Explosion).ToList(); Assert.AreEqual(1, explosives.Count); gameSession = EnvironmentGlobal.Turn(20); explosives = gameSession.CelestialObjects.Where(obj => obj.OwnerId == 5005 && obj is Explosion).ToList(); Assert.AreEqual(0, explosives.Count); }
public void PropulsionModule_TurnLeft_Test() { var server = EnvironmentGlobal.CreateGameServer("CommandsTests"); var gameSession = EnvironmentGlobal.GetSession(server); var spaceship = gameSession.GetPlayerSpaceShip(); var module = spaceship.GetPropulsionModules().First(); double turnRotationSpeed = MobilityInDegrees / (new EngineSettings().UnitsPerSecond *module.ReloadTime); server.Command(server.SessionId, ModuleCommand.ToJson(gameSession, module.TurnLeft)); Assert.AreEqual(1, server.Commands.Count); server.TurnCalculation(1); gameSession = EnvironmentGlobal.GetSession(server); spaceship = gameSession.GetPlayerSpaceShip(); Assert.AreEqual(90 - turnRotationSpeed, spaceship.Direction); // Reloading time server.Wait(3); server.Command(server.SessionId, ModuleCommand.ToJson(gameSession, module.TurnLeft)); server.TurnCalculation(1); spaceship = EnvironmentGlobal.GetSession(server).GetPlayerSpaceShip(); Assert.AreEqual(80 - 1 * turnRotationSpeed, spaceship.Direction); server.TurnCalculation(1); spaceship = EnvironmentGlobal.GetSession(server).GetPlayerSpaceShip(); Assert.AreEqual(80 - 2 * turnRotationSpeed, spaceship.Direction); }
private void Event_OpenFire(object sender, EventArgs e) { var environment = (TacticalEnvironment)Tag; var targetId = environment.GetActiveObject().Id; var moduleId = environment.Action.ModuleId; var actionId = environment.Action.ActionId; var spacecraft = environment.Session.GetPlayerSpaceShip(); var module = spacecraft.GetWeaponModule(moduleId); var commandBody = ModuleCommand.ToJson(environment.Session, module.Shot, targetId, moduleId, actionId); Global.Game.ExecuteCommand(new EngineCore.Command(commandBody)); environment.SetAction(0, 0, TacticalMode.General); environment.CancelAction(); Global.Game.SessionResume(); Close(); }
public void WeaponModule_Shot_Test() { var settings = new EngineSettings { DebugProperties = new DebugProperties(true, true) }; var server = EnvironmentGlobal.CreateGameServer("CommandsTests_Weapon", settings); server.EnableDebugMode(); var gameSession = EnvironmentGlobal.GetSession(server); var spaceship = gameSession.GetPlayerSpaceShip(); var targetSpacecraft = gameSession.GetCelestialObject(1000348945).ToSpaceship(); var module = spaceship.GetWeaponModules().First(); IDebugProperties debug = new DebugProperties(true, true); server.Command(server.SessionId, ModuleCommand.ToJson(gameSession, module.Shot, 1000348945, ((IModule)module).Id, 1)); Assert.AreEqual(1, server.Commands.Count); Assert.AreEqual(200, targetSpacecraft.Shields); Assert.AreEqual(false, targetSpacecraft.IsDestroyed); server.TurnCalculation(10); gameSession = EnvironmentGlobal.GetSession(server); spaceship = gameSession.GetPlayerSpaceShip(); targetSpacecraft = gameSession.GetCelestialObject(1000348945, false).ToSpaceship(); Assert.AreEqual(0, server.Commands.Count); Assert.AreEqual(170, targetSpacecraft.Shields); Assert.AreEqual(false, targetSpacecraft.IsDestroyed); server.Wait(5); server.Command(server.SessionId, ModuleCommand.ToJson(gameSession, module.Shot, 1000348945, ((IModule)module).Id, 1)); server.TurnCalculation(10); gameSession = EnvironmentGlobal.GetSession(server); targetSpacecraft = gameSession.GetCelestialObject(1000348945, false).ToSpaceship(); Assert.AreEqual(140, targetSpacecraft.Shields); Assert.AreEqual(false, targetSpacecraft.IsDestroyed); server.Command(server.SessionId, ModuleCommand.ToJson(gameSession, module.Shot, 1000348945, ((IModule)module).Id, 1)); server.TurnCalculation(10); gameSession = EnvironmentGlobal.GetSession(server); targetSpacecraft = gameSession.GetCelestialObject(1000348945, false).ToSpaceship(); Assert.AreEqual(110, targetSpacecraft.Shields); Assert.AreEqual(false, targetSpacecraft.IsDestroyed); server.Command(server.SessionId, ModuleCommand.ToJson(gameSession, module.Shot, 1000348945, ((IModule)module).Id, 1)); server.TurnCalculation(10); gameSession = EnvironmentGlobal.GetSession(server); targetSpacecraft = gameSession.GetCelestialObject(1000348945, false).ToSpaceship(); Assert.AreEqual(80, targetSpacecraft.Shields); Assert.AreEqual(false, targetSpacecraft.IsDestroyed); server.Command(server.SessionId, ModuleCommand.ToJson(gameSession, module.Shot, 1000348945, ((IModule)module).Id, 1)); server.TurnCalculation(10); gameSession = EnvironmentGlobal.GetSession(server); targetSpacecraft = gameSession.GetCelestialObject(1000348945, false).ToSpaceship(); Assert.AreEqual(50, targetSpacecraft.Shields); Assert.AreEqual(false, targetSpacecraft.IsDestroyed); server.Command(server.SessionId, ModuleCommand.ToJson(gameSession, module.Shot, 1000348945, ((IModule)module).Id, 1)); server.TurnCalculation(10); gameSession = EnvironmentGlobal.GetSession(server); targetSpacecraft = gameSession.GetCelestialObject(1000348945, false).ToSpaceship(); Assert.AreEqual(20, targetSpacecraft.Shields); Assert.AreEqual(false, targetSpacecraft.IsDestroyed); server.Command(server.SessionId, ModuleCommand.ToJson(gameSession, module.Shot, 1000348945, ((IModule)module).Id, 1)); server.TurnCalculation(10); gameSession = EnvironmentGlobal.GetSession(server); targetSpacecraft = gameSession.GetCelestialObject(1000348945, false).ToSpaceship(); Assert.AreEqual(true, targetSpacecraft.IsDestroyed); }