Ejemplo n.º 1
0
        private static List <SquadState> GenerateTempCollection(Unit[] units, IEnumerable <SquadState> current)
        {
            List <SquadState> result = new List <SquadState>(units.Length);

            foreach (Unit unit in units)
            {
                SquadState squadState = null;
                if (current != null)
                {
                    foreach (SquadState existState in current)
                    {
                        if (ReferenceEquals(existState.Unit, unit))
                        {
                            squadState = existState;
                            break;
                        }
                    }
                }

                if (squadState == null)
                {
                    squadState = new SquadState(unit, 0, 0);
                }

                result.Add(squadState);
            }

            return(result);
        }
Ejemplo n.º 2
0
        internal SquadAttack(Battle battle, ICollection <UnitAttackArgs> attacks)
        {
            IDictionary <int, SquadState> losses = new SortedDictionary <int, SquadState>();

            m_unitAttack = new List <UnitAttack>(attacks.Count);
            int attackerId = int.MinValue;

            foreach (UnitAttackArgs arg in attacks)
            {
                Unit attacker;
                Unit target;
                if (arg.AttackerSide == BattleSideType.Player)
                {
                    attacker = arg.AttackerUnit == PlayerUnits.GENERAL ? battle.General : battle.Units[arg.AttackerUnit];
                    target   = arg.TargetUnit == PlayerUnits.GENERAL ? battle.EnemyGeneral : battle.EnemyUnits[arg.TargetUnit];
                }
                else
                {
                    attacker = arg.AttackerUnit == PlayerUnits.GENERAL ? battle.General : battle.EnemyUnits[arg.AttackerUnit];
                    target   = arg.TargetUnit == PlayerUnits.GENERAL ? battle.EnemyGeneral : battle.Units[arg.TargetUnit];
                }

                m_unit = attacker;
                if (attackerId != arg.AttackerUnitId)
                {
                    attackerId = arg.AttackerUnitId;
                    m_count++;
                }

                UnitAttack.Add(new UnitAttack(attacker, arg.AttackerUnitId, target, arg.Damage, arg.UnitHealth));

                SquadState squadState;
                if (!losses.TryGetValue(arg.TargetUnit, out squadState))
                {
                    squadState = new SquadState(target, 0, 0);
                    losses.Add(arg.TargetUnit, squadState);
                }

                if (squadState != null)
                {
                    if (arg.Damage >= arg.UnitHealth)
                    {
                        squadState.Count++;
                    }

                    squadState.Health += Math.Min(arg.Damage, arg.UnitHealth);
                }
            }

            m_totalDamage = new List <SquadState>(losses.Count);
            foreach (KeyValuePair <int, SquadState> pair in losses)
            {
                TotalDamage.Add(pair.Value);
            }
        }