Refactor and generalize NPCEvent logic

This commit is contained in:
2023-09-10 20:02:52 +02:00
committed by gsemaj
parent 2924a27eb4
commit 6a69388822
3 changed files with 13 additions and 22 deletions

View File

@@ -316,12 +316,10 @@ void CombatNPC::transition(AIState newState, EntityRef src) {
transition(AIState::INACTIVE, id);
}
// TODO: Properly refactor this
if (newState == AIState::DEAD && src.kind == EntityKind::PLAYER) {
for (NPCEvent& event : NPCManager::NPCEvents)
if (event.trigger == ON_KILLED && event.npcType == type)
event.handler(src.sock, this);
}
// trigger special NPCEvents, if applicable
for (NPCEvent& event : NPCManager::NPCEvents)
if (event.triggerState == newState && event.npcType == type)
event.handler(this);
}
#pragma endregion