public static void Execute() { if (!GlobalVars.Gyms.Farm) { Logger.Debug("Farm gyms is not enabled."); return; } //narrow map data to gyms within walking distance var gyms = GetNearbyGyms(); Logger.Debug("gyms: " + gyms.Count()); var gymsWithinRangeStanding = gyms.Where(i => LocationUtils.CalculateDistanceInMeters(Logic.objClient.CurrentLatitude, Logic.objClient.CurrentLongitude, i.Latitude, i.Longitude) <= 40); var inRange = gymsWithinRangeStanding.Count(); Logger.Debug("gymsWithinRangeStanding: " + inRange); if (gymsWithinRangeStanding.Any()) { Logger.ColoredConsoleWrite(ConsoleColor.DarkGray, $"(Gym) - {inRange} gyms are within range of the user"); foreach (var element in gymsWithinRangeStanding) { var gym = element; if (gymsVisited.Contains(gym.Id)) { Logger.ColoredConsoleWrite(ConsoleColor.DarkGray, "(Gym) - This gym was already visited."); continue; } var attackCount = 1; while (attackCount <= GlobalVars.Gyms.MaxAttacks && !gymsVisited.Contains(gym.Id)) { Logger.Debug("(Gym) - Attack number " + attackCount); CheckAndPutInNearbyGym(gym, Logic.objClient); attackCount++; if (attackCount <= GlobalVars.Gyms.MaxAttacks && !gymsVisited.Contains(gym.Id)) { RandomHelper.RandomSleep(900); gym = GetNearbyGyms().FirstOrDefault(x => x.Id == gym.Id); } if (attackCount > GlobalVars.Gyms.MaxAttacks) { Logger.Warning("(Gym) - Maximum number of attacks reached. Will be checked after of one minute."); AddVisited(gym.Id, 60000); } } Setout.SetCheckTimeToRun(); RandomHelper.RandomSleep(300); } GlobalVars.PauseTheWalking &= !restoreWalkingAfterLogic; } }
public static void Execute() { if (!GlobalVars.Gyms.Farm) { Logger.Debug("Farm gyms is not enabled."); return; } //narrow map data to gyms within walking distance var gyms = GetNearbyGyms(); var gymsWithinRangeStanding = gyms.Where(i => LocationUtils.CalculateDistanceInMeters(Logic.objClient.CurrentLatitude, Logic.objClient.CurrentLongitude, i.Latitude, i.Longitude) <= 40); Logger.Debug("gymsWithinRangeStanding: " + gymsWithinRangeStanding.Count() + " (of " + gyms.Count() + ")"); if (gymsWithinRangeStanding.Any()) { Logger.Debug("(Gym) Reviving pokemons."); ReviveAndCurePokemons(Logic.objClient); Logger.ColoredConsoleWrite(ConsoleColor.DarkGray, $"(Gym) {gymsWithinRangeStanding.Count()} gyms are within your range."); foreach (FortData gym in gymsWithinRangeStanding) { if (gymsVisited.Contains(gym.Id)) { Logger.ColoredConsoleWrite(ConsoleColor.DarkGray, $"(Gym) This gym was already visited."); continue; } if (gym.RaidInfo != null && !gym.RaidInfo.IsRaidHidden) { Logger.ColoredConsoleWrite(ConsoleColor.DarkGray, $"(Gym) This gym is in Raid mode (still not supported), skipping."); AddVisited(gym.Id); continue; } if (GlobalVars.Gyms.Farm && (gym.OwnedByTeam == TeamColor.Neutral || gym.OwnedByTeam == Logic.objClient.Player.PlayerResponse.PlayerData.Team)) { CheckAndPutInNearbyGym(gym, Logic.objClient); // We can add training later } if (GlobalVars.Gyms.Attack && (gym.OwnedByTeam != TeamColor.Neutral && gym.OwnedByTeam != Logic.objClient.Player.PlayerResponse.PlayerData.Team)) { var gymDetails = Logic.objClient.Fort.GymGetInfo(gym.Id, gym.Latitude, gym.Longitude); if (gymDetails.GymStatusAndDefenders.GymDefender.Count >= 1 && gymDetails.GymStatusAndDefenders.GymDefender.Count <= GlobalVars.Gyms.NumDefenders) { restoreWalkingAfterLogic = !GlobalVars.PauseTheWalking; GlobalVars.PauseTheWalking = true; Logger.Debug("(Gym) Stop walking."); var attackCount = 1; while (attackCount <= GlobalVars.Gyms.MaxAttacks) { Logger.Debug($"(Gym: {gymDetails.Name}) We can attack this {gym.OwnedByTeam} gym. Attack number: " + attackCount); BattleState isVictory = GymsLogicAttack.AttackGym(gym, Logic.objClient); switch (isVictory) { case BattleState.StateUnset: Logger.ColoredConsoleWrite(gymColorLog, $"(Gym: {gymDetails.Name}) NULL detected, something failed."); attackCount = GlobalVars.Gyms.MaxAttacks; break; case BattleState.Defeated: Logger.ColoredConsoleWrite(gymColorLog, $"(Gym: {gymDetails.Name}) Battle Lost."); attackCount = GlobalVars.Gyms.MaxAttacks; break; default: Logger.ColoredConsoleWrite(gymColorLog, $"(Gym: {gymDetails.Name}) We have won the attack."); RandomHelper.RandomSleep(2000); gyms = GetNearbyGyms(); // Add: refresh only this gym CheckAndPutInNearbyGym(gym, Logic.objClient); break; } attackCount++; Logger.Debug("(Gym) Reviving pokemons."); ReviveAndCurePokemons(Logic.objClient); } Logger.Warning($"(Gym) Maximum number of {GlobalVars.Gyms.MaxAttacks} attacks reached."); } else { Logger.ColoredConsoleWrite(gymColorLog, $"(Gym) This gym has more than {GlobalVars.Gyms.NumDefenders} defenders, skipping."); continue; } } AddVisited(gym.Id); Setout.SetCheckTimeToRun(); } GlobalVars.PauseTheWalking &= !restoreWalkingAfterLogic; } }