mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-24 14:01:05 +00:00
Refactor and generalize NPCEvent logic
This commit is contained in:
parent
2924a27eb4
commit
6a69388822
@ -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) {
|
||||
// trigger special NPCEvents, if applicable
|
||||
for (NPCEvent& event : NPCManager::NPCEvents)
|
||||
if (event.trigger == ON_KILLED && event.npcType == type)
|
||||
event.handler(src.sock, this);
|
||||
}
|
||||
if (event.triggerState == newState && event.npcType == type)
|
||||
event.handler(this);
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
|
@ -293,13 +293,12 @@ BaseNPC* NPCManager::getNearestNPC(std::set<Chunk*>* chunks, int X, int Y, int Z
|
||||
return npc;
|
||||
}
|
||||
|
||||
// TODO: Move this to MobAI, possibly
|
||||
// TODO: Move this to separate file in ai/ subdir when implementing more events
|
||||
#pragma region NPCEvents
|
||||
|
||||
// summon right arm and stage 2 body
|
||||
static void lordFuseStageTwo(CNSocket *sock, BaseNPC *npc) {
|
||||
static void lordFuseStageTwo(CombatNPC *npc) {
|
||||
Mob *oldbody = (Mob*)npc; // adaptium, stun
|
||||
Player *plr = PlayerManager::getPlayer(sock);
|
||||
|
||||
std::cout << "Lord Fuse stage two" << std::endl;
|
||||
|
||||
@ -320,9 +319,8 @@ static void lordFuseStageTwo(CNSocket *sock, BaseNPC *npc) {
|
||||
}
|
||||
|
||||
// summon left arm and stage 3 body
|
||||
static void lordFuseStageThree(CNSocket *sock, BaseNPC *npc) {
|
||||
static void lordFuseStageThree(CombatNPC *npc) {
|
||||
Mob *oldbody = (Mob*)npc;
|
||||
Player *plr = PlayerManager::getPlayer(sock);
|
||||
|
||||
std::cout << "Lord Fuse stage three" << std::endl;
|
||||
|
||||
@ -342,8 +340,8 @@ static void lordFuseStageThree(CNSocket *sock, BaseNPC *npc) {
|
||||
}
|
||||
|
||||
std::vector<NPCEvent> NPCManager::NPCEvents = {
|
||||
NPCEvent(2466, ON_KILLED, lordFuseStageTwo),
|
||||
NPCEvent(2467, ON_KILLED, lordFuseStageThree),
|
||||
NPCEvent(2466, AIState::DEAD, lordFuseStageTwo),
|
||||
NPCEvent(2467, AIState::DEAD, lordFuseStageThree),
|
||||
};
|
||||
|
||||
#pragma endregion NPCEvents
|
||||
|
@ -14,20 +14,15 @@
|
||||
|
||||
#define RESURRECT_HEIGHT 400
|
||||
|
||||
enum Trigger {
|
||||
ON_KILLED,
|
||||
ON_COMBAT
|
||||
};
|
||||
|
||||
typedef void (*NPCEventHandler)(CNSocket*, BaseNPC*);
|
||||
typedef void (*NPCEventHandler)(CombatNPC*);
|
||||
|
||||
struct NPCEvent {
|
||||
int32_t npcType;
|
||||
int trigger;
|
||||
AIState triggerState;
|
||||
NPCEventHandler handler;
|
||||
|
||||
NPCEvent(int32_t t, int tr, NPCEventHandler hndlr)
|
||||
: npcType(t), trigger(tr), handler(hndlr) {}
|
||||
NPCEvent(int32_t t, AIState tr, NPCEventHandler hndlr)
|
||||
: npcType(t), triggerState(tr), handler(hndlr) {}
|
||||
};
|
||||
|
||||
namespace NPCManager {
|
||||
|
Loading…
Reference in New Issue
Block a user