Add hatelist removal for far distances and time

This commit is contained in:
Michael Cook (mackal)
2018-01-18 15:44:51 -05:00
parent 7adc93d806
commit d8bbb428d8
3 changed files with 36 additions and 0 deletions
+30
View File
@@ -107,6 +107,7 @@ void HateList::SetHateAmountOnEnt(Mob* other, uint32 in_hate, uint32 in_damage)
entity->hatelist_damage = in_damage;
if (in_hate > 0)
entity->stored_hate_amount = in_hate;
entity->last_modified = Timer::GetCurrentTime();
}
}
@@ -208,6 +209,7 @@ void HateList::AddEntToHateList(Mob *in_entity, int32 in_hate, int32 in_damage,
in_entity->CastToClient()->IncrementAggroCount();
}
}
entity->last_modified = Timer::GetCurrentTime();
}
bool HateList::RemoveEntFromHateList(Mob *in_entity)
@@ -646,3 +648,31 @@ void HateList::SpellCast(Mob *caster, uint32 spell_id, float range, Mob* ae_cent
iter++;
}
}
void HateList::RemoveStaleEntries(int time_ms, float dist)
{
auto it = list.begin();
auto cur_time = Timer::GetCurrentTime();
while (it != list.end()) {
auto m = (*it)->entity_on_hatelist;
if (m) {
// 10 mins or distance
if ((cur_time - (*it)->last_modified > time_ms) || hate_owner->CalculateDistance(m->GetX(), m->GetY(), m->GetZ()) > dist) {
parse->EventNPC(EVENT_HATE_LIST, hate_owner->CastToNPC(), m, "0", 0);
if (m->IsClient()) {
m->CastToClient()->DecrementAggroCount();
m->CastToClient()->RemoveXTarget(hate_owner, true);
}
delete (*it);
it = list.erase(it);
continue;
}
}
++it;
}
}