2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "DBCStores.h"
23 #include "ObjectAccessor.h"
26 #include "GridNotifiers.h"
27 #include "GridNotifiersImpl.h"
31 TotemAI::Permissible(const Creature
*creature
)
33 if( creature
->isTotem() )
34 return PERMIT_BASE_PROACTIVE
;
36 return PERMIT_BASE_NO
;
39 TotemAI::TotemAI(Creature
*c
) : CreatureAI(c
), i_victimGuid(0)
44 TotemAI::MoveInLineOfSight(Unit
*)
48 void TotemAI::EnterEvadeMode()
50 m_creature
->CombatStop(true);
54 TotemAI::UpdateAI(const uint32
/*diff*/)
56 if (getTotem().GetTotemType() != TOTEM_ACTIVE
)
59 if (!m_creature
->isAlive() || m_creature
->IsNonMeleeSpellCasted(false))
63 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(getTotem().GetSpell());
68 SpellRangeEntry
const* srange
= sSpellRangeStore
.LookupEntry(spellInfo
->rangeIndex
);
69 float max_range
= GetSpellMaxRange(srange
);
71 // SPELLMOD_RANGE not applied in this place just because not existence range mods for attacking totems
73 // pointer to appropriate target if found any
74 Unit
* victim
= i_victimGuid
? ObjectAccessor::GetUnit(*m_creature
, i_victimGuid
) : NULL
;
76 // Search victim if no, not attackable, or out of range, or friendly (possible in case duel end)
78 !victim
->isTargetableForAttack() || !m_creature
->IsWithinDistInMap(victim
, max_range
) ||
79 m_creature
->IsFriendlyTo(victim
) || !victim
->isVisibleForOrDetect(m_creature
,false) )
81 CellPair
p(MaNGOS::ComputeCellPair(m_creature
->GetPositionX(),m_creature
->GetPositionY()));
83 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
87 MaNGOS::NearestAttackableUnitInObjectRangeCheck
u_check(m_creature
, m_creature
, max_range
);
88 MaNGOS::UnitLastSearcher
<MaNGOS::NearestAttackableUnitInObjectRangeCheck
> checker(m_creature
,victim
, u_check
);
90 TypeContainerVisitor
<MaNGOS::UnitLastSearcher
<MaNGOS::NearestAttackableUnitInObjectRangeCheck
>, GridTypeMapContainer
> grid_object_checker(checker
);
91 TypeContainerVisitor
<MaNGOS::UnitLastSearcher
<MaNGOS::NearestAttackableUnitInObjectRangeCheck
>, WorldTypeMapContainer
> world_object_checker(checker
);
93 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
94 cell_lock
->Visit(cell_lock
, grid_object_checker
, *m_creature
->GetMap());
95 cell_lock
->Visit(cell_lock
, world_object_checker
, *m_creature
->GetMap());
102 i_victimGuid
= victim
->GetGUID();
105 m_creature
->SetInFront(victim
); // client change orientation by self
106 m_creature
->CastSpell(victim
, getTotem().GetSpell(), false);
113 TotemAI::IsVisible(Unit
*) const
119 TotemAI::AttackStart(Unit
*)
123 Totem
& TotemAI::getTotem()
125 return static_cast<Totem
&>(*m_creature
);