Rochet2
2015-08-19 23:17:00 +03:00
parent 2517ed6442
commit f51217b0c4
4 changed files with 47 additions and 13 deletions

View File

@@ -20,6 +20,8 @@ struct ElunaCreatureAI : ScriptedAI
{ {
// used to delay the spawn hook triggering on AI creation // used to delay the spawn hook triggering on AI creation
bool justSpawned; bool justSpawned;
// used to delay movementinform hook (WP hook)
std::vector< std::pair<uint32, uint32> > movepoints;
#ifndef TRINITY #ifndef TRINITY
#define me m_creature #define me m_creature
#endif #endif
@@ -42,6 +44,16 @@ struct ElunaCreatureAI : ScriptedAI
JustRespawned(); JustRespawned();
} }
if (!movepoints.empty())
{
for (auto& point : movepoints)
{
if (!sEluna->MovementInform(me, point.first, point.second))
ScriptedAI::MovementInform(point.first, point.second);
}
movepoints.clear();
}
if (!sEluna->UpdateAI(me, diff)) if (!sEluna->UpdateAI(me, diff))
{ {
#ifdef TRINITY #ifdef TRINITY
@@ -100,8 +112,9 @@ struct ElunaCreatureAI : ScriptedAI
//Called at waypoint reached or PointMovement end //Called at waypoint reached or PointMovement end
void MovementInform(uint32 type, uint32 id) override void MovementInform(uint32 type, uint32 id) override
{ {
if (!sEluna->MovementInform(me, type, id)) // delayed since hook triggers before actually reaching the point
ScriptedAI::MovementInform(type, id); // and starting new movement would bug
movepoints.push_back(std::make_pair(type, id));
} }
// Called before EnterCombat even before the creature is in combat. // Called before EnterCombat even before the creature is in combat.

View File

@@ -45,8 +45,8 @@ bool ElunaUtil::ObjectDistanceOrderPred::operator()(WorldObject const* pLeft, Wo
} }
ElunaUtil::WorldObjectInRangeCheck::WorldObjectInRangeCheck(bool nearest, WorldObject const* obj, float range, ElunaUtil::WorldObjectInRangeCheck::WorldObjectInRangeCheck(bool nearest, WorldObject const* obj, float range,
uint16 typeMask, uint32 entry, uint32 hostile) : uint16 typeMask, uint32 entry, uint32 hostile, uint32 dead) :
i_obj(obj), i_hostile(hostile), i_entry(entry), i_range(range), i_typeMask(typeMask), i_nearest(nearest) i_obj(obj), i_hostile(hostile), i_entry(entry), i_range(range), i_typeMask(typeMask), i_dead(dead), i_nearest(nearest)
{ {
} }
WorldObject const& ElunaUtil::WorldObjectInRangeCheck::GetFocusObject() const WorldObject const& ElunaUtil::WorldObjectInRangeCheck::GetFocusObject() const
@@ -66,10 +66,10 @@ bool ElunaUtil::WorldObjectInRangeCheck::operator()(WorldObject* u)
if (Unit* unit = u->ToUnit()) if (Unit* unit = u->ToUnit())
{ {
#ifdef CMANGOS #ifdef CMANGOS
if (!unit->isAlive()) if (i_dead && (i_dead == 1) != unit->isAlive())
return false; return false;
#else #else
if (!unit->IsAlive()) if (i_dead && (i_dead == 1) != unit->IsAlive())
return false; return false;
#endif #endif
if (i_hostile) if (i_hostile)

View File

@@ -97,15 +97,16 @@ namespace ElunaUtil
{ {
public: public:
WorldObjectInRangeCheck(bool nearest, WorldObject const* obj, float range, WorldObjectInRangeCheck(bool nearest, WorldObject const* obj, float range,
uint16 typeMask = 0, uint32 entry = 0, uint32 hostile = 0); uint16 typeMask = 0, uint32 entry = 0, uint32 hostile = 0, uint32 dead = 0);
WorldObject const& GetFocusObject() const; WorldObject const& GetFocusObject() const;
bool operator()(WorldObject* u); bool operator()(WorldObject* u);
WorldObject const* i_obj; WorldObject const* i_obj;
uint32 i_hostile; uint32 i_hostile; // 0 both, 1 hostile, 2 friendly
uint32 i_entry; uint32 i_entry;
float i_range; float i_range;
uint16 i_typeMask; uint16 i_typeMask;
uint32 i_dead; // 0 both, 1 alive, 2 dead
bool i_nearest; bool i_nearest;
}; };

View File

@@ -156,15 +156,19 @@ namespace LuaWorldObject
* Returns the nearest [Player] object in sight of the [WorldObject] or within the given range * Returns the nearest [Player] object in sight of the [WorldObject] or within the given range
* *
* @param float range = 533.33333 : optionally set range. Default range is grid size * @param float range = 533.33333 : optionally set range. Default range is grid size
* @param uint32 hostile = 0 : 0 both, 1 hostile, 2 friendly
* @param uint32 dead = 1 : 0 both, 1 alive, 2 dead
* *
* @return [Player] nearestPlayer * @return [Player] nearestPlayer
*/ */
int GetNearestPlayer(Eluna* /*E*/, lua_State* L, WorldObject* obj) int GetNearestPlayer(Eluna* /*E*/, lua_State* L, WorldObject* obj)
{ {
float range = Eluna::CHECKVAL<float>(L, 2, SIZE_OF_GRIDS); float range = Eluna::CHECKVAL<float>(L, 2, SIZE_OF_GRIDS);
uint32 hostile = Eluna::CHECKVAL<uint32>(L, 3, 0);
uint32 dead = Eluna::CHECKVAL<uint32>(L, 4, 1);
Unit* target = NULL; Unit* target = NULL;
ElunaUtil::WorldObjectInRangeCheck checker(true, obj, range, TYPEMASK_PLAYER); ElunaUtil::WorldObjectInRangeCheck checker(true, obj, range, TYPEMASK_PLAYER, 0, hostile, dead);
#ifndef TRINITY #ifndef TRINITY
MaNGOS::UnitLastSearcher<ElunaUtil::WorldObjectInRangeCheck> searcher(target, checker); MaNGOS::UnitLastSearcher<ElunaUtil::WorldObjectInRangeCheck> searcher(target, checker);
Cell::VisitWorldObjects(obj, searcher, range); Cell::VisitWorldObjects(obj, searcher, range);
@@ -209,6 +213,8 @@ namespace LuaWorldObject
* *
* @param float range = 533.33333 : optionally set range. Default range is grid size * @param float range = 533.33333 : optionally set range. Default range is grid size
* @param uint32 entryId = 0 : optionally set entry ID of creature to find * @param uint32 entryId = 0 : optionally set entry ID of creature to find
* @param uint32 hostile = 0 : 0 both, 1 hostile, 2 friendly
* @param uint32 dead = 1 : 0 both, 1 alive, 2 dead
* *
* @return [Creature] nearestCreature * @return [Creature] nearestCreature
*/ */
@@ -216,9 +222,11 @@ namespace LuaWorldObject
{ {
float range = Eluna::CHECKVAL<float>(L, 2, SIZE_OF_GRIDS); float range = Eluna::CHECKVAL<float>(L, 2, SIZE_OF_GRIDS);
uint32 entry = Eluna::CHECKVAL<uint32>(L, 3, 0); uint32 entry = Eluna::CHECKVAL<uint32>(L, 3, 0);
uint32 hostile = Eluna::CHECKVAL<uint32>(L, 4, 0);
uint32 dead = Eluna::CHECKVAL<uint32>(L, 5, 1);
Creature* target = NULL; Creature* target = NULL;
ElunaUtil::WorldObjectInRangeCheck checker(true, obj, range, TYPEMASK_UNIT, entry); ElunaUtil::WorldObjectInRangeCheck checker(true, obj, range, TYPEMASK_UNIT, entry, hostile, dead);
#ifndef TRINITY #ifndef TRINITY
MaNGOS::CreatureLastSearcher<ElunaUtil::WorldObjectInRangeCheck> searcher(target, checker); MaNGOS::CreatureLastSearcher<ElunaUtil::WorldObjectInRangeCheck> searcher(target, checker);
Cell::VisitGridObjects(obj, searcher, range); Cell::VisitGridObjects(obj, searcher, range);
@@ -235,15 +243,19 @@ namespace LuaWorldObject
* Returns a table of [Player] objects in sight of the [WorldObject] or within the given range * Returns a table of [Player] objects in sight of the [WorldObject] or within the given range
* *
* @param float range = 533.33333 : optionally set range. Default range is grid size * @param float range = 533.33333 : optionally set range. Default range is grid size
* @param uint32 hostile = 0 : 0 both, 1 hostile, 2 friendly
* @param uint32 dead = 1 : 0 both, 1 alive, 2 dead
* *
* @return table playersInRange : table of [Player]s * @return table playersInRange : table of [Player]s
*/ */
int GetPlayersInRange(Eluna* /*E*/, lua_State* L, WorldObject* obj) int GetPlayersInRange(Eluna* /*E*/, lua_State* L, WorldObject* obj)
{ {
float range = Eluna::CHECKVAL<float>(L, 2, SIZE_OF_GRIDS); float range = Eluna::CHECKVAL<float>(L, 2, SIZE_OF_GRIDS);
uint32 hostile = Eluna::CHECKVAL<uint32>(L, 3, 0);
uint32 dead = Eluna::CHECKVAL<uint32>(L, 4, 1);
std::list<Player*> list; std::list<Player*> list;
ElunaUtil::WorldObjectInRangeCheck checker(false, obj, range, TYPEMASK_PLAYER); ElunaUtil::WorldObjectInRangeCheck checker(false, obj, range, TYPEMASK_PLAYER, 0, hostile, dead);
#ifndef TRINITY #ifndef TRINITY
MaNGOS::PlayerListSearcher<ElunaUtil::WorldObjectInRangeCheck> searcher(list, checker); MaNGOS::PlayerListSearcher<ElunaUtil::WorldObjectInRangeCheck> searcher(list, checker);
Cell::VisitWorldObjects(obj, searcher, range); Cell::VisitWorldObjects(obj, searcher, range);
@@ -272,6 +284,8 @@ namespace LuaWorldObject
* *
* @param float range = 533.33333 : optionally set range. Default range is grid size * @param float range = 533.33333 : optionally set range. Default range is grid size
* @param uint32 entryId = 0 : optionally set entry ID of creatures to find * @param uint32 entryId = 0 : optionally set entry ID of creatures to find
* @param uint32 hostile = 0 : 0 both, 1 hostile, 2 friendly
* @param uint32 dead = 1 : 0 both, 1 alive, 2 dead
* *
* @return table creaturesInRange : table of [Creature]s * @return table creaturesInRange : table of [Creature]s
*/ */
@@ -279,9 +293,11 @@ namespace LuaWorldObject
{ {
float range = Eluna::CHECKVAL<float>(L, 2, SIZE_OF_GRIDS); float range = Eluna::CHECKVAL<float>(L, 2, SIZE_OF_GRIDS);
uint32 entry = Eluna::CHECKVAL<uint32>(L, 3, 0); uint32 entry = Eluna::CHECKVAL<uint32>(L, 3, 0);
uint32 hostile = Eluna::CHECKVAL<uint32>(L, 3, 0);
uint32 dead = Eluna::CHECKVAL<uint32>(L, 4, 1);
std::list<Creature*> list; std::list<Creature*> list;
ElunaUtil::WorldObjectInRangeCheck checker(false, obj, range, TYPEMASK_UNIT, entry); ElunaUtil::WorldObjectInRangeCheck checker(false, obj, range, TYPEMASK_UNIT, entry, hostile, dead);
#ifndef TRINITY #ifndef TRINITY
MaNGOS::CreatureListSearcher<ElunaUtil::WorldObjectInRangeCheck> searcher(list, checker); MaNGOS::CreatureListSearcher<ElunaUtil::WorldObjectInRangeCheck> searcher(list, checker);
Cell::VisitGridObjects(obj, searcher, range); Cell::VisitGridObjects(obj, searcher, range);
@@ -351,6 +367,7 @@ namespace LuaWorldObject
* @param [TypeMask] type = 0 : the [TypeMask] that the [WorldObject] must be. This can contain multiple types. 0 will be ingored * @param [TypeMask] type = 0 : the [TypeMask] that the [WorldObject] must be. This can contain multiple types. 0 will be ingored
* @param uint32 entry = 0 : the entry of the [WorldObject], 0 will be ingored * @param uint32 entry = 0 : the entry of the [WorldObject], 0 will be ingored
* @param uint32 hostile = 0 : specifies whether the [WorldObject] needs to be 1 hostile, 2 friendly or 0 either * @param uint32 hostile = 0 : specifies whether the [WorldObject] needs to be 1 hostile, 2 friendly or 0 either
* @param uint32 dead = 1 : 0 both, 1 alive, 2 dead
* *
* @return [WorldObject] worldObject * @return [WorldObject] worldObject
*/ */
@@ -360,6 +377,7 @@ namespace LuaWorldObject
uint16 type = Eluna::CHECKVAL<uint16>(L, 3, 0); // TypeMask uint16 type = Eluna::CHECKVAL<uint16>(L, 3, 0); // TypeMask
uint32 entry = Eluna::CHECKVAL<uint32>(L, 4, 0); uint32 entry = Eluna::CHECKVAL<uint32>(L, 4, 0);
uint32 hostile = Eluna::CHECKVAL<uint32>(L, 5, 0); // 0 none, 1 hostile, 2 friendly uint32 hostile = Eluna::CHECKVAL<uint32>(L, 5, 0); // 0 none, 1 hostile, 2 friendly
uint32 dead = Eluna::CHECKVAL<uint32>(L, 6, 1); // 0 both, 1 alive, 2 dead
float x, y, z; float x, y, z;
obj->GetPosition(x, y, z); obj->GetPosition(x, y, z);
@@ -386,6 +404,7 @@ namespace LuaWorldObject
* @param [TypeMask] type = 0 : the [TypeMask] that the [WorldObject] must be. This can contain multiple types. 0 will be ingored * @param [TypeMask] type = 0 : the [TypeMask] that the [WorldObject] must be. This can contain multiple types. 0 will be ingored
* @param uint32 entry = 0 : the entry of the [WorldObject], 0 will be ingored * @param uint32 entry = 0 : the entry of the [WorldObject], 0 will be ingored
* @param uint32 hostile = 0 : specifies whether the [WorldObject] needs to be 1 hostile, 2 friendly or 0 either * @param uint32 hostile = 0 : specifies whether the [WorldObject] needs to be 1 hostile, 2 friendly or 0 either
* @param uint32 dead = 1 : 0 both, 1 alive, 2 dead
* *
* @return table worldObjectList : table of [WorldObject]s * @return table worldObjectList : table of [WorldObject]s
*/ */
@@ -395,10 +414,11 @@ namespace LuaWorldObject
uint16 type = Eluna::CHECKVAL<uint16>(L, 3, 0); // TypeMask uint16 type = Eluna::CHECKVAL<uint16>(L, 3, 0); // TypeMask
uint32 entry = Eluna::CHECKVAL<uint32>(L, 4, 0); uint32 entry = Eluna::CHECKVAL<uint32>(L, 4, 0);
uint32 hostile = Eluna::CHECKVAL<uint32>(L, 5, 0); // 0 none, 1 hostile, 2 friendly uint32 hostile = Eluna::CHECKVAL<uint32>(L, 5, 0); // 0 none, 1 hostile, 2 friendly
uint32 dead = Eluna::CHECKVAL<uint32>(L, 6, 1); // 0 both, 1 alive, 2 dead
float x, y, z; float x, y, z;
obj->GetPosition(x, y, z); obj->GetPosition(x, y, z);
ElunaUtil::WorldObjectInRangeCheck checker(false, obj, range, type, entry, hostile); ElunaUtil::WorldObjectInRangeCheck checker(false, obj, range, type, entry, hostile, dead);
std::list<WorldObject*> list; std::list<WorldObject*> list;
#ifndef TRINITY #ifndef TRINITY