mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-12 13:41:31 +00:00
Fix, cleanup and simplify the roambox logic and cleanup a bunch of other related code
This commit is contained in:
parent
7cc5b143fc
commit
4b6ab34fd9
@ -90,6 +90,7 @@ enum LogCategory {
|
||||
FixZ,
|
||||
Food,
|
||||
Traps,
|
||||
NPCRoamBox,
|
||||
MaxCategoryID /* Don't Remove this*/
|
||||
};
|
||||
|
||||
@ -144,7 +145,8 @@ static const char* LogCategoryName[LogCategory::MaxCategoryID] = {
|
||||
"HP Update",
|
||||
"FixZ",
|
||||
"Food",
|
||||
"Traps"
|
||||
"Traps",
|
||||
"NPC Roam Box"
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -3425,14 +3425,15 @@ void EntityList::ProcessMove(Client *c, const glm::vec3& location)
|
||||
}
|
||||
}
|
||||
|
||||
void EntityList::ProcessMove(NPC *n, float x, float y, float z)
|
||||
{
|
||||
void EntityList::ProcessMove(NPC *n, float x, float y, float z) {
|
||||
float last_x = n->GetX();
|
||||
float last_y = n->GetY();
|
||||
float last_z = n->GetZ();
|
||||
|
||||
std::list<quest_proximity_event> events;
|
||||
|
||||
for (auto iter = area_list.begin(); iter != area_list.end(); ++iter) {
|
||||
|
||||
Area &a = (*iter);
|
||||
bool old_in = true;
|
||||
bool new_in = true;
|
||||
@ -3457,7 +3458,8 @@ void EntityList::ProcessMove(NPC *n, float x, float y, float z)
|
||||
evt.area_id = a.id;
|
||||
evt.area_type = a.type;
|
||||
events.push_back(evt);
|
||||
} else if (!old_in && new_in) {
|
||||
}
|
||||
else if (!old_in && new_in) {
|
||||
//were not in but now are
|
||||
quest_proximity_event evt;
|
||||
evt.event_id = EVENT_ENTER_AREA;
|
||||
|
||||
@ -1481,8 +1481,14 @@ void Merc::AI_Process() {
|
||||
if (RuleB(Mercs, MercsUsePathing) && zone->pathing) {
|
||||
bool WaypointChanged, NodeReached;
|
||||
|
||||
glm::vec3 Goal = UpdatePath(GetTarget()->GetX(), GetTarget()->GetY(), GetTarget()->GetZ(),
|
||||
GetRunspeed(), WaypointChanged, NodeReached);
|
||||
glm::vec3 Goal = UpdatePath(
|
||||
GetTarget()->GetX(),
|
||||
GetTarget()->GetY(),
|
||||
GetTarget()->GetZ(),
|
||||
GetRunspeed(),
|
||||
WaypointChanged,
|
||||
NodeReached
|
||||
);
|
||||
|
||||
if (WaypointChanged)
|
||||
tar_ndx = 20;
|
||||
|
||||
@ -981,7 +981,7 @@ public:
|
||||
|
||||
inline bool CheckAggro(Mob* other) {return hate_list.IsEntOnHateList(other);}
|
||||
float CalculateHeadingToTarget(float in_x, float in_y) { return HeadingAngleToMob(in_x, in_y); }
|
||||
virtual bool CalculateNewPosition(float x, float y, float z, int speed, bool checkZ = true, bool calcheading = true);
|
||||
virtual bool CalculateNewPosition(float x, float y, float z, float speed, bool check_z = true, bool calculate_heading = true);
|
||||
float CalculateDistance(float x, float y, float z);
|
||||
float GetGroundZ(float new_x, float new_y, float z_offset=0.0);
|
||||
void SendTo(float new_x, float new_y, float new_z);
|
||||
@ -989,7 +989,7 @@ public:
|
||||
float GetZOffset() const;
|
||||
float GetDefaultRaceSize() const;
|
||||
void FixZ(int32 z_find_offset = 5);
|
||||
float GetFixedZ(glm::vec3 position, int32 z_find_offset = 5);
|
||||
float GetFixedZ(glm::vec3 destination, int32 z_find_offset = 5);
|
||||
|
||||
void NPCSpecialAttacks(const char* parse, int permtag, bool reset = true, bool remove = false);
|
||||
inline uint32 DontHealMeBefore() const { return pDontHealMeBefore; }
|
||||
@ -1165,7 +1165,7 @@ protected:
|
||||
int _GetWalkSpeed() const;
|
||||
int _GetRunSpeed() const;
|
||||
int _GetFearSpeed() const;
|
||||
virtual bool MakeNewPositionAndSendUpdate(float x, float y, float z, int speed, bool checkZ = true, bool calcHeading = true);
|
||||
virtual bool MakeNewPositionAndSendUpdate(float x, float y, float z, float speed, bool check_z = true, bool calculate_heading = true);
|
||||
|
||||
virtual bool AI_EngagedCastCheck() { return(false); }
|
||||
virtual bool AI_PursueCastCheck() { return(false); }
|
||||
@ -1443,7 +1443,7 @@ protected:
|
||||
std::unique_ptr<Timer> AI_feign_remember_timer;
|
||||
std::unique_ptr<Timer> AI_check_signal_timer;
|
||||
std::unique_ptr<Timer> AI_scan_door_open_timer;
|
||||
uint32 pLastFightingDelayMoving;
|
||||
uint32 time_until_can_move;
|
||||
HateList hate_list;
|
||||
std::set<uint32> feign_memory_list;
|
||||
// This is to keep track of mobs we cast faction mod spells on
|
||||
|
||||
391
zone/mob_ai.cpp
391
zone/mob_ai.cpp
@ -30,6 +30,7 @@
|
||||
#include "string_ids.h"
|
||||
#include "water_map.h"
|
||||
#include "fastmath.h"
|
||||
#include "../common/data_verification.h"
|
||||
|
||||
#include <glm/gtx/projection.hpp>
|
||||
#include <algorithm>
|
||||
@ -459,8 +460,8 @@ void NPC::AI_Init()
|
||||
roambox_min_x = 0;
|
||||
roambox_min_y = 0;
|
||||
roambox_distance = 0;
|
||||
roambox_movingto_x = 0;
|
||||
roambox_movingto_y = 0;
|
||||
roambox_destination_x = 0;
|
||||
roambox_destination_y = 0;
|
||||
roambox_min_delay = 2500;
|
||||
roambox_delay = 2500;
|
||||
}
|
||||
@ -476,9 +477,9 @@ void Mob::AI_Start(uint32 iMoveDelay) {
|
||||
return;
|
||||
|
||||
if (iMoveDelay)
|
||||
pLastFightingDelayMoving = Timer::GetCurrentTime() + iMoveDelay;
|
||||
time_until_can_move = Timer::GetCurrentTime() + iMoveDelay;
|
||||
else
|
||||
pLastFightingDelayMoving = 0;
|
||||
time_until_can_move = 0;
|
||||
|
||||
pAIControlled = true;
|
||||
AI_think_timer = std::unique_ptr<Timer>(new Timer(AIthink_duration));
|
||||
@ -1098,10 +1099,10 @@ void Mob::AI_Process() {
|
||||
//
|
||||
if (RuleB(Combat, EnableFearPathing)) {
|
||||
if (currently_fleeing) {
|
||||
if((IsRooted() || (IsBlind() && CombatRange(hate_list.GetClosestEntOnHateList(this)))) && !IsPetStop() && !IsPetRegroup()) {
|
||||
if ((IsRooted() || (IsBlind() && CombatRange(hate_list.GetClosestEntOnHateList(this)))) && !IsPetStop() &&
|
||||
!IsPetRegroup()) {
|
||||
//make sure everybody knows were not moving, for appearance sake
|
||||
if(IsMoving())
|
||||
{
|
||||
if (IsMoving()) {
|
||||
if (target)
|
||||
SetHeading(CalculateHeadingToTarget(target->GetX(), target->GetY()));
|
||||
SetCurrentSpeed(0);
|
||||
@ -1109,7 +1110,8 @@ void Mob::AI_Process() {
|
||||
}
|
||||
//continue on to attack code, ensuring that we execute the engaged code
|
||||
engaged = true;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if (AI_movement_timer->Check()) {
|
||||
// Check if we have reached the last fear point
|
||||
if ((std::abs(GetX() - m_FearWalkTarget.x) < 0.1) &&
|
||||
@ -1117,16 +1119,22 @@ void Mob::AI_Process() {
|
||||
// Calculate a new point to run to
|
||||
CalculateNewFearpoint();
|
||||
}
|
||||
if(!RuleB(Pathing, Fear) || !zone->pathing)
|
||||
{
|
||||
CalculateNewPosition(m_FearWalkTarget.x, m_FearWalkTarget.y, m_FearWalkTarget.z, GetFearSpeed(), true);
|
||||
if (!RuleB(Pathing, Fear) || !zone->pathing) {
|
||||
CalculateNewPosition(
|
||||
m_FearWalkTarget.x,
|
||||
m_FearWalkTarget.y,
|
||||
m_FearWalkTarget.z,
|
||||
GetFearSpeed(),
|
||||
true
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
bool WaypointChanged, NodeReached;
|
||||
|
||||
glm::vec3 Goal = UpdatePath(m_FearWalkTarget.x, m_FearWalkTarget.y, m_FearWalkTarget.z,
|
||||
GetFearSpeed(), WaypointChanged, NodeReached);
|
||||
glm::vec3 Goal = UpdatePath(
|
||||
m_FearWalkTarget.x, m_FearWalkTarget.y, m_FearWalkTarget.z,
|
||||
GetFearSpeed(), WaypointChanged, NodeReached
|
||||
);
|
||||
|
||||
if (WaypointChanged)
|
||||
tar_ndx = 20;
|
||||
@ -1183,10 +1191,8 @@ void Mob::AI_Process() {
|
||||
// from above, so no extra blind checks needed
|
||||
if ((IsRooted() && !GetSpecialAbility(IGNORE_ROOT_AGGRO_RULES)) || IsBlind())
|
||||
SetTarget(hate_list.GetClosestEntOnHateList(this));
|
||||
else
|
||||
{
|
||||
if (AI_target_check_timer->Check())
|
||||
{
|
||||
else {
|
||||
if (AI_target_check_timer->Check()) {
|
||||
if (IsFocused()) {
|
||||
if (!target) {
|
||||
SetTarget(hate_list.GetEntWithMostHateOnList(this));
|
||||
@ -1248,21 +1254,16 @@ void Mob::AI_Process() {
|
||||
|
||||
bool is_combat_range = CombatRange(target);
|
||||
|
||||
if (is_combat_range)
|
||||
{
|
||||
if (AI_movement_timer->Check())
|
||||
{
|
||||
if (CalculateHeadingToTarget(GetTarget()->GetX(), GetTarget()->GetY()) != m_Position.w)
|
||||
{
|
||||
if (is_combat_range) {
|
||||
if (AI_movement_timer->Check()) {
|
||||
if (CalculateHeadingToTarget(GetTarget()->GetX(), GetTarget()->GetY()) != m_Position.w) {
|
||||
SetHeading(CalculateHeadingToTarget(GetTarget()->GetX(), GetTarget()->GetY()));
|
||||
SendPosition();
|
||||
}
|
||||
SetCurrentSpeed(0);
|
||||
}
|
||||
if (IsMoving())
|
||||
{
|
||||
if (CalculateHeadingToTarget(GetTarget()->GetX(), GetTarget()->GetY()) != m_Position.w)
|
||||
{
|
||||
if (IsMoving()) {
|
||||
if (CalculateHeadingToTarget(GetTarget()->GetX(), GetTarget()->GetY()) != m_Position.w) {
|
||||
SetHeading(CalculateHeadingToTarget(GetTarget()->GetX(), GetTarget()->GetY()));
|
||||
SendPosition();
|
||||
}
|
||||
@ -1330,16 +1331,17 @@ void Mob::AI_Process() {
|
||||
}
|
||||
|
||||
if ((IsPet() || IsTempPet()) && IsPetOwnerClient()) {
|
||||
if (spellbonuses.PC_Pet_Rampage[0] || itembonuses.PC_Pet_Rampage[0] || aabonuses.PC_Pet_Rampage[0]) {
|
||||
int chance = spellbonuses.PC_Pet_Rampage[0] + itembonuses.PC_Pet_Rampage[0] + aabonuses.PC_Pet_Rampage[0];
|
||||
if (spellbonuses.PC_Pet_Rampage[0] || itembonuses.PC_Pet_Rampage[0] ||
|
||||
aabonuses.PC_Pet_Rampage[0]) {
|
||||
int chance = spellbonuses.PC_Pet_Rampage[0] + itembonuses.PC_Pet_Rampage[0] +
|
||||
aabonuses.PC_Pet_Rampage[0];
|
||||
if (zone->random.Roll(chance)) {
|
||||
Rampage(nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (GetSpecialAbility(SPECATK_RAMPAGE) && !specialed)
|
||||
{
|
||||
if (GetSpecialAbility(SPECATK_RAMPAGE) && !specialed) {
|
||||
int rampage_chance = GetSpecialAbilityParam(SPECATK_RAMPAGE, 0);
|
||||
rampage_chance = rampage_chance > 0 ? rampage_chance : 20;
|
||||
if (zone->random.Roll(rampage_chance)) {
|
||||
@ -1373,8 +1375,7 @@ void Mob::AI_Process() {
|
||||
}
|
||||
}
|
||||
|
||||
if (GetSpecialAbility(SPECATK_AREA_RAMPAGE) && !specialed)
|
||||
{
|
||||
if (GetSpecialAbility(SPECATK_AREA_RAMPAGE) && !specialed) {
|
||||
int rampage_chance = GetSpecialAbilityParam(SPECATK_AREA_RAMPAGE, 0);
|
||||
rampage_chance = rampage_chance > 0 ? rampage_chance : 20;
|
||||
if (zone->random.Roll(rampage_chance)) {
|
||||
@ -1434,7 +1435,7 @@ void Mob::AI_Process() {
|
||||
Heal();
|
||||
BuffFadeAll();
|
||||
AI_walking_timer->Start(100);
|
||||
pLastFightingDelayMoving = Timer::GetCurrentTime();
|
||||
time_until_can_move = Timer::GetCurrentTime();
|
||||
return;
|
||||
}
|
||||
else if (tar != nullptr) {
|
||||
@ -1445,8 +1446,7 @@ void Mob::AI_Process() {
|
||||
}
|
||||
|
||||
// See if we can summon the mob to us
|
||||
if (!HateSummon())
|
||||
{
|
||||
if (!HateSummon()) {
|
||||
//could not summon them, check ranged...
|
||||
if (GetSpecialAbility(SPECATK_RANGED_ATK))
|
||||
doranged = true;
|
||||
@ -1456,18 +1456,18 @@ void Mob::AI_Process() {
|
||||
if (AI_PursueCastCheck()) {
|
||||
//we did something, so do not process movement.
|
||||
}
|
||||
else if (AI_movement_timer->Check() && target)
|
||||
{
|
||||
else if (AI_movement_timer->Check() && target) {
|
||||
if (!IsRooted()) {
|
||||
Log(Logs::Detail, Logs::AI, "Pursuing %s while engaged.", target->GetName());
|
||||
if (!RuleB(Pathing, Aggro) || !zone->pathing)
|
||||
CalculateNewPosition(target->GetX(), target->GetY(), target->GetZ(), GetRunspeed());
|
||||
else
|
||||
{
|
||||
else {
|
||||
bool WaypointChanged, NodeReached;
|
||||
|
||||
glm::vec3 Goal = UpdatePath(target->GetX(), target->GetY(), target->GetZ(),
|
||||
GetRunspeed(), WaypointChanged, NodeReached);
|
||||
glm::vec3 Goal = UpdatePath(
|
||||
target->GetX(), target->GetY(), target->GetZ(),
|
||||
GetRunspeed(), WaypointChanged, NodeReached
|
||||
);
|
||||
|
||||
if (WaypointChanged)
|
||||
tar_ndx = 20;
|
||||
@ -1503,58 +1503,53 @@ void Mob::AI_Process() {
|
||||
if (remember_client == nullptr) {
|
||||
//they are gone now...
|
||||
RememberedCharID = feign_memory_list.erase(RememberedCharID);
|
||||
} else if (!remember_client->GetFeigned()) {
|
||||
}
|
||||
else if (!remember_client->GetFeigned()) {
|
||||
AddToHateList(remember_client->CastToMob(), 1);
|
||||
RememberedCharID = feign_memory_list.erase(RememberedCharID);
|
||||
break;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
//they are still feigned, carry on...
|
||||
++RememberedCharID;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (AI_IdleCastCheck())
|
||||
{
|
||||
if (AI_IdleCastCheck()) {
|
||||
//we processed a spell action, so do nothing else.
|
||||
}
|
||||
else if (zone->CanDoCombat() && CastToNPC()->WillAggroNPCs() && AI_scan_area_timer->Check())
|
||||
{
|
||||
else if (zone->CanDoCombat() && CastToNPC()->WillAggroNPCs() && AI_scan_area_timer->Check()) {
|
||||
|
||||
/*
|
||||
* NPC to NPC aggro checking, npc needs npc_aggro flag
|
||||
*/
|
||||
|
||||
Mob *temp_target = entity_list.AICheckNPCtoNPCAggro(this, GetAggroRange(), GetAssistRange());
|
||||
if (temp_target) {
|
||||
AddToHateList(temp_target);
|
||||
}
|
||||
|
||||
AI_scan_area_timer->Disable();
|
||||
AI_scan_area_timer->Start(RandomTimer(RuleI(NPC, NPCToNPCAggroTimerMin), RuleI(NPC, NPCToNPCAggroTimerMax)), false);
|
||||
AI_scan_area_timer->Start(
|
||||
RandomTimer(RuleI(NPC, NPCToNPCAggroTimerMin), RuleI(NPC, NPCToNPCAggroTimerMax)),
|
||||
false
|
||||
);
|
||||
|
||||
}
|
||||
else if (AI_movement_timer->Check() && !IsRooted())
|
||||
{
|
||||
if (IsPet())
|
||||
{
|
||||
else if (AI_movement_timer->Check() && !IsRooted()) {
|
||||
if (IsPet()) {
|
||||
// we're a pet, do as we're told
|
||||
switch (pStandingPetOrder)
|
||||
{
|
||||
case SPO_Follow:
|
||||
{
|
||||
switch (pStandingPetOrder) {
|
||||
case SPO_Follow: {
|
||||
|
||||
Mob *owner = GetOwner();
|
||||
if (owner == nullptr)
|
||||
break;
|
||||
|
||||
//if(owner->IsClient())
|
||||
// printf("Pet start pos: (%f, %f, %f)\n", GetX(), GetY(), GetZ());
|
||||
|
||||
glm::vec4 ownerPos = owner->GetPosition();
|
||||
float dist = DistanceSquared(m_Position, ownerPos);
|
||||
float distz = ownerPos.z - m_Position.z;
|
||||
|
||||
if (dist >= 400 || distz > 100)
|
||||
{
|
||||
if (dist >= 400 || distz > 100) {
|
||||
int speed = GetWalkspeed();
|
||||
if (dist >= 1225) // 35
|
||||
speed = GetRunspeed();
|
||||
@ -1565,44 +1560,25 @@ void Mob::AI_Process() {
|
||||
SendPositionUpdate();
|
||||
moved = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
CalculateNewPosition(owner->GetX(), owner->GetY(), owner->GetZ(), speed);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(moved)
|
||||
{
|
||||
else {
|
||||
if (moved) {
|
||||
this->FixZ();
|
||||
SetCurrentSpeed(0);
|
||||
moved = false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
//fix up Z
|
||||
float zdiff = GetZ() - owner->GetZ();
|
||||
if(zdiff < 0)
|
||||
zdiff = 0 - zdiff;
|
||||
if(zdiff > 2.0f) {
|
||||
SendTo(GetX(), GetY(), owner->GetZ());
|
||||
SendPosition();
|
||||
}
|
||||
|
||||
if(owner->IsClient())
|
||||
printf("Pet pos: (%f, %f, %f)\n", GetX(), GetY(), GetZ());
|
||||
*/
|
||||
|
||||
break;
|
||||
}
|
||||
case SPO_Sit:
|
||||
{
|
||||
case SPO_Sit: {
|
||||
SetAppearance(eaSitting, false);
|
||||
break;
|
||||
}
|
||||
case SPO_Guard:
|
||||
{
|
||||
case SPO_Guard: {
|
||||
//only NPCs can guard stuff. (forced by where the guard movement code is in the AI)
|
||||
if (IsNPC()) {
|
||||
CastToNPC()->NextGuardPosition();
|
||||
@ -1614,24 +1590,22 @@ void Mob::AI_Process() {
|
||||
return;
|
||||
}
|
||||
/* Entity has been assigned another entity to follow */
|
||||
else if (GetFollowID())
|
||||
{
|
||||
else if (GetFollowID()) {
|
||||
Mob *follow = entity_list.GetMob(GetFollowID());
|
||||
if (!follow) SetFollowID(0);
|
||||
else
|
||||
{
|
||||
if (!follow) { SetFollowID(0); }
|
||||
else {
|
||||
float dist2 = DistanceSquared(m_Position, follow->GetPosition());
|
||||
int followdist = GetFollowDistance();
|
||||
|
||||
if (dist2 >= followdist) // Default follow distance is 100
|
||||
{
|
||||
int speed = GetWalkspeed();
|
||||
if (dist2 >= followdist + 150)
|
||||
if (dist2 >= followdist + 150) {
|
||||
speed = GetRunspeed();
|
||||
}
|
||||
CalculateNewPosition(follow->GetX(), follow->GetY(), follow->GetZ(), speed);
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
moved = false;
|
||||
SetCurrentSpeed(0);
|
||||
}
|
||||
@ -1640,20 +1614,21 @@ void Mob::AI_Process() {
|
||||
else //not a pet, and not following somebody...
|
||||
{
|
||||
// dont move till a bit after you last fought
|
||||
if (pLastFightingDelayMoving < Timer::GetCurrentTime())
|
||||
{
|
||||
if (this->IsClient())
|
||||
{
|
||||
// LD timer expired, drop out of world
|
||||
if (this->CastToClient()->IsLD())
|
||||
if (time_until_can_move < Timer::GetCurrentTime()) {
|
||||
if (this->IsClient()) {
|
||||
|
||||
/**
|
||||
* LD timer expired, drop out of world
|
||||
*/
|
||||
if (this->CastToClient()->IsLD()) {
|
||||
this->CastToClient()->Disconnect();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(IsNPC())
|
||||
{
|
||||
if(RuleB(NPC, SmartLastFightingDelayMoving) && !feign_memory_list.empty())
|
||||
{
|
||||
if (IsNPC()) {
|
||||
if (RuleB(NPC, SmartLastFightingDelayMoving) && !feign_memory_list.empty()) {
|
||||
minLastFightingDelayMoving = 0;
|
||||
maxLastFightingDelayMoving = 0;
|
||||
}
|
||||
@ -1661,92 +1636,83 @@ void Mob::AI_Process() {
|
||||
CastToNPC()->AI_DoMovement();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // else if (AImovement_timer->Check())
|
||||
}
|
||||
}
|
||||
|
||||
//Do Ranged attack here
|
||||
if(doranged)
|
||||
{
|
||||
if (doranged) {
|
||||
RangedAttack(target);
|
||||
}
|
||||
}
|
||||
|
||||
void NPC::AI_DoMovement() {
|
||||
float walksp = GetMovespeed();
|
||||
if(walksp <= 0.0f)
|
||||
return; //this is idle movement at walk speed, and we are unable to walk right now.
|
||||
|
||||
float move_speed = GetMovespeed();
|
||||
|
||||
if (move_speed <= 0.0f) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Roambox logic sets precedence
|
||||
*/
|
||||
if (roambox_distance > 0) {
|
||||
if (
|
||||
roambox_movingto_x > roambox_max_x
|
||||
|| roambox_movingto_x < roambox_min_x
|
||||
|| roambox_movingto_y > roambox_max_y
|
||||
|| roambox_movingto_y < roambox_min_y
|
||||
)
|
||||
{
|
||||
float movedist = roambox_distance*roambox_distance;
|
||||
float movex = zone->random.Real(0, movedist);
|
||||
float movey = movedist - movex;
|
||||
movex = sqrtf(movex);
|
||||
movey = sqrtf(movey);
|
||||
movex *= zone->random.Int(0, 1) ? 1 : -1;
|
||||
movey *= zone->random.Int(0, 1) ? 1 : -1;
|
||||
roambox_movingto_x = GetX() + movex;
|
||||
roambox_movingto_y = GetY() + movey;
|
||||
//Try to calculate new coord using distance.
|
||||
if (roambox_movingto_x > roambox_max_x || roambox_movingto_x < roambox_min_x)
|
||||
roambox_movingto_x -= movex * 2;
|
||||
if (roambox_movingto_y > roambox_max_y || roambox_movingto_y < roambox_min_y)
|
||||
roambox_movingto_y -= movey * 2;
|
||||
//New coord is still invalid, ignore distance and just pick a new random coord.
|
||||
//If we're here we may have a roambox where one side is shorter than the specified distance. Commons, Wkarana, etc.
|
||||
if (roambox_movingto_x > roambox_max_x || roambox_movingto_x < roambox_min_x)
|
||||
roambox_movingto_x = zone->random.Real(roambox_min_x+1,roambox_max_x-1);
|
||||
if (roambox_movingto_y > roambox_max_y || roambox_movingto_y < roambox_min_y)
|
||||
roambox_movingto_y = zone->random.Real(roambox_min_y+1,roambox_max_y-1);
|
||||
Log(Logs::Detail, Logs::AI,
|
||||
"Roam Box: d=%.3f (%.3f->%.3f,%.3f->%.3f): Go To (%.3f,%.3f)",
|
||||
roambox_distance, roambox_min_x, roambox_max_x, roambox_min_y,
|
||||
roambox_max_y, roambox_movingto_x, roambox_movingto_y);
|
||||
|
||||
if (!IsMoving()) {
|
||||
auto move_x = static_cast<float>(zone->random.Real(-roambox_distance, roambox_distance));
|
||||
auto move_y = static_cast<float>(zone->random.Real(-roambox_distance, roambox_distance));
|
||||
|
||||
roambox_destination_x = EQEmu::Clamp((GetX() + move_x), roambox_min_x, roambox_min_y);
|
||||
roambox_destination_y = EQEmu::Clamp((GetY() + move_y), roambox_min_y, roambox_max_y);
|
||||
|
||||
this->FixZ();
|
||||
|
||||
Log(Logs::Detail,
|
||||
Logs::NPCRoamBox,
|
||||
"Calculate | NPC: %s distance %.3f | min_x %.3f | max_x %.3f | final_x %.3f | min_y %.3f | max_y %.3f | final_y %.3f",
|
||||
this->GetCleanName(),
|
||||
roambox_distance,
|
||||
roambox_min_x,
|
||||
roambox_max_x,
|
||||
roambox_destination_x,
|
||||
roambox_min_y,
|
||||
roambox_max_y,
|
||||
roambox_destination_y);
|
||||
}
|
||||
|
||||
Log(Logs::Detail, Logs::AI, "Roam Box: d=%.3f (%.3f->%.3f,%.3f->%.3f): Go To (%.3f,%.3f)",
|
||||
roambox_distance, roambox_min_x, roambox_max_x, roambox_min_y, roambox_max_y, roambox_movingto_x, roambox_movingto_y);
|
||||
|
||||
float new_z = this->FindGroundZ(m_Position.x, m_Position.y, 5) + GetZOffset();
|
||||
|
||||
if (!CalculateNewPosition(roambox_movingto_x, roambox_movingto_y, new_z, walksp, true))
|
||||
{
|
||||
this->FixZ(); // FixZ on final arrival point.
|
||||
roambox_movingto_x = roambox_max_x + 1; // force update
|
||||
pLastFightingDelayMoving = Timer::GetCurrentTime() + RandomTimer(roambox_min_delay, roambox_delay);
|
||||
if (!CalculateNewPosition(roambox_destination_x, roambox_destination_y, GetFixedZ(m_Position), move_speed, true)) {
|
||||
time_until_can_move = Timer::GetCurrentTime() + RandomTimer(roambox_min_delay, roambox_delay);
|
||||
SetMoving(false);
|
||||
SendPosition(); // makes mobs stop clientside
|
||||
this->FixZ();
|
||||
SendPosition();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else if (roamer)
|
||||
{
|
||||
if (AI_walking_timer->Check())
|
||||
{
|
||||
else if (roamer) {
|
||||
if (AI_walking_timer->Check()) {
|
||||
movetimercompleted = true;
|
||||
AI_walking_timer->Disable();
|
||||
}
|
||||
|
||||
|
||||
int32 gridno = CastToNPC()->GetGrid();
|
||||
|
||||
if (gridno > 0 || cur_wp == -2) {
|
||||
if (movetimercompleted == true) { // time to pause at wp is over
|
||||
AI_SetupNextWaypoint();
|
||||
} // endif (movetimercompleted==true)
|
||||
else if (!(AI_walking_timer->Enabled()))
|
||||
{ // currently moving
|
||||
else if (!(AI_walking_timer->Enabled())) { // currently moving
|
||||
bool doMove = true;
|
||||
if (m_CurrentWayPoint.x == GetX() && m_CurrentWayPoint.y == GetY())
|
||||
{ // are we there yet? then stop
|
||||
Log(Logs::Detail, Logs::AI, "We have reached waypoint %d (%.3f,%.3f,%.3f) on grid %d", cur_wp, GetX(), GetY(), GetZ(), GetGrid());
|
||||
if (m_CurrentWayPoint.x == GetX() && m_CurrentWayPoint.y == GetY()) { // are we there yet? then stop
|
||||
Log(Logs::Detail,
|
||||
Logs::AI,
|
||||
"We have reached waypoint %d (%.3f,%.3f,%.3f) on grid %d",
|
||||
cur_wp,
|
||||
GetX(),
|
||||
GetY(),
|
||||
GetZ(),
|
||||
GetGrid());
|
||||
|
||||
SetWaypointPause();
|
||||
SetAppearance(eaStanding, false);
|
||||
@ -1776,32 +1742,41 @@ void NPC::AI_DoMovement() {
|
||||
if (cur_wp == 1)
|
||||
ClearFeignMemory();
|
||||
}
|
||||
if (doMove)
|
||||
{ // not at waypoint yet or at 0 pause WP, so keep moving
|
||||
if (doMove) { // not at waypoint yet or at 0 pause WP, so keep moving
|
||||
if (!RuleB(Pathing, AggroReturnToGrid) || !zone->pathing || (DistractedFromGrid == 0))
|
||||
CalculateNewPosition(m_CurrentWayPoint.x, m_CurrentWayPoint.y, m_CurrentWayPoint.z, walksp, true);
|
||||
else
|
||||
{
|
||||
CalculateNewPosition(
|
||||
m_CurrentWayPoint.x,
|
||||
m_CurrentWayPoint.y,
|
||||
m_CurrentWayPoint.z,
|
||||
move_speed,
|
||||
true
|
||||
);
|
||||
else {
|
||||
bool WaypointChanged;
|
||||
bool NodeReached;
|
||||
glm::vec3 Goal = UpdatePath(m_CurrentWayPoint.x, m_CurrentWayPoint.y, m_CurrentWayPoint.z, walksp, WaypointChanged, NodeReached);
|
||||
glm::vec3 Goal = UpdatePath(
|
||||
m_CurrentWayPoint.x,
|
||||
m_CurrentWayPoint.y,
|
||||
m_CurrentWayPoint.z,
|
||||
move_speed,
|
||||
WaypointChanged,
|
||||
NodeReached
|
||||
);
|
||||
if (WaypointChanged)
|
||||
tar_ndx = 20;
|
||||
|
||||
if (NodeReached)
|
||||
entity_list.OpenDoorsNear(CastToNPC());
|
||||
|
||||
CalculateNewPosition(Goal.x, Goal.y, Goal.z, walksp, true);
|
||||
CalculateNewPosition(Goal.x, Goal.y, Goal.z, move_speed, true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} // endif (gridno > 0)
|
||||
// handle new quest grid command processing
|
||||
else if (gridno < 0)
|
||||
{ // this mob is under quest control
|
||||
if (movetimercompleted==true)
|
||||
{ // time to pause has ended
|
||||
else if (gridno < 0) { // this mob is under quest control
|
||||
if (movetimercompleted == true) { // time to pause has ended
|
||||
SetGrid(0 - GetGrid()); // revert to AI control
|
||||
Log(Logs::Detail, Logs::Pathing, "Quest pathing is finished. Resuming on grid %d", GetGrid());
|
||||
|
||||
@ -1812,39 +1787,55 @@ void NPC::AI_DoMovement() {
|
||||
}
|
||||
|
||||
}
|
||||
else if (IsGuarding())
|
||||
{
|
||||
else if (IsGuarding()) {
|
||||
bool CP2Moved;
|
||||
if(!RuleB(Pathing, Guard) || !zone->pathing)
|
||||
CP2Moved = CalculateNewPosition(m_GuardPoint.x, m_GuardPoint.y, m_GuardPoint.z, walksp);
|
||||
else
|
||||
{
|
||||
if(!((m_Position.x == m_GuardPoint.x) && (m_Position.y == m_GuardPoint.y) && (m_Position.z == m_GuardPoint.z)))
|
||||
{
|
||||
if (!RuleB(Pathing, Guard) || !zone->pathing) {
|
||||
CP2Moved = CalculateNewPosition(m_GuardPoint.x, m_GuardPoint.y, m_GuardPoint.z, move_speed);
|
||||
}
|
||||
else {
|
||||
if (!((m_Position.x == m_GuardPoint.x) && (m_Position.y == m_GuardPoint.y) &&
|
||||
(m_Position.z == m_GuardPoint.z))) {
|
||||
|
||||
bool WaypointChanged, NodeReached;
|
||||
glm::vec3 Goal = UpdatePath(m_GuardPoint.x, m_GuardPoint.y, m_GuardPoint.z, walksp, WaypointChanged, NodeReached);
|
||||
if(WaypointChanged)
|
||||
|
||||
glm::vec3 Goal = UpdatePath(
|
||||
m_GuardPoint.x,
|
||||
m_GuardPoint.y,
|
||||
m_GuardPoint.z,
|
||||
move_speed,
|
||||
WaypointChanged,
|
||||
NodeReached
|
||||
);
|
||||
if (WaypointChanged) {
|
||||
tar_ndx = 20;
|
||||
}
|
||||
|
||||
if(NodeReached)
|
||||
if (NodeReached) {
|
||||
entity_list.OpenDoorsNear(CastToNPC());
|
||||
|
||||
CP2Moved = CalculateNewPosition(Goal.x, Goal.y, Goal.z, walksp);
|
||||
}
|
||||
else
|
||||
|
||||
CP2Moved = CalculateNewPosition(Goal.x, Goal.y, Goal.z, move_speed);
|
||||
}
|
||||
else {
|
||||
CP2Moved = false;
|
||||
}
|
||||
|
||||
}
|
||||
if (!CP2Moved)
|
||||
{
|
||||
if (!CP2Moved) {
|
||||
if (moved) {
|
||||
Log(Logs::Detail, Logs::AI, "Reached guard point (%.3f,%.3f,%.3f)", m_GuardPoint.x, m_GuardPoint.y, m_GuardPoint.z);
|
||||
Log(Logs::Detail,
|
||||
Logs::AI,
|
||||
"Reached guard point (%.3f,%.3f,%.3f)",
|
||||
m_GuardPoint.x,
|
||||
m_GuardPoint.y,
|
||||
m_GuardPoint.z);
|
||||
|
||||
ClearFeignMemory();
|
||||
moved = false;
|
||||
if (GetTarget() == nullptr || DistanceSquared(m_Position, GetTarget()->GetPosition()) >= 5*5 )
|
||||
{
|
||||
if (GetTarget() == nullptr || DistanceSquared(m_Position, GetTarget()->GetPosition()) >= 5 * 5) {
|
||||
SetHeading(m_GuardPoint.w);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
FaceTarget(GetTarget());
|
||||
}
|
||||
SetCurrentSpeed(0);
|
||||
@ -1968,11 +1959,11 @@ void Mob::AI_Event_NoLongerEngaged() {
|
||||
if (!IsAIControlled())
|
||||
return;
|
||||
this->AI_walking_timer->Start(RandomTimer(3000,20000));
|
||||
pLastFightingDelayMoving = Timer::GetCurrentTime();
|
||||
time_until_can_move = Timer::GetCurrentTime();
|
||||
if (minLastFightingDelayMoving == maxLastFightingDelayMoving)
|
||||
pLastFightingDelayMoving += minLastFightingDelayMoving;
|
||||
time_until_can_move += minLastFightingDelayMoving;
|
||||
else
|
||||
pLastFightingDelayMoving += zone->random.Int(minLastFightingDelayMoving, maxLastFightingDelayMoving);
|
||||
time_until_can_move += zone->random.Int(minLastFightingDelayMoving, maxLastFightingDelayMoving);
|
||||
// So mobs don't keep running as a ghost until AIwalking_timer fires
|
||||
// if they were moving prior to losing all hate
|
||||
// except if we're a pet, then we might run into some issues with pets backing off when they should immediately be moving
|
||||
|
||||
@ -242,8 +242,8 @@ NPC::NPC(const NPCType* d, Spawn2* in_respawn, const glm::vec4& position, int if
|
||||
roambox_max_y = -2;
|
||||
roambox_min_x = -2;
|
||||
roambox_min_y = -2;
|
||||
roambox_movingto_x = -2;
|
||||
roambox_movingto_y = -2;
|
||||
roambox_destination_x = -2;
|
||||
roambox_destination_y = -2;
|
||||
roambox_min_delay = 1000;
|
||||
roambox_delay = 1000;
|
||||
p_depop = false;
|
||||
|
||||
16
zone/npc.h
16
zone/npc.h
@ -311,9 +311,17 @@ public:
|
||||
void SaveGuardSpot(bool iClearGuardSpot = false);
|
||||
inline bool IsGuarding() const { return(m_GuardPoint.w != 0); }
|
||||
void SaveGuardSpotCharm();
|
||||
|
||||
void RestoreGuardSpotCharm();
|
||||
void AI_SetRoambox(float iDist, float iRoamDist, uint32 iDelay = 2500, uint32 iMinDelay = 2500);
|
||||
void AI_SetRoambox(float iDist, float iMaxX, float iMinX, float iMaxY, float iMinY, uint32 iDelay = 2500, uint32 iMinDelay = 2500);
|
||||
|
||||
void AI_SetRoambox(
|
||||
float max_distance,
|
||||
float roam_distance_variance,
|
||||
uint32 delay = 2500,
|
||||
uint32 min_delay = 2500
|
||||
);
|
||||
|
||||
void AI_SetRoambox(float distance, float max_x, float min_x, float max_y, float min_y, uint32 delay = 2500, uint32 min_delay = 2500);
|
||||
|
||||
//mercenary stuff
|
||||
void LoadMercTypes();
|
||||
@ -530,8 +538,8 @@ protected:
|
||||
float roambox_min_x;
|
||||
float roambox_min_y;
|
||||
float roambox_distance;
|
||||
float roambox_movingto_x;
|
||||
float roambox_movingto_y;
|
||||
float roambox_destination_x;
|
||||
float roambox_destination_y;
|
||||
uint32 roambox_delay;
|
||||
uint32 roambox_min_delay;
|
||||
|
||||
|
||||
124
zone/spawn2.cpp
124
zone/spawn2.cpp
@ -145,10 +145,11 @@ bool Spawn2::Process() {
|
||||
return true;
|
||||
|
||||
//grab our spawn group
|
||||
SpawnGroup* sg = zone->spawn_group_list.GetSpawnGroup(spawngroup_id_);
|
||||
SpawnGroup *spawn_group = zone->spawn_group_list.GetSpawnGroup(spawngroup_id_);
|
||||
|
||||
if(NPCPointerValid() && (sg->despawn == 0 || condition_id != 0))
|
||||
if (NPCPointerValid() && (spawn_group->despawn == 0 || condition_id != 0)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (timer.Check()) {
|
||||
timer.Disable();
|
||||
@ -159,25 +160,39 @@ bool Spawn2::Process() {
|
||||
//then we reset the timer and try again next time.
|
||||
if (condition_id != SC_AlwaysEnabled
|
||||
&& !zone->spawn_conditions.Check(condition_id, condition_min_value)) {
|
||||
Log(Logs::Detail, Logs::Spawns, "Spawn2 %d: spawning prevented by spawn condition %d", spawn2_id, condition_id);
|
||||
Log(Logs::Detail,
|
||||
Logs::Spawns,
|
||||
"Spawn2 %d: spawning prevented by spawn condition %d",
|
||||
spawn2_id,
|
||||
condition_id);
|
||||
Reset();
|
||||
return (true);
|
||||
}
|
||||
|
||||
if (sg == nullptr) {
|
||||
if (spawn_group == nullptr) {
|
||||
database.LoadSpawnGroupsByID(spawngroup_id_, &zone->spawn_group_list);
|
||||
sg = zone->spawn_group_list.GetSpawnGroup(spawngroup_id_);
|
||||
spawn_group = zone->spawn_group_list.GetSpawnGroup(spawngroup_id_);
|
||||
}
|
||||
|
||||
if (sg == nullptr) {
|
||||
Log(Logs::Detail, Logs::Spawns, "Spawn2 %d: Unable to locate spawn group %d. Disabling.", spawn2_id, spawngroup_id_);
|
||||
if (spawn_group == nullptr) {
|
||||
Log(Logs::Detail,
|
||||
Logs::Spawns,
|
||||
"Spawn2 %d: Unable to locate spawn group %d. Disabling.",
|
||||
spawn2_id,
|
||||
spawngroup_id_);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//have the spawn group pick an NPC for us
|
||||
uint32 npcid = sg->GetNPCType();
|
||||
uint32 npcid = spawn_group->GetNPCType();
|
||||
if (npcid == 0) {
|
||||
Log(Logs::Detail, Logs::Spawns, "Spawn2 %d: Spawn group %d did not yeild an NPC! not spawning.", spawn2_id, spawngroup_id_);
|
||||
Log(Logs::Detail,
|
||||
Logs::Spawns,
|
||||
"Spawn2 %d: Spawn group %d did not yeild an NPC! not spawning.",
|
||||
spawn2_id,
|
||||
spawngroup_id_);
|
||||
|
||||
Reset(); //try again later (why?)
|
||||
return (true);
|
||||
}
|
||||
@ -185,16 +200,24 @@ bool Spawn2::Process() {
|
||||
//try to find our NPC type.
|
||||
const NPCType *tmp = database.LoadNPCTypesData(npcid);
|
||||
if (tmp == nullptr) {
|
||||
Log(Logs::Detail, Logs::Spawns, "Spawn2 %d: Spawn group %d yeilded an invalid NPC type %d", spawn2_id, spawngroup_id_, npcid);
|
||||
Log(Logs::Detail,
|
||||
Logs::Spawns,
|
||||
"Spawn2 %d: Spawn group %d yeilded an invalid NPC type %d",
|
||||
spawn2_id,
|
||||
spawngroup_id_,
|
||||
npcid);
|
||||
Reset(); //try again later
|
||||
return (true);
|
||||
}
|
||||
|
||||
if(tmp->unique_spawn_by_name)
|
||||
{
|
||||
if(!entity_list.LimitCheckName(tmp->name))
|
||||
{
|
||||
Log(Logs::Detail, Logs::Spawns, "Spawn2 %d: Spawn group %d yeilded NPC type %d, which is unique and one already exists.", spawn2_id, spawngroup_id_, npcid);
|
||||
if (tmp->unique_spawn_by_name) {
|
||||
if (!entity_list.LimitCheckName(tmp->name)) {
|
||||
Log(Logs::Detail,
|
||||
Logs::Spawns,
|
||||
"Spawn2 %d: Spawn group %d yeilded NPC type %d, which is unique and one already exists.",
|
||||
spawn2_id,
|
||||
spawngroup_id_,
|
||||
npcid);
|
||||
timer.Start(5000); //try again in five seconds.
|
||||
return (true);
|
||||
}
|
||||
@ -202,30 +225,32 @@ bool Spawn2::Process() {
|
||||
|
||||
if (tmp->spawn_limit > 0) {
|
||||
if (!entity_list.LimitCheckType(npcid, tmp->spawn_limit)) {
|
||||
Log(Logs::Detail, Logs::Spawns, "Spawn2 %d: Spawn group %d yeilded NPC type %d, which is over its spawn limit (%d)", spawn2_id, spawngroup_id_, npcid, tmp->spawn_limit);
|
||||
Log(Logs::Detail,
|
||||
Logs::Spawns,
|
||||
"Spawn2 %d: Spawn group %d yeilded NPC type %d, which is over its spawn limit (%d)",
|
||||
spawn2_id,
|
||||
spawngroup_id_,
|
||||
npcid,
|
||||
tmp->spawn_limit);
|
||||
timer.Start(5000); //try again in five seconds.
|
||||
return (true);
|
||||
}
|
||||
}
|
||||
|
||||
bool ignore_despawn = false;
|
||||
if (npcthis)
|
||||
{
|
||||
if (npcthis) {
|
||||
ignore_despawn = npcthis->IgnoreDespawn();
|
||||
}
|
||||
|
||||
if (ignore_despawn)
|
||||
{
|
||||
if (ignore_despawn) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sg->despawn != 0 && condition_id == 0 && !ignore_despawn)
|
||||
{
|
||||
if (spawn_group->despawn != 0 && condition_id == 0 && !ignore_despawn) {
|
||||
zone->Despawn(spawn2_id);
|
||||
}
|
||||
|
||||
if (IsDespawned)
|
||||
{
|
||||
if (IsDespawned) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -236,23 +261,61 @@ bool Spawn2::Process() {
|
||||
|
||||
npcthis = npc;
|
||||
npc->AddLootTable();
|
||||
if (npc->DropsGlobalLoot())
|
||||
if (npc->DropsGlobalLoot()) {
|
||||
npc->CheckGlobalLootTables();
|
||||
}
|
||||
npc->SetSp2(spawngroup_id_);
|
||||
npc->SaveGuardPointAnim(anim);
|
||||
npc->SetAppearance((EmuAppearance) anim);
|
||||
entity_list.AddNPC(npc);
|
||||
//this limit add must be done after the AddNPC since we need the entity ID.
|
||||
entity_list.LimitAddNPC(npc);
|
||||
if(sg->roamdist && sg->roambox[0] && sg->roambox[1] && sg->roambox[2] && sg->roambox[3] && sg->delay && sg->min_delay)
|
||||
npc->AI_SetRoambox(sg->roamdist,sg->roambox[0],sg->roambox[1],sg->roambox[2],sg->roambox[3],sg->delay,sg->min_delay);
|
||||
|
||||
/**
|
||||
* Roambox init
|
||||
*/
|
||||
if (spawn_group->roamdist && spawn_group->roambox[0] && spawn_group->roambox[1] && spawn_group->roambox[2] &&
|
||||
spawn_group->roambox[3] && spawn_group->delay && spawn_group->min_delay) {
|
||||
|
||||
npc->AI_SetRoambox(
|
||||
spawn_group->roamdist,
|
||||
spawn_group->roambox[0],
|
||||
spawn_group->roambox[1],
|
||||
spawn_group->roambox[2],
|
||||
spawn_group->roambox[3],
|
||||
spawn_group->delay,
|
||||
spawn_group->min_delay
|
||||
);
|
||||
}
|
||||
|
||||
if (zone->InstantGrids()) {
|
||||
Log(Logs::Detail, Logs::Spawns, "Spawn2 %d: Group %d spawned %s (%d) at (%.3f, %.3f, %.3f).", spawn2_id, spawngroup_id_, npc->GetName(), npcid, x, y, z);
|
||||
Log(Logs::Detail,
|
||||
Logs::Spawns,
|
||||
"Spawn2 %d: Group %d spawned %s (%d) at (%.3f, %.3f, %.3f).",
|
||||
spawn2_id,
|
||||
spawngroup_id_,
|
||||
npc->GetName(),
|
||||
npcid,
|
||||
x,
|
||||
y,
|
||||
z);
|
||||
|
||||
LoadGrid();
|
||||
} else {
|
||||
Log(Logs::Detail, Logs::Spawns, "Spawn2 %d: Group %d spawned %s (%d) at (%.3f, %.3f, %.3f). Grid loading delayed.", spawn2_id, spawngroup_id_, tmp->name, npcid, x, y, z);
|
||||
}
|
||||
else {
|
||||
Log(Logs::Detail,
|
||||
Logs::Spawns,
|
||||
"Spawn2 %d: Group %d spawned %s (%d) at (%.3f, %.3f, %.3f). Grid loading delayed.",
|
||||
spawn2_id,
|
||||
spawngroup_id_,
|
||||
tmp->name,
|
||||
npcid,
|
||||
x,
|
||||
y,
|
||||
z);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -278,7 +341,6 @@ void Spawn2::LoadGrid() {
|
||||
Log(Logs::Detail, Logs::Spawns, "Spawn2 %d: Loading grid %d for %s", spawn2_id, grid_, npcthis->GetName());
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
All three of these actions basically say that the mob which was
|
||||
associated with this spawn point is no longer relavent.
|
||||
|
||||
@ -42,19 +42,27 @@ struct wp_distance
|
||||
int index;
|
||||
};
|
||||
|
||||
void NPC::AI_SetRoambox(float iDist, float iRoamDist, uint32 iDelay, uint32 iMinDelay) {
|
||||
AI_SetRoambox(iDist, GetX() + iRoamDist, GetX() - iRoamDist, GetY() + iRoamDist, GetY() - iRoamDist, iDelay, iMinDelay);
|
||||
void NPC::AI_SetRoambox(float max_distance, float roam_distance_variance, uint32 delay, uint32 min_delay) {
|
||||
AI_SetRoambox(
|
||||
max_distance,
|
||||
GetX() + roam_distance_variance,
|
||||
GetX() - roam_distance_variance,
|
||||
GetY() + roam_distance_variance,
|
||||
GetY() - roam_distance_variance,
|
||||
delay,
|
||||
min_delay
|
||||
);
|
||||
}
|
||||
|
||||
void NPC::AI_SetRoambox(float iDist, float iMaxX, float iMinX, float iMaxY, float iMinY, uint32 iDelay, uint32 iMinDelay) {
|
||||
roambox_distance = iDist;
|
||||
roambox_max_x = iMaxX;
|
||||
roambox_min_x = iMinX;
|
||||
roambox_max_y = iMaxY;
|
||||
roambox_min_y = iMinY;
|
||||
roambox_movingto_x = roambox_max_x + 1; // this will trigger a recalc
|
||||
roambox_delay = iDelay;
|
||||
roambox_min_delay = iMinDelay;
|
||||
void NPC::AI_SetRoambox(float distance, float max_x, float min_x, float max_y, float min_y, uint32 delay, uint32 min_delay) {
|
||||
roambox_distance = distance;
|
||||
roambox_max_x = max_x;
|
||||
roambox_min_x = min_x;
|
||||
roambox_max_y = max_y;
|
||||
roambox_min_y = min_y;
|
||||
roambox_destination_x = roambox_max_x + 1; // this will trigger a recalc
|
||||
roambox_delay = delay;
|
||||
roambox_min_delay = min_delay;
|
||||
}
|
||||
|
||||
void NPC::DisplayWaypointInfo(Client *c) {
|
||||
@ -199,7 +207,7 @@ void NPC::MoveTo(const glm::vec4& position, bool saveguardspot)
|
||||
}
|
||||
|
||||
cur_wp_pause = 0;
|
||||
pLastFightingDelayMoving = 0;
|
||||
time_until_can_move = 0;
|
||||
if (AI_walking_timer->Enabled())
|
||||
AI_walking_timer->Start(100);
|
||||
}
|
||||
@ -438,22 +446,16 @@ float Mob::CalculateDistance(float x, float y, float z) {
|
||||
return (float)sqrtf(((m_Position.x - x)*(m_Position.x - x)) + ((m_Position.y - y)*(m_Position.y - y)) + ((m_Position.z - z)*(m_Position.z - z)));
|
||||
}
|
||||
|
||||
bool Mob::MakeNewPositionAndSendUpdate(float x, float y, float z, int speed, bool checkZ, bool calcHeading) {
|
||||
bool Mob::MakeNewPositionAndSendUpdate(float x, float y, float z, float speed, bool check_z, bool calculate_heading) {
|
||||
if (GetID() == 0)
|
||||
return true;
|
||||
|
||||
if (speed <= 0)
|
||||
{
|
||||
if (speed <= 0) {
|
||||
SetCurrentSpeed(0);
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((m_Position.x - x == 0) && (m_Position.y - y == 0)) {//spawn is at target coords
|
||||
if (m_Position.z - z != 0) {
|
||||
m_Position.z = z;
|
||||
Log(Logs::Detail, Logs::AI, "Calc Position2 (%.3f, %.3f, %.3f): Jumping pure Z.", x, y, z);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if ((std::abs(m_Position.x - x) < 0.1) && (std::abs(m_Position.y - y) < 0.1)) {
|
||||
@ -464,16 +466,17 @@ bool Mob::MakeNewPositionAndSendUpdate(float x, float y, float z, int speed, boo
|
||||
m_Position.x = x;
|
||||
m_Position.y = y;
|
||||
m_Position.z = z;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool send_update = false;
|
||||
int compare_steps = 20;
|
||||
if (tar_ndx < compare_steps && m_TargetLocation.x == x && m_TargetLocation.y == y) {
|
||||
|
||||
float new_x = m_Position.x + m_TargetV.x * tar_vector;
|
||||
float new_y = m_Position.y + m_TargetV.y * tar_vector;
|
||||
float new_z = m_Position.z + m_TargetV.z * tar_vector;
|
||||
|
||||
if (IsNPC()) {
|
||||
entity_list.ProcessMove(CastToNPC(), new_x, new_y, new_z);
|
||||
}
|
||||
@ -482,14 +485,14 @@ bool Mob::MakeNewPositionAndSendUpdate(float x, float y, float z, int speed, boo
|
||||
m_Position.y = new_y;
|
||||
m_Position.z = new_z;
|
||||
|
||||
if(checkZ && fix_z_timer.Check() &&
|
||||
(!this->IsEngaged() || flee_mode || currently_fleeing))
|
||||
if (check_z && fix_z_timer.Check() && (!this->IsEngaged() || flee_mode || currently_fleeing)) {
|
||||
this->FixZ();
|
||||
|
||||
tar_ndx++;
|
||||
return true;
|
||||
}
|
||||
|
||||
tar_ndx++;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (tar_ndx > 50) {
|
||||
tar_ndx--;
|
||||
@ -497,6 +500,7 @@ bool Mob::MakeNewPositionAndSendUpdate(float x, float y, float z, int speed, boo
|
||||
else {
|
||||
tar_ndx = 0;
|
||||
}
|
||||
|
||||
m_TargetLocation = glm::vec3(x, y, z);
|
||||
|
||||
float nx = this->m_Position.x;
|
||||
@ -530,10 +534,8 @@ bool Mob::MakeNewPositionAndSendUpdate(float x, float y, float z, int speed, boo
|
||||
|
||||
// mob move fix
|
||||
|
||||
if (numsteps<20)
|
||||
{
|
||||
if (numsteps>1)
|
||||
{
|
||||
if (numsteps < 20) {
|
||||
if (numsteps > 1) {
|
||||
tar_vector = 1.0f;
|
||||
m_TargetV.x = m_TargetV.x / (float) numsteps;
|
||||
m_TargetV.y = m_TargetV.y / (float) numsteps;
|
||||
@ -549,12 +551,12 @@ bool Mob::MakeNewPositionAndSendUpdate(float x, float y, float z, int speed, boo
|
||||
m_Position.x = new_x;
|
||||
m_Position.y = new_y;
|
||||
m_Position.z = new_z;
|
||||
if (calcHeading)
|
||||
if (calculate_heading) {
|
||||
m_Position.w = CalculateHeadingToTarget(x, y);
|
||||
}
|
||||
tar_ndx = 20 - numsteps;
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
if (IsNPC()) {
|
||||
entity_list.ProcessMove(CastToNPC(), x, y, z);
|
||||
}
|
||||
@ -581,6 +583,7 @@ bool Mob::MakeNewPositionAndSendUpdate(float x, float y, float z, int speed, boo
|
||||
float new_x = m_Position.x + m_TargetV.x * tar_vector;
|
||||
float new_y = m_Position.y + m_TargetV.y * tar_vector;
|
||||
float new_z = m_Position.z + m_TargetV.z * tar_vector;
|
||||
|
||||
if (IsNPC()) {
|
||||
entity_list.ProcessMove(CastToNPC(), new_x, new_y, new_z);
|
||||
}
|
||||
@ -588,11 +591,12 @@ bool Mob::MakeNewPositionAndSendUpdate(float x, float y, float z, int speed, boo
|
||||
m_Position.x = new_x;
|
||||
m_Position.y = new_y;
|
||||
m_Position.z = new_z;
|
||||
if (calcHeading)
|
||||
if (calculate_heading) {
|
||||
m_Position.w = CalculateHeadingToTarget(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
if (checkZ && fix_z_timer.Check() && !this->IsEngaged())
|
||||
if (check_z && fix_z_timer.Check() && !this->IsEngaged())
|
||||
this->FixZ();
|
||||
|
||||
SetMoving(true);
|
||||
@ -600,13 +604,11 @@ bool Mob::MakeNewPositionAndSendUpdate(float x, float y, float z, int speed, boo
|
||||
|
||||
m_Delta = glm::vec4(m_Position.x - nx, m_Position.y - ny, m_Position.z - nz, 0.0f);
|
||||
|
||||
if (IsClient())
|
||||
{
|
||||
if (IsClient()) {
|
||||
SendPositionUpdate(1);
|
||||
CastToClient()->ResetPositionTimer();
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
SendPositionUpdate();
|
||||
SetAppearance(eaStanding, false);
|
||||
}
|
||||
@ -615,8 +617,8 @@ bool Mob::MakeNewPositionAndSendUpdate(float x, float y, float z, int speed, boo
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Mob::CalculateNewPosition(float x, float y, float z, int speed, bool checkZ, bool calcHeading) {
|
||||
return MakeNewPositionAndSendUpdate(x, y, z, speed);
|
||||
bool Mob::CalculateNewPosition(float x, float y, float z, float speed, bool check_z, bool calculate_heading) {
|
||||
return MakeNewPositionAndSendUpdate(x, y, z, speed, check_z);
|
||||
}
|
||||
|
||||
void NPC::AssignWaypoints(int32 grid)
|
||||
@ -746,10 +748,11 @@ void Mob::SendToFixZ(float new_x, float new_y, float new_z) {
|
||||
}
|
||||
}
|
||||
|
||||
float Mob::GetFixedZ(glm::vec3 dest, int32 z_find_offset) {
|
||||
float Mob::GetFixedZ(glm::vec3 destination, int32 z_find_offset) {
|
||||
BenchTimer timer;
|
||||
timer.reset();
|
||||
float new_z = dest.z;
|
||||
|
||||
float new_z = destination.z;
|
||||
|
||||
if (zone->HasMap() && RuleB(Map, FixZWhenMoving)) {
|
||||
|
||||
@ -765,7 +768,7 @@ float Mob::GetFixedZ(glm::vec3 dest, int32 z_find_offset) {
|
||||
/*
|
||||
* Any more than 5 in the offset makes NPC's hop/snap to ceiling in small corridors
|
||||
*/
|
||||
new_z = this->FindDestGroundZ(dest, z_find_offset);
|
||||
new_z = this->FindDestGroundZ(destination, z_find_offset);
|
||||
if (new_z != BEST_Z_INVALID) {
|
||||
new_z += this->GetZOffset();
|
||||
|
||||
@ -776,9 +779,15 @@ float Mob::GetFixedZ(glm::vec3 dest, int32 z_find_offset) {
|
||||
|
||||
auto duration = timer.elapsed();
|
||||
|
||||
Log(Logs::Moderate, Logs::FixZ,
|
||||
Log(Logs::Moderate,
|
||||
Logs::FixZ,
|
||||
"Mob::GetFixedZ() (%s) returned %4.3f at %4.3f, %4.3f, %4.3f - Took %lf",
|
||||
this->GetCleanName(), new_z, dest.x, dest.y, dest.z, duration);
|
||||
this->GetCleanName(),
|
||||
new_z,
|
||||
destination.x,
|
||||
destination.y,
|
||||
destination.z,
|
||||
duration);
|
||||
}
|
||||
|
||||
return new_z;
|
||||
@ -790,13 +799,16 @@ void Mob::FixZ(int32 z_find_offset /*= 5*/) {
|
||||
|
||||
if (!IsClient() && new_z != m_Position.z) {
|
||||
if ((new_z > -2000) && new_z != BEST_Z_INVALID) {
|
||||
if (RuleB(Map, MobZVisualDebug))
|
||||
if (RuleB(Map, MobZVisualDebug)) {
|
||||
this->SendAppearanceEffect(78, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
m_Position.z = new_z;
|
||||
} else {
|
||||
if (RuleB(Map, MobZVisualDebug))
|
||||
}
|
||||
else {
|
||||
if (RuleB(Map, MobZVisualDebug)) {
|
||||
this->SendAppearanceEffect(103, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
Log(Logs::General, Logs::FixZ, "%s is failing to find Z %f",
|
||||
this->GetCleanName(), std::abs(m_Position.z - new_z));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user