mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-12 17:51:28 +00:00
Add TryMoveAlong(distance, angle)
This will take a distance you would like to move and an EQ angle you would like to move relative to current heading (so 0 is in front, 256 behind) Exported to Lua as well
This commit is contained in:
parent
7e7f5f0bd6
commit
8f66527e02
@ -282,6 +282,16 @@ void Lua_Mob::GMMove(double x, double y, double z, double heading, bool send_upd
|
||||
self->GMMove(static_cast<float>(x), static_cast<float>(y), static_cast<float>(z), static_cast<float>(heading), send_update);
|
||||
}
|
||||
|
||||
void Lua_Mob::TryMoveAlong(float distance, float angle) {
|
||||
Lua_Safe_Call_Void();
|
||||
self->TryMoveAlong(distance, angle);
|
||||
}
|
||||
|
||||
void Lua_Mob::TryMoveAlong(float distance, float angle, bool send) {
|
||||
Lua_Safe_Call_Void();
|
||||
self->TryMoveAlong(distance, angle, send);
|
||||
}
|
||||
|
||||
bool Lua_Mob::HasProcs() {
|
||||
Lua_Safe_Call_Bool();
|
||||
return self->HasProcs();
|
||||
@ -2197,6 +2207,8 @@ luabind::scope lua_register_mob() {
|
||||
.def("GMMove", (void(Lua_Mob::*)(double,double,double))&Lua_Mob::GMMove)
|
||||
.def("GMMove", (void(Lua_Mob::*)(double,double,double,double))&Lua_Mob::GMMove)
|
||||
.def("GMMove", (void(Lua_Mob::*)(double,double,double,double,bool))&Lua_Mob::GMMove)
|
||||
.def("TryMoveAlong", (void(Lua_Mob::*)(float,float))&Lua_Mob::TryMoveAlong)
|
||||
.def("TryMoveAlong", (void(Lua_Mob::*)(float,float,bool))&Lua_Mob::TryMoveAlong)
|
||||
.def("HasProcs", &Lua_Mob::HasProcs)
|
||||
.def("IsInvisible", (bool(Lua_Mob::*)(void))&Lua_Mob::IsInvisible)
|
||||
.def("IsInvisible", (bool(Lua_Mob::*)(Lua_Mob))&Lua_Mob::IsInvisible)
|
||||
|
||||
@ -74,6 +74,8 @@ public:
|
||||
void GMMove(double x, double y, double z);
|
||||
void GMMove(double x, double y, double z, double heading);
|
||||
void GMMove(double x, double y, double z, double heading, bool send_update);
|
||||
void TryMoveAlong(float distance, float heading);
|
||||
void TryMoveAlong(float distance, float heading, bool send);
|
||||
bool HasProcs();
|
||||
bool IsInvisible();
|
||||
bool IsInvisible(Lua_Mob other);
|
||||
|
||||
@ -578,6 +578,7 @@ public:
|
||||
void SetFlyMode(uint8 flymode);
|
||||
inline void Teleport(glm::vec3 NewPosition) { m_Position.x = NewPosition.x; m_Position.y = NewPosition.y;
|
||||
m_Position.z = NewPosition.z; };
|
||||
void TryMoveAlong(float distance, float angle, bool send = true);
|
||||
|
||||
//AI
|
||||
static uint32 GetLevelCon(uint8 mylevel, uint8 iOtherLevel);
|
||||
|
||||
@ -29,10 +29,13 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#include "npc.h"
|
||||
#include "quest_parser_collection.h"
|
||||
#include "water_map.h"
|
||||
#include "fastmath.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
extern FastMath g_Math;
|
||||
|
||||
struct wp_distance
|
||||
{
|
||||
float dist;
|
||||
@ -990,6 +993,35 @@ float Mob::GetZOffset() const {
|
||||
return 0.2 * GetSize() * offset;
|
||||
}
|
||||
|
||||
// This function will try to move the mob along the relative angle a set distance
|
||||
// if it can't be moved, it will lower the distance and try again
|
||||
// If we want to move on like say a spawn, we can pass send as false
|
||||
void Mob::TryMoveAlong(float distance, float angle, bool send)
|
||||
{
|
||||
angle += GetHeading();
|
||||
angle = FixHeading(angle);
|
||||
|
||||
glm::vec3 tmp_pos;
|
||||
glm::vec3 new_pos = GetPosition();
|
||||
new_pos.x += distance * g_Math.FastSin(angle);
|
||||
new_pos.y += distance * g_Math.FastCos(angle);
|
||||
new_pos.z += GetZOffset();
|
||||
|
||||
if (zone->HasMap()) {
|
||||
auto new_z = zone->zonemap->FindClosestZ(new_pos, nullptr);
|
||||
if (new_z != BEST_Z_INVALID)
|
||||
new_pos.z = new_z;
|
||||
|
||||
if (zone->zonemap->FindClosestLoS(GetPosition(), new_pos, tmp_pos))
|
||||
new_pos = tmp_pos;
|
||||
}
|
||||
|
||||
new_pos.z = GetFixedZ(new_pos);
|
||||
Teleport(new_pos);
|
||||
if (send)
|
||||
SendPositionUpdate();
|
||||
}
|
||||
|
||||
int ZoneDatabase::GetHighestGrid(uint32 zoneid) {
|
||||
|
||||
std::string query = StringFormat("SELECT COALESCE(MAX(id), 0) FROM grid WHERE zoneid = %i", zoneid);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user