예제 #1
0
        private void SetRelationalProperties()
        {
            if (_season != null && Clans?.Count() > 0)
            {
                _groupId = $"{_season.ToShortDateString()};{Clans.OrderBy(c => c.ClanTag).First().ClanTag}";
            }

            if (Clans?.Count() > 0 && _season != null)
            {
                foreach (var clan in Clans)
                {
                    clan.LeagueClanId = $"{_season.ToShortDateString()};{clan.ClanTag}";
                }
            }
        }
예제 #2
0
        //public override bool Equals(object? obj)
        //{
        //    return Equals(obj as ClanWarLeagueGroup);
        //}

        //public bool Equals(ClanWarLeagueGroup? other)
        //{
        //    return other != null &&
        //           Season == other.Season &&
        //           Clans.OrderBy(c => c.Tag).First().Tag == other.Clans.OrderBy(c => c.Tag).First().Tag;
        //}

        public override int GetHashCode()
        {
            return(HashCode.Combine(Clans.OrderBy(c => c.Tag).First().Tag, Season));
        }
예제 #3
0
        public void Initialize()
        {
            Clans = Clans.OrderBy(x => x.ClanTag).ToList();

            WarId = $"{PreparationStartTimeUtc};{Clans[0].ClanTag}";

            //ClanTag1 = Clans.First().ClanTag;

            Flags.WarId = WarId;

            TimeSpan timeSpan = StartTimeUtc - PreparationStartTimeUtc;

            if (timeSpan.TotalHours == 24 ||
                timeSpan.TotalHours == 20 ||
                timeSpan.TotalHours == 16 ||
                timeSpan.TotalHours == 12 ||
                timeSpan.TotalHours == 8 ||
                timeSpan.TotalHours == 6 ||
                timeSpan.TotalHours == 4 ||
                timeSpan.TotalHours == 2 ||
                timeSpan.TotalHours == 1 ||
                timeSpan.TotalMinutes == 30 ||
                timeSpan.TotalMinutes == 15)
            {
                WarType = WarType.Friendly;
            }

            if (WarIsOverOrAllAttacksUsed())
            {
                if (Clans[0].Stars == Clans[1].Stars)
                {
                    if (Clans[0].DestructionPercentage == Clans[1].DestructionPercentage)
                    {
                        Clans[0].Result = Result.Draw;
                        Clans[1].Result = Result.Draw;
                    }
                    else if (Clans[0].DestructionPercentage > Clans[1].DestructionPercentage)
                    {
                        Clans[0].Result = Result.Win;
                        Clans[1].Result = Result.Lose;
                    }
                    else
                    {
                        Clans[0].Result = Result.Lose;
                        Clans[1].Result = Result.Win;
                    }
                }
                else if (Clans[0].Stars > Clans[1].Stars)
                {
                    Clans[0].Result = Result.Win;
                    Clans[1].Result = Result.Lose;
                }
                else
                {
                    Clans[0].Result = Result.Lose;
                    Clans[1].Result = Result.Win;
                }
            }

            foreach (WarClanApiModel clan in Clans)
            {
                foreach (WarVillageApiModel warVillage in clan.Villages.EmptyIfNull())
                {
                    foreach (AttackApiModel attack in warVillage.Attacks.EmptyIfNull())
                    {
                        if (!Attacks.Any(a => a.Order == attack.Order))
                        {
                            Attacks.Add(attack);
                        }
                    }
                }
            }

            Attacks = Attacks.OrderBy(a => a.Order).ToList();

            var attacksByDefenderTag = Attacks.GroupBy(a => a.DefenderTag);

            foreach (var defendingVillage in attacksByDefenderTag)
            {
                defendingVillage.OrderBy(d => d.Order).First().Fresh = true;
            }

            foreach (var attack in Attacks)
            {
                foreach (var clan in Clans)
                {
                    WarVillageApiModel?attacker = clan.Villages.FirstOrDefault(m => m.VillageTag == attack.AttackerTag);

                    if (attacker != null)
                    {
                        attack.AttackerClanTag = clan.ClanTag;
                    }

                    WarVillageApiModel?defender = clan.Villages.FirstOrDefault(m => m.VillageTag == attack.DefenderTag);

                    if (defender != null)
                    {
                        attack.DefenderClanTag = clan.ClanTag;
                    }
                }
            }

            foreach (WarClanApiModel clan in Clans)
            {
                clan.DefenseCount = Attacks.Count(a => a.DefenderClanTag == clan.ClanTag);
            }
        }