mirror of
https://github.com/mangosfour/server.git
synced 2025-12-13 22:37:03 +00:00
[7951] Mope call for help code to function form Event AI code to allow use it from C++ scripts also.
Signed-off-by: VladimirMangos <vladimir@getmangos.com>
This commit is contained in:
parent
0b3a4bf5a5
commit
48fee42129
5 changed files with 55 additions and 51 deletions
|
|
@ -1777,6 +1777,25 @@ void Creature::CallAssistance()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Creature::CallForHelp(float fRadius)
|
||||||
|
{
|
||||||
|
if (fRadius <= 0.0f || !getVictim() || isPet() || isCharmed())
|
||||||
|
return;
|
||||||
|
|
||||||
|
CellPair p(MaNGOS::ComputeCellPair(GetPositionX(), GetPositionY()));
|
||||||
|
Cell cell(p);
|
||||||
|
cell.data.Part.reserved = ALL_DISTRICT;
|
||||||
|
cell.SetNoCreate();
|
||||||
|
|
||||||
|
MaNGOS::CallOfHelpCreatureInRangeDo u_do(this, getVictim(), fRadius);
|
||||||
|
MaNGOS::CreatureWorker<MaNGOS::CallOfHelpCreatureInRangeDo> worker(this, u_do);
|
||||||
|
|
||||||
|
TypeContainerVisitor<MaNGOS::CreatureWorker<MaNGOS::CallOfHelpCreatureInRangeDo>, GridTypeMapContainer > grid_creature_searcher(worker);
|
||||||
|
|
||||||
|
CellLock<GridReadGuard> cell_lock(cell, p);
|
||||||
|
cell_lock->Visit(cell_lock, grid_creature_searcher, *GetMap());
|
||||||
|
}
|
||||||
|
|
||||||
bool Creature::CanAssistTo(const Unit* u, const Unit* enemy, bool checkfaction /*= true*/) const
|
bool Creature::CanAssistTo(const Unit* u, const Unit* enemy, bool checkfaction /*= true*/) const
|
||||||
{
|
{
|
||||||
// we don't need help from zombies :)
|
// we don't need help from zombies :)
|
||||||
|
|
|
||||||
|
|
@ -604,6 +604,7 @@ class MANGOS_DLL_SPEC Creature : public Unit
|
||||||
float GetAttackDistance(Unit const* pl) const;
|
float GetAttackDistance(Unit const* pl) const;
|
||||||
|
|
||||||
void DoFleeToGetAssistance();
|
void DoFleeToGetAssistance();
|
||||||
|
void CallForHelp(float fRadius);
|
||||||
void CallAssistance();
|
void CallAssistance();
|
||||||
void SetNoCallAssistance(bool val) { m_AlreadyCallAssistance = val; }
|
void SetNoCallAssistance(bool val) { m_AlreadyCallAssistance = val; }
|
||||||
void SetNoSearchAssistance(bool val) { m_AlreadySearchedAssistance = val; }
|
void SetNoSearchAssistance(bool val) { m_AlreadySearchedAssistance = val; }
|
||||||
|
|
|
||||||
|
|
@ -27,43 +27,8 @@
|
||||||
#include "GameEventMgr.h"
|
#include "GameEventMgr.h"
|
||||||
#include "GridNotifiers.h"
|
#include "GridNotifiers.h"
|
||||||
#include "GridNotifiersImpl.h"
|
#include "GridNotifiersImpl.h"
|
||||||
#include "WorldPacket.h"
|
|
||||||
#include "InstanceData.h"
|
#include "InstanceData.h"
|
||||||
|
|
||||||
namespace MaNGOS
|
|
||||||
{
|
|
||||||
class CallOfHelpCreatureInRangeDo // do attack at call of help to friendly crearture
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CallOfHelpCreatureInRangeDo(Unit* funit, Unit* enemy, float range)
|
|
||||||
: i_funit(funit), i_enemy(enemy), i_range(range)
|
|
||||||
{}
|
|
||||||
void operator()(Creature* u)
|
|
||||||
{
|
|
||||||
if (u == i_funit)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!u->CanAssistTo(i_funit, i_enemy, false))
|
|
||||||
return;
|
|
||||||
|
|
||||||
// too far
|
|
||||||
if( !i_funit->IsWithinDistInMap(u, i_range) )
|
|
||||||
return;
|
|
||||||
|
|
||||||
// only if see assisted creature
|
|
||||||
if( !i_funit->IsWithinLOSInMap(u) )
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(u->AI())
|
|
||||||
u->AI()->AttackStart(i_enemy);
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
Unit* const i_funit;
|
|
||||||
Unit* const i_enemy;
|
|
||||||
float i_range;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CreatureEventAIHolder::UpdateRepeatTimer( Creature* creature, uint32 repeatMin, uint32 repeatMax )
|
bool CreatureEventAIHolder::UpdateRepeatTimer( Creature* creature, uint32 repeatMin, uint32 repeatMax )
|
||||||
{
|
{
|
||||||
if (repeatMin == repeatMax)
|
if (repeatMin == repeatMax)
|
||||||
|
|
@ -780,21 +745,7 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
|
||||||
break;
|
break;
|
||||||
case ACTION_T_CALL_FOR_HELP:
|
case ACTION_T_CALL_FOR_HELP:
|
||||||
{
|
{
|
||||||
if (!m_creature->getVictim())
|
m_creature->CallForHelp(action.call_for_help.radius);
|
||||||
return;
|
|
||||||
|
|
||||||
CellPair p(MaNGOS::ComputeCellPair(m_creature->GetPositionX(), m_creature->GetPositionY()));
|
|
||||||
Cell cell(p);
|
|
||||||
cell.data.Part.reserved = ALL_DISTRICT;
|
|
||||||
cell.SetNoCreate();
|
|
||||||
|
|
||||||
MaNGOS::CallOfHelpCreatureInRangeDo u_do(m_creature, m_creature->getVictim(), action.call_for_help.radius);
|
|
||||||
MaNGOS::CreatureWorker<MaNGOS::CallOfHelpCreatureInRangeDo> worker(m_creature, u_do);
|
|
||||||
|
|
||||||
TypeContainerVisitor<MaNGOS::CreatureWorker<MaNGOS::CallOfHelpCreatureInRangeDo>, GridTypeMapContainer > grid_creature_searcher(worker);
|
|
||||||
|
|
||||||
CellLock<GridReadGuard> cell_lock(cell, p);
|
|
||||||
cell_lock->Visit(cell_lock, grid_creature_searcher, *m_creature->GetMap());
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ACTION_T_SET_SHEATH:
|
case ACTION_T_SET_SHEATH:
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@
|
||||||
#include "GameObject.h"
|
#include "GameObject.h"
|
||||||
#include "Player.h"
|
#include "Player.h"
|
||||||
#include "Unit.h"
|
#include "Unit.h"
|
||||||
|
#include "CreatureAI.h"
|
||||||
|
|
||||||
class Player;
|
class Player;
|
||||||
//class Map;
|
//class Map;
|
||||||
|
|
@ -856,6 +857,38 @@ namespace MaNGOS
|
||||||
float i_range;
|
float i_range;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// do attack at call of help to friendly crearture
|
||||||
|
class CallOfHelpCreatureInRangeDo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CallOfHelpCreatureInRangeDo(Unit* funit, Unit* enemy, float range)
|
||||||
|
: i_funit(funit), i_enemy(enemy), i_range(range)
|
||||||
|
{}
|
||||||
|
void operator()(Creature* u)
|
||||||
|
{
|
||||||
|
if (u == i_funit)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!u->CanAssistTo(i_funit, i_enemy, false))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// too far
|
||||||
|
if (!i_funit->IsWithinDistInMap(u, i_range))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// only if see assisted creature
|
||||||
|
if (!i_funit->IsWithinLOSInMap(u))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (u->AI())
|
||||||
|
u->AI()->AttackStart(i_enemy);
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
Unit* const i_funit;
|
||||||
|
Unit* const i_enemy;
|
||||||
|
float i_range;
|
||||||
|
};
|
||||||
|
|
||||||
struct AnyDeadUnitCheck
|
struct AnyDeadUnitCheck
|
||||||
{
|
{
|
||||||
bool operator()(Unit* u) { return !u->isAlive(); }
|
bool operator()(Unit* u) { return !u->isAlive(); }
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef __REVISION_NR_H__
|
#ifndef __REVISION_NR_H__
|
||||||
#define __REVISION_NR_H__
|
#define __REVISION_NR_H__
|
||||||
#define REVISION_NR "7950"
|
#define REVISION_NR "7951"
|
||||||
#endif // __REVISION_NR_H__
|
#endif // __REVISION_NR_H__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue