[12676] AI-Event throwing and receiving implementation

Add new AI hooks to
* SendAIEvent (either around the npc, or to a specified npc)
* ReceiveAIEvent (hook to receive sent events)
This commit is contained in:
Schmoozerd 2013-08-19 16:32:06 +03:00 committed by Antz
parent 60a7bec73f
commit c7a07a7dc6
5 changed files with 141 additions and 63 deletions

View file

@ -97,34 +97,6 @@ VendorItem const* VendorItemData::FindItemCostPair(uint32 item_id, uint8 type, u
return NULL;
}
bool AssistDelayEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/)
{
if (Unit* victim = m_owner.GetMap()->GetUnit(m_victimGuid))
{
while (!m_assistantGuids.empty())
{
Creature* assistant = m_owner.GetMap()->GetAnyTypeCreature(*m_assistantGuids.rbegin());
m_assistantGuids.pop_back();
if (assistant && assistant->CanAssistTo(&m_owner, victim))
{
assistant->SetNoCallAssistance(true);
if (assistant->AI())
assistant->AI()->AttackStart(victim);
}
}
}
return true;
}
AssistDelayEvent::AssistDelayEvent(ObjectGuid victim, Unit& owner, std::list<Creature*> const& assistants) : BasicEvent(), m_victimGuid(victim), m_owner(owner)
{
// Pushing guids because in delay can happen some creature gets despawned => invalid pointer
m_assistantGuids.reserve(assistants.size());
for (std::list<Creature*>::const_iterator itr = assistants.begin(); itr != assistants.end(); ++itr)
m_assistantGuids.push_back((*itr)->GetObjectGuid());
}
bool ForcedDespawnDelayEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/)
{
m_owner.ForcedDespawn();
@ -1800,24 +1772,7 @@ void Creature::CallAssistance()
if (!m_AlreadyCallAssistance && getVictim() && !isCharmed())
{
SetNoCallAssistance(true);
float radius = sWorld.getConfig(CONFIG_FLOAT_CREATURE_FAMILY_ASSISTANCE_RADIUS);
if (radius > 0)
{
std::list<Creature*> assistList;
{
MaNGOS::AnyAssistCreatureInRangeCheck u_check(this, getVictim(), radius);
MaNGOS::CreatureListSearcher<MaNGOS::AnyAssistCreatureInRangeCheck> searcher(assistList, u_check);
Cell::VisitGridObjects(this, searcher, radius);
}
if (!assistList.empty())
{
AssistDelayEvent* e = new AssistDelayEvent(getVictim()->GetObjectGuid(), *this, assistList);
m_Events.AddEvent(e, m_Events.CalculateTime(sWorld.getConfig(CONFIG_UINT32_CREATURE_FAMILY_ASSISTANCE_DELAY)));
}
}
AI()->SendAIEvent(AI_EVENT_CALL_ASSISTANCE, getVictim(), sWorld.getConfig(CONFIG_UINT32_CREATURE_FAMILY_ASSISTANCE_DELAY), sWorld.getConfig(CONFIG_FLOAT_CREATURE_FAMILY_ASSISTANCE_RADIUS));
}
}
@ -1846,7 +1801,7 @@ bool Creature::CanAssistTo(const Unit* u, const Unit* enemy, bool checkfaction /
return false;
// skip fighting creature
if (isInCombat())
if (enemy && isInCombat())
return false;
// only free creature
@ -1866,7 +1821,7 @@ bool Creature::CanAssistTo(const Unit* u, const Unit* enemy, bool checkfaction /
}
// skip non hostile to caster enemy creatures
if (!IsHostileTo(enemy))
if (enemy && !IsHostileTo(enemy))
return false;
return true;