public async Task Handle(FortData gym) { if (!gymStatus.ContainsKey(gym.Id)) { var gymDetailsResponse = await GetGymDetails(gym); if (gymDetailsResponse != null) { var gymDetails = new GymDetails(gym, gymDetailsResponse.Name, gymDetailsResponse.ImageUrls.FirstOrDefault(), pogoInstance.Configuration.Name); pogoInstance.Database.AddGymDetails(gymDetails); gymStatus.Add(gym.Id, gymDetails); } } else { var gymDetails = gymStatus[gym.Id]; bool isInBattle = gym.IsInBattle && !gymDetails.IsInBattle; bool isNowNeutral = gym.OwnedByTeam == TeamColor.Neutral && gymDetails.Owner != TeamColor.Neutral; bool hasChangedOwner = gym.OwnedByTeam != gymDetails.Owner; gymDetails.Update(gym); pogoInstance.Database.UpdateGymDetails(gymDetails); Messages.IMessage message = null; if (isInBattle) { if (!pogoInstance.Configuration.IgnoreGymUnderAttack) { log.Info($"Gym, {gymDetails.Name}, is under attack"); message = new GymUnderAttackMessage(gymDetails, pogoInstance.Configuration); } } else if (isNowNeutral) { log.Info($"Gym, {gymDetails.Name}, is now neutral"); message = new GymNeutralMessage(gymDetails, pogoInstance.Configuration); } else if (hasChangedOwner) { log.Info($"Gym, {gymDetails.Name}, has been taken by {gymDetails.Owner.ToTeamName()}"); message = new GymHasBeenTakenMessage(gymDetails, pogoInstance.Configuration); } if (message != null) { message.Send(); } } }
public void Handle(FortData gym) { if (!cachedGyms.ContainsKey(gym.Id)) { cachedGyms.Add(gym.Id, new CachedGymData { GymData = gym }); } else { var cachedData = cachedGyms[gym.Id]; if (cachedData.GymDetails == null) { cachedData.GymDetails = GetGymDetails(gym); if (cachedData.GymDetails == null) { return; } } Messages.IMessage message = null; if (gym.IsInBattle && !cachedData.GymData.IsInBattle) { message = new GymUnderAttackMessage(gym, cachedData.GymDetails, pogoInstance.Configuration); } else if (gym.OwnedByTeam == TeamColor.Neutral && cachedData.GymData.OwnedByTeam != TeamColor.Neutral) { message = new GymNeutralMessage(gym, cachedData.GymDetails, pogoInstance.Configuration); } else if (gym.OwnedByTeam != cachedData.GymData.OwnedByTeam) { message = new GymHasBeenTakenMessage(gym, cachedData.GymDetails, pogoInstance.Configuration); } if (message != null) { message.Send(); } cachedData.GymData = gym; } }