diff --git a/LuaFunctions.cpp b/LuaFunctions.cpp index 95e3287..08b0ef2 100644 --- a/LuaFunctions.cpp +++ b/LuaFunctions.cpp @@ -220,6 +220,16 @@ ElunaRegister WorldObjectMethods[] = // Boolean { "IsWithinLoS", &LuaWorldObject::IsWithinLoS }, + { "IsInMap", &LuaWorldObject::IsInMap }, + { "IsWithinDist3d", &LuaWorldObject::IsWithinDist3d }, + { "IsWithinDist2d", &LuaWorldObject::IsWithinDist2d }, + { "IsWithinDist", &LuaWorldObject::IsWithinDist }, + { "IsWithinDistInMap", &LuaWorldObject::IsWithinDistInMap }, + { "IsInRange", &LuaWorldObject::IsInRange }, + { "IsInRange2d", &LuaWorldObject::IsInRange2d }, + { "IsInRange3d", &LuaWorldObject::IsInRange3d }, + { "IsInFront", &LuaWorldObject::IsInFront }, + { "IsInBack", &LuaWorldObject::IsInBack }, // Other { "SummonGameObject", &LuaWorldObject::SummonGameObject }, @@ -359,7 +369,6 @@ ElunaRegister UnitMethods[] = { "IsStopped", &LuaUnit::IsStopped }, { "HasUnitState", &LuaUnit::HasUnitState }, { "IsQuestGiver", &LuaUnit::IsQuestGiver }, - { "IsWithinDistInMap", &LuaUnit::IsWithinDistInMap }, { "IsInAccessiblePlaceFor", &LuaUnit::IsInAccessiblePlaceFor }, { "IsVendor", &LuaUnit::IsVendor }, { "IsRooted", &LuaUnit::IsRooted }, diff --git a/UnitMethods.h b/UnitMethods.h index fdcbbe5..36acdd2 100644 --- a/UnitMethods.h +++ b/UnitMethods.h @@ -91,22 +91,6 @@ namespace LuaUnit return 1; } - /** - * Returns true if the [WorldObject] is within given radius of the [Unit]. - * - * @param [WorldObject] obj - * @param float radius - * @return bool withinDist - */ - int IsWithinDistInMap(lua_State* L, Unit* unit) - { - WorldObject* obj = Eluna::CHECKOBJ(L, 2); - float radius = Eluna::CHECKVAL(L, 3); - - Eluna::Push(L, unit->IsWithinDistInMap(obj, radius)); - return 1; - } - /** * Returns true if the [Unit] is in an accessible place for the given [Creature]. * diff --git a/WorldObjectMethods.h b/WorldObjectMethods.h index 2fa105b..db72bd9 100644 --- a/WorldObjectMethods.h +++ b/WorldObjectMethods.h @@ -476,7 +476,7 @@ namespace LuaWorldObject int GetDistance(lua_State* L, WorldObject* obj) { WorldObject* target = Eluna::CHECKOBJ(L, 2, false); - if (target && target->IsInWorld()) + if (target) Eluna::Push(L, obj->GetDistance(target)); else { @@ -508,7 +508,7 @@ namespace LuaWorldObject float x, y, z; obj->GetPosition(x, y, z); WorldObject* target = Eluna::CHECKOBJ(L, 2, false); - if (target && target->IsInWorld()) + if (target) { float x2, y2, z2; target->GetPosition(x2, y2, z2); @@ -544,7 +544,7 @@ namespace LuaWorldObject int GetDistance2d(lua_State* L, WorldObject* obj) { WorldObject* target = Eluna::CHECKOBJ(L, 2, false); - if (target && target->IsInWorld()) + if (target) Eluna::Push(L, obj->GetDistance2d(target)); else { @@ -574,7 +574,7 @@ namespace LuaWorldObject float x, y, z; obj->GetPosition(x, y, z); WorldObject* target = Eluna::CHECKOBJ(L, 2, false); - if (target && target->IsInWorld()) + if (target) { float x2, y2, z2; target->GetPosition(x2, y2, z2); @@ -633,7 +633,7 @@ namespace LuaWorldObject { WorldObject* target = Eluna::CHECKOBJ(L, 2, false); - if (target && target->IsInWorld()) + if (target) Eluna::Push(L, obj->GetAngle(target)); else { @@ -877,6 +877,207 @@ namespace LuaWorldObject return 1; } + /** + * Returns true if the [WorldObject]s are on the same map + * + * @param [WorldObject] worldobject + * @return bool isInMap + */ + int IsInMap(lua_State* L, WorldObject* obj) + { + WorldObject* target = Eluna::CHECKOBJ(L, 2, true); + Eluna::Push(L, obj->IsInMap(target)); + return 1; + } + + /** + * Returns true if the point is in the given distance of the [WorldObject] + * + * Notice that the distance is measured from the edge of the [WorldObject]. + * + * @param float x + * @param float y + * @param float z + * @param float distance + * @return bool isInDistance + */ + int IsWithinDist3d(lua_State* L, WorldObject* obj) + { + float x = Eluna::CHECKVAL(L, 2); + float y = Eluna::CHECKVAL(L, 3); + float z = Eluna::CHECKVAL(L, 4); + float dist = Eluna::CHECKVAL(L, 5); + Eluna::Push(L, obj->IsWithinDist3d(x, y, z, dist)); + return 1; + } + + /** + * Returns true if the point is in the given distance of the [WorldObject] + * + * The distance is measured only in x,y coordinates. + * Notice that the distance is measured from the edge of the [WorldObject]. + * + * @param float x + * @param float y + * @param float distance + * @return bool isInDistance + */ + int IsWithinDist2d(lua_State* L, WorldObject* obj) + { + float x = Eluna::CHECKVAL(L, 2); + float y = Eluna::CHECKVAL(L, 3); + float dist = Eluna::CHECKVAL(L, 4); + Eluna::Push(L, obj->IsWithinDist2d(x, y, dist)); + return 1; + } + + /** + * Returns true if the target is in the given distance of the [WorldObject] + * + * Notice that the distance is measured from the edge of the [WorldObject]s. + * + * @param [WorldObject] target + * @param float distance + * @param bool is3D = true : if false, only x,y coordinates used for checking + * @return bool isInDistance + */ + int IsWithinDist(lua_State* L, WorldObject* obj) + { + WorldObject* target = Eluna::CHECKOBJ(L, 2, true); + float distance = Eluna::CHECKVAL(L, 3); + float is3D = Eluna::CHECKVAL(L, 4, true); + Eluna::Push(L, obj->IsWithinDist(target, distance, is3D)); + return 1; + } + + /** + * Returns true if the [WorldObject] is on the same map and within given distance + * + * Notice that the distance is measured from the edge of the [WorldObject]s. + * + * @param [WorldObject] target + * @param float distance + * @param bool is3D = true : if false, only x,y coordinates used for checking + * @return bool isInDistance + */ + int IsWithinDistInMap(lua_State* L, WorldObject* obj) + { + WorldObject* target = Eluna::CHECKOBJ(L, 2); + float distance = Eluna::CHECKVAL(L, 3); + float is3D = Eluna::CHECKVAL(L, 4, true); + + Eluna::Push(L, obj->IsWithinDistInMap(target, distance)); + return 1; + } + + /** + * Returns true if the target is within given range + * + * Notice that the distance is measured from the edge of the [WorldObject]s. + * + * @param [WorldObject] target + * @param float minrange + * @param float maxrange + * @param bool is3D = true : if false, only x,y coordinates used for checking + * @return bool isInDistance + */ + int IsInRange(lua_State* L, WorldObject* obj) + { + WorldObject* target = Eluna::CHECKOBJ(L, 2); + float minrange = Eluna::CHECKVAL(L, 3); + float maxrange = Eluna::CHECKVAL(L, 4); + float is3D = Eluna::CHECKVAL(L, 5, true); + + Eluna::Push(L, obj->IsInRange(target, minrange, maxrange, is3D)); + return 1; + } + + /** + * Returns true if the point is within given range + * + * Notice that the distance is measured from the edge of the [WorldObject]. + * + * @param float x + * @param float y + * @param float minrange + * @param float maxrange + * @return bool isInDistance + */ + int IsInRange2d(lua_State* L, WorldObject* obj) + { + float x = Eluna::CHECKVAL(L, 2); + float y = Eluna::CHECKVAL(L, 3); + float minrange = Eluna::CHECKVAL(L, 4); + float maxrange = Eluna::CHECKVAL(L, 5); + + Eluna::Push(L, obj->IsInRange2d(x, y, minrange, maxrange)); + return 1; + } + + /** + * Returns true if the point is within given range + * + * Notice that the distance is measured from the edge of the [WorldObject]. + * + * @param float x + * @param float y + * @param float z + * @param float minrange + * @param float maxrange + * @return bool isInDistance + */ + int IsInRange3d(lua_State* L, WorldObject* obj) + { + float x = Eluna::CHECKVAL(L, 2); + float y = Eluna::CHECKVAL(L, 3); + float z = Eluna::CHECKVAL(L, 4); + float minrange = Eluna::CHECKVAL(L, 5); + float maxrange = Eluna::CHECKVAL(L, 6); + + Eluna::Push(L, obj->IsInRange3d(x, y, z, minrange, maxrange)); + return 1; + } + + /** + * Returns true if the target is in the given arc in front of the [WorldObject] + * + * @param [WorldObject] target + * @param float arc = pi + * @return bool isInFront + */ + int IsInFront(lua_State* L, WorldObject* obj) + { + WorldObject* target = Eluna::CHECKOBJ(L, 2); + float arc = Eluna::CHECKVAL(L, 3, static_cast(M_PI)); + +#ifdef MANGOS + Eluna::Push(L, obj->IsInFront(target, arc)); +#else + Eluna::Push(L, obj->isInFront(target, arc)); +#endif + return 1; + } + + /** + * Returns true if the target is in the given arc behind the [WorldObject] + * + * @param [WorldObject] target + * @param float arc = pi + * @return bool isInBack + */ + int IsInBack(lua_State* L, WorldObject* obj) + { + WorldObject* target = Eluna::CHECKOBJ(L, 2); + float arc = Eluna::CHECKVAL(L, 3, static_cast(M_PI)); + +#ifdef MANGOS + Eluna::Push(L, obj->IsInBack(target, arc)); +#else + Eluna::Push(L, obj->isInBack(target, arc)); +#endif + return 1; + } + /** * The [WorldObject] plays music to a [Player] *