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