c5cccdec10
Port From (https://github.com/TrinityCore/TrinityCore/commit/261eb201bf107cef441d9b075e8f23bf0edfbaf0) Port From (https://github.com/TrinityCore/TrinityCore/commit/526b16fea41fb69a302fdebe8a727e175949f04b) Port From (https://github.com/TrinityCore/TrinityCore/commit/8b7dce6521323e788ebf28297ec941a6f9bf876f) Port From (https://github.com/TrinityCore/TrinityCore/commit/5334467f493eb16141f4ad0bce956bc3e19244a0) Port From (https://github.com/TrinityCore/TrinityCore/commit/1e7725c15b149baaf96731231239769e482ec2ed) Port From (https://github.com/TrinityCore/TrinityCore/commit/21712f475383f6f3fae107706f5de5195f75b760)
71 lines
2.9 KiB
C#
71 lines
2.9 KiB
C#
// Copyright (c) CypherCore <http://github.com/CypherCore> All rights reserved.
|
|
// Licensed under the GNU GENERAL PUBLIC LICENSE. See LICENSE file in the project root for full license information.
|
|
|
|
using Framework.Constants;
|
|
using Game.Entities;
|
|
using Game.Maps;
|
|
|
|
namespace Game.AI
|
|
{
|
|
public class TotemAI : NullCreatureAI
|
|
{
|
|
ObjectGuid _victimGuid;
|
|
|
|
public TotemAI(Creature creature) : base(creature)
|
|
{
|
|
Cypher.Assert(creature.IsTotem(), $"TotemAI: AI assigned to a no-totem creature ({creature.GetGUID()})!");
|
|
_victimGuid = ObjectGuid.Empty;
|
|
}
|
|
|
|
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(), me.GetMap().GetDifficultyID());
|
|
if (spellInfo == null)
|
|
return;
|
|
|
|
// Get spell range
|
|
float max_range = spellInfo.GetMaxRange(false);
|
|
|
|
// SpellModOp.Range not applied in this place just because not existence range mods for attacking totems
|
|
|
|
Unit victim = !_victimGuid.IsEmpty() ? Global.ObjAccessor.GetUnit(me, _victimGuid) : null;
|
|
|
|
// Search victim if no, not attackable, or out of range, or friendly (possible in case duel end)
|
|
CanSeeOrDetectExtraArgs canSeeOrDetectExtraArgs = new CanSeeOrDetectExtraArgs() {
|
|
IgnorePhaseShift = spellInfo.HasAttribute(SpellAttr6.IgnorePhaseShift),
|
|
IncludeHiddenBySpawnTracking = spellInfo.HasAttribute(SpellAttr8.AllowTargetsHiddenBySpawnTracking),
|
|
IncludeAnyPrivateObject = spellInfo.HasAttribute(SpellCustomAttributes.CanTargetAnyPrivateObject)
|
|
};
|
|
if (victim == null || !victim.IsTargetableForAttack() || !me.IsWithinDistInMap(victim, max_range) || me.IsFriendlyTo(victim) || !me.CanSeeOrDetect(victim, canSeeOrDetectExtraArgs))
|
|
{
|
|
float extraSearchRadius = max_range > 0.0f ? SharedConst.ExtraCellSearchRadius : 0.0f;
|
|
var u_check = new NearestAttackableUnitInObjectRangeCheck(me, me.GetCharmerOrOwnerOrSelf(), max_range);
|
|
var checker = new UnitLastSearcher(me, u_check);
|
|
Cell.VisitAllObjects(me, checker, max_range + extraSearchRadius);
|
|
victim = checker.GetResult();
|
|
}
|
|
|
|
// If have target
|
|
if (victim != null)
|
|
{
|
|
// remember
|
|
_victimGuid = victim.GetGUID();
|
|
|
|
// attack
|
|
me.CastSpell(victim, me.ToTotem().GetSpell());
|
|
}
|
|
else
|
|
_victimGuid.Clear();
|
|
}
|
|
|
|
public override void AttackStart(Unit victim) { }
|
|
}
|
|
}
|