[7808] Move corpse search code in function with template arg for class-check. Author: Astellar
This let reuse code for other similar near corpse target selection spells.
Also provided currently not used class-checks for 2 spells
--HG--
branch : trunk
This commit is contained in:
@@ -650,6 +650,7 @@ class TRINITY_DLL_SPEC Creature : public Unit
|
|||||||
bool IsVisibleInGridForPlayer(Player const* pl) const;
|
bool IsVisibleInGridForPlayer(Player const* pl) const;
|
||||||
|
|
||||||
void RemoveCorpse();
|
void RemoveCorpse();
|
||||||
|
bool isDeadByDefault() const { return m_isDeadByDefault; };
|
||||||
|
|
||||||
time_t const& GetRespawnTime() const { return m_respawnTime; }
|
time_t const& GetRespawnTime() const { return m_respawnTime; }
|
||||||
time_t GetRespawnTimeEx() const;
|
time_t GetRespawnTimeEx() const;
|
||||||
|
|||||||
@@ -499,6 +499,53 @@ namespace Trinity
|
|||||||
// CHECKS && DO classes
|
// CHECKS && DO classes
|
||||||
|
|
||||||
// WorldObject check classes
|
// WorldObject check classes
|
||||||
|
class RaiseDeadObjectCheck
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RaiseDeadObjectCheck(Unit* funit, float range) : i_funit(funit), i_range(range) {}
|
||||||
|
bool operator()(Creature* u)
|
||||||
|
{
|
||||||
|
if (i_funit->GetTypeId()!=TYPEID_PLAYER || !((Player*)i_funit)->isHonorOrXPTarget(u) ||
|
||||||
|
u->getDeathState() != CORPSE || u->isDeadByDefault() || u->isInFlight() ||
|
||||||
|
( u->GetCreatureTypeMask() & (1 << (CREATURE_TYPE_HUMANOID-1)) )==0 ||
|
||||||
|
(u->GetDisplayId() != u->GetNativeDisplayId()))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return i_funit->IsWithinDistInMap(u, i_range);
|
||||||
|
}
|
||||||
|
template<class NOT_INTERESTED> bool operator()(NOT_INTERESTED*) { return false; }
|
||||||
|
private:
|
||||||
|
Unit* const i_funit;
|
||||||
|
float i_range;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ExplodeCorpseObjectCheck
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ExplodeCorpseObjectCheck(Unit* funit, float range) : i_funit(funit), i_range(range) {}
|
||||||
|
bool operator()(Player* u)
|
||||||
|
{
|
||||||
|
if (u->getDeathState()!=CORPSE || u->isInFlight() ||
|
||||||
|
u->HasAuraType(SPELL_AURA_GHOST) || (u->GetDisplayId() != u->GetNativeDisplayId()))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return i_funit->IsWithinDistInMap(u, i_range);
|
||||||
|
}
|
||||||
|
bool operator()(Creature* u)
|
||||||
|
{
|
||||||
|
if (u->getDeathState()!=CORPSE || u->isInFlight() || u->isDeadByDefault() ||
|
||||||
|
(u->GetDisplayId() != u->GetNativeDisplayId()) ||
|
||||||
|
(u->GetCreatureTypeMask() & CREATURE_TYPEMASK_MECHANICAL_OR_ELEMENTAL)!=0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return i_funit->IsWithinDistInMap(u, i_range);
|
||||||
|
}
|
||||||
|
template<class NOT_INTERESTED> bool operator()(NOT_INTERESTED*) { return false; }
|
||||||
|
private:
|
||||||
|
Unit* const i_funit;
|
||||||
|
float i_range;
|
||||||
|
};
|
||||||
|
|
||||||
class CannibalizeObjectCheck
|
class CannibalizeObjectCheck
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -508,10 +555,7 @@ namespace Trinity
|
|||||||
if( i_funit->IsFriendlyTo(u) || u->isAlive() || u->isInFlight() )
|
if( i_funit->IsFriendlyTo(u) || u->isAlive() || u->isInFlight() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(i_funit->IsWithinDistInMap(u, i_range) )
|
return i_funit->IsWithinDistInMap(u, i_range);
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
bool operator()(Corpse* u);
|
bool operator()(Corpse* u);
|
||||||
bool operator()(Creature* u)
|
bool operator()(Creature* u)
|
||||||
@@ -520,10 +564,7 @@ namespace Trinity
|
|||||||
(u->GetCreatureTypeMask() & CREATURE_TYPEMASK_HUMANOID_OR_UNDEAD)==0)
|
(u->GetCreatureTypeMask() & CREATURE_TYPEMASK_HUMANOID_OR_UNDEAD)==0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(i_funit->IsWithinDistInMap(u, i_range) )
|
return i_funit->IsWithinDistInMap(u, i_range);
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
template<class NOT_INTERESTED> bool operator()(NOT_INTERESTED*) { return false; }
|
template<class NOT_INTERESTED> bool operator()(NOT_INTERESTED*) { return false; }
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -1820,6 +1820,7 @@ enum CreatureType
|
|||||||
};
|
};
|
||||||
|
|
||||||
uint32 const CREATURE_TYPEMASK_HUMANOID_OR_UNDEAD = (1 << (CREATURE_TYPE_HUMANOID-1)) | (1 << (CREATURE_TYPE_UNDEAD-1));
|
uint32 const CREATURE_TYPEMASK_HUMANOID_OR_UNDEAD = (1 << (CREATURE_TYPE_HUMANOID-1)) | (1 << (CREATURE_TYPE_UNDEAD-1));
|
||||||
|
uint32 const CREATURE_TYPEMASK_MECHANICAL_OR_ELEMENTAL = (1 << (CREATURE_TYPE_MECHANICAL-1)) | (1 << (CREATURE_TYPE_ELEMENTAL-1));
|
||||||
|
|
||||||
// CreatureFamily.dbc
|
// CreatureFamily.dbc
|
||||||
enum CreatureFamily
|
enum CreatureFamily
|
||||||
|
|||||||
+30
-11
@@ -476,6 +476,35 @@ Spell::~Spell()
|
|||||||
delete m_spellValue;
|
delete m_spellValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
WorldObject* Spell::FindCorpseUsing()
|
||||||
|
{
|
||||||
|
// non-standard target selection
|
||||||
|
float max_range = GetSpellMaxRange(m_spellInfo, false);
|
||||||
|
|
||||||
|
CellPair p(MaNGOS::ComputeCellPair(m_caster->GetPositionX(), m_caster->GetPositionY()));
|
||||||
|
Cell cell(p);
|
||||||
|
cell.data.Part.reserved = ALL_DISTRICT;
|
||||||
|
cell.SetNoCreate();
|
||||||
|
|
||||||
|
WorldObject* result = NULL;
|
||||||
|
|
||||||
|
T u_check(m_caster, max_range);
|
||||||
|
MaNGOS::WorldObjectSearcher<T> searcher(m_caster, result, u_check);
|
||||||
|
|
||||||
|
TypeContainerVisitor<MaNGOS::WorldObjectSearcher<T>, GridTypeMapContainer > grid_searcher(searcher);
|
||||||
|
CellLock<GridReadGuard> cell_lock(cell, p);
|
||||||
|
cell_lock->Visit(cell_lock, grid_searcher, *m_caster->GetMap());
|
||||||
|
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
TypeContainerVisitor<MaNGOS::WorldObjectSearcher<T>, WorldTypeMapContainer > world_searcher(searcher);
|
||||||
|
cell_lock->Visit(cell_lock, world_searcher, *m_caster->GetMap());
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void Spell::FillTargetMap()
|
void Spell::FillTargetMap()
|
||||||
{
|
{
|
||||||
for(uint32 i = 0; i < 3; ++i)
|
for(uint32 i = 0; i < 3; ++i)
|
||||||
@@ -535,17 +564,7 @@ void Spell::FillTargetMap()
|
|||||||
{
|
{
|
||||||
case 20577: // Cannibalize
|
case 20577: // Cannibalize
|
||||||
{
|
{
|
||||||
// non-standard target selection
|
WorldObject* result = FindCorpseUsing<MaNGOS::CannibalizeObjectCheck> ();
|
||||||
SpellRangeEntry const* srange = sSpellRangeStore.LookupEntry(m_spellInfo->rangeIndex);
|
|
||||||
float max_range = GetSpellMaxRangeForHostile(srange);
|
|
||||||
WorldObject* result = NULL;
|
|
||||||
|
|
||||||
Trinity::CannibalizeObjectCheck u_check(m_caster, max_range);
|
|
||||||
Trinity::WorldObjectSearcher<Trinity::CannibalizeObjectCheck > searcher(m_caster, result, u_check);
|
|
||||||
m_caster->VisitNearbyGridObject(max_range, searcher);
|
|
||||||
if(!result)
|
|
||||||
m_caster->VisitNearbyWorldObject(max_range, searcher);
|
|
||||||
|
|
||||||
|
|
||||||
if(result)
|
if(result)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -412,6 +412,8 @@ class Spell
|
|||||||
|
|
||||||
void SetTargetMap(uint32 i, uint32 cur);
|
void SetTargetMap(uint32 i, uint32 cur);
|
||||||
|
|
||||||
|
template<typename T> WorldObject* FindCorpseUsing();
|
||||||
|
|
||||||
bool CheckTarget( Unit* target, uint32 eff );
|
bool CheckTarget( Unit* target, uint32 eff );
|
||||||
bool CanAutoCast(Unit* target);
|
bool CanAutoCast(Unit* target);
|
||||||
void CheckSrc() { if(!m_targets.HasSrc()) m_targets.setSrc(m_caster); }
|
void CheckSrc() { if(!m_targets.HasSrc()) m_targets.setSrc(m_caster); }
|
||||||
|
|||||||
Reference in New Issue
Block a user