[Quest API] Add GetHateListClosest(), GetHateListClosestBot(), GetHateListClosestClient(), and GetHateListClosestNPC() methods/overloads to Perl/Lua (#3359)

* Add HateListClosestClient available for scripting.

* Add other methods.

* Use pre-existing constants.

* Typos

* Update mob.h

---------

Co-authored-by: Kinglykrab <kinglykrab@gmail.com>
This commit is contained in:
RekkasGit
2023-05-15 21:23:19 -04:00
committed by GitHub
parent fa55fd1664
commit 32f7dc3d1b
6 changed files with 135 additions and 15 deletions
+37 -11
View File
@@ -155,28 +155,54 @@ Mob* HateList::GetDamageTopOnHateList(Mob* hater)
return current;
}
Mob* HateList::GetClosestEntOnHateList(Mob *hater, bool skip_mezzed) {
Mob* HateList::GetClosestEntOnHateList(Mob *hater, bool skip_mezzed, EntityFilterType entity_type) {
Mob* close_entity = nullptr;
float close_distance = 99999.9f;
float this_distance;
auto iterator = list.begin();
while (iterator != list.end()) {
if (skip_mezzed && (*iterator)->entity_on_hatelist->IsMezzed()) {
++iterator;
for (const auto& e : list) {
if (!e->entity_on_hatelist) {
continue;
}
this_distance = DistanceSquaredNoZ((*iterator)->entity_on_hatelist->GetPosition(), hater->GetPosition());
if ((*iterator)->entity_on_hatelist != nullptr && this_distance <= close_distance) {
close_distance = this_distance;
close_entity = (*iterator)->entity_on_hatelist;
if (skip_mezzed && e->entity_on_hatelist->IsMezzed()) {
continue;
}
switch (entity_type) {
case EntityFilterType::Bots:
if (!e->entity_on_hatelist->IsBot()) {
continue;
}
break;
case EntityFilterType::Clients:
if (!e->entity_on_hatelist->IsClient()) {
continue;
}
break;
case EntityFilterType::NPCs:
if (!e->entity_on_hatelist->IsNPC()) {
continue;
}
break;
case EntityFilterType::All:
default:
break;
}
this_distance = DistanceSquaredNoZ(e->entity_on_hatelist->GetPosition(), hater->GetPosition());
if (this_distance <= close_distance) {
close_distance = this_distance;
close_entity = e->entity_on_hatelist;
}
++iterator;
}
if ((!close_entity && hater->IsNPC()) || (close_entity && close_entity->DivineAura()))
if (
(!close_entity && hater->IsNPC()) ||
(close_entity && close_entity->DivineAura())
) {
close_entity = hater->CastToNPC()->GetHateTop();
}
return close_entity;
}