private static List <string> GenerateFormationReadout(GameFormation f, List <GameUnit> allUnits, List <GamePlayer> players)
        {
            var readout = new List <string>();

            var player = players.Where(p => p.Id == f.PlayerId.ToString()).FirstOrDefault() ?? new GamePlayer()
            {
                Name = "Unknown Player"
            };

            var playerStrings = new List <string>()
            {
                $"Player {player.Id}",
                player.Team,
                (player.Key <= 0 ? player.Name : $"{player.Name} [{player.Key}]"),
                player.Email,
                string.IsNullOrWhiteSpace(player.Objectives) ? null : $"\"{player.Objectives}\""
            }.Where(s => !string.IsNullOrWhiteSpace(s));

            readout.AddRange(WrapDecorated(string.Join(" -- ", playerStrings), ReadoutWidth, "* ", " *", 5));

            readout.AddRange(WrapDecorated($"Area Screen Rating '{f.GetFormationAreaScreenRating()}'", ReadoutWidth, "* ", " *"));
            readout.AddRange(WrapDecorated($"MaxThrust '{f.MaxThrust}'", ReadoutWidth, "* ", " *"));
            readout.AddRange(WrapDecorated($"Units ({f.Units.Count})", ReadoutWidth, "* ", " *"));
            foreach (var u in f.Units)
            {
                var uR         = allUnits.Where(ur => ur.IdNumeric == u.UnitId).First();
                var unitString = $"- {uR.ToString()} ({uR.Status}) -- Thrust {uR.GetCurrentThrust()}";
                if (uR.GetCurrentThrust() > f.MaxThrust)
                {
                    unitString += $" ({f.MaxThrust}+{u.ExtraThrust})";
                }

                if (u.IsFormationFlag)
                {
                    unitString += $" -- Flagship";
                }

                unitString += $" -- HitChance {f.GetHitChancePercentage(u.UnitId):0.##}%";

                readout.AddRange(WrapDecorated(unitString, ReadoutWidth, "*   ", " *", 5));

                readout.AddRange(PrintReadoutCollection("Fire Allocations", uR.FireAllocation));
            }

            return(readout);
        }
Пример #2
0
        protected override IList <GameEvent> ReceiveWeaponAttackEvent(GameEvent arg)
        {
            var result = new List <GameEvent>();

            var evt = arg as WeaponAttackEvent ??
                      throw ReceiverArgumentMismatch(nameof(arg), arg.GetType(), MethodBase.GetCurrentMethod().Name, typeof(AttackEvent));

            // Unit receives event if:
            // a) WeaponAttack is assigned to this Unit's Formation
            // b) Attack's percentile roll is within this Unit's PercentileRange
            if (evt.TargetingData.Target.FormationId == this.unitFormationInfo.FormationId &&
                this.unitFormationInfo.CoversPercentile(evt.UnitAssignmentPercentile))
            {
                var           target          = evt.TargetingData.Target.UnitActor.unitFormationInfo;
                GameFormation targetFormation = target.GetFormationReference();
                GameUnit      targetUnit      = target.GetUnitReference();

                GameFormation attackerFormation = this.unitFormationInfo.GetFormationReference();
                GameUnit      attackerUnit      = this.unitFormationInfo.GetUnitReference();
                int           firingRange       = evt.TargetingData.FormationRange;

                result.Add(new UnitStatusEvent()
                {
                    Description = $"UnitStatus: [{this.UnitId}]{this.UnitName}",
                    Message     = $"[{targetFormation.FormationId}]{targetFormation.FormationName}:[{targetUnit.IdNumeric}]{targetUnit.Name}"
                                  + $" covers percentile range {this.unitFormationInfo.PercentileLowerBound}-{this.unitFormationInfo.PercentileUpperBound},"
                                  + $" so incoming attack with percentile roll {evt.UnitAssignmentPercentile} targets it.",
                    Exchange = evt.Exchange,
                    Volley   = evt.Volley
                });

                WeaponSystem weapon = evt.AttackData.Weapon;

                // TODO: Add ability to override this from AttackData and/or TargetingData?
                Constants.DamageType effectiveDamageType = weapon.GetDamageType();

                int evasionDRM = -1 * targetFormation.GetOrdersForVolley(evt.Volley).EvasionSuccesses;

                int otherDRM = targetFormation.GetDRMVersusWeaponType(weapon.GetType())
                               + targetUnit.GetDRMVersusWeaponType(weapon.GetType());

                var localScreens = targetUnit.GetLocalScreenRating();
                var areaScreens  = targetFormation.GetFormationAreaScreenRating();

                ScreenRating totalScreenRating = ScreenRating.Combine(localScreens, areaScreens);

                DamageResult weaponAttackResult = this.ResolveWeaponAttack(weapon, firingRange, totalScreenRating, evasionDRM, otherDRM);

                var statusMsg = $"[{attackerUnit.IdNumeric}]{attackerUnit.Name} fires [{weapon.Id}]{weapon.SystemName} at [{targetUnit.IdNumeric}]{targetUnit.Name}"
                                + $"\n\t\t -- Net modifiers: Range {firingRange}"
                                + $", Screen {weapon.FinalizeScreenValue(totalScreenRating)}"
                                + $", Evasion DRM {weapon.FinalizeEvasionDRM(evasionDRM)}"
                                + $", Other DRM {otherDRM}"
                                + $"\n\t\t -- Rolls {weaponAttackResult.RollString()}"
                                + $"\n\t\t -- Deals {weaponAttackResult.ToString()}";

                result.Add(new UnitStatusEvent()
                {
                    Description = $"UnitStatus: [{this.UnitId}]{this.UnitName}",
                    Message     = statusMsg,
                    Exchange    = evt.Exchange,
                    Volley      = evt.Volley
                });
            }

            return(result);
        }