コード例 #1
0
        public CombatReportView(CombatReport cr)
        {
            InitializeComponent();
            this.DataContext = cr;



            FullUnitView attackingUnitView = new FullUnitView(cr.AttackingUnit);
            FullUnitView defensingUnitView = new FullUnitView(cr.DefensingUnit);

            attackingUnitView.VerticalAlignment   = System.Windows.VerticalAlignment.Top;
            attackingUnitView.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            defensingUnitView.VerticalAlignment   = System.Windows.VerticalAlignment.Bottom;
            defensingUnitView.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            attackingUnitView.Margin = new Thickness(0, 50, 0, 0);
            defensingUnitView.Margin = new Thickness(0, 0, 0, 0);

            grid.Children.Add(attackingUnitView);
            grid.Children.Add(defensingUnitView);

            /*
             * this.lblAttackingUnitDead.Visibility = cr.AttackingUnitDead ? Visibility.Visible : System.Windows.Visibility.Collapsed;
             * this.lblDefensingUnitDead.Visibility = cr.DefensingUnitDead ? Visibility.Visible : System.Windows.Visibility.Collapsed;
             *
             * this.lblAttackingUnitLostHealth.Content = "-" + cr.AttackingUnitLostHealth;
             * this.lblDefensingUnitLostHealth.Content = "-" + cr.Def;
             * */
        }
コード例 #2
0
        private void RemoveReportIfBothDeleted(CombatReport report)
        {
            if (!(report.IsDeletedByAttacker && report.IsDeletedByDefender))
            {
                return;
            }

            _context.Divisions.RemoveRange(report.Attackers);
            _context.Divisions.RemoveRange(report.Defenders);
            _context.Divisions.RemoveRange(report.Losses);
            _context.Reports.Remove(report);
        }
コード例 #3
0
 public void AddCombatReport(CombatReport _combatReport)
 {
     combatReports.Add(_combatReport); // add a combat report to the list
 }
コード例 #4
0
        /// <summary>
        /// Handles combat calculations for all incoming attacks of a country. The order of the attacks is randomized.
        /// </summary>
        /// <param name="context">The <see cref="UnderSeaDatabaseContext"/> that is used to access the database.</param>
        /// <param name="country">The country to handle. The commands, incoming attacks, the attack's divisions, parent country,
        /// parent country builidings, researches, events, and effects must be loaded.</param>
        /// <param name="globals">The <see cref="GlobalValue"/>s to use.</param>
        /// <exception cref="ArgumentNullException">Thrown if an argument was null.</exception>
        public void HandleCombat(UnderSeaDatabaseContext context, Model.Entities.Country country, GlobalValue globals)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (country == null)
            {
                throw new ArgumentNullException(nameof(country));
            }

            if (globals == null)
            {
                throw new ArgumentNullException(nameof(globals));
            }

            // Randomize the incoming attacks, excluding the defending forces
            var incomingAttacks = country.IncomingAttacks
                                  .Where(c => !c.ParentCountry.Equals(country))
                                  .Select(c => new { Order = rng.Next(), Command = c })
                                  .OrderBy(x => x.Order)
                                  .Select(x => x.Command)
                                  .ToList();

            var defenders = country.GetAllDefending();
            var builder   = country.ParseAllEffectForCountry(context, globals, Parsers, false);

            foreach (var attack in incomingAttacks)
            {
                (double attackPower, double attackMods, double attackBase) = GetCurrentUnitPower(attack, globals, true,
                                                                                                 attack.ParentCountry.ParseAllEffectForCountry(context, globals, Parsers, false));
                (double defensePower, double defenseMods, double defenseBase) = GetCurrentUnitPower(defenders, globals,
                                                                                                    false, builder);

                var losses = attackPower > defensePower
                    ? CullUnits(defenders, globals.UnitLossOnLostBatle)
                    : CullUnits(attack, globals.UnitLossOnLostBatle);

                var report = new CombatReport
                {
                    Attacker  = attack.ParentCountry,
                    Defender  = country,
                    Attackers = attack.Divisions.Select(d => new Division
                    {
                        Count = d.Count, Unit = d.Unit
                    }).ToList(),
                    Defenders = defenders.Divisions.Select(d => new Division
                    {
                        Count = d.Count, Unit = d.Unit
                    }).ToList(),
                    TotalAttackPower  = attackPower,
                    TotalDefensePower = defensePower,
                    AttackModifier    = attackMods,
                    DefenseModifier   = defenseMods,
                    BaseAttackPower   = attackBase,
                    BaseDefensePower  = defenseBase,
                    Round             = globals.Round,
                    PearlLoot         = 0,
                    CoralLoot         = 0,
                    Losses            = losses
                };

                if (attackPower > defensePower)
                {
                    var pearlLoot = (long)Math.Round(country.Pearls * globals.LootPercentage);
                    var coralLoot = (long)Math.Round(country.Corals * globals.LootPercentage);
                    country.Pearls  -= pearlLoot;
                    country.Corals  -= coralLoot;
                    report.CoralLoot = coralLoot;
                    report.PearlLoot = pearlLoot;
                }

                context.Reports.Add(report);
            }
        }