internal static void ProcessRemoteInput(ShipCommand commandPacket) { if (commandPacket.Owner != ConnectionManager.ConnectionID) { OnCommandReceived(commandPacket); } }
public static void Build(ShipCommand command, int playerNumber) { var game = Match.GetInstance(); var player = game.GetPlayer(playerNumber); switch (command) { case ShipCommand.BuildAlienFactory: if (player.AlienFactory != null) { throw new AlreadyHasBuildingException(); } BuildBuilding(game, player, new Entities.Buildings.AlienFactory(playerNumber)); break; case ShipCommand.BuildMissileController: if (player.MissileController != null) { throw new AlreadyHasBuildingException(); } BuildBuilding(game, player, new MissileController(playerNumber)); break; } }
internal static void DestroyBuilding(ShipCommand Command, int PlayerNumber) { var player = Match.GetInstance().GetPlayer(PlayerNumber); var deltaY = PlayerNumber == 1 ? 1 : -1; var ship = player.Ship; var buildingX = ship.X; var buildingY = ship.Y + deltaY; var building = Match.GetInstance().Map.GetEntity(buildingX, buildingY); if (Command == ShipCommand.BuildMissileController) { player.MissileController = null; player.MissileLimit -= Settings.Default.MissileLimitBoost; player.Lives += Settings.Default.MissileControllerCost; } else { player.AlienFactory = null; player.AlienWaveSize -= Settings.Default.AlienFactoryWaveSizeBoost; player.Lives += Settings.Default.AlienFactoryCost; } if (building != null) { Match.GetInstance().Map.RemoveEntity(building); } }
private void SendShipCommandToNearest(int shipId, ShipCommand player_command, int target_id, int point_id) { int[] nearest = NearestShipIds(shipId); foreach (int entryId in nearest) { if (playerShipInverse.ContainsKey(entryId)) { using (var writer = DarkRiftWriter.Create()) { writer.Write(shipId); writer.Write((int)player_command); writer.Write(target_id); writer.Write(point_id); //Console.WriteLine("sending {0} bytes to player {1}",writer.Length,entry.Key); using (var msg = Message.Create(Game.ShipCommand, writer)) { //Console.WriteLine("sending message tag {0} of {1} bytes to player {2}", msg.Tag,msg.DataLength,entry.Key); //Console.WriteLine(_loginPlugin); //Console.WriteLine(_loginPlugin.Clients.Count); //Console.WriteLine(_loginPlugin.UsersLoggedIn.Count); IClient cl = _loginPlugin.Clients[playerShipInverse[entryId]]; //Console.WriteLine("client id {0}",cl.ID); cl.SendMessage(msg, SendMode.Unreliable); } //Console.WriteLine("sended {0} nearest ships to player {1}", Nearest(entry.Value).Length, entry.Key); } } } }
public static void Build(ShipCommand command, int playerNumber) { var game = Match.GetInstance(); var player = game.GetPlayer(playerNumber); switch (command) { case ShipCommand.BuildAlienFactory: if (player.AlienFactory != null) { throw new AlreadyHasBuildingException(); } BuildBuilding(game, player, new Entities.Buildings.AlienFactory(playerNumber)); break; case ShipCommand.BuildMissileController: if (player.MissileController != null) { throw new AlreadyHasBuildingException(); } BuildBuilding(game, player, new MissileController(playerNumber)); break; } }
private void ProcessInput(int elapsedTime) { visualState = VisualStates.Idle; // reset visual state if (Command.Left) { Rotate(-1 * RotationRate * elapsedTime); } if (Command.Right) { Rotate(RotationRate * elapsedTime); } if (Command.Thrust) { AccelerateShip(elapsedTime); } if (Command.Shields) { RaiseShields(elapsedTime); } _timeSinceLastShot += elapsedTime; if (Command.Shoot) { Fire(elapsedTime); } Command = new ShipCommand("", 0); }
internal static void ProcessLocalInput() { KeyboardState keyboardState = Keyboard.GetState(); int commands = 0; if (keyboardState.IsKeyDown(Keys.Left)) { commands += (int)CommandFlags.Left; } if (keyboardState.IsKeyDown(Keys.Right)) { commands += (int)CommandFlags.Right; } if (keyboardState.IsKeyDown(Keys.Up)) { commands += (int)CommandFlags.Thrust; } if (keyboardState.IsKeyDown(Keys.Down)) { commands += (int)CommandFlags.Shields; } if (keyboardState.IsKeyDown(Keys.Space)) { commands += (int)CommandFlags.Shoot; } string source = ConnectionManager.ConnectionID; ShipCommand commandPacket = new ShipCommand(source, commands); OnCommandReceived(commandPacket); ConnectionManager.SendShipCommand(commandPacket); }
public void Command(ShipCommand command, SpaceObject target = null, int point_id = 0) { if (target != null) { SetTarget(target); } switch (command) { case ShipCommand.MoveTo: GoToTarget(); break; //case ShipCommand.SetTarget: // SetTarget(target); // break; //case ShipCommand.SetTargetShip: // SetTarget(target); // break; case ShipCommand.Atack: Atack_target(point_id); break; case ShipCommand.WarpTo: WarpToTarget(); break; } }
public void SetShipMove(ShipMove move) { movePercent = 0.0f; pathPoints = new List <Vector3>(); pathPoints.Add(transform.position); foreach (Vector2 w in move.waypoints) { Vector3 point = new Vector3(w.x, 0, w.y); Vector3 adjustWaypoint = Quaternion.AngleAxis(transform.eulerAngles.y, Vector3.up) * point + transform.position; pathPoints.Add(adjustWaypoint); } if (playerController != null) { ShipCommand c = playerController.GetShipCommand(this.shipID); c.shipMove = move; UpdateMovementPath(); } pathSelectionController.ShowPath(); if (playerController != null && playerController.GetSelectedObject() == this.gameObject) { playerController.UpdateInfoUI(); } }
public void ProcessRemoteInput(ShipCommand commandPacket) { if (commandPacket.Owner != _connectionManager.LocalPlayerID) { OnCommandReceived(commandPacket); } }
public void SendUserCommand(ShipCommand command, GameObject target = null, int point_id = -1) { int target_id = -1; switch (command) { case ShipCommand.SetTargetShip: target_id = (target != null) ? target.GetComponent <ShipMotor>().thisShip.p.Id : -1; var targetShipData = (target != null) ? target.GetComponent <ShipMotor>().thisShip.p : null; player.GetComponent <ShipMotor>().thisShip.Command(command, targetShipData, point_id); break; case ShipCommand.SetTarget: target_id = (target != null) ? target.GetComponent <SOParametres>().thisServerObject.Id : -1; var targetData = (target != null) ? target.GetComponent <SOParametres>().thisServerObject : null; player.GetComponent <ShipMotor>().thisShip.Command(command, targetData, point_id); break; default: player.GetComponent <ShipMotor>().thisShip.Command(command, null, point_id); break; } Debug.Log(command + " " + target_id + " " + point_id); GameManager.SendPlayerShipCommands(command, target_id, point_id); }
public void DecreaseSelectedShipMove() { if (selectedObject != null) { ShipController shipController = selectedObject.GetComponent <ShipController>(); if (shipController != null && shipController.shipOwner == playerID) { ShipCommand shipCommand = GetShipCommand(shipController); List <ShipMove> shipMoves = new List <ShipMove>(GlobalShipMoves.ShipMoves()); int currentMoveId = shipMoves.FindIndex(x => x.name == shipCommand.shipMove.name); int newMoveId = currentMoveId - 1; if (newMoveId < 0) { newMoveId = shipMoves.Count - 1; } SetSelectedShipMove(newMoveId); } } }
public void IncreaseSelectedShipAction() { if (selectedObject != null) { ShipController shipController = selectedObject.GetComponent <ShipController>(); if (shipController != null && shipController.shipOwner == playerID) { ShipCommand shipCommand = GetShipCommand(shipController); List <ShipAction> shipActions = new List <ShipAction>(GlobalShipActions.ShipActions()); int currentActionId = shipActions.FindIndex(x => x.name == shipCommand.shipAction.name); int newActionId = currentActionId + 1; if (shipActions.Count <= newActionId) { newActionId = 0; } SetSelectedShipAction(newActionId); } } }
public void TestMoveIntoRightWallPlayerOne() { // Given var game = Match.GetInstance(); game.StartNewGame(true); var map = game.Map; var ship = game.GetPlayer(1).Ship; const ShipCommand direction = ShipCommand.MoveRight; // When while (ship.X + ship.Width < map.Width - 1) { ship.Command = direction; game.Update(); } ship.Command = direction; game.Update(); // Then Assert.IsInstanceOfType(map.GetEntity(map.Width - 1, ship.Y), typeof(Wall), "Rightmost tile is not a wall after ship moved into it"); Assert.IsInstanceOfType(map.GetEntity(ship.X, ship.Y), typeof(Ship), "Leftmost ship tile is missing after moving into a right wall"); Assert.IsInstanceOfType(map.GetEntity(ship.X + 1, ship.Y), typeof(Ship), "Center ship tile is missing after moving into a right wall"); Assert.IsInstanceOfType(map.GetEntity(ship.X + 2, ship.Y), typeof(Ship), "Rightmost ship tile is missing after moving into a right wall"); Assert.AreEqual(map.Width - 4, ship.X, "Ship x is not " + (map.Width - 4) + "as expected after moving into a right wall"); }
public void SetSelectedShipAction(int actionID) { if (selectedObject != null && canUpdateCmds) { ShipController shipController = selectedObject.GetComponent <ShipController>(); if (shipController != null && shipController.shipOwner == playerID) { ShipCommand shipCommand = GetShipCommand(shipController); List <ShipAction> shipActions = new List <ShipAction>(GlobalShipActions.ShipActions()); if (shipActions.Count > actionID && 0 <= actionID) { List <ShipActionAvailablityEnum> actionAvailability = GameRunner.GetShipActionAvailability(shipController, shipCommand); if (actionAvailability[actionID] == ShipActionAvailablityEnum.ENABLED) { shipCommand.shipAction = shipActions[actionID]; shipController.UpdateActionVisual(); } } } } UpdateCommandUI(); UpdateInfoUI(); }
private void ProcessIncomingPacket(object sender, PacketReceivedEventArgs e) { if (e.Packet.Type == PacketType.ShipCommand) { ShipCommand command = e.Packet as ShipCommand; ProcessRemoteInput(command); } }
public Ship(int id, int playerNumber, int x, int y, int width, int height, bool alive, ShipCommand command, string commandFeedback) : base(id, playerNumber, x, y, width, height, alive, EntityType.Ship) { OnDestroyedEvent += OnDestroy; Command = command; CommandFeedback = commandFeedback; }
public Ship(int id, int playerNumber, int x, int y, int width, int height, bool alive, ShipCommand command, string commandFeedback) : base(id, playerNumber, x, y, width, height, alive, EntityType.Ship) { OnDestroyedEvent += OnDestroy; Command = command; CommandFeedback = commandFeedback; }
internal void CommandReceivedHandler(object sender, CommandReceivedEventArgs args) { ShipCommand packet = args.CommandPacket; if (Owner == packet.Owner) { Command = packet; } }
public NullShip(GameModel model) : base(model) { Location = new Vector2(View.GameView.PlayArea.Width / 2, View.GameView.PlayArea.Height / 2); Velocity = new Vector2(Stopped, 0); this.Type = EntityType.Ship; Height = 1; Width = 1; ShieldEnergy = 100; Command = new ShipCommand("", 0); }
private void RotateWayPointRelToShipBy90Deg(ShipCommand shipCommand) { if (shipCommand != ShipCommand.TurnRight && shipCommand != ShipCommand.TurnLeft) { return; } var tempNorthCoord = NorthCoord; NorthCoord = shipCommand == ShipCommand.TurnLeft ? EastCoord : -EastCoord; EastCoord = shipCommand == ShipCommand.TurnLeft ? -tempNorthCoord : tempNorthCoord; }
internal override void Initialize() { base.Initialize(); Location = new Vector2(0, 0); Velocity = new Vector2(Stopped, 0); this.Type = EntityType.Ship; Height = ShipHeight; Width = ShipWidth; ShieldEnergy = 100; Command = new ShipCommand("", 0); }
public void UpdateCommandUI() { if (selectedObject != null) { ShipController shipController = selectedObject.GetComponent <ShipController>(); if (shipController != null && shipController.shipOwner == playerID) { ShipCommand shipCommand = GetShipCommand(shipController); uiController.UpdateCommandUI(shipCommand.shipMove.name, GameRunner.GetShipActionAvailability(shipController, shipCommand)); } } }
public bool CheckIfAllCommandsAreIn() { foreach (ShipController sc in shipControllers) { ShipCommand c = GetShipCommand(sc.shipID); if (c == null) { return(false); } } return(true); }
public static void SendPlayerShipCommands(ShipCommand command, int target_id, int point_id) { using (var writer = DarkRiftWriter.Create()) { writer.Write((int)command); writer.Write(target_id); writer.Write(point_id); using (var msg = Message.Create(GameTags.PlayerCommand, writer)) { GameControl.Client.SendMessage(msg, SendMode.Reliable); } } }
/// <summary> /// Updates a ship /// </summary> /// <param name="id"></param> /// <param name="cmd"></param> /// <returns></returns> public async Task <Ship> Update(int id, ShipCommand cmd) { cmd.Validate <ShipCommand, ShipCommandValidator>(); var ship = await ctx.Ships.FindAsync(id); ship.Name = cmd.Name; ship.Imd = cmd.Imd; ship.Mmsi = cmd.Mmsi; ship.CustomerId = cmd.CustomerId; await ctx.SaveChangesAsync(); return(ship); }
/// <summary> /// Creates a ship /// </summary> /// <param name="cmd"></param> /// <returns></returns> public async Task <Ship> Create(ShipCommand cmd) { cmd.Validate <ShipCommand, ShipCommandValidator>(); var record = ctx.Ships.Add(new Ship { Name = cmd.Name, Imd = cmd.Imd, Mmsi = cmd.Mmsi, CustomerId = cmd.CustomerId }); await ctx.SaveChangesAsync(); return(record.Entity); }
private void SendShipCommand(int ship_id, ShipCommand command, int target_id, int point) { if (nearestShips.ContainsKey(ship_id)) { SpaceObject target = null; if (target_id != -1) { //TODO может случится что цель не находится в поле видимости игрока must найти варианты решения if (nearestShips.ContainsKey(target_id)) { target = nearestShips[target_id].GetComponent <ShipMotor>().thisShip.p; } if (nearestSOs.ContainsKey(target_id)) { target = nearestSOs[target_id].GetComponent <SOParametres>().thisServerObject; } } nearestShips[ship_id].GetComponent <ShipMotor>().thisShip.Command(command, target, point); } }
private void SaveShipCommand(ShipCommand shipCommand) { var shipCommandString = shipCommand.ToString(); var filename = Path.Combine(OutputPath, Settings.Default.OutputFile); try { using (var file = new StreamWriter(filename)) { file.WriteLine(shipCommandString); } Log("Command: " + shipCommandString); } catch (IOException e) { Log(String.Format("Unable to write command file: {0}", filename)); var trace = new StackTrace(e); Log(String.Format("Stacktrace: {0}", trace)); } }
public void SetSelectedShipMove(int moveID) { if (selectedObject != null && canUpdateCmds) { ShipController shipController = selectedObject.GetComponent <ShipController>(); if (shipController != null && shipController.shipOwner == playerID) { ShipCommand shipCommand = GetShipCommand(shipController); List <ShipMove> shipMoves = new List <ShipMove>(GlobalShipMoves.ShipMoves()); if (shipMoves.Count > moveID && 0 <= moveID) { shipCommand.shipMove = shipMoves[moveID]; shipController.UpdateMovementPath(); } } } UpdateCommandUI(); UpdateInfoUI(); }
public void ProcessLocalInput() { KeyboardState keyboardState = Keyboard.GetState(); int commands = 0; if (keyboardState.IsKeyDown(Keys.Left)) { commands += (int)CommandFlags.Left; } if (keyboardState.IsKeyDown(Keys.Right)) { commands += (int)CommandFlags.Right; } if (keyboardState.IsKeyDown(Keys.Up)) { commands += (int)CommandFlags.Thrust; } if (keyboardState.IsKeyDown(Keys.Down)) { commands += (int)CommandFlags.Shields; } if (keyboardState.IsKeyDown(Keys.Space)) { commands += (int)CommandFlags.Shoot; } string source = _connectionManager.LocalPlayerID; if (source != null) { ShipCommand commandPacket = new ShipCommand(source, commands); OnCommandReceived(commandPacket); _connectionManager.SendShipCommandToHost(commandPacket); } }
public void GetPlayerShipCommand(string player, ShipCommand player_command, int target_id, int point_id) { gamePlugin.WriteToLog(player + " " + player_command + " " + target_id + " " + point_id, DarkRift.LogType.Info); SendShipCommandToNearest(playerShip[player], player_command, target_id, point_id); Ship _playerShip = ships [playerShip[player]]; SpaceObject _target; switch (player_command) { case ShipCommand.SetTargetShip: _target = target_id != -1 ? ships[target_id].p : null; _playerShip.Command(player_command, _target); break; case ShipCommand.SetTarget: _target = target_id != -1 ? gamePlugin.serverSO.GetSpaceObject(target_id) : null; _playerShip.Command(player_command, _target); break; case ShipCommand.WarpTo: _target = target_id != -1 ? gamePlugin.serverSO.GetSpaceObject(target_id) : null; _playerShip.Command(player_command, _target); break; case ShipCommand.MoveTo: _target = target_id != -1 ? gamePlugin.serverSO.GetSpaceObject(target_id) : null; _playerShip.Command(player_command, _target); break; case ShipCommand.Atack: _target = target_id != -1 ? gamePlugin.serverSO.GetSpaceObject(target_id) : null; _playerShip.Command(player_command, _target, point_id); break; } }
public virtual void ApplyCommand(ShipCommand command) { switch (command.Type) { case ShipCommandType.North: case ShipCommandType.South: case ShipCommandType.East: case ShipCommandType.West: AdjustShipLocation((Direction)command.Type, command.Value); break; case ShipCommandType.Left: ShipLocation.TurnLeft(command.Value / 90); break; case ShipCommandType.Right: ShipLocation.TurnRight(command.Value / 90); break; case ShipCommandType.Forward: AdjustShipLocation(ShipLocation.FacedDirection.Direction, command.Value); break; } }
public BotMove(ShipCommand command = ShipCommand.Nothing, double probability = 1.0) : base(probability) { Command = command; }
public BuildingInfo(ShipCommand command, EntityType type, int cost) { Command = command; Type = type; Cost = cost; }
private void SaveShipCommand(ShipCommand shipCommand) { var shipCommandString = shipCommand.ToString(); var filename = Path.Combine(OutputPath, Settings.Default.OutputFile); try { using (var file = new StreamWriter(filename)) { file.WriteLine(shipCommandString); } } catch (IOException e) { var trace = new StackTrace(e); } }
private void IterativeDeeepening() { var score = -1; var Command = ShipCommand.Nothing; Node<ShipCommand> next = new Node<ShipCommand>(Command, score); var game = Match.GetInstance(); int depthLimit; try { for (depthLimit = 3; ; depthLimit += 4) { next = MatchRunner.ExpectiMax(game, PlayerType.OpponentAliens, 0, depthLimit); } } catch (ThreadAbortException) { ShipMove = next.Command; } }