Exemplo n.º 1
0
        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();
                }
            }
        }
Exemplo n.º 2
0
 public void AddGymDetails(GymDetails gymDetails)
 {
     try
     {
         lock (dbLock)
         {
             using (var context = new PogoDBContext())
             {
                 context.GymDetails.Add(gymDetails);
                 context.SaveChanges();
             }
         }
     }
     catch (Exception ex)
     {
         log.Error(ex, "Failed to add gym details to database.");
     }
 }
Exemplo n.º 3
0
        public void UpdateGymDetails(GymDetails gymDetails)
        {
            try
            {
                lock (dbLock)
                {
                    using (var context = new PogoDBContext())
                    {
                        var oldGymDetails = context.GymDetails.FirstOrDefault(g => g.GymID == gymDetails.GymID && g.InstanceName == gymDetails.InstanceName);
                        oldGymDetails.IsInBattle       = gymDetails.IsInBattle;
                        oldGymDetails.Owner            = gymDetails.Owner;
                        oldGymDetails.StrongestPokemon = gymDetails.StrongestPokemon;
                        oldGymDetails.LastUpdate       = gymDetails.LastUpdate;

                        context.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex, "Failed to update gym details in database.");
            }
        }
Exemplo n.º 4
0
 public GymUnderAttackMessage(GymDetails gymDetails, InstanceConfiguration configuration) : base(configuration)
 {
     this.gymDetails = gymDetails;
 }
Exemplo n.º 5
0
 public GymNeutralMessage(GymDetails gymDetails, InstanceConfiguration configuration) : base(configuration)
 {
     this.gymDetails = gymDetails;
 }
Exemplo n.º 6
0
 public GymHasBeenTakenMessage(GymDetails gymDetails, InstanceConfiguration configuration) : base(configuration)
 {
     this.gymDetails = gymDetails;
 }