[int64] Hate Fixes (#2163)

* Hate fixes

* Update perl_hateentry.cpp

* Update perl_hateentry.cpp
This commit is contained in:
Chris Miles 2022-05-09 20:49:43 -05:00 committed by GitHub
parent 763fc82379
commit 209b0eb273
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 119 additions and 47 deletions

View File

@ -129,6 +129,7 @@ namespace Logs {
Saylink,
ChecksumVerification,
CombatRecord,
Hate,
MaxCategoryID /* Don't Remove this */
};
@ -216,6 +217,7 @@ namespace Logs {
"Saylink",
"ChecksumVerification",
"CombatRecord",
"Hate",
};
}

View File

@ -716,6 +716,16 @@
OutF(LogSys, Logs::Detail, Logs::CombatRecord, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\
} while (0)
#define LogHate(message, ...) do {\
if (LogSys.log_settings[Logs::Hate].is_category_enabled == 1)\
OutF(LogSys, Logs::General, Logs::Hate, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\
} while (0)
#define LogHateDetail(message, ...) do {\
if (LogSys.log_settings[Logs::Hate].is_category_enabled == 1)\
OutF(LogSys, Logs::Detail, Logs::Hate, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\
} while (0)
#define Log(debug_level, log_category, message, ...) do {\
if (LogSys.log_settings[log_category].is_category_enabled == 1)\
LogSys.Out(debug_level, log_category, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\
@ -1154,6 +1164,12 @@
#define LogCombatRecordDetail(message, ...) do {\
} while (0)
#define LogHate(message, ...) do {\
} while (0)
#define LogHateDetail(message, ...) do {\
} while (0)
#define Log(debug_level, log_category, message, ...) do {\
} while (0)

View File

