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, 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, AllowCrossClassTrainers, false)
RULE_CATEGORY_END()
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);
bool partial = false;
bool error = false;
auto pathlist = zone->pathing->FindRoute(Start, End, partial, error);
bool stuck = false;
auto pathlist = zone->pathing->FindRoute(Start, End, partial, stuck);
if (pathlist.empty() || error || partial)
if (pathlist.empty() || partial)
{
EQApplicationPacket outapp(OP_FindPersonReply, 0);
QueuePacket(&outapp);

View File

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

View File

@ -445,7 +445,7 @@ Mob::Mob(const char* in_name,
AssistAggro = false;
npc_assist_cap = 0;
PathRecalcTimer.reset(new Timer(1500));
PathRecalcTimer.reset(new Timer(500));
PathingLoopCount = 0;
}
@ -1240,6 +1240,13 @@ void Mob::FillSpawnStruct(NewSpawn_Struct* ns, Mob* ForWho)
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)

View File

@ -29,7 +29,7 @@ public:
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 void DebugCommand(Client *c, const Seperator *sep) = 0;

View File

@ -33,16 +33,12 @@ PathfinderNavmesh::~PathfinderNavmesh()
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;
error = false;
if (!m_impl->nav_mesh) {
error = true;
IPath Route;
Route.push_back(end);
return Route;
return IPath();
}
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);
if (!start_ref || !end_ref) {
error = true;
IPath Route;
Route.push_back(end);
return Route;
return IPath();
}
int npoly = 0;
@ -89,6 +82,11 @@ IPathfinder::IPath PathfinderNavmesh::FindRoute(const glm::vec3 &start, const gl
if (path[npoly - 1] != end_ref) {
m_impl->query->closestPointOnPoly(path[npoly - 1], &dest_location[0], &epos[0], 0);
partial = true;
auto dist = DistanceSquared(epos, current_location);
if (dist < 10.0f) {
stuck = true;
}
}
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);
if (dtStatusFailed(status)) {
error = true;
IPath Route;
Route.push_back(end);
return Route;
return IPath();
}
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)
{
bool partial = false;
bool error = false;
auto path = FindRoute(start, end, partial, error);
bool stuck = false;
auto path = FindRoute(start, end, partial, stuck);
std::vector<FindPerson_Point> points;
if (!partial && !error) {
if (!partial) {
FindPerson_Point p;
for (auto &node : path)
{

View File

@ -9,7 +9,7 @@ public:
PathfinderNavmesh(const std::string &path);
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 void DebugCommand(Client *c, const Seperator *sep);

View File

@ -1,9 +1,9 @@
#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;
stuck = false;
IPath ret;
ret.push_back(start);
ret.push_back(end);

View File

@ -8,7 +8,7 @@ public:
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 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;
error = false;
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));
if (result_start_n.size() == 0) {
error = true;
return IPath();
}
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));
if (result_end_n.size() == 0) {
error = true;
return IPath();
}
@ -183,11 +181,7 @@ IPathfinder::IPath PathfinderWaypoint::FindRoute(const glm::vec3 &start, const g
return Route;
}
error = true;
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;
return IPath();
}
glm::vec3 PathfinderWaypoint::GetRandomLocation()
@ -401,8 +395,8 @@ void PathfinderWaypoint::ShowNodes()
void PathfinderWaypoint::ShowPath(Client *c, const glm::vec3 &start, const glm::vec3 &end)
{
bool partial = false;
bool error = false;
auto path = FindRoute(start, end, partial, error);
bool stuck = false;
auto path = FindRoute(start, end, partial, stuck);
std::vector<FindPerson_Point> points;
FindPerson_Point p;

View File

@ -11,7 +11,7 @@ public:
PathfinderWaypoint(const std::string &path);
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 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()) {
bool partial = false;
bool error = false;
Route = zone->pathing->FindRoute(From, To, partial, error);
bool stuck = false;
Route = zone->pathing->FindRoute(From, To, partial, stuck);
AdjustRoute(Route, flymode, GetModelOffset());
PathingDestination = To;
WaypointChanged = true;
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()) {
return To;
}
@ -60,14 +72,26 @@ glm::vec3 Mob::UpdatePath(float ToX, float ToY, float ToZ, float Speed, bool &Wa
if (!SameDestination) {
//We had a route but our target position moved too much
bool partial = false;
bool error = false;
Route = zone->pathing->FindRoute(From, To, partial, error);
bool stuck = false;
Route = zone->pathing->FindRoute(From, To, partial, stuck);
AdjustRoute(Route, flymode, GetModelOffset());
PathingDestination = To;
WaypointChanged = true;
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()) {
return To;
}
@ -123,12 +147,24 @@ glm::vec3 Mob::UpdatePath(float ToX, float ToY, float ToZ, float Speed, bool &Wa
if (Route.empty()) {
bool partial = false;
bool error = false;
Route = zone->pathing->FindRoute(From, To, partial, error);
bool stuck = false;
Route = zone->pathing->FindRoute(From, To, partial, stuck);
AdjustRoute(Route, flymode, GetModelOffset());
PathingDestination = To;
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()) {
return To;
}