Add logging for flee

This commit is contained in:
Akkadius 2020-01-03 17:23:51 -06:00
parent 3a10131a00
commit 9dda9098a0
4 changed files with 69 additions and 29 deletions

View File

@ -112,6 +112,7 @@ namespace Logs {
AICastBeneficialClose, AICastBeneficialClose,
AoeCast, AoeCast,
EntityManagement, EntityManagement,
Flee,
MaxCategoryID /* Don't Remove this */ MaxCategoryID /* Don't Remove this */
}; };
@ -183,6 +184,7 @@ namespace Logs {
"AI Cast Beneficial Close", "AI Cast Beneficial Close",
"AOE Cast", "AOE Cast",
"Entity Management", "Entity Management",
"Flee",
}; };
} }

View File

@ -541,6 +541,16 @@
OutF(LogSys, Logs::Detail, Logs::EntityManagement, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\ OutF(LogSys, Logs::Detail, Logs::EntityManagement, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\
} while (0) } while (0)
#define LogFlee(message, ...) do {\
if (LogSys.log_settings[Logs::Flee].is_category_enabled == 1)\
OutF(LogSys, Logs::General, Logs::Flee, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\
} while (0)
#define LogFleeDetail(message, ...) do {\
if (LogSys.log_settings[Logs::Flee].is_category_enabled == 1)\
OutF(LogSys, Logs::Detail, Logs::Flee, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\
} while (0)
#define Log(debug_level, log_category, message, ...) do {\ #define Log(debug_level, log_category, message, ...) do {\
if (LogSys.log_settings[log_category].is_category_enabled == 1)\ if (LogSys.log_settings[log_category].is_category_enabled == 1)\
LogSys.Out(debug_level, log_category, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\ LogSys.Out(debug_level, log_category, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\

View File

@ -30,51 +30,65 @@ extern Zone* zone;
#define FEAR_PATHING_DEBUG #define FEAR_PATHING_DEBUG
//this is called whenever we are damaged to process possible fleeing //this is called whenever we are damaged to process possible fleeing
void Mob::CheckFlee() { void Mob::CheckFlee()
{
// if mob is dead why would you run? // if mob is dead why would you run?
if(GetHP() == 0) { if (GetHP() == 0) {
return; return;
} }
// if were already fleeing, don't need to check more... // if were already fleeing, don't need to check more...
if(flee_mode && currently_fleeing) { if (flee_mode && currently_fleeing) {
return; return;
} }
//dont bother if we are immune to fleeing //dont bother if we are immune to fleeing
if(GetSpecialAbility(IMMUNE_FLEEING) || spellbonuses.ImmuneToFlee) { if (GetSpecialAbility(IMMUNE_FLEEING) || spellbonuses.ImmuneToFlee) {
LogFlee("Mob [{}] is immune to fleeing via special ability or spell bonus", GetCleanName());
return; return;
} }
// Check if Flee Timer is cleared // Check if Flee Timer is cleared
if(!flee_timer.Check()) { if (!flee_timer.Check()) {
return; return;
} }
int hpratio = GetIntHPRatio(); int hp_ratio = GetIntHPRatio();
int fleeratio = GetSpecialAbility(FLEE_PERCENT); // if a special flee_percent exists int flee_ratio = GetSpecialAbility(FLEE_PERCENT); // if a special flee_percent exists
Mob *hate_top = GetHateTop(); Mob *hate_top = GetHateTop();
LogFlee("Mob [{}] hp_ratio [{}] flee_ratio [{}]", GetCleanName(), hp_ratio, flee_ratio);
// Sanity Check for race conditions // Sanity Check for race conditions
if(hate_top == nullptr) { if (hate_top == nullptr) {
return; return;
} }
// If no special flee_percent check for Gray or Other con rates // If no special flee_percent check for Gray or Other con rates
if(GetLevelCon(hate_top->GetLevel(), GetLevel()) == CON_GRAY && fleeratio == 0 && RuleB(Combat, FleeGray) && GetLevel() <= RuleI(Combat, FleeGrayMaxLevel)) { if (GetLevelCon(hate_top->GetLevel(), GetLevel()) == CON_GRAY && flee_ratio == 0 && RuleB(Combat, FleeGray) &&
fleeratio = RuleI(Combat, FleeGrayHPRatio); GetLevel() <= RuleI(Combat, FleeGrayMaxLevel)) {
} else if(fleeratio == 0) { flee_ratio = RuleI(Combat, FleeGrayHPRatio);
fleeratio = RuleI(Combat, FleeHPRatio ); LogFlee("Mob [{}] using combat flee gray hp_ratio [{}] flee_ratio [{}]", GetCleanName(), hp_ratio, flee_ratio);
}
else if (flee_ratio == 0) {
flee_ratio = RuleI(Combat, FleeHPRatio);
LogFlee("Mob [{}] using combat flee hp_ratio [{}] flee_ratio [{}]", GetCleanName(), hp_ratio, flee_ratio);
} }
// Mob does not have low enough health to flee bool mob_has_low_enough_health_to_flee = hp_ratio >= flee_ratio;
if(hpratio >= fleeratio) { if (mob_has_low_enough_health_to_flee) {
LogFlee(
"Mob [{}] does not have low enough health to flee | hp_ratio [{}] flee_ratio [{}]",
GetCleanName(),
hp_ratio,
flee_ratio
);
return; return;
} }
// Sanity Check this should never happen... // Sanity Check this should never happen...
if(!hate_top) { if (!hate_top) {
currently_fleeing = true; currently_fleeing = true;
StartFleeing(); StartFleeing();
return; return;
@ -82,14 +96,14 @@ void Mob::CheckFlee() {
int other_ratio = hate_top->GetIntHPRatio(); int other_ratio = hate_top->GetIntHPRatio();
// If the Client is nearing death the NPC will not flee and instead try to kill the client. // If the Client is nearing death the NPC will not flee and instead try to kill the client.
if(other_ratio < 20) { if (other_ratio < 20) {
return; return;
} }
// Flee Chance checking based on con. // Flee Chance checking based on con.
uint32 con = GetLevelCon(hate_top->GetLevel(), GetLevel()); uint32 con = GetLevelCon(hate_top->GetLevel(), GetLevel());
int flee_chance; int flee_chance;
switch(con) { switch (con) {
//these values are not 100% researched //these values are not 100% researched
case CON_GRAY: case CON_GRAY:
flee_chance = 100; flee_chance = 100;
@ -108,13 +122,29 @@ void Mob::CheckFlee() {
break; break;
} }
LogFlee(
"Post con-switch | Mob [{}] con [{}] hp_ratio [{}] flee_ratio [{}] flee_chance [{}]",
GetCleanName(),
hp_ratio,
flee_ratio
);
// If we got here we are allowed to roll on flee chance if there is not other hated NPC's in the area. // If we got here we are allowed to roll on flee chance if there is not other hated NPC's in the area.
// ALWAYS_FLEE, skip roll // ALWAYS_FLEE, skip roll
// if FleeIfNotAlone is true, we skip alone check // if FleeIfNotAlone is true, we skip alone check
// roll chance // roll chance
if (GetSpecialAbility(ALWAYS_FLEE) || if (GetSpecialAbility(ALWAYS_FLEE) ||
((RuleB(Combat, FleeIfNotAlone) || entity_list.GetHatedCount(hate_top, this, true) == 0) && ((RuleB(Combat, FleeIfNotAlone) || entity_list.GetHatedCount(hate_top, this, true) == 0) &&
zone->random.Roll(flee_chance))) { zone->random.Roll(flee_chance))) {
LogFlee(
"Passed all checks to flee | Mob [{}] con [{}] hp_ratio [{}] flee_ratio [{}] flee_chance [{}]",
GetCleanName(),
hp_ratio,
flee_ratio,
flee_chance
);
currently_fleeing = true; currently_fleeing = true;
StartFleeing(); StartFleeing();
} }
@ -160,7 +190,8 @@ void Mob::ProcessFlee()
} }
} }
void Mob::CalculateNewFearpoint() { void Mob::CalculateNewFearpoint()
{
if (RuleB(Pathing, Fear) && zone->pathing) { if (RuleB(Pathing, Fear) && zone->pathing) {
auto Node = zone->pathing->GetRandomLocation(glm::vec3(GetX(), GetY(), GetZ())); auto Node = zone->pathing->GetRandomLocation(glm::vec3(GetX(), GetY(), GetZ()));
if (Node.x != 0.0f || Node.y != 0.0f || Node.z != 0.0f) { if (Node.x != 0.0f || Node.y != 0.0f || Node.z != 0.0f) {
@ -170,9 +201,7 @@ void Mob::CalculateNewFearpoint() {
return; return;
} }
Log(Logs::Detail, LogPathing("No path found to selected node during CalculateNewFearpoint.");
Logs::Pathing,
"No path found to selected node during CalculateNewFearpoint.");
} }
} }

View File

@ -4011,10 +4011,9 @@ void Mob::BuffFadeBySlot(int slot, bool iRecalcBonuses)
break; break;
} }
case SE_ImmuneFleeing: case SE_ImmuneFleeing: {
{ if (RuleB(Combat, EnableFearPathing)) {
if(RuleB(Combat, EnableFearPathing)){ if (flee_mode) {
if(flee_mode) {
currently_fleeing = true; currently_fleeing = true;
CheckFlee(); CheckFlee();
break; break;