Пример #1
0
        public CombatWeapon GetWeapon(CombatUnit target)
        {
            CombatWeapon picked                = null;
            float        damage                = 0;
            float        singleAttackDamage    = 0;
            int          framesUntilNextAttack = 0;

            foreach (CombatWeapon weapon in Weapons)
            {
                if (target.IsAir && !weapon.AttacksAir && !target.IsGround)
                {
                    continue;
                }
                if (target.IsGround && !weapon.AttacksGround && !target.IsAir)
                {
                    continue;
                }

                int   newSingleAttackDamage    = weapon.GetDamage(target);
                int   newFramesUntilNextAttack = weapon.GetFramesUntilNextAttack();
                float newDamage = newSingleAttackDamage * weapon.Attacks / newFramesUntilNextAttack;

                if (newDamage < damage)
                {
                    continue;
                }

                picked                = weapon;
                damage                = newDamage;
                singleAttackDamage    = newSingleAttackDamage;
                framesUntilNextAttack = newFramesUntilNextAttack;
            }
            return(picked);
        }
Пример #2
0
        public void Attack(SimulationState state, CombatWeapon weapon, CombatUnit target, bool isSecondaryAttack, float partDamage)
        {
            float singleAttackDamage    = weapon.GetDamage(target) * partDamage;
            int   framesUntilNextAttack = weapon.GetFramesUntilNextAttack();

            target.DealDamage(state, singleAttackDamage, false);

            if (!isSecondaryAttack)
            {
                FramesUntilNextAttack = framesUntilNextAttack;
            }
            PreviousAttackTarget = target;

            if (weapon.Attacks > 1)
            {
                if (isSecondaryAttack)
                {
                    AdditionalAttacksRemaining--;
                }
                else
                {
                    AdditionalAttacksRemaining = weapon.Attacks - 1;
                }
                SecondaryAttackFrame  = state.SimulationFrame + weapon.FramesUntilSecondaryAttack;
                SecondaryAttackWeapon = weapon;
            }
        }
Пример #3
0
        public int GetDamage(CombatUnit target)
        {
            int result = Damage;

            if (BonusDamage > 0 && target.Attributes.Contains(BonusDamageAttribute))
            {
                result += BonusDamage;
            }
            return(result);
        }
Пример #4
0
 public void Clear(List <CombatUnit> units)
 {
     for (int i = units.Count - 1; i >= 0; i--)
     {
         CombatUnit unit = units[i];
         if (unit.Health <= 0)
         {
             units[i] = units[units.Count - 1];
             units.RemoveAt(units.Count - 1);
         }
     }
 }
Пример #5
0
        private void StepUnit(CombatUnit unit)
        {
            if (unit.Energy < unit.EnergyMax && unit.EnergyMax > 0)
            {
                unit.Energy = System.Math.Min(unit.Energy + 0.03516f, unit.EnergyMax);
            }

            if (unit.FramesUntilNextAttack > 0)
            {
                unit.FramesUntilNextAttack--;
            }
            if (unit.SecondaryAttackFrame == SimulationFrame && unit.AdditionalAttacksRemaining > 0)
            {
                unit.PerformAdditionalAttack(this);
            }

            Action action = unit.GetAction(this);

            if (!(action is Attack))
            {
                unit.AdditionalAttacksRemaining = 0;
            }
            action.Perform(this, unit);

            foreach (Buff buff in unit.Buffs)
            {
                buff.OnFrame(this, unit);
            }

            bool buffRemoved = false;

            for (int i = unit.Buffs.Count - 1; i >= 0; i--)
            {
                Buff buff = unit.Buffs[i];
                if (buff.ExpireFrame > SimulationFrame)
                {
                    continue;
                }
                buffRemoved = true;
                unit.Buffs.RemoveAt(i);
                if (buff is DamageProcessor)
                {
                    unit.DamageProcessors.Remove((DamageProcessor)buff);
                }
            }
            if (buffRemoved)
            {
                unit.RecalculateBuffs();
            }
        }
Пример #6
0
 public void AddUnit(CombatUnit unit)
 {
     if (unit.Owner == 1)
     {
         Player1Units.Add(unit);
     }
     else if (unit.Owner == 2)
     {
         Player2Units.Add(unit);
     }
     else if (Bot.Debug)
     {
         throw new System.ArgumentException("Can't add unit. Owner " + unit.Owner + "unknown.");
     }
 }
