[Quest API] (Performance) Check spell or cast events exist before export and execute (#2897)

* [Quest API] Optionally parse spell/cast events

# Notes
- Optionally parses `EVENT_CAST`, `EVENT_CAST_BEGIN`, `EVENT_CAST_ON`, `EVENT_SPELL_EFFECT_NPC`, `EVENT_SPELL_EFFECT_CLIENT`, `EVENT_SPELL_EFFECT_BOT`, `EVENT_SPELL_EFFECT_BUFF_TIC_CLIENT`, `EVENT_SPELL_EFFECT_BUFF_TIC_NPC`, `EVENT_SPELL_EFFECT_BUFF_TIC_BOT`, `EVENT_SPELL_FADE`, and `EVENT_SPELL_EFFECT_TRANSLOCATE_COMPLETE`.

* Cleanup

* PR comment fixes

---------

Co-authored-by: Akkadius <akkadius1@gmail.com>
This commit is contained in:
Alex King
2023-02-13 00:26:17 -05:00
committed by GitHub
parent 805a9c5f59
commit 9f619859d1
3 changed files with 170 additions and 91 deletions
+71 -29
View File
@@ -238,25 +238,44 @@ bool Mob::CastSpell(uint16 spell_id, uint16 target_id, CastingSlot slot,
}
}
std::string export_string = fmt::format(
"{} {} {}",
spell_id,
GetID(),
GetCasterLevel(spell_id)
);
if (IsClient()) {
if (parse->EventPlayer(EVENT_CAST_BEGIN, CastToClient(), export_string, 0) != 0) {
if (IsDiscipline(spell_id)) {
CastToClient()->SendDisciplineTimer(spells[spell_id].timer_id, 0);
} else {
CastToClient()->SendSpellBarEnable(spell_id);
if (parse->PlayerHasQuestSub(EVENT_CAST_BEGIN)) {
const auto& export_string = fmt::format(
"{} {} {}",
spell_id,
GetID(),
GetCasterLevel(spell_id)
);
if (parse->EventPlayer(EVENT_CAST_BEGIN, CastToClient(), export_string, 0) != 0) {
if (IsDiscipline(spell_id)) {
CastToClient()->SendDisciplineTimer(spells[spell_id].timer_id, 0);
}
else {
CastToClient()->SendSpellBarEnable(spell_id);
}
return false;
}
return false;
}
} else if (IsNPC()) {
parse->EventNPC(EVENT_CAST_BEGIN, CastToNPC(), nullptr, export_string, 0);
if (parse->HasQuestSub(GetNPCTypeID(), EVENT_CAST_BEGIN)) {
const auto& export_string = fmt::format(
"{} {} {}",
spell_id,
GetID(),
GetCasterLevel(spell_id)
);
parse->EventNPC(EVENT_CAST_BEGIN, CastToNPC(), nullptr, export_string, 0);
}
} else if (IsBot()) {
parse->EventBot(EVENT_CAST_BEGIN, CastToBot(), nullptr, export_string, 0);
if (parse->BotHasQuestSub(EVENT_CAST_BEGIN)) {
const auto& export_string = fmt::format(
"{} {} {}",
spell_id,
GetID(),
GetCasterLevel(spell_id)
);
parse->EventBot(EVENT_CAST_BEGIN, CastToBot(), nullptr, export_string, 0);
}
}
//To prevent NPC ghosting when spells are cast from scripts
@@ -1635,18 +1654,25 @@ void Mob::CastedSpellFinished(uint16 spell_id, uint32 target_id, CastingSlot slo
// at this point the spell has successfully been cast
//
std::string export_string = fmt::format(
const auto& export_string = fmt::format(
"{} {} {}",
spell_id,
GetID(),
GetCasterLevel(spell_id)
);
if (IsClient()) {
parse->EventPlayer(EVENT_CAST, CastToClient(), export_string, 0);
if (parse->PlayerHasQuestSub(EVENT_CAST)) {
parse->EventPlayer(EVENT_CAST, CastToClient(), export_string, 0);
}
} else if (IsNPC()) {
parse->EventNPC(EVENT_CAST, CastToNPC(), nullptr, export_string, 0);
if (parse->HasQuestSub(GetNPCTypeID(), EVENT_CAST)) {
parse->EventNPC(EVENT_CAST, CastToNPC(), nullptr, export_string, 0);
}
} else if (IsBot()) {
parse->EventBot(EVENT_CAST, CastToBot(), nullptr, export_string, 0);
if (parse->BotHasQuestSub(EVENT_CAST)) {
parse->EventBot(EVENT_CAST, CastToBot(), nullptr, export_string, 0);
}
}
if(bard_song_mode)
@@ -3639,20 +3665,36 @@ bool Mob::SpellOnTarget(
(spellOwner->IsClient() ? FilterPCSpells : FilterNPCSpells) /* EQ Filter Type: (8 or 9) */
);
/* Send the EVENT_CAST_ON event */
const auto export_string = fmt::format(
"{} {} {}",
spell_id,
GetID(),
caster_level
);
if (spelltar->IsNPC()) {
parse->EventNPC(EVENT_CAST_ON, spelltar->CastToNPC(), this, export_string, 0);
if (parse->HasQuestSub(spelltar->GetNPCTypeID(), EVENT_CAST_ON)) {
const auto& export_string = fmt::format(
"{} {} {}",
spell_id,
GetID(),
caster_level
);
parse->EventNPC(EVENT_CAST_ON, spelltar->CastToNPC(), this, export_string, 0);
}
} else if (spelltar->IsClient()) {
parse->EventPlayer(EVENT_CAST_ON, spelltar->CastToClient(), export_string, 0);
if (parse->PlayerHasQuestSub(EVENT_CAST_ON)) {
const auto& export_string = fmt::format(
"{} {} {}",
spell_id,
GetID(),
caster_level
);
parse->EventPlayer(EVENT_CAST_ON, spelltar->CastToClient(), export_string, 0);
}
} else if (spelltar->IsBot()) {
parse->EventBot(EVENT_CAST_ON, spelltar->CastToBot(), this, export_string, 0);
if (parse->BotHasQuestSub(EVENT_CAST_ON)) {
const auto& export_string = fmt::format(
"{} {} {}",
spell_id,
GetID(),
caster_level
);
parse->EventBot(EVENT_CAST_ON, spelltar->CastToBot(), this, export_string, 0);
}
}
mod_spell_cast(spell_id, spelltar, reflect_effectiveness, use_resist_adjust, resist_adjust, isproc);