public override void DoAction() { Player newPlayer = new Player(tank); PlayerJoinedEventArgs args = new PlayerJoinedEventArgs(newPlayer); Bot.InvokePlayerJoined(args); args.Dispose(); }
/// <summary> /// Find the shortest path to the destination using the A* algorithm. /// </summary> /// <param name="map"></param> /// <param name="player"></param> /// <param name="destinationX">The destination x (in "pixels").</param> /// <param name="destinationY">The destination y (in "pixels").</param> /// <exception cref="InvalidOperationException">Thrown if the target destination /// is unreachable.</exception> public Path FindPath(Map map, Player player, int destinationX, int destinationY) { MinotaurPathfinder.Pathfinder pathfinder = new MinotaurPathfinder.Pathfinder(map); pathfinder.Pathfind(map, player, destinationX, destinationY); Path path = new Path(); foreach (MinotaurPathfinder.MetaCompleteSquare square in pathfinder.FullPath()) { path.AppendNode(new Node(square.X, square.Y)); } pathfinder.Dispose(); return path; }
/// <summary> /// Check if a player is in range of another player. /// </summary> /// <param name="player"></param> /// <returns></returns> public bool IsInRange(Player player) { MetaPlayer testPlayer = players[player.ID]; return testPlayer.Player.IsInRangeOf(player); }
/// <summary> /// Add a player to the game. Does nothing if the player was already added. /// </summary> /// <param name="player">Player to add.</param> /// <param name="isLocalPlayer">True if the player is the bot.</param> public void AddPlayer(Player player, bool isLocalPlayer) { if (players.ContainsKey(player.ID)) { // Do not add duplicates. return; } players[player.ID] = new MetaPlayer(player) { GoalAngle = player.Angle, IsLocalPlayer = isLocalPlayer }; }
public override void Dispose() { Player = null; }
/// <summary> /// /// </summary> /// <param name="player"></param> public PlayerOutOfRangeEventArgs(Player player) { Player = player; }
public void Pathfind(Map map, Player player, int destinationX, int destinationY) { /* * * Find path from hero to monster. First, get coordinates * of hero. * * */ Point startingPoint = new Point((int)player.Position.x / 64, -(int)player.Position.y / 64); startingX = startingPoint.X; startingY = startingPoint.Y; this.destinationX = destinationX / 64; this.destinationY = (destinationY / 64); // Initialize path. for (int y = 0; y < map.Height; ++y) { for (int x = 0; x < map.Width; ++x) { SquareContent content = SquareContent.Empty; Tile tile = map.GetTile(x, y); if (!tile.IsPassable) { content = SquareContent.Wall; } else if (x == startingX && y == startingY) { content = SquareContent.Starting; } _squares[x, y] = new CompleteSquare() { X = -1, Y = -1, IsPath = false, ContentCode = content, DistanceSteps = 10000 }; } } /* * * Hero starts at distance of 0. * * */ _squares[startingPoint.X, startingPoint.Y].DistanceSteps = 0; while (true) { bool madeProgress = false; /* * * Look at each square on the board. * * */ foreach (Point mainPoint in AllSquares()) { int x = mainPoint.X; int y = mainPoint.Y; /* * * If the square is open, look through valid moves given * the coordinates of that square. * * */ Tile relevantTile = map.GetTile(x, y); if (relevantTile.IsPassable) { int passHere = _squares[x, y].DistanceSteps; foreach (Point movePoint in ValidMoves(x, y)) { int newX = movePoint.X; int newY = movePoint.Y; int newPass = passHere + 1; if (_squares[newX, newY].DistanceSteps > newPass) { _squares[newX, newY].DistanceSteps = newPass; madeProgress = true; } } } } if (!madeProgress) { break; } } HighlightPath(); }
public MetaPlayer(Player player) { Player = player; GoalTileX = -1; GoalTileY = -1; SecondsUntilAngle = 0; SecondsUntilGoal = 0; InRange = false; }
/// <summary> /// Set a player's rotation data (who isn't the bot itself). This is done in a /// thread-safe way. /// </summary> /// <param name="player"></param> /// <param name="angle"></param> /// <param name="direction"></param> public void SetPlayerRotation(Player player, double angle, VTankObject.Direction direction) { player.Angle = angle; player.RotationDirection = direction; }
public ProjectileHitEventArgs(Player victim, int damage, bool killingBlow) { Victim = victim; DamageDealt = damage; KillingBlow = killingBlow; }
public PlayerRespawnEventArgs(Player player) { Player = player; }
/// <summary> /// Creates event arguments about a player. /// </summary> /// <param name="playerID">The player's ID number.</param> public PlayerJoinedEventArgs(Player player) { Player = player; }
/// <summary> /// /// </summary> /// <param name="player"></param> public PlayerInRangeEventArgs(Player player) { Player = player; }
/// <summary> /// /// </summary> /// <param name="player"></param> public PlayerLeftEventArgs(Player player) { Player = player; }
/// <summary> /// Rotate [player] until he is facing [angleInRadians]. /// </summary> /// <param name="player">Player to rotate.</param> /// <param name="angleInRadians">Angle to rotate to. This is not a theta value.</param> public void RotateTo(Player player, double angleInRadians) { MetaPlayer currentPlayer = players[player.ID]; currentPlayer.GoalAngle = (angleInRadians) % (Math.PI * 2.0f); double currentAngle = player.Angle; double distance = 0; VTankObject.Direction result = ShortestDistance(currentAngle, angleInRadians, out distance); if (result == VTankObject.Direction.RIGHT) { player.RotationDirection = VTankObject.Direction.RIGHT; } else { player.RotationDirection = VTankObject.Direction.LEFT; } // Time = distance/velocity double timeInSeconds = Math.Abs( distance / (ANGULAR_VELOCITY * player.SpeedFactor)); currentPlayer.SecondsUntilAngle = timeInSeconds; bot.GameServer.Rotate(currentAngle, player.RotationDirection); }
public override void Dispose() { Victim = null; }
/// <summary> /// Set a player's movement data (who isn't the bot itself). This is done in a /// thread-safe way. /// </summary> /// <param name="player"></param> /// <param name="position"></param> /// <param name="direction"></param> public void SetPlayerMovement(Player player, VTankObject.Point position, VTankObject.Direction direction) { player.SetPosition(position); player.MovementDirection = direction; }
/// <summary> /// /// </summary> /// <param name="playerWhoFired"></param> /// <param name="projectile"></param> public ProjectileFiredEventArgs(Player playerWhoFired, Projectile projectile) { PlayerWhoFired = playerWhoFired; Projectile = projectile; }
/// <summary> /// Calculates how long it will take for the player to reach the target node. /// </summary> /// <param name="player"></param> /// <param name="node"></param> /// <returns></returns> private static double SecondsUntilNextNode(Player player, Node current, Node next) { int halfTile = Tile.TILE_SIZE_IN_PIXELS / 2; int x1 = (current.X * Tile.TILE_SIZE_IN_PIXELS) + halfTile; int x2 = (next.X * Tile.TILE_SIZE_IN_PIXELS) + halfTile; int y1 = (current.Y * Tile.TILE_SIZE_IN_PIXELS) - halfTile; int y2 = (next.Y * Tile.TILE_SIZE_IN_PIXELS) - halfTile; // Find distance to next point. double distance = Math.Sqrt(Math.Pow(y1 - y2, 2) + Math.Pow(x1 - x2, 2)); // T = D / V double seconds = distance / (VELOCITY * player.SpeedFactor); return seconds; }
public static Path FindPath(Map map, Player player, int destinationPixelsX, int destinationPixelsY) { return Path.Optimize( Algorithm.FindPath(map, player, destinationPixelsX, destinationPixelsY)); }
/// <summary> /// Refresh the player list. /// </summary> public void RefreshPlayerList() { Game.Reset(); bool localPlayerFound = false; GameSession.Tank[] tanks = GameServer.GetPlayerList(); for (int i = 0; i < tanks.Length; ++i) { bool isLocalPlayer = false; Player newPlayer = new Player(tanks[i]); if (newPlayer.Name.Equals(localTankName, StringComparison.CurrentCultureIgnoreCase)) { // Found local player. Player = newPlayer; isLocalPlayer = true; localPlayerFound = true; } Game.AddPlayer(newPlayer, isLocalPlayer); } if (!localPlayerFound) { throw new Exception("Fatal error: Local player not found in player list."); } }
/// <summary> /// Check if this player is in range of another player. The range is an /// arbitrary radius around the tank. /// </summary> /// <param name="other">Other player.</param> /// <returns>True if this player is in range of another player.</returns> public bool IsInRangeOf(Player other) { double x1 = Position.x; double x2 = other.Position.x; double y1 = Position.y; double y2 = other.Position.y; distance = Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2)); if (distance > Weapon.Projectile.Range) { return false; } return true; }