mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-16 22:58:34 +00:00
[Quest API] Add Scripting Support to Mercenaries (#4500)
* [Quest API] Add Scripting Support to Mercenaries * Cleanup * Cleanup * Update lua_merc.h * Update mob.cpp * XYZH * Final * Update attack.cpp * Update attack.cpp * Simplify event invocation * Inline example * Nullptr init example * EVENT_TIMER simplify add EventPlayerNpcBotMerc * EVENT_TIMER_START * Remove has_start_event * EVENT_TIMER_START with settimerMS * EVENT_POPUP_RESPONSE * Consolidation * Update attack.cpp * Push * Update quest_parser_collection.h * Comments * Cleanup per comments --------- Co-authored-by: Akkadius <akkadius1@gmail.com>
This commit is contained in:
+87
-232
@@ -90,12 +90,9 @@ void QuestManager::Process() {
|
||||
while (cur != end) {
|
||||
if (cur->Timer_.Enabled() && cur->Timer_.Check()) {
|
||||
if (cur->mob) {
|
||||
if (cur->mob->IsNPC()) {
|
||||
if (parse->HasQuestSub(cur->mob->GetNPCTypeID(), EVENT_TIMER)) {
|
||||
parse->EventNPC(EVENT_TIMER, cur->mob->CastToNPC(), nullptr, cur->name, 0);
|
||||
}
|
||||
}
|
||||
else if (cur->mob->IsEncounter()) {
|
||||
parse->EventMob(EVENT_TIMER, cur->mob, nullptr, [&]() { return cur->name; }, 0);
|
||||
|
||||
if (cur->mob->IsEncounter()) {
|
||||
parse->EventEncounter(
|
||||
EVENT_TIMER,
|
||||
cur->mob->CastToEncounter()->GetEncounterName(),
|
||||
@@ -104,17 +101,6 @@ void QuestManager::Process() {
|
||||
nullptr
|
||||
);
|
||||
}
|
||||
else if (cur->mob->IsClient()) {
|
||||
if (parse->PlayerHasQuestSub(EVENT_TIMER)) {
|
||||
//this is inheriently unsafe if we ever make it so more than npc/client start timers
|
||||
parse->EventPlayer(EVENT_TIMER, cur->mob->CastToClient(), cur->name, 0);
|
||||
}
|
||||
}
|
||||
else if (cur->mob->IsBot()) {
|
||||
if (parse->BotHasQuestSub(EVENT_TIMER)) {
|
||||
parse->EventBot(EVENT_TIMER, cur->mob->CastToBot(), nullptr, cur->name, 0);
|
||||
}
|
||||
}
|
||||
|
||||
//we MUST reset our iterator since the quest could have removed/added any
|
||||
//number of timers... worst case we have to check a bunch of timers twice
|
||||
@@ -539,32 +525,20 @@ void QuestManager::settimer(const std::string& timer_name, uint32 seconds, Mob*
|
||||
return;
|
||||
}
|
||||
|
||||
const bool has_start_event = (
|
||||
(mob->IsClient() && parse->PlayerHasQuestSub(EVENT_TIMER_START)) ||
|
||||
(mob->IsBot() && parse->BotHasQuestSub(EVENT_TIMER_START)) ||
|
||||
(mob->IsNPC() && parse->HasQuestSub(mob->GetNPCTypeID(), EVENT_TIMER_START))
|
||||
);
|
||||
std::function<std::string()> f = [&]() {
|
||||
return fmt::format(
|
||||
"{} {}",
|
||||
timer_name,
|
||||
seconds * 1000
|
||||
);
|
||||
};
|
||||
|
||||
if (!QTimerList.empty()) {
|
||||
for (auto& e : QTimerList) {
|
||||
if (e.mob && e.mob == mob && e.name == timer_name) {
|
||||
e.Timer_.Start(seconds * 1000, false);
|
||||
|
||||
if (has_start_event) {
|
||||
const std::string& export_string = fmt::format(
|
||||
"{} {}",
|
||||
timer_name,
|
||||
seconds * 1000
|
||||
);
|
||||
|
||||
if (mob->IsClient()) {
|
||||
parse->EventPlayer(EVENT_TIMER_START, mob->CastToClient(), export_string, 0);
|
||||
} else if (mob->IsBot()) {
|
||||
parse->EventBot(EVENT_TIMER_START, mob->CastToBot(), nullptr, export_string, 0);
|
||||
} else if (mob->IsNPC()) {
|
||||
parse->EventNPC(EVENT_TIMER_START, mob->CastToNPC(), nullptr, export_string, 0);
|
||||
}
|
||||
}
|
||||
parse->EventMob(EVENT_TIMER_START, mob, nullptr, f);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -573,21 +547,7 @@ void QuestManager::settimer(const std::string& timer_name, uint32 seconds, Mob*
|
||||
|
||||
QTimerList.emplace_back(QuestTimer(seconds * 1000, mob, timer_name));
|
||||
|
||||
if (has_start_event) {
|
||||
const std::string& export_string = fmt::format(
|
||||
"{} {}",
|
||||
timer_name,
|
||||
seconds * 1000
|
||||
);
|
||||
|
||||
if (mob->IsClient()) {
|
||||
parse->EventPlayer(EVENT_TIMER_START, mob->CastToClient(), export_string, 0);
|
||||
} else if (mob->IsBot()) {
|
||||
parse->EventBot(EVENT_TIMER_START, mob->CastToBot(), nullptr, export_string, 0);
|
||||
} else if (mob->IsNPC()) {
|
||||
parse->EventNPC(EVENT_TIMER_START, mob->CastToNPC(), nullptr, export_string, 0);
|
||||
}
|
||||
}
|
||||
parse->EventMob(EVENT_TIMER_START, mob, nullptr, f);
|
||||
}
|
||||
|
||||
void QuestManager::settimerMS(const std::string& timer_name, uint32 milliseconds)
|
||||
@@ -598,11 +558,13 @@ void QuestManager::settimerMS(const std::string& timer_name, uint32 milliseconds
|
||||
return;
|
||||
}
|
||||
|
||||
const bool has_start_event = (
|
||||
(owner->IsClient() && parse->PlayerHasQuestSub(EVENT_TIMER_START)) ||
|
||||
(owner->IsBot() && parse->BotHasQuestSub(EVENT_TIMER_START)) ||
|
||||
(owner->IsNPC() && parse->HasQuestSub(owner->GetNPCTypeID(), EVENT_TIMER_START))
|
||||
);
|
||||
std::function<std::string()> f = [&]() {
|
||||
return fmt::format(
|
||||
"{} {}",
|
||||
timer_name,
|
||||
milliseconds
|
||||
);
|
||||
};
|
||||
|
||||
if (questitem) {
|
||||
questitem->SetTimer(timer_name, milliseconds);
|
||||
@@ -625,21 +587,7 @@ void QuestManager::settimerMS(const std::string& timer_name, uint32 milliseconds
|
||||
if (e.mob && e.mob == owner && e.name == timer_name) {
|
||||
e.Timer_.Start(milliseconds, false);
|
||||
|
||||
if (has_start_event) {
|
||||
const std::string& export_string = fmt::format(
|
||||
"{} {}",
|
||||
e.name,
|
||||
milliseconds
|
||||
);
|
||||
|
||||
if (owner->IsClient()) {
|
||||
parse->EventPlayer(EVENT_TIMER_START, owner->CastToClient(), export_string, 0);
|
||||
} else if (owner->IsBot()) {
|
||||
parse->EventBot(EVENT_TIMER_START, owner->CastToBot(), nullptr, export_string, 0);
|
||||
} else if (owner->IsNPC()) {
|
||||
parse->EventNPC(EVENT_TIMER_START, owner->CastToNPC(), nullptr, export_string, 0);
|
||||
}
|
||||
}
|
||||
parse->EventMob(EVENT_TIMER_START, owner, nullptr, f);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -648,21 +596,7 @@ void QuestManager::settimerMS(const std::string& timer_name, uint32 milliseconds
|
||||
|
||||
QTimerList.emplace_back(QuestTimer(milliseconds, owner, timer_name));
|
||||
|
||||
if (has_start_event) {
|
||||
const std::string& export_string = fmt::format(
|
||||
"{} {}",
|
||||
timer_name,
|
||||
milliseconds
|
||||
);
|
||||
|
||||
if (owner->IsClient()) {
|
||||
parse->EventPlayer(EVENT_TIMER_START, owner->CastToClient(), export_string, 0);
|
||||
} else if (owner->IsBot()) {
|
||||
parse->EventBot(EVENT_TIMER_START, owner->CastToBot(), nullptr, export_string, 0);
|
||||
} else if (owner->IsNPC()) {
|
||||
parse->EventNPC(EVENT_TIMER_START, owner->CastToNPC(), nullptr, export_string, 0);
|
||||
}
|
||||
}
|
||||
parse->EventMob(EVENT_TIMER_START, owner, nullptr, f);
|
||||
}
|
||||
|
||||
void QuestManager::settimerMS(const std::string& timer_name, uint32 milliseconds, EQ::ItemInstance* inst)
|
||||
@@ -678,32 +612,20 @@ void QuestManager::settimerMS(const std::string& timer_name, uint32 milliseconds
|
||||
return;
|
||||
}
|
||||
|
||||
const bool has_start_event = (
|
||||
(m->IsClient() && parse->PlayerHasQuestSub(EVENT_TIMER_START)) ||
|
||||
(m->IsBot() && parse->BotHasQuestSub(EVENT_TIMER_START)) ||
|
||||
(m->IsNPC() && parse->HasQuestSub(m->GetNPCTypeID(), EVENT_TIMER_START))
|
||||
);
|
||||
std::function<std::string()> f = [&]() {
|
||||
return fmt::format(
|
||||
"{} {}",
|
||||
timer_name,
|
||||
milliseconds
|
||||
);
|
||||
};
|
||||
|
||||
if (!QTimerList.empty()) {
|
||||
for (auto& e : QTimerList) {
|
||||
if (e.mob && e.mob == m && e.name == timer_name) {
|
||||
e.Timer_.Start(milliseconds, false);
|
||||
|
||||
if (has_start_event) {
|
||||
const std::string& export_string = fmt::format(
|
||||
"{} {}",
|
||||
timer_name,
|
||||
milliseconds
|
||||
);
|
||||
|
||||
if (m->IsClient()) {
|
||||
parse->EventPlayer(EVENT_TIMER_START, m->CastToClient(), export_string, 0);
|
||||
} else if (m->IsBot()) {
|
||||
parse->EventBot(EVENT_TIMER_START, m->CastToBot(), nullptr, export_string, 0);
|
||||
} else if (m->IsNPC()) {
|
||||
parse->EventNPC(EVENT_TIMER_START, m->CastToNPC(), nullptr, export_string, 0);
|
||||
}
|
||||
}
|
||||
parse->EventMob(EVENT_TIMER_START, m, nullptr, f);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -712,21 +634,7 @@ void QuestManager::settimerMS(const std::string& timer_name, uint32 milliseconds
|
||||
|
||||
QTimerList.emplace_back(QuestTimer(milliseconds, m, timer_name));
|
||||
|
||||
if (has_start_event) {
|
||||
const std::string& export_string = fmt::format(
|
||||
"{} {}",
|
||||
timer_name,
|
||||
milliseconds
|
||||
);
|
||||
|
||||
if (m->IsClient()) {
|
||||
parse->EventPlayer(EVENT_TIMER_START, m->CastToClient(), export_string, 0);
|
||||
} else if (m->IsBot()) {
|
||||
parse->EventBot(EVENT_TIMER_START, m->CastToBot(), nullptr, export_string, 0);
|
||||
} else if (m->IsNPC()) {
|
||||
parse->EventNPC(EVENT_TIMER_START, m->CastToNPC(), nullptr, export_string, 0);
|
||||
}
|
||||
}
|
||||
parse->EventMob(EVENT_TIMER_START, m, nullptr, f);
|
||||
}
|
||||
|
||||
void QuestManager::stoptimer(const std::string& timer_name)
|
||||
@@ -751,23 +659,16 @@ void QuestManager::stoptimer(const std::string& timer_name)
|
||||
return;
|
||||
}
|
||||
|
||||
const bool has_stop_event = (
|
||||
(owner->IsClient() && parse->PlayerHasQuestSub(EVENT_TIMER_STOP)) ||
|
||||
(owner->IsBot() && parse->BotHasQuestSub(EVENT_TIMER_STOP)) ||
|
||||
(owner->IsNPC() && parse->HasQuestSub(owner->GetNPCTypeID(), EVENT_TIMER_STOP))
|
||||
);
|
||||
|
||||
for (auto e = QTimerList.begin(); e != QTimerList.end(); ++e) {
|
||||
if (e->mob && e->mob == owner && e->name == timer_name) {
|
||||
if (has_stop_event) {
|
||||
if (owner->IsClient()) {
|
||||
parse->EventPlayer(EVENT_TIMER_STOP, owner->CastToClient(), timer_name, 0);
|
||||
} else if (owner->IsBot()) {
|
||||
parse->EventBot(EVENT_TIMER_STOP, owner->CastToBot(), nullptr, timer_name, 0);
|
||||
} else if (owner->IsNPC()) {
|
||||
parse->EventNPC(EVENT_TIMER_STOP, owner->CastToNPC(), nullptr, timer_name, 0);
|
||||
parse->EventMob(
|
||||
EVENT_TIMER_STOP,
|
||||
owner,
|
||||
nullptr,
|
||||
[&]() {
|
||||
return timer_name;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
QTimerList.erase(e);
|
||||
break;
|
||||
@@ -792,23 +693,16 @@ void QuestManager::stoptimer(const std::string& timer_name, Mob* m)
|
||||
return;
|
||||
}
|
||||
|
||||
const bool has_stop_event = (
|
||||
(m->IsClient() && parse->PlayerHasQuestSub(EVENT_TIMER_STOP)) ||
|
||||
(m->IsBot() && parse->BotHasQuestSub(EVENT_TIMER_STOP)) ||
|
||||
(m->IsNPC() && parse->HasQuestSub(m->GetNPCTypeID(), EVENT_TIMER_STOP))
|
||||
);
|
||||
|
||||
for (auto e = QTimerList.begin(); e != QTimerList.end();) {
|
||||
if (e->mob && e->mob == m) {
|
||||
if (has_stop_event) {
|
||||
if (m->IsClient()) {
|
||||
parse->EventPlayer(EVENT_TIMER_STOP, m->CastToClient(), e->name, 0);
|
||||
} else if (m->IsBot()) {
|
||||
parse->EventBot(EVENT_TIMER_STOP, m->CastToBot(), nullptr, e->name, 0);
|
||||
} else if (m->IsNPC()) {
|
||||
parse->EventNPC(EVENT_TIMER_STOP, m->CastToNPC(), nullptr, e->name, 0);
|
||||
parse->EventMob(
|
||||
EVENT_TIMER_STOP,
|
||||
m,
|
||||
nullptr,
|
||||
[&]() {
|
||||
return timer_name;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
QTimerList.erase(e);
|
||||
break;
|
||||
@@ -847,23 +741,16 @@ void QuestManager::stopalltimers()
|
||||
return;
|
||||
}
|
||||
|
||||
const bool has_stop_event = (
|
||||
(owner->IsClient() && parse->PlayerHasQuestSub(EVENT_TIMER_STOP)) ||
|
||||
(owner->IsBot() && parse->BotHasQuestSub(EVENT_TIMER_STOP)) ||
|
||||
(owner->IsNPC() && parse->HasQuestSub(owner->GetNPCTypeID(), EVENT_TIMER_STOP))
|
||||
);
|
||||
|
||||
for (auto e = QTimerList.begin(); e != QTimerList.end();) {
|
||||
if (e->mob && e->mob == owner) {
|
||||
if (has_stop_event) {
|
||||
if (owner->IsClient()) {
|
||||
parse->EventPlayer(EVENT_TIMER_STOP, owner->CastToClient(), e->name, 0);
|
||||
} else if (owner->IsBot()) {
|
||||
parse->EventBot(EVENT_TIMER_STOP, owner->CastToBot(), nullptr, e->name, 0);
|
||||
} else if (owner->IsNPC()) {
|
||||
parse->EventNPC(EVENT_TIMER_STOP, owner->CastToNPC(), nullptr, e->name, 0);
|
||||
parse->EventMob(
|
||||
EVENT_TIMER_STOP,
|
||||
owner,
|
||||
nullptr,
|
||||
[&]() {
|
||||
return e->name;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
e = QTimerList.erase(e);
|
||||
} else {
|
||||
@@ -903,23 +790,16 @@ void QuestManager::stopalltimers(Mob* m)
|
||||
return;
|
||||
}
|
||||
|
||||
const bool has_stop_event = (
|
||||
(m->IsClient() && parse->PlayerHasQuestSub(EVENT_TIMER_STOP)) ||
|
||||
(m->IsBot() && parse->BotHasQuestSub(EVENT_TIMER_STOP)) ||
|
||||
(m->IsNPC() && parse->HasQuestSub(m->GetNPCTypeID(), EVENT_TIMER_STOP))
|
||||
);
|
||||
|
||||
for (auto e = QTimerList.begin(); e != QTimerList.end();) {
|
||||
if (e->mob && e->mob == m) {
|
||||
if (has_stop_event) {
|
||||
if (m->IsClient()) {
|
||||
parse->EventPlayer(EVENT_TIMER_STOP, m->CastToClient(), e->name, 0);
|
||||
} else if (m->IsBot()) {
|
||||
parse->EventBot(EVENT_TIMER_STOP, m->CastToBot(), nullptr, e->name, 0);
|
||||
} else if (m->IsNPC()) {
|
||||
parse->EventNPC(EVENT_TIMER_STOP, m->CastToNPC(), nullptr, e->name, 0);
|
||||
parse->EventMob(
|
||||
EVENT_TIMER_STOP,
|
||||
m,
|
||||
nullptr,
|
||||
[&]() {
|
||||
return e->name;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
e = QTimerList.erase(e);
|
||||
} else {
|
||||
@@ -955,12 +835,6 @@ void QuestManager::pausetimer(const std::string& timer_name, Mob* m)
|
||||
|
||||
uint32 milliseconds = 0;
|
||||
|
||||
const bool has_pause_event = (
|
||||
(mob->IsClient() && parse->PlayerHasQuestSub(EVENT_TIMER_PAUSE)) ||
|
||||
(mob->IsBot() && parse->BotHasQuestSub(EVENT_TIMER_PAUSE)) ||
|
||||
(mob->IsNPC() && parse->HasQuestSub(mob->GetNPCTypeID(), EVENT_TIMER_PAUSE))
|
||||
);
|
||||
|
||||
if (!QTimerList.empty()) {
|
||||
for (auto e = QTimerList.begin(); e != QTimerList.end(); ++e) {
|
||||
if (e->mob && e->mob == mob && e->name == timer_name) {
|
||||
@@ -979,21 +853,18 @@ void QuestManager::pausetimer(const std::string& timer_name, Mob* m)
|
||||
}
|
||||
);
|
||||
|
||||
if (has_pause_event) {
|
||||
const std::string& export_string = fmt::format(
|
||||
"{} {}",
|
||||
timer_name,
|
||||
milliseconds
|
||||
);
|
||||
|
||||
if (mob->IsClient()) {
|
||||
parse->EventPlayer(EVENT_TIMER_PAUSE, mob->CastToClient(), export_string, 0);
|
||||
} else if (mob->IsBot()) {
|
||||
parse->EventBot(EVENT_TIMER_PAUSE, mob->CastToBot(), nullptr, export_string, 0);
|
||||
} else if (mob->IsNPC()) {
|
||||
parse->EventNPC(EVENT_TIMER_PAUSE, mob->CastToNPC(), nullptr, export_string, 0);
|
||||
parse->EventMob(
|
||||
EVENT_TIMER_PAUSE,
|
||||
mob,
|
||||
nullptr,
|
||||
[&]() {
|
||||
return fmt::format(
|
||||
"{} {}",
|
||||
timer_name,
|
||||
milliseconds
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
LogQuests("Pausing timer [{}] for [{}] with [{}] ms remaining", timer_name, owner->GetName(), milliseconds);
|
||||
}
|
||||
@@ -1031,11 +902,13 @@ void QuestManager::resumetimer(const std::string& timer_name, Mob* m)
|
||||
return;
|
||||
}
|
||||
|
||||
const bool has_resume_event = (
|
||||
(mob->IsClient() && parse->PlayerHasQuestSub(EVENT_TIMER_RESUME)) ||
|
||||
(mob->IsBot() && parse->BotHasQuestSub(EVENT_TIMER_RESUME)) ||
|
||||
(mob->IsNPC() && parse->HasQuestSub(mob->GetNPCTypeID(), EVENT_TIMER_RESUME))
|
||||
);
|
||||
std::function<std::string()> f = [&]() {
|
||||
return fmt::format(
|
||||
"{} {}",
|
||||
timer_name,
|
||||
milliseconds
|
||||
);
|
||||
};
|
||||
|
||||
if (!QTimerList.empty()) {
|
||||
for (auto e : QTimerList) {
|
||||
@@ -1049,21 +922,8 @@ void QuestManager::resumetimer(const std::string& timer_name, Mob* m)
|
||||
milliseconds
|
||||
);
|
||||
|
||||
if (has_resume_event) {
|
||||
const std::string& export_string = fmt::format(
|
||||
"{} {}",
|
||||
timer_name,
|
||||
milliseconds
|
||||
);
|
||||
parse->EventMob(EVENT_TIMER_RESUME, mob, nullptr, f);
|
||||
|
||||
if (mob->IsClient()) {
|
||||
parse->EventPlayer(EVENT_TIMER_RESUME, mob->CastToClient(), export_string, 0);
|
||||
} else if (mob->IsBot()) {
|
||||
parse->EventBot(EVENT_TIMER_RESUME, mob->CastToBot(), nullptr, export_string, 0);
|
||||
} else if (mob->IsNPC()) {
|
||||
parse->EventNPC(EVENT_TIMER_RESUME, mob->CastToNPC(), nullptr, export_string, 0);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1071,21 +931,7 @@ void QuestManager::resumetimer(const std::string& timer_name, Mob* m)
|
||||
|
||||
QTimerList.emplace_back(QuestTimer(milliseconds, m, timer_name));
|
||||
|
||||
if (has_resume_event) {
|
||||
const std::string& export_string = fmt::format(
|
||||
"{} {}",
|
||||
timer_name,
|
||||
milliseconds
|
||||
);
|
||||
|
||||
if (mob->IsClient()) {
|
||||
parse->EventPlayer(EVENT_TIMER_RESUME, mob->CastToClient(), export_string, 0);
|
||||
} else if (mob->IsBot()) {
|
||||
parse->EventBot(EVENT_TIMER_RESUME, mob->CastToBot(), nullptr, export_string, 0);
|
||||
} else if (mob->IsNPC()) {
|
||||
parse->EventNPC(EVENT_TIMER_RESUME, mob->CastToNPC(), nullptr, export_string, 0);
|
||||
}
|
||||
}
|
||||
parse->EventMob(EVENT_TIMER_RESUME, mob, nullptr, f);
|
||||
|
||||
LogQuests(
|
||||
"Creating a new timer and resuming [{}] for [{}] with [{}] ms remaining",
|
||||
@@ -4213,6 +4059,15 @@ Bot *QuestManager::GetBot() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Merc *QuestManager::GetMerc() const {
|
||||
if (!quests_running_.empty()) {
|
||||
running_quest e = quests_running_.top();
|
||||
return (e.owner && e.owner->IsMerc()) ? e.owner->CastToMerc() : nullptr;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Mob *QuestManager::GetOwner() const {
|
||||
if(!quests_running_.empty()) {
|
||||
running_quest e = quests_running_.top();
|
||||
|
||||
Reference in New Issue
Block a user