public bool ReadyForSimulation()
        {
            var ret = AttackHands.Any(p => p.UnitsView.Any(pp => pp.Count > 0)) &&
                      (DefenceHands.Any(p => p.UnitsView.Any(pp => pp.Count > 0)) ||
                       DefenceTurrels.Any(p => p.Count > 0));

            return(ret);
        }
Пример #2
0
        public LogBattle SimBattle()
        {
            var logBattle = new LogBattle();

            AttackHands.ForEach(p => p.ResetArmor());
            DefenceHands.ForEach(p => p.ResetArmor());
            DefenceTurrelsGroups.ForEach(p => p.ResetArmor());
            logBattle.StartWeight         = AttackHands.Sum(p => p.UnitGroups.Sum(pp => pp.TotalWeight));
            logBattle.StartDefendedWeight = DefenceHands.Sum(p => p.UnitGroups.Sum(pp => pp.TotalWeight));
            while (AttackHands.Any(p => p.AnyBattleUnitAlive) &&
                   (DefenceHands.Any(p => p.AnyAlive) || DefenceTurrelsGroups.Any(p => p.IsAnyAlive)))
            {
                // Раунд Атакующего
                var values           = SelectAttackUnits(AttackHands);
                var attackHand       = values.Hand;
                var attackUnitsGroup = values.Group;
                var defenceHand      = DefenceHands.Where(p => p.AnyAlive).OrderBy(p => p.AttackOrder).FirstOrDefault() ??
                                       new Hand {
                    UnitGroups = DefenceTurrelsGroups
                };
                var defenceHandForLog =
                    DefenceHands.Where(p => p.AnyAlive).OrderBy(p => p.AttackOrder).FirstOrDefault()?.UnitGroups;
                defenceHandForLog = defenceHandForLog?.Concat(DefenceTurrelsGroups).ToList() ?? DefenceTurrelsGroups;
                var logRound = ExecuteRoundWithLog(attackUnitsGroup, defenceHand.UnitGroups, true, attackHand.UnitGroups, defenceHandForLog);
                logRound.RoundType = RoundType.AgressorFleet;
                logBattle.Rounds.Add(logRound);

                // Раунд кораблей Обороняющегося
                values           = SelectAttackUnits(DefenceHands);
                attackHand       = values.Hand;
                attackUnitsGroup = values.Group;
                defenceHand      = AttackHands.Where(p => p.AnyAlive).OrderBy(p => p.AttackOrder).FirstOrDefault();
                if (defenceHand?.AnyAlive == true && attackHand?.AnyAlive == true)
                {
                    logRound           = ExecuteRoundWithLog(attackUnitsGroup, defenceHand.UnitGroups, true, attackHand.UnitGroups.Concat(DefenceTurrelsGroups).ToList(), defenceHand.UnitGroups);
                    logRound.RoundType = RoundType.DefenceFleet;
                    logBattle.Rounds.Add(logRound);
                }

                // Раунд пушек Обороняющегося
                values           = SelectAttackUnits(DefenceTurrelsGroups);
                attackHand       = values.Hand;
                attackUnitsGroup = values.Group;
                defenceHand      = AttackHands.Where(p => p.AnyAlive).OrderBy(p => p.AttackOrder).FirstOrDefault();
                if (defenceHand?.AnyAlive == true && attackHand?.AnyAlive == true)
                {
                    var isDefenceTakeDamage = DefenceHands.Any(p => p.AnyAlive);
                    logRound           = ExecuteRoundWithLog(attackUnitsGroup, defenceHand.UnitGroups, isDefenceTakeDamage, attackHand.UnitGroups, defenceHand.UnitGroups);
                    logRound.RoundType = RoundType.DefenceTurrels;
                    logBattle.Rounds.Add(logRound);
                }
            }
            logBattle.EndWeight         = AttackHands.Sum(p => p.UnitGroups.Sum(pp => pp.TotalWeight));
            logBattle.EndDefendedWeight = DefenceHands.Sum(p => p.UnitGroups.Sum(pp => pp.TotalWeight));
            return(logBattle);
        }