mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-22 12:18:27 +00:00
[Quest API] Let HasQuestSub check encounters (#2435)
This fixes an edge case where trading would not detect the npc had a quest handler if it was registered inside a Lua encounter.
This commit is contained in:
@@ -97,8 +97,13 @@ void QuestParserCollection::RemoveEncounter(const std::string name) {
|
||||
}
|
||||
}
|
||||
|
||||
bool QuestParserCollection::HasQuestSub(uint32 npcid, QuestEventID evt) {
|
||||
return HasQuestSubLocal(npcid, evt) || HasQuestSubGlobal(evt);
|
||||
bool QuestParserCollection::HasQuestSub(uint32 npcid, QuestEventID evt, bool check_encounters) {
|
||||
return HasQuestSubLocal(npcid, evt) || HasQuestSubGlobal(evt) || (check_encounters && NPCHasEncounterSub(npcid, evt));
|
||||
}
|
||||
|
||||
bool QuestParserCollection::NPCHasEncounterSub(uint32 npc_id, QuestEventID evt) {
|
||||
std::string package_name = "npc_" + std::to_string(npc_id);
|
||||
return HasEncounterSub(evt, package_name);
|
||||
}
|
||||
|
||||
bool QuestParserCollection::HasQuestSubLocal(uint32 npcid, QuestEventID evt) {
|
||||
@@ -151,8 +156,12 @@ bool QuestParserCollection::HasQuestSubGlobal(QuestEventID evt) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool QuestParserCollection::PlayerHasQuestSub(QuestEventID evt) {
|
||||
return PlayerHasQuestSubLocal(evt) || PlayerHasQuestSubGlobal(evt);
|
||||
bool QuestParserCollection::PlayerHasQuestSub(QuestEventID evt, bool check_encounters) {
|
||||
return PlayerHasQuestSubLocal(evt) || PlayerHasQuestSubGlobal(evt) || (check_encounters && PlayerHasEncounterSub(evt));
|
||||
}
|
||||
|
||||
bool QuestParserCollection::PlayerHasEncounterSub(QuestEventID evt) {
|
||||
return HasEncounterSub(evt, "player");
|
||||
}
|
||||
|
||||
bool QuestParserCollection::PlayerHasQuestSubLocal(QuestEventID evt) {
|
||||
@@ -187,7 +196,16 @@ bool QuestParserCollection::PlayerHasQuestSubGlobal(QuestEventID evt) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool QuestParserCollection::SpellHasQuestSub(uint32 spell_id, QuestEventID evt) {
|
||||
bool QuestParserCollection::SpellHasEncounterSub(uint32 spell_id, QuestEventID evt) {
|
||||
std::string package_name = "spell_" + std::to_string(spell_id);
|
||||
return HasEncounterSub(evt, package_name);
|
||||
}
|
||||
|
||||
bool QuestParserCollection::SpellHasQuestSub(uint32 spell_id, QuestEventID evt, bool check_encounters) {
|
||||
if (check_encounters && SpellHasEncounterSub(spell_id, evt)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto iter = _spell_quest_status.find(spell_id);
|
||||
if(iter != _spell_quest_status.end()) {
|
||||
//loaded or failed to load
|
||||
@@ -209,10 +227,22 @@ bool QuestParserCollection::SpellHasQuestSub(uint32 spell_id, QuestEventID evt)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool QuestParserCollection::ItemHasQuestSub(EQ::ItemInstance *itm, QuestEventID evt) {
|
||||
bool QuestParserCollection::ItemHasEncounterSub(EQ::ItemInstance* item, QuestEventID evt) {
|
||||
if (item) {
|
||||
std::string package_name = "item_" + std::to_string(item->GetID());
|
||||
return HasEncounterSub(evt, package_name);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool QuestParserCollection::ItemHasQuestSub(EQ::ItemInstance *itm, QuestEventID evt, bool check_encounters) {
|
||||
if (itm == nullptr)
|
||||
return false;
|
||||
|
||||
if (check_encounters && ItemHasEncounterSub(itm, evt)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string item_script;
|
||||
if(itm->GetItem()->ScriptFileID != 0) {
|
||||
item_script = "script_";
|
||||
@@ -245,6 +275,18 @@ bool QuestParserCollection::ItemHasQuestSub(EQ::ItemInstance *itm, QuestEventID
|
||||
return false;
|
||||
}
|
||||
|
||||
bool QuestParserCollection::HasEncounterSub(QuestEventID evt, const std::string& package_name) {
|
||||
for (auto it = _encounter_quest_status.begin(); it != _encounter_quest_status.end(); ++it) {
|
||||
if (it->second != QuestFailedToLoad) {
|
||||
auto qit = _interfaces.find(it->second);
|
||||
if (qit != _interfaces.end() && qit->second->HasEncounterSub(package_name, evt)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int QuestParserCollection::EventNPC(QuestEventID evt, NPC *npc, Mob *init, std::string data, uint32 extra_data,
|
||||
std::vector<std::any> *extra_pointers) {
|
||||
int rd = DispatchEventNPC(evt, npc, init, data, extra_data, extra_pointers);
|
||||
|
||||
Reference in New Issue
Block a user