//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 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); }