/// <summary> /// See if the Attacker is next to the Defender by the distance of Range /// /// If either the X or Y distance is less than or equal the range, then they can hit /// </summary> /// <param name="Attacker"></param> /// <param name="Defender"></param> /// <returns></returns> public bool IsTargetInRange(EntityInfoModel Attacker, EntityInfoModel Defender) { var locationAttacker = GetLocationForPlayer(Attacker); var locationDefender = GetLocationForPlayer(Defender); if (locationAttacker == null) { return(false); } if (locationDefender == null) { return(false); } // Get X distance in absolute value var distance = Math.Abs(CalculateDistance(locationAttacker, locationDefender)); var AttackerRange = Attacker.GetRange(); // Can Reach on X? if (distance <= AttackerRange) { return(true); } return(false); }
/// <summary> /// Find the Player on the map /// Return their information /// /// If they don't exist, return null /// </summary> /// <param name="data"></param> /// <returns></returns> public MapModelLocation GetLocationForPlayer(EntityInfoModel player) { if (player == null) { return(null); } foreach (var data in MapGridLocation) { if (data.Player.Guid.Equals(player.Guid)) { return(data); } } return(null); }
/// <summary> /// Remove the Player from the Map /// Replaces with Empty Square /// </summary> /// <param name="data"></param> /// <returns></returns> public bool RemovePlayerFromMap(EntityInfoModel data) { if (data == null) { return(false); } for (var x = 0; x < MapXAxiesCount; x++) { for (var y = 0; y < MapYAxiesCount; y++) { if (MapGridLocation[x, y].Player.Guid.Equals(data.Guid)) { MapGridLocation[x, y] = new MapModelLocation { Column = x, Row = y, Player = EmptySquare }; return(true); } } } // Not found return(false); }