internal void Update(CocApi cocApi, ClanApiModel downloadedClan) { lock (_updateLock) { Logger ??= cocApi.Logger; if (ReferenceEquals(this, downloadedClan)) { return; } Swallow(() => UpdateClan(cocApi, downloadedClan), nameof(UpdateClan)); Swallow(() => UpdateLabels(cocApi, downloadedClan), nameof(UpdateLabels)); Swallow(() => UpdateBadge(cocApi, downloadedClan), nameof(UpdateBadge)); Swallow(() => UpdateLocation(cocApi, downloadedClan), nameof(UpdateLocation)); Swallow(() => AnnounceDonations(cocApi, downloadedClan), nameof(AnnounceDonations)); Swallow(() => AnnounceVillageChanges(cocApi, downloadedClan), nameof(AnnounceVillageChanges)); //Swallow(() => UpdateVillages(downloadedClan), nameof(UpdateVillages)); Swallow(() => VillagesLeft(cocApi, downloadedClan), nameof(VillagesLeft)); Swallow(() => VillagesJoined(cocApi, downloadedClan), nameof(VillagesJoined)); UpdateAtUtc = downloadedClan.UpdateAtUtc; Expires = downloadedClan.Expires; } }
private void VillagesJoined(CocApi cocApi, ClanApiModel downloadedClan) { List <ClanVillageApiModel> newVillages = new List <ClanVillageApiModel>(); if (downloadedClan.Villages == null) { return; } //if (Villages == null) //{ // Villages = new List<ClanVillageApiModel>(); //} foreach (ClanVillageApiModel clanVillage in downloadedClan.Villages) { if (!Villages?.Any(m => m.VillageTag == clanVillage.VillageTag) == true) { newVillages.Add(clanVillage); //Villages.Add(clanVillage); } } cocApi.VillagesJoinedEvent(this, newVillages); }
private void UpdateVillage(CocApi cocApi, VillageApiModel downloadedVillage) { if (downloadedVillage.AttackWins != AttackWins || downloadedVillage.BestTrophies != BestTrophies || downloadedVillage.BestVersusTrophies != BestVersusTrophies || downloadedVillage.BuilderHallLevel != BuilderHallLevel || //downloadedVillage.DefenseWins != DefenseWins || //downloadedVillage.Donations != Donations || //downloadedVillage.DonationsReceived != DonationsReceived || //downloadedVillage.ExpLevel != ExpLevel || //downloadedVillage.Name != Name || //downloadedVillage.Role != Role || downloadedVillage.TownHallLevel != TownHallLevel || downloadedVillage.TownHallWeaponLevel != TownHallWeaponLevel || //downloadedVillage.Trophies != Trophies || //downloadedVillage.VersusBattleWinCount != VersusBattleWinCount || //downloadedVillage.VersusBattleWins != VersusBattleWins || //downloadedVillage.VersusTrophies != VersusTrophies || downloadedVillage.WarStars != WarStars ) { cocApi.VillageChangedEvent(this, downloadedVillage); //AttackWins = downloadedVillage.AttackWins; //BestTrophies = downloadedVillage.BestTrophies; //BestVersusTrophies = downloadedVillage.BestVersusTrophies; //BuilderHallLevel = downloadedVillage.BuilderHallLevel; ////Name = downloadedVillage.Name; ////Role = downloadedVillage.Role; //TownHallLevel = downloadedVillage.TownHallLevel; //TownHallWeaponLevel = downloadedVillage.TownHallWeaponLevel; //WarStars = downloadedVillage.WarStars; } }
private void UpdateWar(CocApi cocApi, IWar?downloadedWar) { ICurrentWarApiModel?currentWar = downloadedWar as ICurrentWarApiModel; if (currentWar == null || currentWar.WarId != WarId) { return; } //foreach(var clan in Clans) //{ // clan.BadgeUrls = downloadedWar.Clans.First(c => c.ClanTag == clan.ClanTag).BadgeUrls; // clan.ClanLevel = downloadedWar.Clans.First(c => c.ClanTag == clan.ClanTag).ClanLevel; // clan.Name = downloadedWar.Clans.First(c => c.ClanTag == clan.ClanTag).Name; //} if (EndTimeUtc != currentWar.EndTimeUtc || StartTimeUtc != currentWar.StartTimeUtc || State != currentWar.State ) { cocApi.WarChangedEvent(this, currentWar); //EndTimeUtc = downloadedWar.EndTimeUtc; //StartTimeUtc = downloadedWar.StartTimeUtc; //State = downloadedWar.State; } }
//internal void AnnounceNewWar(CocApi cocApi) //{ // lock (NewWarLock) // { // if (Flags.WarAnnounced) return; // foreach(var clan in Clans) // { // if (cocApi.AllClans.TryGetValue(clan.ClanTag, out ClanApiModel storedClan)) // { // //we only announce wars if this flag is false to avoid spamming new war events when the program starts. // if (storedClan.AnnounceWars) // { // cocApi.NewWarEvent(this); // break; // } // } // } // Flags.WarAnnounced = true; // } //} private void SendWarNotifications(CocApi cocApi, IWar?downloadedWar) { ICurrentWarApiModel?currentWar = downloadedWar as ICurrentWarApiModel; if (Flags.WarIsAccessible && (currentWar == null || currentWar.WarId != WarId)) { Flags.WarIsAccessible = false; cocApi.WarIsAccessibleChangedEvent(this); } else if (!Flags.WarIsAccessible && (currentWar?.WarId == WarId)) { Flags.WarIsAccessible = true; cocApi.WarIsAccessibleChangedEvent(this); } if (!Flags.WarStartingSoon && State == WarState.Preparation && DateTime.UtcNow > WarStartingSoonUtc) { cocApi.WarStartingSoonEvent(this); Flags.WarEndingSoon = true; } if (!Flags.WarEndingSoon && State == WarState.InWar && DateTime.UtcNow > WarEndingSoonUtc) { cocApi.WarEndingSoonEvent(this); Flags.WarEndingSoon = true; } if (!Flags.WarEndNotSeen && (currentWar == null || WarId != currentWar.WarId) && EndTimeUtc < DateTime.UtcNow) { Flags.WarEndNotSeen = true; cocApi.WarEndNotSeenEvent(this); } if (!Flags.WarStarted && StartTimeUtc < DateTime.UtcNow) { Flags.WarStarted = true; cocApi.WarStartedEvent(this); } if (!Flags.WarEnded && EndTimeUtc < DateTime.UtcNow) { Flags.WarEnded = true; cocApi.WarEndedEvent(this); } if (!Flags.WarEndSeen && State == WarState.InWar && currentWar?.State == WarState.WarEnded) { Flags.WarEndSeen = true; cocApi.WarEndSeenEvent(this); } }
private void UpdateVillageVersusBattleWinCount(CocApi cocApi, VillageApiModel downloadedVillage) { if (downloadedVillage.VersusBattleWinCount != VersusBattleWinCount) { cocApi.VillageVersusBattleWinCountChangedEvent(this, downloadedVillage.VersusBattleWinCount); //VersusBattleWinCount = downloadedVillage.VersusBattleWinCount; } }
private void UpdateVillageVersusTrophies(CocApi cocApi, VillageApiModel downloadedVillage) { if (downloadedVillage.VersusTrophies != VersusTrophies) { cocApi.VillageVersusTrophiesChangedEvent(this, downloadedVillage.VersusTrophies); //VersusTrophies = downloadedVillage.VersusTrophies; } }
private void UpdateVillageVersusBattleWins(CocApi cocApi, VillageApiModel downloadedVillage) { if (downloadedVillage.VersusBattleWins != VersusBattleWins) { cocApi.VillageVersusBattleWinsChangedEvent(this, downloadedVillage.VersusBattleWins); //VersusBattleWins = downloadedVillage.VersusBattleWins; } }
private void UpdateVillageExpLevel(CocApi cocApi, VillageApiModel downloadedVillage) { if (downloadedVillage.ExpLevel != ExpLevel) { cocApi.VillageExpLevelChangedEvent(this, downloadedVillage.ExpLevel); //ExpLevel = downloadedVillage.ExpLevel; } }
private void UpdateVillageDefenseWins(CocApi cocApi, VillageApiModel downloadedVillage) { if (downloadedVillage.DefenseWins != DefenseWins) { cocApi.VillageDefenseWinsChangedEvent(this, downloadedVillage.DefenseWins); //DefenseWins = downloadedVillage.DefenseWins; } }
public TokenObject(CocApi cocApi, string token, TimeSpan tokenTimeOut) { _cocApi = cocApi; Token = token; _tokenTimeOut = tokenTimeOut; _clearRateLimitTimer.AutoReset = false; _clearRateLimitTimer.Interval = 5000; _clearRateLimitTimer.Elapsed += ClearRateLimit; }
private void UpdateAttacks(CocApi cocApi, IWar?downloadedWar) { ICurrentWarApiModel?currentWar = downloadedWar as ICurrentWarApiModel; if (currentWar == null || currentWar.WarId != WarId) { return; } List <AttackApiModel> newAttacks = currentWar.Attacks.Where(a => a.Order > Attacks.Count()).ToList(); //foreach (AttackApiModel attack in downloadedWar.Attacks) //{ // if (!Attacks.Any(a => a.Order == attack.Order)) // { // Attacks.Add(attack); // } //} //foreach (WarClanApiModel clan in Clans) //{ // foreach (WarVillageApiModel warVillage in clan.Villages.EmptyIfNull()) // { // foreach (AttackApiModel downloadedAttack in downloadedWar.Attacks.Where(a => a.AttackerTag == warVillage.VillageTag)) // { // if (!warVillage.Attacks.Any(a => a.Order == downloadedAttack.Order)) // { // if (warVillage.Attacks == null) // { // warVillage.Attacks = new List<AttackApiModel>(); // } // warVillage.Attacks.Add(downloadedAttack); // } // } // } //} //foreach (var clan in Clans) //{ // clan.AttackCount = downloadedWar.Clans.First(c => c.ClanTag == clan.ClanTag).AttackCount; // clan.DefenseCount = downloadedWar.Clans.First(c => c.ClanTag == clan.ClanTag).DefenseCount; // clan.DestructionPercentage = downloadedWar.Clans.First(c => c.ClanTag == clan.ClanTag).DestructionPercentage; // clan.Stars = downloadedWar.Clans.First(c => c.ClanTag == clan.ClanTag).Stars; //} cocApi.NewAttacksEvent(currentWar, newAttacks); }
private void UpdateLegendLeagueStatistics(CocApi cocApi, VillageApiModel downloadedVillage) { if (LegendStatistics == null && downloadedVillage.LegendStatistics == null) { return; } if (LegendStatistics == null && downloadedVillage.LegendStatistics != null) { cocApi.VillageReachedLegendsLeagueEvent(downloadedVillage); } //LegendStatistics = downloadedVillage.LegendStatistics; }
internal void Update(CocApi cocApi, VillageApiModel downloadedVillage) { lock (_updateLock) { Logger ??= cocApi.Logger; if (ReferenceEquals(this, downloadedVillage)) { return; } Swallow(() => UpdateVillage(cocApi, downloadedVillage), nameof(UpdateVillage)); Swallow(() => UpdateLabels(cocApi, downloadedVillage), nameof(UpdateLabels)); Swallow(() => UpdateVillageDefenseWins(cocApi, downloadedVillage), nameof(UpdateVillageDefenseWins)); //UpdateVillageDonations(cocApi, downloadedVillage); //UpdateVillageDonationsReceived(cocApi, downloadedVillage); Swallow(() => UpdateVillageExpLevel(cocApi, downloadedVillage), nameof(UpdateVillageExpLevel)); Swallow(() => UpdateVillageTrophies(cocApi, downloadedVillage), nameof(UpdateVillageTrophies)); Swallow(() => UpdateVillageVersusBattleWinCount(cocApi, downloadedVillage), nameof(UpdateVillageVersusBattleWinCount)); Swallow(() => UpdateVillageVersusBattleWins(cocApi, downloadedVillage), nameof(UpdateVillageVersusBattleWins)); Swallow(() => UpdateVillageVersusTrophies(cocApi, downloadedVillage), nameof(UpdateVillageVersusTrophies)); //UpdateVillageLeague(cocApi, downloadedVillage); Swallow(() => UpdateVillageAchievements(cocApi, downloadedVillage), nameof(UpdateVillageAchievements)); Swallow(() => UpdateVillageTroops(cocApi, downloadedVillage), nameof(UpdateVillageTroops)); Swallow(() => UpdateVillageHeroes(cocApi, downloadedVillage), nameof(UpdateVillageHeroes)); Swallow(() => UpdateVillageSpells(cocApi, downloadedVillage), nameof(UpdateVillageSpells)); Swallow(() => UpdateLegendLeagueStatistics(cocApi, downloadedVillage), nameof(UpdateLegendLeagueStatistics)); //UpdateAtUtc = downloadedVillage.UpdateAtUtc; //Expires = downloadedVillage.Expires; } }
private void UpdateLabels(CocApi cocApi, ClanApiModel downloadedClan) { if (Labels == null && downloadedClan.Labels == null) { return; } if (Labels != null && Labels.Count() > 0 && (downloadedClan.Labels == null || downloadedClan.Labels.Count() == 0)) { cocApi.ClanLabelsRemovedEvent(downloadedClan, Labels); //Labels = downloadedClan.Labels; } else if ((Labels == null || Labels.Count() == 0) && downloadedClan.Labels != null && downloadedClan.Labels.Count() > 0) { cocApi.ClanLabelsAddedEvent(downloadedClan, downloadedClan.Labels); //Labels = downloadedClan.Labels; } else { List <ClanLabelApiModel> added = new List <ClanLabelApiModel>(); List <ClanLabelApiModel> removed = new List <ClanLabelApiModel>(); foreach (ClanLabelApiModel labelApiModel in Labels.EmptyIfNull()) { if (!downloadedClan.Labels.Any(l => l.Id == labelApiModel.Id)) { removed.Add(labelApiModel); } } foreach (ClanLabelApiModel labelApiModel in downloadedClan.Labels.EmptyIfNull()) { if (!Labels.Any(l => l.Id == labelApiModel.Id)) { added.Add(labelApiModel); } } cocApi.ClanLabelsRemovedEvent(downloadedClan, removed); cocApi.ClanLabelsAddedEvent(downloadedClan, added); //Labels = downloadedClan.Labels; } }
private void UpdateLeagueTeamSize(CocApi cocApi, ILeagueGroup?leagueGroup) { if (leagueGroup is LeagueGroupApiModel leagueGroupApiModel) { if (leagueGroupApiModel.TeamSize > 15) { return; } if (Clans.Any(c => c.AttackCount > 15)) { leagueGroupApiModel.TeamSize = 30; cocApi.LeagueGroupTeamSizeChangeDetectedEvent(leagueGroupApiModel); } } }
private void UpdateClan(CocApi cocApi, ClanApiModel downloadedClan) { if (ClanPoints != downloadedClan.ClanPoints) { cocApi.ClanPointsChangedEvent(this, downloadedClan.ClanPoints); //ClanPoints = downloadedClan.ClanPoints; } if (ClanVersusPoints != downloadedClan.ClanVersusPoints) { cocApi.ClanVersusPointsChangedEvent(this, downloadedClan.ClanVersusPoints); //ClanVersusPoints = downloadedClan.ClanVersusPoints; } if (ClanLevel != downloadedClan.ClanLevel || Description != downloadedClan.Description || IsWarLogPublic != downloadedClan.IsWarLogPublic || VillageCount != downloadedClan.VillageCount || Name != downloadedClan.Name || RequiredTrophies != downloadedClan.RequiredTrophies || Recruitment != downloadedClan.Recruitment || WarFrequency != downloadedClan.WarFrequency || WarLosses != downloadedClan.WarLosses || WarTies != downloadedClan.WarTies || WarWins != downloadedClan.WarWins || WarWinStreak != downloadedClan.WarWinStreak ) { cocApi.ClanChangedEvent(this, downloadedClan); //ClanLevel = downloadedClan.ClanLevel; //Description = downloadedClan.Description; //IsWarLogPublic = downloadedClan.IsWarLogPublic; //VillageCount = downloadedClan.VillageCount; //Name = downloadedClan.Name; //RequiredTrophies = downloadedClan.RequiredTrophies; //Recruitment = downloadedClan.Recruitment; //WarFrequency = downloadedClan.WarFrequency; //WarLosses = downloadedClan.WarLosses; //WarTies = downloadedClan.WarWins; //WarWinStreak = downloadedClan.WarWinStreak; } }
private void UpdateBadge(CocApi cocApi, ClanApiModel downloadedClan) { if (BadgeUrls == null && downloadedClan.BadgeUrls != null) { cocApi.ClanBadgeUrlChangedEvent(this, downloadedClan); return; } if (BadgeUrls == null && downloadedClan.BadgeUrls != null | BadgeUrls?.Large != downloadedClan.BadgeUrls?.Large || BadgeUrls?.Medium != downloadedClan.BadgeUrls?.Medium || BadgeUrls?.Small != downloadedClan.BadgeUrls?.Small) { cocApi.ClanBadgeUrlChangedEvent(this, downloadedClan); //BadgeUrls = downloadedClan.BadgeUrls; } }
public EventHandlerService(LogService logService, CocApi cocApi) { _logService = logService; _cocApi = cocApi; _cocApi.ClanChanged += CocApi_ClanChanged; _cocApi.IsAvailableChanged += CocApi_IsAvailableChanged; _cocApi.VillagesJoined += CocApi_MembersJoined; _cocApi.ClanBadgeUrlChanged += CocApi_ClanBadgeUrlChanged; _cocApi.ClanLocationChanged += CocApi_ClanLocationChanged; _cocApi.NewAttacks += CocApi_NewAttacks; _cocApi.ClanPointsChanged += CocApi_ClanPointsChanged; _cocApi.ClanVersusPointsChanged += CocApi_ClanVersusPointsChanged; _cocApi.NewWar += CocApi_NewWar; _cocApi.WarIsAccessibleChanged += CocApi_WarIsAccessibleChanged; _cocApi.LeagueGroupTeamSizeChangeDetected += CocApi_LeagueSizeChangeDetected; _cocApi.VillageReachedLegendsLeague += CocApi_VillageReachedLegendsLeague; _cocApi.ClanVillageNameChanged += CocApi_ClanVillageNameChanged; _cocApi.ClanVillagesLeagueChanged += CocApi_ClanVillagesLeagueChanged;; _cocApi.ClanVillagesRoleChanged += CocApi_ClanVillagesRoleChanged; _cocApi.VillageLabelsAdded += CocApi_VillageLabelsAdded; _cocApi.VillageLabelsRemoved += CocApi_VillageLabelsRemoved; _cocApi.WarStarted += CocApi_WarStarted; _cocApi.WarStartingSoon += CocApi_WarStartingSoon; }
public static void Initialize(CocApi cocApi, CocApiConfiguration cfg, IEnumerable <string> tokens) { _cocApi = cocApi; _cfg = cfg; ApiClient.DefaultRequestHeaders.Accept.Clear(); ApiClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); foreach (string token in tokens) { TokenObject tokenObject = new TokenObject(cocApi, token, _cfg.TokenTimeOut); _tokenObjects.Add(tokenObject); } _jsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); }
private void UpdateLocation(CocApi cocApi, ClanApiModel downloadedClan) { if (Location == null && downloadedClan.Location != null) { cocApi.ClanLocationChangedEvent(this, downloadedClan); return; } if (Location == null && downloadedClan.Location != null || Location?.CountryCode != downloadedClan.Location?.CountryCode || Location?.Id != downloadedClan.Location?.Id || Location?.IsCountry != downloadedClan.Location?.IsCountry || Location?.Name != downloadedClan.Location?.Name) { cocApi.ClanLocationChangedEvent(this, downloadedClan); //Location = downloadedClan.Location; } }
internal void Update(CocApi cocApi, IWar?downloadedWar, ILeagueGroup?leagueGroupApiModel) { lock (_updateLock) { if (ReferenceEquals(this, downloadedWar)) { return; } SendWarNotifications(cocApi, downloadedWar); UpdateWar(cocApi, downloadedWar); UpdateAttacks(cocApi, downloadedWar); UpdateLeagueTeamSize(cocApi, leagueGroupApiModel); //if (downloadedWar?.WarId == WarId) //{ // Expires = downloadedWar.Expires; // UpdateAtUtc = downloadedWar.UpdateAtUtc; // CacheExpiresAtUtc = downloadedWar.CacheExpiresAtUtc; // foreach (var clan in Clans) // { // cocApi.AllWarsByClanTag.TryGetValue(clan.ClanTag, out IWar storedWar); // cocApi.AllWars[clan.ClanTag] as ICurrentWarApiModel; // if (storedWar == null || storedWar.UpdateAtUtc < UpdateAtUtc) // { // cocApi.AllWarsByClanTag[clan.ClanTag] = this; // if (leagueGroupApiModel != null) // { // cocApi.AllLeagueGroups[clan.ClanTag] = leagueGroupApiModel; // } // } // } //} } }
private void UpdateVillageSpells(CocApi cocApi, VillageApiModel downloadedVillage) { List <VillageSpellApiModel> newSpells = new List <VillageSpellApiModel>(); foreach (VillageSpellApiModel spell in downloadedVillage.Spells.EmptyIfNull()) { VillageSpellApiModel?oldSpell = Spells.FirstOrDefault(s => s.Name == spell.Name); if (oldSpell == null || oldSpell.Level < spell.Level) { newSpells.Add(spell); } } if (newSpells.Count() > 0) { cocApi.VillageSpellsChangedEvent(this, newSpells); //Spells = downloadedVillage.Spells; } }
private void UpdateVillageTroops(CocApi cocApi, VillageApiModel downloadedVillage) { List <TroopApiModel> newTroops = new List <TroopApiModel>(); foreach (TroopApiModel troop in downloadedVillage.Troops.EmptyIfNull()) { TroopApiModel?oldTroop = Troops.FirstOrDefault(t => t.Name == troop.Name); if (oldTroop == null || oldTroop.Level < troop.Level) { newTroops.Add(troop); } } if (newTroops.Count() > 0) { cocApi.VillageTroopsChangedEvent(this, newTroops); //Troops = downloadedVillage.Troops; } }
//private void UpdateVillages(ClanApiModel downloadedClan) //{ // foreach (ClanVillageApiModel oldClanVillage in Villages.EmptyIfNull()) // { // ClanVillageApiModel newClanVillage = downloadedClan.Villages.FirstOrDefault(m => m.VillageTag == oldClanVillage.VillageTag); // if (newClanVillage == null) { continue; } // oldClanVillage.League = newClanVillage.League; // oldClanVillage.Name = newClanVillage.Name; // oldClanVillage.Role = newClanVillage.Role; // oldClanVillage.ExpLevel = newClanVillage.ExpLevel; // oldClanVillage.ClanRank = newClanVillage.ClanRank; // oldClanVillage.PreviousClanRank = newClanVillage.PreviousClanRank; // oldClanVillage.Donations = newClanVillage.Donations; // oldClanVillage.DonationsReceived = newClanVillage.DonationsReceived; // oldClanVillage.Trophies = newClanVillage.Trophies; // oldClanVillage.VersusTrophies = newClanVillage.VersusTrophies; // } //} private void AnnounceDonations(CocApi cocApi, ClanApiModel downloadedClan) { Dictionary <string, Tuple <ClanVillageApiModel, int> > receiving = new Dictionary <string, Tuple <ClanVillageApiModel, int> >(); Dictionary <string, Tuple <ClanVillageApiModel, int> > donating = new Dictionary <string, Tuple <ClanVillageApiModel, int> >(); foreach (ClanVillageApiModel oldClanVillage in Villages.EmptyIfNull()) { ClanVillageApiModel?newClanVillage = downloadedClan.Villages.FirstOrDefault(m => m.VillageTag == oldClanVillage.VillageTag); if (newClanVillage == null) { continue; } if (oldClanVillage.DonationsReceived < newClanVillage.DonationsReceived) { receiving.Add(oldClanVillage.VillageTag, Tuple.Create(oldClanVillage, newClanVillage.DonationsReceived)); } if (oldClanVillage.Donations < newClanVillage.Donations) { donating.Add(oldClanVillage.VillageTag, Tuple.Create(oldClanVillage, newClanVillage.Donations)); } bool resetSent = false; if (!resetSent && oldClanVillage.DonationsReceived > newClanVillage.DonationsReceived || oldClanVillage.Donations > newClanVillage.Donations) { cocApi.ClanDonationsResetEvent(this, downloadedClan); resetSent = true; } } cocApi.ClanDonationsEvent(receiving, donating); }
private void VillagesLeft(CocApi cocApi, ClanApiModel downloadedClan) { List <ClanVillageApiModel> leftVillages = new List <ClanVillageApiModel>(); //if (Villages == null) //{ // return; //} foreach (ClanVillageApiModel clanVillage in Villages.EmptyIfNull()) { if (!downloadedClan.Villages.Any(m => m.VillageTag == clanVillage.VillageTag)) { leftVillages.Add(clanVillage); } } foreach (ClanVillageApiModel clanVillage in leftVillages) { //Villages.Remove(clanVillage); } cocApi.VillagesLeftEvent(this, leftVillages); }
private void UpdateVillageAchievements(CocApi cocApi, VillageApiModel downloadedVillage) { List <AchievementApiModel> newAchievements = new List <AchievementApiModel>(); foreach (AchievementApiModel achievement in downloadedVillage.Achievements.EmptyIfNull()) { if (achievement.Value > achievement.Target) { AchievementApiModel oldAchievement = Achievements.FirstOrDefault(a => a.Name == achievement.Name); if (oldAchievement == null || oldAchievement.Value < oldAchievement.Target) { newAchievements.Add(achievement); } } } if (newAchievements.Count() > 0) { cocApi.VillageAchievementsChangedEvent(this, newAchievements); //Achievements = downloadedVillage.Achievements; } }
private void AnnounceVillageChanges(CocApi cocApi, ClanApiModel downloadedClan) { Dictionary <string, Tuple <ClanVillageApiModel, VillageLeagueApiModel> > leagueChanges = new Dictionary <string, Tuple <ClanVillageApiModel, VillageLeagueApiModel> >(); Dictionary <string, Tuple <ClanVillageApiModel, Role> > roleChanges = new Dictionary <string, Tuple <ClanVillageApiModel, Role> >(); foreach (ClanVillageApiModel oldClanVillage in Villages.EmptyIfNull()) { ClanVillageApiModel newClanVillage = downloadedClan.Villages.FirstOrDefault(m => m.VillageTag == oldClanVillage.VillageTag); if (newClanVillage == null) { continue; } if ((oldClanVillage.League == null && newClanVillage.League != null) || (oldClanVillage.League != null && newClanVillage.League != null && oldClanVillage.League.Id != newClanVillage.League.Id)) { leagueChanges.Add(oldClanVillage.VillageTag, Tuple.Create(oldClanVillage, newClanVillage.League)); } if (oldClanVillage.Name != newClanVillage.Name) { cocApi.ClanVillageNameChangedEvent(oldClanVillage, newClanVillage.Name); } if (oldClanVillage.Role != newClanVillage.Role) { roleChanges.Add(oldClanVillage.VillageTag, Tuple.Create(oldClanVillage, newClanVillage.Role)); } } cocApi.ClanVillagesLeagueChangedEvent(leagueChanges); cocApi.ClanVillagesRoleChangedEvent(roleChanges); }
/// <summary> /// This is an internal CocApiLibrary class that you do not need to instantiate. /// </summary> /// <param name="cocApi"></param> public UpdateService(CocApi cocApi) { _cocApi = cocApi; }