当前位置: 首页>>代码示例>>C#>>正文


C# Unit.GetAttackRange方法代码示例

本文整理汇总了C#中Unit.GetAttackRange方法的典型用法代码示例。如果您正苦于以下问题:C# Unit.GetAttackRange方法的具体用法?C# Unit.GetAttackRange怎么用?C# Unit.GetAttackRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Unit的用法示例。


在下文中一共展示了Unit.GetAttackRange方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BestAutoAttackTarget

        /// <summary>
        ///     Find enemy hero that takes least hits to kill
        /// </summary>
        /// <param name="source">
        ///     Source hero
        /// </param>
        /// <param name="bonusRange">
        ///     The bonus Range.
        /// </param>
        /// <returns>
        ///     The <see cref="Hero" />.
        /// </returns>
        public static Hero BestAutoAttackTarget(Unit source, float bonusRange = 0)
        {
            var attackRange = source.GetAttackRange();
            var aaDmg = source.MinimumDamage + source.BonusDamage;
            Hero bestTarget = null;
            var lastHitsToKill = 0f;
            foreach (var enemyHero in Heroes.All)
            {
                if (
                    !(enemyHero.IsValid && enemyHero.Team != source.Team && enemyHero.IsAlive && enemyHero.IsVisible
                      && enemyHero.Distance2D(source)
                      <= attackRange + enemyHero.HullRadius + bonusRange + source.HullRadius + 50
                      && !enemyHero.IsInvul()
                      && !enemyHero.HasModifier("modifier_skeleton_king_reincarnation_scepter_active")))
                {
                    continue;
                }

                var takenDmg = enemyHero.DamageTaken(aaDmg, DamageType.Physical, source, false);
                var hitsToKill = enemyHero.Health / takenDmg;
                if (bestTarget != null && !(lastHitsToKill > hitsToKill))
                {
                    continue;
                }

                bestTarget = enemyHero;
                lastHitsToKill = hitsToKill;
            }

            return bestTarget;
        }
开发者ID:EnsageSharp,项目名称:Ensage.Common,代码行数:43,代码来源:TargetSelector.cs

示例2: Cast

 public static bool Cast(
     Ability ability,
     Unit target,
     Unit buffTarget,
     string name,
     List<Modifier> modifiers,
     bool togglearmlet = false)
 {
     if (name == "item_armlet")
     {
         if (buffTarget.Modifiers.Any(x => x.Name == "modifier_ice_blast"))
         {
             return false;
         }
         if (!togglearmlet && buffTarget.Distance2D(target) > Math.Max(target.GetAttackRange(), 500))
         {
             return false;
         }
         var armlettoggled = modifiers.Any(x => x.Name == "modifier_item_armlet_unholy_strength")
                             && ability.IsToggled;
         Game.ExecuteCommand("dota_player_units_auto_attack_after_spell 0");
         ManageAutoAttack.AutoAttackDisabled = true;
         if (armlettoggled)
         {
             ability.ToggleAbility();
             ability.ToggleAbility();
             return true;
         }
         ability.ToggleAbility();
         return true;
     }
     if (!(buffTarget.Distance2D(target) < MyHeroInfo.AttackRange() + 150))
     {
         return false;
     }
     SoulRing.Cast(ability);
     if (ability.Name == "templar_assassin_refraction")
     {
         var meld = AbilityMain.Me.Spellbook.Spell2;
         if (meld != null && meld.CanBeCasted())
         {
             if (
                 !(target.Distance2D(MyHeroInfo.Position)
                   < (AbilityMain.Me.GetAttackRange() + 50 + target.HullRadius + AbilityMain.Me.HullRadius))
                 || Orbwalking.AttackOnCooldown(target) || AbilityMain.Me.IsAttacking()
                 || (target.Predict(Game.Ping).Distance2D(MyHeroInfo.Position)
                     > (AbilityMain.Me.GetAttackRange() + 50 + target.HullRadius + AbilityMain.Me.HullRadius))
                 || !Utils.SleepCheck("GlobalCasting"))
             {
                 return false;
             }
             Game.ExecuteCommand("dota_player_units_auto_attack_after_spell 0");
             ManageAutoAttack.AutoAttackDisabled = true;
             ability.UseAbility();
             if (Nuke.Cast(meld, target, NameManager.Name(meld)))
             {
                 DelayAction.Add(
                     new DelayActionItem(
                         (int)meld.GetCastDelay(AbilityMain.Me, target) * 1000 + 100,
                         () =>
                             {
                                 AbilityMain.Me.Attack(target);
                             },
                         CancellationToken.None));
             }
             Utils.Sleep(meld.GetCastDelay(AbilityMain.Me,target)*1000, "GlobalCasting");
             Utils.Sleep(meld.GetHitDelay(target, name) * 1000 + 200, "casting");
             Utils.Sleep(meld.GetHitDelay(target, name) * 1000 + 200, ability.Handle.ToString());
             return true;
         }
     }
     if (ability.IsAbilityBehavior(AbilityBehavior.NoTarget, name))
     {
         Game.ExecuteCommand("dota_player_units_auto_attack_after_spell 0");
         ManageAutoAttack.AutoAttackDisabled = true;
         ability.UseAbility();
         return true;
     }
     Game.ExecuteCommand("dota_player_units_auto_attack_after_spell 0");
     ManageAutoAttack.AutoAttackDisabled = true;
     ability.UseAbility(buffTarget);
     return true;
 }
开发者ID:dendimonster,项目名称:EnsageSharp,代码行数:83,代码来源:Buff.cs

示例3: GetLowestHPCreep

        /// <summary>
        ///     Checks for lowest health creep in attack range
        /// </summary>
        /// <param name="source">
        ///     The source.
        /// </param>
        /// <param name="bonusRange">
        ///     The bonus Range.
        /// </param>
        /// <returns>
        ///     The <see cref="Unit" />.
        /// </returns>
        public static Unit GetLowestHPCreep(Unit source, float bonusRange = 0)
        {
            try
            {
                var attackRange = source.GetAttackRange() + bonusRange;
                var lowestHp =
                    Creeps.All.Where(
                        x =>
                        x.IsValid && x.IsSpawned
                        && (x.ClassID == ClassID.CDOTA_BaseNPC_Tower || x.ClassID == ClassID.CDOTA_BaseNPC_Creep_Lane
                            || x.ClassID == ClassID.CDOTA_BaseNPC_Creep
                            || x.ClassID == ClassID.CDOTA_BaseNPC_Creep_Neutral
                            || x.ClassID == ClassID.CDOTA_BaseNPC_Creep_Siege
                            || x.ClassID == ClassID.CDOTA_BaseNPC_Additive
                            || x.ClassID == ClassID.CDOTA_BaseNPC_Barracks
                            || x.ClassID == ClassID.CDOTA_BaseNPC_Building
                            || x.ClassID == ClassID.CDOTA_BaseNPC_Creature) && x.IsAlive && x.IsVisible
                        && x.Team != source.Team && x.Distance2D(source) < attackRange + 100)
                        .MinOrDefault(creep => creep.Health);
                return lowestHp;
            }
            catch (Exception)
            {
                // no   
            }

            return null;
        }
开发者ID:EnsageSharp,项目名称:Ensage.Common,代码行数:40,代码来源:TargetSelector.cs


注:本文中的Unit.GetAttackRange方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。