Add custom feature, cross-class skill trainer, fix up stuck detection and added a better solution to it.

This commit is contained in:
KimLS 2017-09-09 00:24:30 -07:00
parent 1a4aa1692a
commit ccdebf0116
12 changed files with 92 additions and 53 deletions

View File

@ -151,6 +151,7 @@ RULE_BOOL(Character, UseOldBindWound, false) // Uses the original bind wound beh
RULE_BOOL(Character, GrantHoTTOnCreate, false) // Grant Health of Target's Target leadership AA on character creation RULE_BOOL(Character, GrantHoTTOnCreate, false) // Grant Health of Target's Target leadership AA on character creation
RULE_BOOL(Character, UseOldConSystem, false) // Grant Health of Target's Target leadership AA on character creation RULE_BOOL(Character, UseOldConSystem, false) // Grant Health of Target's Target leadership AA on character creation
RULE_BOOL(Character, OPClientUpdateVisualDebug, false) // Shows a pulse and forward directional particle each time the client sends its position to server RULE_BOOL(Character, OPClientUpdateVisualDebug, false) // Shows a pulse and forward directional particle each time the client sends its position to server
RULE_BOOL(Character, AllowCrossClassTrainers, false)
RULE_CATEGORY_END() RULE_CATEGORY_END()
RULE_CATEGORY(Mercs) RULE_CATEGORY(Mercs)

View File

@ -5750,10 +5750,10 @@ void Client::Handle_OP_FindPersonRequest(const EQApplicationPacket *app)
glm::vec3 End(target->GetX(), target->GetY(), target->GetZ() + (target->GetSize() < 6.0 ? 6 : target->GetSize()) * HEAD_POSITION); glm::vec3 End(target->GetX(), target->GetY(), target->GetZ() + (target->GetSize() < 6.0 ? 6 : target->GetSize()) * HEAD_POSITION);
bool partial = false; bool partial = false;
bool error = false; bool stuck = false;
auto pathlist = zone->pathing->FindRoute(Start, End, partial, error); auto pathlist = zone->pathing->FindRoute(Start, End, partial, stuck);
if (pathlist.empty() || error || partial) if (pathlist.empty() || partial)
{ {
EQApplicationPacket outapp(OP_FindPersonReply, 0); EQApplicationPacket outapp(OP_FindPersonReply, 0);
QueuePacket(&outapp); QueuePacket(&outapp);

View File

@ -1527,9 +1527,11 @@ void Client::OPGMTraining(const EQApplicationPacket *app)
return; return;
//you can only use your own trainer, client enforces this, but why trust it //you can only use your own trainer, client enforces this, but why trust it
if (!RuleB(Character, AllowCrossClassTrainers)) {
int trains_class = pTrainer->GetClass() - (WARRIORGM - WARRIOR); int trains_class = pTrainer->GetClass() - (WARRIORGM - WARRIOR);
if(GetClass() != trains_class) if (GetClass() != trains_class)
return; return;
}
//you have to be somewhat close to a trainer to be properly using them //you have to be somewhat close to a trainer to be properly using them
if(DistanceSquared(m_Position,pTrainer->GetPosition()) > USE_NPC_RANGE2) if(DistanceSquared(m_Position,pTrainer->GetPosition()) > USE_NPC_RANGE2)
@ -1580,9 +1582,11 @@ void Client::OPGMEndTraining(const EQApplicationPacket *app)
return; return;
//you can only use your own trainer, client enforces this, but why trust it //you can only use your own trainer, client enforces this, but why trust it
if (!RuleB(Character, AllowCrossClassTrainers)) {
int trains_class = pTrainer->GetClass() - (WARRIORGM - WARRIOR); int trains_class = pTrainer->GetClass() - (WARRIORGM - WARRIOR);
if(GetClass() != trains_class) if (GetClass() != trains_class)
return; return;
}
//you have to be somewhat close to a trainer to be properly using them //you have to be somewhat close to a trainer to be properly using them
if(DistanceSquared(m_Position, pTrainer->GetPosition()) > USE_NPC_RANGE2) if(DistanceSquared(m_Position, pTrainer->GetPosition()) > USE_NPC_RANGE2)
@ -1609,9 +1613,11 @@ void Client::OPGMTrainSkill(const EQApplicationPacket *app)
return; return;
//you can only use your own trainer, client enforces this, but why trust it //you can only use your own trainer, client enforces this, but why trust it
if (!RuleB(Character, AllowCrossClassTrainers)) {
int trains_class = pTrainer->GetClass() - (WARRIORGM - WARRIOR); int trains_class = pTrainer->GetClass() - (WARRIORGM - WARRIOR);
if(GetClass() != trains_class) if (GetClass() != trains_class)
return; return;
}
//you have to be somewhat close to a trainer to be properly using them //you have to be somewhat close to a trainer to be properly using them
if(DistanceSquared(m_Position, pTrainer->GetPosition()) > USE_NPC_RANGE2) if(DistanceSquared(m_Position, pTrainer->GetPosition()) > USE_NPC_RANGE2)

View File

@ -445,7 +445,7 @@ Mob::Mob(const char* in_name,
AssistAggro = false; AssistAggro = false;
npc_assist_cap = 0; npc_assist_cap = 0;
PathRecalcTimer.reset(new Timer(1500)); PathRecalcTimer.reset(new Timer(500));
PathingLoopCount = 0; PathingLoopCount = 0;
} }
@ -1240,6 +1240,13 @@ void Mob::FillSpawnStruct(NewSpawn_Struct* ns, Mob* ForWho)
ns->spawn.flymode = 0; ns->spawn.flymode = 0;
} }
if (RuleB(Character, AllowCrossClassTrainers) && ForWho) {
if (ns->spawn.class_ >= WARRIORGM && ns->spawn.class_ <= BERSERKERGM) {
int trainer_class = WARRIORGM + (ForWho->GetClass() - 1);
ns->spawn.class_ = trainer_class;
}
}
} }
void Mob::CreateDespawnPacket(EQApplicationPacket* app, bool Decay) void Mob::CreateDespawnPacket(EQApplicationPacket* app, bool Decay)

