コード例 #1
0
ファイル: ScriptedAI.cs プロジェクト: spadd/CypherCore
        //Returns friendly unit with the most amount of hp missing from max hp
        public Unit DoSelectLowestHpFriendly(float range, uint minHPDiff = 1)
        {
            var u_check  = new MostHPMissingInRange <Unit>(me, range, minHPDiff);
            var searcher = new UnitLastSearcher(me, u_check);

            Cell.VisitAllObjects(me, searcher, range);

            return(searcher.GetTarget());
        }
コード例 #2
0
        public override void UpdateAI(uint diff)
        {
            if (me.ToTotem().GetTotemType() != TotemType.Active)
            {
                return;
            }

            if (!me.IsAlive() || me.IsNonMeleeSpellCast(false))
            {
                return;
            }

            // Search spell
            var spellInfo = Global.SpellMgr.GetSpellInfo(me.ToTotem().GetSpell());

            if (spellInfo == null)
            {
                return;
            }

            // Get spell range
            float max_range = spellInfo.GetMaxRange(false);

            // SPELLMOD_RANGE not applied in this place just because not existence range mods for attacking totems

            Unit victim = !i_victimGuid.IsEmpty() ? Global.ObjAccessor.GetUnit(me, i_victimGuid) : null;

            // Search victim if no, not attackable, or out of range, or friendly (possible in case duel end)
            if (victim == null || !victim.isTargetableForAttack() || !me.IsWithinDistInMap(victim, max_range) ||
                me.IsFriendlyTo(victim) || !me.CanSeeOrDetect(victim))
            {
                victim = null;
                var u_check = new NearestAttackableUnitInObjectRangeCheck(me, me, max_range);
                var checker = new UnitLastSearcher(me, u_check);
                Cell.VisitAllObjects(me, checker, max_range);
                victim = checker.GetTarget();
            }

            // If have target
            if (victim != null)
            {
                // remember
                i_victimGuid = victim.GetGUID();

                // attack
                me.SetInFront(victim);                         // client change orientation by self
                me.CastSpell(victim, me.ToTotem().GetSpell(), false);
            }
            else
            {
                i_victimGuid.Clear();
            }
        }