[8449] Deprecate healing/damage item mods and merge internal data in to spell power.
[getmangos.git] / src / game / TotemAI.cpp
blobb826bef03f0b48a6e10587301ca003acea6204da
1 /*
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
19 #include "TotemAI.h"
20 #include "Totem.h"
21 #include "Creature.h"
22 #include "DBCStores.h"
23 #include "ObjectAccessor.h"
24 #include "SpellMgr.h"
26 #include "GridNotifiers.h"
27 #include "GridNotifiersImpl.h"
28 #include "CellImpl.h"
30 int
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)
43 void
44 TotemAI::MoveInLineOfSight(Unit *)
48 void TotemAI::EnterEvadeMode()
50 m_creature->CombatStop(true);
53 void
54 TotemAI::UpdateAI(const uint32 /*diff*/)
56 if (getTotem().GetTotemType() != TOTEM_ACTIVE)
57 return;
59 if (!m_creature->isAlive() || m_creature->IsNonMeleeSpellCasted(false))
60 return;
62 // Search spell
63 SpellEntry const *spellInfo = sSpellStore.LookupEntry(getTotem().GetSpell());
64 if (!spellInfo)
65 return;
67 // Get spell rangy
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)
77 if( !victim ||
78 !victim->isTargetableForAttack() || !m_creature->IsWithinDistInMap(victim, max_range) ||
79 m_creature->IsFriendlyTo(victim) || !victim->isVisibleForOrDetect(m_creature,m_creature,false) )
81 CellPair p(MaNGOS::ComputeCellPair(m_creature->GetPositionX(),m_creature->GetPositionY()));
82 Cell cell(p);
83 cell.data.Part.reserved = ALL_DISTRICT;
85 victim = NULL;
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());
98 // If have target
99 if (victim)
101 // remember
102 i_victimGuid = victim->GetGUID();
104 // attack
105 m_creature->SetInFront(victim); // client change orientation by self
106 m_creature->CastSpell(victim, getTotem().GetSpell(), false);
108 else
109 i_victimGuid = 0;
112 bool
113 TotemAI::IsVisible(Unit *) const
115 return false;
118 void
119 TotemAI::AttackStart(Unit *)
123 Totem& TotemAI::getTotem()
125 return static_cast<Totem&>(*m_creature);