2 * Copyright (C) 2005-2008 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
23 #include "Database/DBCStores.h"
24 #include "MapManager.h"
25 #include "ObjectAccessor.h"
28 #include "GridNotifiers.h"
29 #include "GridNotifiersImpl.h"
33 TotemAI::Permissible(const Creature
*creature
)
35 if( creature
->isTotem() )
36 return PERMIT_BASE_PROACTIVE
;
38 return PERMIT_BASE_NO
;
41 TotemAI::TotemAI(Creature
&c
) : i_totem(static_cast<Totem
&>(c
)), i_victimGuid(0)
46 TotemAI::MoveInLineOfSight(Unit
*)
50 void TotemAI::EnterEvadeMode()
56 TotemAI::UpdateAI(const uint32
/*diff*/)
58 if (i_totem
.GetTotemType() != TOTEM_ACTIVE
)
61 if (!i_totem
.isAlive() || i_totem
.IsNonMeleeSpellCasted(false))
65 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(i_totem
.GetSpell());
70 SpellRangeEntry
const* srange
= sSpellRangeStore
.LookupEntry(spellInfo
->rangeIndex
);
71 float max_range
= GetSpellMaxRange(srange
);
73 // SPELLMOD_RANGE not applied in this place just because not existence range mods for attacking totems
75 // pointer to appropriate target if found any
76 Unit
* victim
= i_victimGuid
? ObjectAccessor::GetUnit(i_totem
, i_victimGuid
) : NULL
;
78 // Search victim if no, not attackable, or out of range, or friendly (possible in case duel end)
80 !victim
->isTargetableForAttack() || !i_totem
.IsWithinDistInMap(victim
, max_range
) ||
81 i_totem
.IsFriendlyTo(victim
) || !victim
->isVisibleForOrDetect(&i_totem
,false) )
83 CellPair
p(MaNGOS::ComputeCellPair(i_totem
.GetPositionX(),i_totem
.GetPositionY()));
85 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
89 MaNGOS::NearestAttackableUnitInObjectRangeCheck
u_check(&i_totem
, &i_totem
, max_range
);
90 MaNGOS::UnitLastSearcher
<MaNGOS::NearestAttackableUnitInObjectRangeCheck
> checker(victim
, u_check
);
92 TypeContainerVisitor
<MaNGOS::UnitLastSearcher
<MaNGOS::NearestAttackableUnitInObjectRangeCheck
>, GridTypeMapContainer
> grid_object_checker(checker
);
93 TypeContainerVisitor
<MaNGOS::UnitLastSearcher
<MaNGOS::NearestAttackableUnitInObjectRangeCheck
>, WorldTypeMapContainer
> world_object_checker(checker
);
95 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
96 cell_lock
->Visit(cell_lock
, grid_object_checker
, *i_totem
.GetMap());
97 cell_lock
->Visit(cell_lock
, world_object_checker
, *i_totem
.GetMap());
104 i_victimGuid
= victim
->GetGUID();
107 i_totem
.SetInFront(victim
); // client change orientation by self
108 i_totem
.CastSpell(victim
, i_totem
.GetSpell(), false);
115 TotemAI::IsVisible(Unit
*) const
121 TotemAI::AttackStart(Unit
*)