[2] | 1 | /* |
---|
[102] | 2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
| 3 | * |
---|
[44] | 4 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
---|
[2] | 5 | * |
---|
| 6 | * This program is free software; you can redistribute it and/or modify |
---|
| 7 | * it under the terms of the GNU General Public License as published by |
---|
| 8 | * the Free Software Foundation; either version 2 of the License, or |
---|
| 9 | * (at your option) any later version. |
---|
| 10 | * |
---|
| 11 | * This program is distributed in the hope that it will be useful, |
---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
[44] | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
[2] | 14 | * GNU General Public License for more details. |
---|
| 15 | * |
---|
| 16 | * You should have received a copy of the GNU General Public License |
---|
| 17 | * along with this program; if not, write to the Free Software |
---|
[44] | 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
[2] | 19 | */ |
---|
| 20 | |
---|
| 21 | #include "TotemAI.h" |
---|
| 22 | #include "Totem.h" |
---|
| 23 | #include "Creature.h" |
---|
| 24 | #include "Player.h" |
---|
| 25 | #include "Database/DBCStores.h" |
---|
| 26 | #include "MapManager.h" |
---|
| 27 | #include "ObjectAccessor.h" |
---|
| 28 | #include "SpellMgr.h" |
---|
| 29 | |
---|
| 30 | #include "GridNotifiers.h" |
---|
| 31 | #include "GridNotifiersImpl.h" |
---|
| 32 | #include "CellImpl.h" |
---|
| 33 | |
---|
| 34 | int |
---|
| 35 | TotemAI::Permissible(const Creature *creature) |
---|
| 36 | { |
---|
| 37 | if( creature->isTotem() ) |
---|
| 38 | return PERMIT_BASE_PROACTIVE; |
---|
| 39 | |
---|
| 40 | return PERMIT_BASE_NO; |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | TotemAI::TotemAI(Creature &c) : i_totem(static_cast<Totem&>(c)), i_victimGuid(0) |
---|
| 44 | { |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | void |
---|
| 48 | TotemAI::MoveInLineOfSight(Unit *) |
---|
| 49 | { |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | void TotemAI::EnterEvadeMode() |
---|
| 53 | { |
---|
| 54 | i_totem.CombatStop(); |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | void |
---|
| 58 | TotemAI::UpdateAI(const uint32 /*diff*/) |
---|
| 59 | { |
---|
| 60 | if (i_totem.GetTotemType() != TOTEM_ACTIVE) |
---|
| 61 | return; |
---|
| 62 | |
---|
| 63 | if (!i_totem.isAlive() || i_totem.IsNonMeleeSpellCasted(false)) |
---|
| 64 | return; |
---|
| 65 | |
---|
| 66 | // Search spell |
---|
| 67 | SpellEntry const *spellInfo = sSpellStore.LookupEntry(i_totem.GetSpell()); |
---|
| 68 | if (!spellInfo) |
---|
| 69 | return; |
---|
| 70 | |
---|
| 71 | // Get spell rangy |
---|
| 72 | SpellRangeEntry const* srange = sSpellRangeStore.LookupEntry(spellInfo->rangeIndex); |
---|
| 73 | float max_range = GetSpellMaxRange(srange); |
---|
| 74 | |
---|
| 75 | // SPELLMOD_RANGE not applied in this place just because not existence range mods for attacking totems |
---|
| 76 | |
---|
| 77 | // pointer to appropriate target if found any |
---|
| 78 | Unit* victim = i_victimGuid ? ObjectAccessor::GetUnit(i_totem, i_victimGuid) : NULL; |
---|
| 79 | |
---|
| 80 | // Search victim if no, not attackable, or out of range, or friendly (possible in case duel end) |
---|
| 81 | if( !victim || |
---|
| 82 | !victim->isTargetableForAttack() || !i_totem.IsWithinDistInMap(victim, max_range) || |
---|
| 83 | i_totem.IsFriendlyTo(victim) || !victim->isVisibleForOrDetect(&i_totem,false) ) |
---|
| 84 | { |
---|
[44] | 85 | CellPair p(Trinity::ComputeCellPair(i_totem.GetPositionX(),i_totem.GetPositionY())); |
---|
[2] | 86 | Cell cell(p); |
---|
| 87 | cell.data.Part.reserved = ALL_DISTRICT; |
---|
| 88 | |
---|
| 89 | victim = NULL; |
---|
| 90 | |
---|
[44] | 91 | Trinity::NearestAttackableUnitInObjectRangeCheck u_check(&i_totem, &i_totem, max_range); |
---|
| 92 | Trinity::UnitLastSearcher<Trinity::NearestAttackableUnitInObjectRangeCheck> checker(victim, u_check); |
---|
[2] | 93 | |
---|
[44] | 94 | TypeContainerVisitor<Trinity::UnitLastSearcher<Trinity::NearestAttackableUnitInObjectRangeCheck>, GridTypeMapContainer > grid_object_checker(checker); |
---|
| 95 | TypeContainerVisitor<Trinity::UnitLastSearcher<Trinity::NearestAttackableUnitInObjectRangeCheck>, WorldTypeMapContainer > world_object_checker(checker); |
---|
[2] | 96 | |
---|
| 97 | CellLock<GridReadGuard> cell_lock(cell, p); |
---|
| 98 | cell_lock->Visit(cell_lock, grid_object_checker, *MapManager::Instance().GetMap(i_totem.GetMapId(), &i_totem)); |
---|
| 99 | cell_lock->Visit(cell_lock, world_object_checker, *MapManager::Instance().GetMap(i_totem.GetMapId(), &i_totem)); |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | // If have target |
---|
| 103 | if (victim) |
---|
| 104 | { |
---|
| 105 | // remember |
---|
| 106 | i_victimGuid = victim->GetGUID(); |
---|
| 107 | |
---|
| 108 | // attack |
---|
| 109 | i_totem.SetInFront(victim); // client change orientation by self |
---|
| 110 | i_totem.CastSpell(victim, i_totem.GetSpell(), false); |
---|
| 111 | } |
---|
| 112 | else |
---|
| 113 | i_victimGuid = 0; |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | bool |
---|
| 117 | TotemAI::IsVisible(Unit *) const |
---|
| 118 | { |
---|
| 119 | return false; |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | void |
---|
| 123 | TotemAI::AttackStart(Unit *) |
---|
| 124 | { |
---|
[233] | 125 | // Sentry totem sends ping on attack |
---|
| 126 | if (i_totem.GetEntry() == SENTRY_TOTEM_ENTRY && i_totem.GetOwner()->GetTypeId() == TYPEID_PLAYER) |
---|
| 127 | { |
---|
| 128 | WorldPacket data(MSG_MINIMAP_PING, (8+4+4)); |
---|
| 129 | data << i_totem.GetGUID(); |
---|
| 130 | data << i_totem.GetPositionX(); |
---|
| 131 | data << i_totem.GetPositionY(); |
---|
| 132 | ((Player*)i_totem.GetOwner())->GetSession()->SendPacket(&data); |
---|
| 133 | } |
---|
[2] | 134 | } |
---|