Пример #7
0
        public static CombatUnit FromUnit(Unit unit, List <CombatMicro.CombatMicro> combatMicro, HashSet <uint> upgrades)
        {
            CombatUnit result = new CombatUnit();

            UnitTypeData unitType = UnitTypes.LookUp[unit.UnitType];

            result.Health            = unit.Health;
            result.HealthMax         = (int)unit.HealthMax;
            result.Shield            = unit.Shield;
            result.ShieldMax         = (int)unit.ShieldMax;
            result.Energy            = unit.Energy;
            result.EnergyMax         = (int)unit.EnergyMax;
            result.BaseMovementSpeed = unitType.MovementSpeed;
            result.MovementSpeed     = unitType.MovementSpeed;
            result.IsAir             = unit.IsFlying || unit.UnitType == UnitTypes.COLOSUS;
            result.IsGround          = !unit.IsFlying || unit.UnitType == UnitTypes.COLOSUS;
            result.Armor             = (int)unitType.Armor;
            result.Owner             = unit.Owner == Bot.Main.PlayerId ? 1 : 2;
            result.Pos      = new Point(unit.Pos.X, unit.Pos.Y);
            result.Tag      = (long)unit.Tag;
            result.UnitType = unit.UnitType;
            foreach (Weapon weapon in unitType.Weapons)
            {
                result.Weapons.Add(FromWeapon(weapon));
            }
            foreach (SC2APIProtocol.Attribute attribute in unitType.Attributes)
            {
                result.Attributes.Add(FromAttribute(attribute));
            }
            result.CombatMicros = combatMicro;

            if (unit.UnitType == UnitTypes.ZEALOT && upgrades.Contains(UpgradeType.Charge))
            {
                result.ActionProcessors.Add(new ZealotChargeProcessor());
                result.BaseMovementSpeed = 2.95f;
                result.MovementSpeed     = 2.95f;
            }
            else if (unit.UnitType == UnitTypes.MARAUDER && upgrades.Contains(UpgradeType.ConcussiveShells))
            {
                result.ActionProcessors.Add(new ConcussiveShellsProcessor());
            }
            else if (unit.UnitType == UnitTypes.IMMORTAL)
            {
                result.DamageProcessors.Add(new BarrierDamageProcessor());
            }

            return(result);
        }
Пример #8
0
 private static void DebugUnit(CombatUnit unit)
 {
     FileUtil.Debug("{");
     FileUtil.Debug("  Tag = " + unit.Tag);
     FileUtil.Debug("  Pos = " + unit.Pos);
     FileUtil.Debug("  Health = " + unit.Health);
     if (unit.ShieldMax > 0)
     {
         FileUtil.Debug("  Shield = " + unit.Shield);
     }
     if (unit.EnergyMax > 0)
     {
         FileUtil.Debug("  Energy = " + unit.Energy);
     }
     FileUtil.Debug("  MovementSpeed = " + unit.MovementSpeed);
     FileUtil.Debug("  Buffs = {");
     foreach (Buff buff in unit.Buffs)
     {
         FileUtil.Debug("    " + buff.GetType().Name);
     }
     FileUtil.Debug("  }");
     FileUtil.Debug("}");
 }
Пример #9
0
        private static CombatUnit CreateUnit(uint unitType, bool player1Owned, float x, int health, int shield, int energy, int energyMax, bool isFlying, HashSet <uint> upgrades)
        {
            Tag++;
            Unit unit = new Unit();

            unit.Owner = player1Owned ? (int)Bot.Main.PlayerId : (3 - (int)Bot.Main.PlayerId);
            unit.Pos   = new SC2APIProtocol.Point()
            {
                X = x
            };
            unit.Health    = health;
            unit.HealthMax = health;
            unit.Shield    = shield;
            unit.ShieldMax = shield;
            unit.Energy    = energy;
            unit.EnergyMax = energyMax;
            unit.UnitType  = unitType;
            unit.Tag       = Tag;
            unit.IsFlying  = isFlying;
            CombatMicro.CombatMicro micro;
            if (unit.UnitType == UnitTypes.MEDIVAC)
            {
                micro = new MedivacHealClosest();
            }
            else if (unit.UnitType == UnitTypes.SIEGE_TANK_SIEGED)
            {
                micro = new AttackClosestSiegeTank();
            }
            else
            {
                micro = new AttackClosest();
            }
            CombatUnit result = SimulationUtil.FromUnit(unit, micro, upgrades);

            return(result);
        }
Пример #10
0
 public float DistSq(CombatUnit enemy)
 {
     return((enemy.Pos.X - Pos.X) * (enemy.Pos.X - Pos.X) + (enemy.Pos.Y - Pos.Y) * (enemy.Pos.Y - Pos.Y));
 }
Пример #11
0
 public void Attack(SimulationState state, CombatWeapon weapon, CombatUnit target, bool isSecondaryAttack)
 {
     Attack(state, weapon, target, isSecondaryAttack, 1);
 }