2fc4e3e71f
Core/Misc: 522f537048 followup (https://github.com/TrinityCore/TrinityCore/commit/9a57e95f102a9d35ac8416d02e24c0dddbc755ed) Core/CreatureAI: b6b0353bff followup (https://github.com/TrinityCore/TrinityCore/commit/5d411e0b21b1f1a4653d274d9b1cc7fef17f232b) Core/Spell: move creature focus (https://github.com/TrinityCore/TrinityCore/commit/8c12f36915b2fddd48a5e4c9244c2b0498a64ae9) Core/Unit: 2170541a51 followup (https://github.com/TrinityCore/TrinityCore/commit/2d4549023a6655d19671f7f7e6b4f7c9b71ae632) Core/Misc: cleanup SetInFront uses (https://github.com/TrinityCore/TrinityCore/commit/104e745edfb89f95e34cad7840eae0b6e183bf94) Core/Unit: 229444b74a follow-up (https://github.com/TrinityCore/TrinityCore/commit/6a96addadd5dea633b3066b8d0427302ba514364) Core/Unit: revert 3ea46e57af (https://github.com/TrinityCore/TrinityCore/commit/a46286a803b41b375ed9352858c742626bb85720) Core/Scripts: remove OnDummyEffect hook/sOnDummyEffect ai hook (https://github.com/TrinityCore/TrinityCore/commit/1929ca3aa14f6cd83ea3ac9d7e8c0e2ed0e87a26) Core/Entities: moved PetAura handling to Player where it belongs (https://github.com/TrinityCore/TrinityCore/commit/4f6d38fe9d5c07e6e8eb88e517af71b6cdc4f9f8) Core/Spells: Fixed Chilled to the Bone (https://github.com/TrinityCore/TrinityCore/commit/08635c740a7ee04da9b0cd5045075a9432121b06) Core/Spell: implement pvp trinket immunity against Judgement of Justice (https://github.com/TrinityCore/TrinityCore/commit/05ba662d5daaa3428cc01cdaa3794bf5a073ef17)
82 lines
2.7 KiB
C#
82 lines
2.7 KiB
C#
/*
|
|
* Copyright (C) 2012-2020 CypherCore <http://github.com/CypherCore>
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
using Framework.Constants;
|
|
using Game.Entities;
|
|
using Game.Maps;
|
|
|
|
namespace Game.AI
|
|
{
|
|
public class TotemAI : CreatureAI
|
|
{
|
|
public TotemAI(Creature c) : base(c)
|
|
{
|
|
i_victimGuid = ObjectGuid.Empty;
|
|
}
|
|
|
|
public override void EnterEvadeMode(EvadeReason why)
|
|
{
|
|
me.CombatStop(true);
|
|
}
|
|
|
|
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))
|
|
{
|
|
var u_check = new NearestAttackableUnitInObjectRangeCheck(me, me.GetCharmerOrOwnerOrSelf(), 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.CastSpell(victim, me.ToTotem().GetSpell());
|
|
}
|
|
else
|
|
i_victimGuid.Clear();
|
|
}
|
|
|
|
ObjectGuid i_victimGuid;
|
|
}
|
|
}
|