@ -108,7 +108,7 @@ void EntityList::DescribeAggro(Client *to_who, NPC *from_who, float d, bool verb
}
if (is_engaged) {
uint64 hate_amount = from_who->GetHateAmount(npc);
int64 hate_amount = from_who->GetHateAmount(npc);
to_who->Message(
Chat::White,
fmt::format(
@ -1509,8 +1509,8 @@ bool Mob::PassCharismaCheck(Mob* caster, uint16 spell_id) {
void Mob::RogueEvade(Mob *other)
{
int amount = other->GetHateAmount(this) * zone->random.Int(40, 70) / 100;
other->SetHateAmountOnEnt(this, std::max(100, amount));
int64 amount = other->GetHateAmount(this) * zone->random.Int(40, 70) / 100;
other->SetHateAmountOnEnt(this, std::max((int64)100, amount));
return;
}

View File

@ -1148,7 +1148,7 @@ int64 Mob::GetWeaponDamage(Mob *against, const EQ::ItemData *weapon_item) {
return dmg;
}
int64 Mob::GetWeaponDamage(Mob *against, const EQ::ItemInstance *weapon_item, uint64 *hate)
int64 Mob::GetWeaponDamage(Mob *against, const EQ::ItemInstance *weapon_item, int64 *hate)
{
int64 dmg = 0;
int64 banedmg = 0;
@ -1509,7 +1509,7 @@ bool Client::Attack(Mob* other, int Hand, bool bRiposte, bool IsStrikethrough, b
my_hit.damage_done = 1;
my_hit.min_damage = 0;
uint8 mylevel = GetLevel() ? GetLevel() : 1;
uint64 hate = 0;
int64 hate = 0;
if (weapon)
hate = (weapon->GetItem()->Damage + weapon->GetItem()->ElemDmgAmt);
@ -2749,7 +2749,7 @@ bool NPC::Death(Mob* killer_mob, int64 damage, uint16 spell, EQ::skills::SkillTy
return true;
}
void Mob::AddToHateList(Mob* other, uint64 hate /*= 0*/, int64 damage /*= 0*/, bool iYellForHelp /*= true*/, bool bFrenzy /*= false*/, bool iBuffTic /*= false*/, uint16 spell_id, bool pet_command)
void Mob::AddToHateList(Mob* other, int64 hate /*= 0*/, int64 damage /*= 0*/, bool iYellForHelp /*= true*/, bool bFrenzy /*= false*/, bool iBuffTic /*= false*/, uint16 spell_id, bool pet_command)
{
if (!other)
return;

View File

@ -4211,7 +4211,7 @@ void Bot::AddBotItem(
);
return;
}
if (!database.botdb.SaveItemBySlot(this, slot_id, inst)) {
LogError("Failed to save item by slot to slot [{}] for [{}].", slot_id, GetCleanName());
return;
@ -4267,7 +4267,7 @@ void Bot::RemoveBotItem(uint32 item_id) {
if (!inst || !inst->GetItem()) {
continue;
}
if (inst->GetID() == item_id) {
std::string error_message;
@ -4980,8 +4980,8 @@ void Bot::Damage(Mob *from, int64 damage, uint16 spell_id, EQ::skills::SkillType
}
}
//void Bot::AddToHateList(Mob* other, uint64 hate = 0, int64 damage = 0, bool iYellForHelp = true, bool bFrenzy = false, bool iBuffTic = false)
void Bot::AddToHateList(Mob* other, uint64 hate, int64 damage, bool iYellForHelp, bool bFrenzy, bool iBuffTic, bool pet_command) {
//void Bot::AddToHateList(Mob* other, int64 hate = 0, int64 damage = 0, bool iYellForHelp = true, bool bFrenzy = false, bool iBuffTic = false)
void Bot::AddToHateList(Mob* other, int64 hate, int64 damage, bool iYellForHelp, bool bFrenzy, bool iBuffTic, bool pet_command) {
Mob::AddToHateList(other, hate, damage, iYellForHelp, bFrenzy, iBuffTic, pet_command);
}
@ -5055,7 +5055,7 @@ bool Bot::Attack(Mob* other, int Hand, bool FromRiposte, bool IsStrikethrough, b
my_hit.damage_done = 1;
my_hit.min_damage = 0;
uint8 mylevel = GetLevel() ? GetLevel() : 1;
uint64 hate = 0;
int64 hate = 0;
if (weapon)
hate = (weapon->GetItem()->Damage + weapon->GetItem()->ElemDmgAmt);
@ -6310,7 +6310,7 @@ void Bot::RogueBackstab(Mob *other, bool min_damage, int ReuseTime)
return;
}
uint64 hate = 0;
int64 hate = 0;
int base_damage = GetBaseSkillDamage(EQ::skills::SkillBackstab, other);
hate = base_damage;

View File

@ -217,7 +217,7 @@ public:
bool DoFinishedSpellGroupTarget(uint16 spell_id, Mob* spellTarget, EQ::spells::CastingSlot slot, bool &stopLogic);
void SendBotArcheryWearChange(uint8 material_slot, uint32 material, uint32 color);
void Camp(bool databaseSave = true);
virtual void AddToHateList(Mob* other, uint64 hate = 0, int64 damage = 0, bool iYellForHelp = true, bool bFrenzy = false, bool iBuffTic = false, bool pet_command = false);
virtual void AddToHateList(Mob* other, int64 hate = 0, int64 damage = 0, bool iYellForHelp = true, bool bFrenzy = false, bool iBuffTic = false, bool pet_command = false);
virtual void SetTarget(Mob* mob);
virtual void Zone();
std::vector<AISpells_Struct> GetBotSpells() { return AIspells; }

View File

@ -3618,7 +3618,7 @@ void EntityList::ClearZoneFeignAggro(Mob *targ)
}
}
void EntityList::AggroZone(Mob *who, uint64 hate)
void EntityList::AggroZone(Mob *who, int64 hate)
{
auto it = npc_list.begin();
while (it != npc_list.end()) {

View File

@ -460,7 +460,7 @@ public:
void ClearWaterAggro(Mob* targ);
void ClearFeignAggro(Mob* targ);
void ClearZoneFeignAggro(Mob* targ);
void AggroZone(Mob* who, uint64 hate = 0);
void AggroZone(Mob* who, int64 hate = 0);
bool Fighting(Mob* targ);
void RemoveFromHateLists(Mob* mob, bool settoone = false);

View File

@ -7,7 +7,7 @@ void command_aggrozone(Client *c, const Seperator *sep)
target = c->GetTarget();
}
uint64 hate = 0;
int64 hate = 0;
if (sep->IsNumber(1)) {
hate = std::strtoll(sep->arg[1], nullptr, 10);
}

View File

@ -98,7 +98,7 @@ struct_HateList *HateList::Find(Mob *in_entity)
return nullptr;
}
void HateList::SetHateAmountOnEnt(Mob* other, uint64 in_hate, uint64 in_damage)
void HateList::SetHateAmountOnEnt(Mob* other, int64 in_hate, uint64 in_damage)
{
struct_HateList *entity = Find(other);
if (entity)
@ -199,6 +199,16 @@ void HateList::AddEntToHateList(Mob *in_entity, int64 in_hate, int64 in_damage,
entity->stored_hate_amount += in_hate;
entity->is_entity_frenzy = in_is_entity_frenzied;
entity->last_modified = Timer::GetCurrentTime();
LogHate(
"AddEntToHateList in_entity [{}] ({}) in_hate [{}] in_damage [{}] stored_hate_amount [{}] hatelist_damage [{}]",
in_entity->GetCleanName(),
in_entity->GetID(),
in_hate,
in_damage,
entity->stored_hate_amount,
entity->hatelist_damage
);
}
else if (iAddIfNotExist) {
entity = new struct_HateList;
@ -503,8 +513,21 @@ Mob *HateList::GetEntWithMostHateOnList(bool skip_mezzed){
while (iterator != list.end())
{
struct_HateList *cur = (*iterator);
LogHateDetail(
"Looping GetEntWithMostHateOnList1 [{}] cur [{}] hate [{}] calc [{}]",
cur->entity_on_hatelist->GetMobDescription(),
cur->stored_hate_amount,
hate,
(cur->stored_hate_amount > hate)
);
if (cur && cur->entity_on_hatelist != nullptr && (cur->stored_hate_amount > hate))
{
LogHateDetail(
"Looping GetEntWithMostHateOnList2 [{}]",
cur->entity_on_hatelist->GetMobDescription()
);
if (!skip_mezzed || !cur->entity_on_hatelist->IsMezzed()) {
top = cur->entity_on_hatelist;
hate = cur->stored_hate_amount;

View File

@ -28,10 +28,10 @@ struct ExtraAttackOptions;
struct struct_HateList {
Mob *entity_on_hatelist;
int64 hatelist_damage;
uint64 stored_hate_amount;
int64 stored_hate_amount;
bool is_entity_frenzy;
int8 oor_count; // count on how long we've been out of range
uint64 last_modified; // we need to remove this if it gets higher than 10 mins
uint32 last_modified; // we need to remove this if it gets higher than 10 mins
};
class HateList {
@ -76,7 +76,7 @@ public:
void DoFactionHits(int64 npc_faction_level_id);
void IsEntityInFrenzyMode();
void PrintHateListToClient(Client *c);
void SetHateAmountOnEnt(Mob *other, uint64 in_hate, uint64 in_damage);
void SetHateAmountOnEnt(Mob *other, int64 in_hate, uint64 in_damage);
void SetHateOwner(Mob *new_hate_owner) { hate_owner = new_hate_owner; }
void SpellCast(Mob *caster, uint32 spell_id, float range, Mob *ae_center = nullptr);
void WipeHateList();

View File

@ -30,12 +30,12 @@ void Lua_HateEntry::SetDamage(int64 value) {
self->hatelist_damage = value;
}
uint64 Lua_HateEntry::GetHate() {
int64 Lua_HateEntry::GetHate() {
Lua_Safe_Call_Int();
return self->stored_hate_amount;
}
void Lua_HateEntry::SetHate(uint64 value) {
void Lua_HateEntry::SetHate(int64 value) {
Lua_Safe_Call_Void();
self->stored_hate_amount = value;
}

View File

@ -22,8 +22,8 @@ public:
void SetEnt(Lua_Mob e);
int64 GetDamage();
void SetDamage(int64 value);
uint64 GetHate();
void SetHate(uint64 value);
int64 GetHate();
void SetHate(int64 value);
int GetFrenzy();
void SetFrenzy(bool value);
};

View File

@ -1066,12 +1066,12 @@ void Lua_Mob::DoubleAggro(Lua_Mob other) {
self->DoubleAggro(other);
}
uint64 Lua_Mob::GetHateAmount(Lua_Mob target) {
int64 Lua_Mob::GetHateAmount(Lua_Mob target) {
Lua_Safe_Call_Int();
return self->GetHateAmount(target);
}
uint64 Lua_Mob::GetHateAmount(Lua_Mob target, bool is_damage) {
int64 Lua_Mob::GetHateAmount(Lua_Mob target, bool is_damage) {
Lua_Safe_Call_Int();
return self->GetHateAmount(target, is_damage);
}
@ -2653,8 +2653,8 @@ luabind::scope lua_register_mob() {
.def("GetHandToHandDamage", (int(Lua_Mob::*)(void))&Lua_Mob::GetHandToHandDamage)
.def("GetHandToHandDelay", (int(Lua_Mob::*)(void))&Lua_Mob::GetHandToHandDelay)
.def("GetHaste", (int(Lua_Mob::*)(void))&Lua_Mob::GetHaste)
.def("GetHateAmount", (uint64(Lua_Mob::*)(Lua_Mob))&Lua_Mob::GetHateAmount)
.def("GetHateAmount", (uint64(Lua_Mob::*)(Lua_Mob,bool))&Lua_Mob::GetHateAmount)
.def("GetHateAmount", (int64(Lua_Mob::*)(Lua_Mob))&Lua_Mob::GetHateAmount)
.def("GetHateAmount", (int64(Lua_Mob::*)(Lua_Mob,bool))&Lua_Mob::GetHateAmount)
.def("GetHateClosest", &Lua_Mob::GetHateClosest)
.def("GetHateDamageTop", (Lua_Mob(Lua_Mob::*)(Lua_Mob))&Lua_Mob::GetHateDamageTop)
.def("GetHateList", &Lua_Mob::GetHateList)

View File

@ -230,8 +230,8 @@ public:
void SetHate(Lua_Mob other, int64 hate, int64 damage);
void HalveAggro(Lua_Mob other);
void DoubleAggro(Lua_Mob other);
uint64 GetHateAmount(Lua_Mob target);
uint64 GetHateAmount(Lua_Mob target, bool is_damage);
int64 GetHateAmount(Lua_Mob target);
int64 GetHateAmount(Lua_Mob target, bool is_damage);
uint64 GetDamageAmount(Lua_Mob target);
void WipeHateList();
bool CheckAggro(Lua_Mob other);

View File

@ -4018,7 +4018,7 @@ std::string Mob::GetTargetDescription(Mob* target, uint8 description_type)
auto d = fmt::format(
"{}",
(
(
this == target ?
self_return :
fmt::format(
@ -6865,3 +6865,12 @@ void Mob::SetBucket(std::string bucket_name, std::string bucket_value, std::stri
std::string full_bucket_name = fmt::format("{}-{}", GetBucketKey(), bucket_name);
DataBucket::SetData(full_bucket_name, bucket_value, expiration);
}
std::string Mob::GetMobDescription()
{
return fmt::format(
"[{}] ({})",
GetCleanName(),
GetID()
);
}

View File

@ -682,14 +682,14 @@ public:
//AI
static uint32 GetLevelCon(uint8 mylevel, uint8 iOtherLevel);
inline uint32 GetLevelCon(uint8 iOtherLevel) const { return GetLevelCon(GetLevel(), iOtherLevel); }
virtual void AddToHateList(Mob* other, uint64 hate = 0, int64 damage = 0, bool iYellForHelp = true,
virtual void AddToHateList(Mob* other, int64 hate = 0, int64 damage = 0, bool iYellForHelp = true,
bool bFrenzy = false, bool iBuffTic = false, uint16 spell_id = SPELL_UNKNOWN, bool pet_comand = false);
bool RemoveFromHateList(Mob* mob);
void SetHateAmountOnEnt(Mob* other, int64 hate = 0, int64 damage = 0) { hate_list.SetHateAmountOnEnt(other,hate,damage);}
void HalveAggro(Mob *other) { uint64 in_hate = GetHateAmount(other); SetHateAmountOnEnt(other, (in_hate > 1 ? in_hate / 2 : 1)); }
void DoubleAggro(Mob *other) { uint64 in_hate = GetHateAmount(other); SetHateAmountOnEnt(other, (in_hate ? in_hate * 2 : 1)); }
uint64 GetHateAmount(Mob* tmob, bool is_dam = false) { return hate_list.GetEntHateAmount(tmob,is_dam);}
uint64 GetDamageAmount(Mob* tmob) { return hate_list.GetEntHateAmount(tmob, true);}
void HalveAggro(Mob *other) { int64 in_hate = GetHateAmount(other); SetHateAmountOnEnt(other, (in_hate > 1 ? in_hate / 2 : 1)); }
void DoubleAggro(Mob *other) { int64 in_hate = GetHateAmount(other); SetHateAmountOnEnt(other, (in_hate ? in_hate * 2 : 1)); }
int64 GetHateAmount(Mob* tmob, bool is_dam = false) { return hate_list.GetEntHateAmount(tmob,is_dam);}
int64 GetDamageAmount(Mob* tmob) { return hate_list.GetEntHateAmount(tmob, true);}
int GetHateRatio(Mob *first, Mob *with) { return hate_list.GetHateRatio(first, with); }
Mob* GetHateTop() { return hate_list.GetEntWithMostHateOnList(this);}
Mob* GetSecondaryHate(Mob *skip) { return hate_list.GetEntWithMostHateOnList(this, skip); }
@ -722,6 +722,7 @@ public:
static bool CheckLosFN(glm::vec3 posWatcher, float sizeWatcher, glm::vec3 posTarget, float sizeTarget);
inline void SetLastLosState(bool value) { last_los_check = value; }
inline bool CheckLastLosState() const { return last_los_check; }
std::string GetMobDescription();
//Quest
void CameraEffect(uint32 duration, uint32 intensity, Client *c = nullptr, bool global = false);
@ -1342,7 +1343,7 @@ public:
void DelAssistCap() { --npc_assist_cap; }
void ResetAssistCap() { npc_assist_cap = 0; }
int64 GetWeaponDamage(Mob *against, const EQ::ItemData *weapon_item);
int64 GetWeaponDamage(Mob *against, const EQ::ItemInstance *weapon_item, uint64 *hate = nullptr);
int64 GetWeaponDamage(Mob *against, const EQ::ItemInstance *weapon_item, int64 *hate = nullptr);
int64 GetHPRegen() const;
int64 GetManaRegen() const;

View File

@ -53,7 +53,7 @@ XS(XS_HateEntry_GetHate) {
Perl_croak(aTHX_ "Usage: HateEntry::GetHate(THIS)"); // @categories Script Utility, Hate and Aggro
{
struct_HateList *THIS;
int32 RETVAL;
int64 RETVAL;
dXSTARG;
VALIDATE_THIS_IS_HATE;
RETVAL = THIS->stored_hate_amount;
@ -70,7 +70,7 @@ XS(XS_HateEntry_GetDamage) {
Perl_croak(aTHX_ "Usage: HateEntry::GetDamage(THIS)"); // @categories Script Utility, Hate and Aggro
{
struct_HateList *THIS;
int32 RETVAL;
int64 RETVAL;
dXSTARG;
VALIDATE_THIS_IS_HATE;
RETVAL = THIS->hatelist_damage;

View File

@ -3719,7 +3719,7 @@ XS(XS_Mob_GetHateAmount) {
Perl_croak(aTHX_ "Usage: Mob::GetHateAmount(THIS, Mob* mob, [bool is_damage = false])"); // @categories Hate and Aggro
{
Mob *THIS;
uint32 RETVAL;
int64 RETVAL;
dXSTARG;
Mob *tmob;
bool is_dam;
@ -3752,7 +3752,7 @@ XS(XS_Mob_GetDamageAmount) {
Perl_croak(aTHX_ "Usage: Mob::GetDamageAmount(THIS, Mob* target_mob)"); // @categories Stats and Attributes
{
Mob *THIS;
uint32 RETVAL;
uint64 RETVAL;
dXSTARG;
Mob *tmob;
VALIDATE_THIS_IS_MOB;

View File

@ -165,7 +165,7 @@ void Mob::DoSpecialAttackDamage(Mob *who, EQ::skills::SkillType skill, int32 bas
if (who->GetSpecialAbility(IMMUNE_MELEE_EXCEPT_BANE) && skill != EQ::skills::SkillBackstab)
my_hit.damage_done = DMG_INVULNERABLE;
uint64 hate = my_hit.base_damage;
int64 hate = my_hit.base_damage;
if (hate_override > -1)
hate = hate_override;
@ -609,7 +609,7 @@ void Mob::RogueBackstab(Mob* other, bool min_damage, int ReuseTime)
if (!other)
return;
uint64 hate = 0;
int64 hate = 0;
// make sure we can hit (bane, magical, etc)
if (IsClient()) {
@ -839,7 +839,7 @@ void Mob::DoArcheryAttackDmg(Mob *other, const EQ::ItemInstance *RangeWeapon, co
LogCombat("Ranged attack hit [{}]", other->GetName());
uint64 hate = 0;
int64 hate = 0;
int64 TotalDmg = 0;
int WDmg = 0;
int ADmg = 0;
@ -2042,11 +2042,32 @@ void Mob::Taunt(NPC *who, bool always_succeed, int chance_bonus, bool FromSpell,
tauntchance /= 100.0f;
success = tauntchance > zone->random.Real(0, 1);
LogHate(
"Taunter mob {} target npc {} tauntchance [{}] success [{}] hate_top [{}]",
GetMobDescription(),
who->GetMobDescription(),
tauntchance,
success ? "true" : "false",
hate_top ? hate_top->GetMobDescription() : "not found"
);
}
if (success) {
if (hate_top && hate_top != this) {
int64 newhate = (who->GetNPCHate(hate_top) - who->GetNPCHate(this)) + 1 + bonus_hate;
LogHate(
"Taunter mob {} target npc {} newhate [{}] hated_top {} hate_of_top [{}] this_hate [{}] bonus_hate [{}]",
GetMobDescription(),
who->GetMobDescription(),
newhate,
hate_top->GetMobDescription(),
who->GetNPCHate(hate_top),
who->GetNPCHate(this),
bonus_hate
);
who->CastToNPC()->AddToHateList(this, newhate);
success = true;
} else {
@ -2223,7 +2244,7 @@ void Mob::DoMeleeSkillAttackDmg(Mob *other, uint16 weapon_damage, EQ::skills::Sk
skillinuse = EQ::skills::SkillOffense;
int64 damage = 0;
uint64 hate = 0;
int64 hate = 0;
if (hate == 0 && weapon_damage > 1)
hate = weapon_damage;

View File

@ -4017,7 +4017,7 @@ void Mob::DoBuffTic(const Buffs_Struct &buff, int slot, Mob *caster)
case SE_AddHateOverTimePct: {
if (IsNPC()) {
uint64 new_hate = CastToNPC()->GetHateAmount(caster) * (100 + spell.base_value[i]) / 100;
int64 new_hate = CastToNPC()->GetHateAmount(caster) * (100 + spell.base_value[i]) / 100;
if (new_hate <= 0)
new_hate = 1;

View File

@ -907,7 +907,7 @@ int64 Mob::TuneClientAttack(Mob* other, bool no_avoid, bool no_hit_chance, int h
my_hit.damage_done = 1;
my_hit.min_damage = 0;
uint8 mylevel = GetLevel() ? GetLevel() : 1;
uint64 hate = 0;
int64 hate = 0;
if (weapon)
hate = (weapon->GetItem()->Damage + weapon->GetItem()->ElemDmgAmt);