View File

@ -29,7 +29,7 @@ public:
IPathfinder() { } IPathfinder() { }
virtual ~IPathfinder() { } virtual ~IPathfinder() { }
virtual IPath FindRoute(const glm::vec3 &start, const glm::vec3 &end, bool &partial, bool &error) = 0; virtual IPath FindRoute(const glm::vec3 &start, const glm::vec3 &end, bool &partial, bool &stuck) = 0;
virtual glm::vec3 GetRandomLocation() = 0; virtual glm::vec3 GetRandomLocation() = 0;
virtual void DebugCommand(Client *c, const Seperator *sep) = 0; virtual void DebugCommand(Client *c, const Seperator *sep) = 0;

View File

@ -33,16 +33,12 @@ PathfinderNavmesh::~PathfinderNavmesh()
Clear(); Clear();
} }
IPathfinder::IPath PathfinderNavmesh::FindRoute(const glm::vec3 &start, const glm::vec3 &end, bool &partial, bool &error) IPathfinder::IPath PathfinderNavmesh::FindRoute(const glm::vec3 &start, const glm::vec3 &end, bool &partial, bool &stuck)
{ {
partial = false; partial = false;
error = false;
if (!m_impl->nav_mesh) { if (!m_impl->nav_mesh) {
error = true; return IPath();
IPath Route;
Route.push_back(end);
return Route;
} }
if (!m_impl->query) { if (!m_impl->query) {
@ -74,10 +70,7 @@ IPathfinder::IPath PathfinderNavmesh::FindRoute(const glm::vec3 &start, const gl
m_impl->query->findNearestPoly(&dest_location[0], &ext[0], &filter, &end_ref, 0); m_impl->query->findNearestPoly(&dest_location[0], &ext[0], &filter, &end_ref, 0);
if (!start_ref || !end_ref) { if (!start_ref || !end_ref) {
error = true; return IPath();
IPath Route;
Route.push_back(end);
return Route;
} }
int npoly = 0; int npoly = 0;
@ -89,6 +82,11 @@ IPathfinder::IPath PathfinderNavmesh::FindRoute(const glm::vec3 &start, const gl
if (path[npoly - 1] != end_ref) { if (path[npoly - 1] != end_ref) {
m_impl->query->closestPointOnPoly(path[npoly - 1], &dest_location[0], &epos[0], 0); m_impl->query->closestPointOnPoly(path[npoly - 1], &dest_location[0], &epos[0], 0);
partial = true; partial = true;
auto dist = DistanceSquared(epos, current_location);
if (dist < 10.0f) {
stuck = true;
}
} }
float straight_path[2048 * 3]; float straight_path[2048 * 3];
@ -102,10 +100,7 @@ IPathfinder::IPath PathfinderNavmesh::FindRoute(const glm::vec3 &start, const gl
straight_path_polys, &n_straight_polys, 2048, DT_STRAIGHTPATH_AREA_CROSSINGS); straight_path_polys, &n_straight_polys, 2048, DT_STRAIGHTPATH_AREA_CROSSINGS);
if (dtStatusFailed(status)) { if (dtStatusFailed(status)) {
error = true; return IPath();
IPath Route;
Route.push_back(end);
return Route;
} }
if (n_straight_polys) { if (n_straight_polys) {
@ -292,11 +287,11 @@ void PathfinderNavmesh::Load(const std::string &path)
void PathfinderNavmesh::ShowPath(Client * c, const glm::vec3 &start, const glm::vec3 &end) void PathfinderNavmesh::ShowPath(Client * c, const glm::vec3 &start, const glm::vec3 &end)
{ {
bool partial = false; bool partial = false;
bool error = false; bool stuck = false;
auto path = FindRoute(start, end, partial, error); auto path = FindRoute(start, end, partial, stuck);
std::vector<FindPerson_Point> points; std::vector<FindPerson_Point> points;
if (!partial && !error) { if (!partial) {
FindPerson_Point p; FindPerson_Point p;
for (auto &node : path) for (auto &node : path)
{ {

View File

@ -9,7 +9,7 @@ public:
PathfinderNavmesh(const std::string &path); PathfinderNavmesh(const std::string &path);
virtual ~PathfinderNavmesh(); virtual ~PathfinderNavmesh();
virtual IPath FindRoute(const glm::vec3 &start, const glm::vec3 &end, bool &partial, bool &error); virtual IPath FindRoute(const glm::vec3 &start, const glm::vec3 &end, bool &partial, bool &stuck);
virtual glm::vec3 GetRandomLocation(); virtual glm::vec3 GetRandomLocation();
virtual void DebugCommand(Client *c, const Seperator *sep); virtual void DebugCommand(Client *c, const Seperator *sep);

View File

@ -1,9 +1,9 @@
#include "pathfinder_null.h" #include "pathfinder_null.h"
IPathfinder::IPath PathfinderNull::FindRoute(const glm::vec3 &start, const glm::vec3 &end, bool &partial, bool &error) IPathfinder::IPath PathfinderNull::FindRoute(const glm::vec3 &start, const glm::vec3 &end, bool &partial, bool &stuck)
{ {
error = false;
partial = false; partial = false;
stuck = false;
IPath ret; IPath ret;
ret.push_back(start); ret.push_back(start);
ret.push_back(end); ret.push_back(end);

View File

@ -8,7 +8,7 @@ public:
PathfinderNull() { } PathfinderNull() { }
virtual ~PathfinderNull() { } virtual ~PathfinderNull() { }
virtual IPath FindRoute(const glm::vec3 &start, const glm::vec3 &end, bool &partial, bool &error); virtual IPath FindRoute(const glm::vec3 &start, const glm::vec3 &end, bool &partial, bool &stuck);
virtual glm::vec3 GetRandomLocation(); virtual glm::vec3 GetRandomLocation();
virtual void DebugCommand(Client *c, const Seperator *sep) { } virtual void DebugCommand(Client *c, const Seperator *sep) { }
}; };

View File

@ -114,21 +114,19 @@ PathfinderWaypoint::~PathfinderWaypoint()
{ {
} }
IPathfinder::IPath PathfinderWaypoint::FindRoute(const glm::vec3 &start, const glm::vec3 &end, bool &partial, bool &error) IPathfinder::IPath PathfinderWaypoint::FindRoute(const glm::vec3 &start, const glm::vec3 &end, bool &partial, bool &stuck)
{ {
stuck = false;
partial = false; partial = false;
error = false;
std::vector<RTreeValue> result_start_n; std::vector<RTreeValue> result_start_n;
m_impl->Tree.query(boost::geometry::index::nearest(Point(start.x, start.y, start.z), 1), std::back_inserter(result_start_n)); m_impl->Tree.query(boost::geometry::index::nearest(Point(start.x, start.y, start.z), 1), std::back_inserter(result_start_n));
if (result_start_n.size() == 0) { if (result_start_n.size() == 0) {
error = true;
return IPath(); return IPath();
} }
std::vector<RTreeValue> result_end_n; std::vector<RTreeValue> result_end_n;
m_impl->Tree.query(boost::geometry::index::nearest(Point(end.x, end.y, end.z), 1), std::back_inserter(result_end_n)); m_impl->Tree.query(boost::geometry::index::nearest(Point(end.x, end.y, end.z), 1), std::back_inserter(result_end_n));
if (result_end_n.size() == 0) { if (result_end_n.size() == 0) {
error = true;
return IPath(); return IPath();
} }
@ -183,11 +181,7 @@ IPathfinder::IPath PathfinderWaypoint::FindRoute(const glm::vec3 &start, const g
return Route; return Route;
} }
error = true; return IPath();
IPath Route;
Route.push_front(start);
Route.push_back(glm::vec3(nearest_start.first.get<0>(), nearest_start.first.get<1>(), nearest_start.first.get<2>()));
return Route;
} }
glm::vec3 PathfinderWaypoint::GetRandomLocation() glm::vec3 PathfinderWaypoint::GetRandomLocation()
@ -401,8 +395,8 @@ void PathfinderWaypoint::ShowNodes()
void PathfinderWaypoint::ShowPath(Client *c, const glm::vec3 &start, const glm::vec3 &end) void PathfinderWaypoint::ShowPath(Client *c, const glm::vec3 &start, const glm::vec3 &end)
{ {
bool partial = false; bool partial = false;
bool error = false; bool stuck = false;
auto path = FindRoute(start, end, partial, error); auto path = FindRoute(start, end, partial, stuck);
std::vector<FindPerson_Point> points; std::vector<FindPerson_Point> points;
FindPerson_Point p; FindPerson_Point p;

View File

@ -11,7 +11,7 @@ public:
PathfinderWaypoint(const std::string &path); PathfinderWaypoint(const std::string &path);
virtual ~PathfinderWaypoint(); virtual ~PathfinderWaypoint();
virtual IPath FindRoute(const glm::vec3 &start, const glm::vec3 &end, bool &partial, bool &error); virtual IPath FindRoute(const glm::vec3 &start, const glm::vec3 &end, bool &partial, bool &stuck);
virtual glm::vec3 GetRandomLocation(); virtual glm::vec3 GetRandomLocation();
virtual void DebugCommand(Client *c, const Seperator *sep); virtual void DebugCommand(Client *c, const Seperator *sep);

View File

@ -40,13 +40,25 @@ glm::vec3 Mob::UpdatePath(float ToX, float ToY, float ToZ, float Speed, bool &Wa
if (Route.empty()) { if (Route.empty()) {
bool partial = false; bool partial = false;
bool error = false; bool stuck = false;
Route = zone->pathing->FindRoute(From, To, partial, error); Route = zone->pathing->FindRoute(From, To, partial, stuck);
AdjustRoute(Route, flymode, GetModelOffset()); AdjustRoute(Route, flymode, GetModelOffset());
PathingDestination = To; PathingDestination = To;
WaypointChanged = true; WaypointChanged = true;
NodeReached = false; NodeReached = false;
if (stuck) {
bool partial = false;
bool stuck = false;
auto r = zone->pathing->FindRoute(To, From, partial, stuck);
Route.clear();
auto final_node = r.back();
Route.push_back(final_node);
AdjustRoute(Route, flymode, GetModelOffset());
return (*Route.begin()).pos;
}
if (Route.empty()) { if (Route.empty()) {
return To; return To;
} }
@ -60,14 +72,26 @@ glm::vec3 Mob::UpdatePath(float ToX, float ToY, float ToZ, float Speed, bool &Wa
if (!SameDestination) { if (!SameDestination) {
//We had a route but our target position moved too much //We had a route but our target position moved too much
bool partial = false; bool partial = false;
bool error = false; bool stuck = false;
Route = zone->pathing->FindRoute(From, To, partial, error); Route = zone->pathing->FindRoute(From, To, partial, stuck);
AdjustRoute(Route, flymode, GetModelOffset()); AdjustRoute(Route, flymode, GetModelOffset());
PathingDestination = To; PathingDestination = To;
WaypointChanged = true; WaypointChanged = true;
NodeReached = false; NodeReached = false;
if (stuck) {
bool partial = false;
bool stuck = false;
auto r = zone->pathing->FindRoute(To, From, partial, stuck);
Route.clear();
auto final_node = r.back();
Route.push_back(final_node);
AdjustRoute(Route, flymode, GetModelOffset());
return (*Route.begin()).pos;
}
if (Route.empty()) { if (Route.empty()) {
return To; return To;
} }
@ -123,12 +147,24 @@ glm::vec3 Mob::UpdatePath(float ToX, float ToY, float ToZ, float Speed, bool &Wa
if (Route.empty()) { if (Route.empty()) {
bool partial = false; bool partial = false;
bool error = false; bool stuck = false;
Route = zone->pathing->FindRoute(From, To, partial, error); Route = zone->pathing->FindRoute(From, To, partial, stuck);
AdjustRoute(Route, flymode, GetModelOffset()); AdjustRoute(Route, flymode, GetModelOffset());
PathingDestination = To; PathingDestination = To;
WaypointChanged = true; WaypointChanged = true;
if (stuck) {
bool partial = false;
bool stuck = false;
auto r = zone->pathing->FindRoute(To, From, partial, stuck);
Route.clear();
auto final_node = r.back();
Route.push_back(final_node);
AdjustRoute(Route, flymode, GetModelOffset());
return (*Route.begin()).pos;
}
if(Route.empty()) { if(Route.empty()) {
return To; return To;
} }