mirror of
https://github.com/EQEmu/Server.git
synced 2026-08-28 15:57:58 +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:
+49
-137
@@ -254,53 +254,33 @@ bool Mob::CastSpell(uint16 spell_id, uint16 target_id, CastingSlot slot,
|
||||
}
|
||||
}
|
||||
|
||||
if (IsClient()) {
|
||||
if (parse->PlayerHasQuestSub(EVENT_CAST_BEGIN)) {
|
||||
Mob* spell_target = entity_list.GetMobID(target_id);
|
||||
std::vector<std::any> args = { spell_target };
|
||||
const auto& export_string = fmt::format(
|
||||
Mob* spell_target = entity_list.GetMobID(target_id);
|
||||
std::vector<std::any> args = { spell_target };
|
||||
int return_value = parse->EventMob(
|
||||
EVENT_CAST_BEGIN,
|
||||
this,
|
||||
nullptr,
|
||||
[&]() {
|
||||
return fmt::format(
|
||||
"{} {} {} {}",
|
||||
spell_id,
|
||||
GetID(),
|
||||
GetCasterLevel(spell_id),
|
||||
target_id
|
||||
);
|
||||
if (parse->EventPlayer(EVENT_CAST_BEGIN, CastToClient(), export_string, 0, &args) != 0) {
|
||||
if (IsDiscipline(spell_id)) {
|
||||
CastToClient()->SendDisciplineTimer(spells[spell_id].timer_id, 0);
|
||||
}
|
||||
else {
|
||||
CastToClient()->SendSpellBarEnable(spell_id);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else if (IsNPC()) {
|
||||
if (parse->HasQuestSub(GetNPCTypeID(), EVENT_CAST_BEGIN)) {
|
||||
Mob* spell_target = entity_list.GetMobID(target_id);
|
||||
std::vector<std::any> args = { spell_target };
|
||||
const auto& export_string = fmt::format(
|
||||
"{} {} {} {}",
|
||||
spell_id,
|
||||
GetID(),
|
||||
GetCasterLevel(spell_id),
|
||||
target_id
|
||||
);
|
||||
parse->EventNPC(EVENT_CAST_BEGIN, CastToNPC(), nullptr, export_string, 0, &args);
|
||||
}
|
||||
} else if (IsBot()) {
|
||||
if (parse->BotHasQuestSub(EVENT_CAST_BEGIN)) {
|
||||
Mob* spell_target = entity_list.GetMobID(target_id);
|
||||
std::vector<std::any> args = { spell_target };
|
||||
const auto& export_string = fmt::format(
|
||||
"{} {} {} {}",
|
||||
spell_id,
|
||||
GetID(),
|
||||
GetCasterLevel(spell_id),
|
||||
target_id
|
||||
);
|
||||
parse->EventBot(EVENT_CAST_BEGIN, CastToBot(), nullptr, export_string, 0, &args);
|
||||
},
|
||||
0,
|
||||
&args
|
||||
);
|
||||
|
||||
if (IsClient() && return_value != 0) {
|
||||
if (IsDiscipline(spell_id)) {
|
||||
CastToClient()->SendDisciplineTimer(spells[spell_id].timer_id, 0);
|
||||
} else {
|
||||
CastToClient()->SendSpellBarEnable(spell_id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//To prevent NPC ghosting when spells are cast from scripts
|
||||
@@ -1822,47 +1802,24 @@ void Mob::CastedSpellFinished(uint16 spell_id, uint32 target_id, CastingSlot slo
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// at this point the spell has successfully been cast
|
||||
//
|
||||
std::vector<std::any> args = { spell_target };
|
||||
|
||||
if (IsClient()) {
|
||||
if (parse->PlayerHasQuestSub(EVENT_CAST)) {
|
||||
std::vector<std::any> args = { spell_target };
|
||||
const auto& export_string = fmt::format(
|
||||
parse->EventMob(
|
||||
EVENT_CAST,
|
||||
this,
|
||||
nullptr,
|
||||
[&]() {
|
||||
return fmt::format(
|
||||
"{} {} {} {}",
|
||||
spell_id,
|
||||
GetID(),
|
||||
GetCasterLevel(spell_id),
|
||||
target_id
|
||||
);
|
||||
parse->EventPlayer(EVENT_CAST, CastToClient(), export_string, 0, &args);
|
||||
}
|
||||
} else if (IsNPC()) {
|
||||
if (parse->HasQuestSub(GetNPCTypeID(), EVENT_CAST)) {
|
||||
std::vector<std::any> args = { spell_target };
|
||||
const auto& export_string = fmt::format(
|
||||
"{} {} {} {}",
|
||||
spell_id,
|
||||
GetID(),
|
||||
GetCasterLevel(spell_id),
|
||||
target_id
|
||||
);
|
||||
parse->EventNPC(EVENT_CAST, CastToNPC(), nullptr, export_string, 0, &args);
|
||||
}
|
||||
} else if (IsBot()) {
|
||||
if (parse->BotHasQuestSub(EVENT_CAST)) {
|
||||
std::vector<std::any> args = { spell_target };
|
||||
const auto& export_string = fmt::format(
|
||||
"{} {} {} {}",
|
||||
spell_id,
|
||||
GetID(),
|
||||
GetCasterLevel(spell_id),
|
||||
target_id
|
||||
);
|
||||
parse->EventBot(EVENT_CAST, CastToBot(), nullptr, export_string, 0, &args);
|
||||
}
|
||||
}
|
||||
},
|
||||
0,
|
||||
&args
|
||||
);
|
||||
|
||||
if(bard_song_mode)
|
||||
{
|
||||
@@ -3622,44 +3579,18 @@ int Mob::AddBuff(Mob *caster, uint16 spell_id, int duration, int32 level_overrid
|
||||
);
|
||||
}
|
||||
|
||||
const bool caster_has_block_event = (
|
||||
(caster->IsBot() && parse->BotHasQuestSub(EVENT_SPELL_BLOCKED)) ||
|
||||
(caster->IsClient() && parse->PlayerHasQuestSub(EVENT_SPELL_BLOCKED)) ||
|
||||
(caster->IsNPC() && parse->HasQuestSub(caster->GetNPCTypeID(), EVENT_SPELL_BLOCKED))
|
||||
);
|
||||
|
||||
const bool cast_on_has_block_event = (
|
||||
(IsBot() && parse->BotHasQuestSub(EVENT_SPELL_BLOCKED)) ||
|
||||
(IsClient() && parse->PlayerHasQuestSub(EVENT_SPELL_BLOCKED)) ||
|
||||
(IsNPC() && parse->HasQuestSub(GetNPCTypeID(), EVENT_SPELL_BLOCKED))
|
||||
);
|
||||
|
||||
if (caster_has_block_event || cast_on_has_block_event) {
|
||||
const std::string& export_string = fmt::format(
|
||||
std::function<std::string()> f = [&]() {
|
||||
return fmt::format(
|
||||
"{} {}",
|
||||
curbuf.spellid,
|
||||
spell_id
|
||||
);
|
||||
};
|
||||
|
||||
if (caster_has_block_event) {
|
||||
if (caster->IsBot()) {
|
||||
parse->EventBot(EVENT_SPELL_BLOCKED, caster->CastToBot(), this, export_string, 0);
|
||||
} else if (caster->IsClient()) {
|
||||
parse->EventPlayer(EVENT_SPELL_BLOCKED, caster->CastToClient(), export_string, 0);
|
||||
} else if (caster->IsNPC()) {
|
||||
parse->EventNPC(EVENT_SPELL_BLOCKED, caster->CastToNPC(), this, export_string, 0);
|
||||
}
|
||||
}
|
||||
parse->EventMob(EVENT_SPELL_BLOCKED, caster, this, f);
|
||||
|
||||
if (cast_on_has_block_event && caster != this) {
|
||||
if (IsBot()) {
|
||||
parse->EventBot(EVENT_SPELL_BLOCKED, CastToBot(), caster, export_string, 0);
|
||||
} else if (IsClient()) {
|
||||
parse->EventPlayer(EVENT_SPELL_BLOCKED, CastToClient(), export_string, 0);
|
||||
} else if (IsNPC()) {
|
||||
parse->EventNPC(EVENT_SPELL_BLOCKED, CastToNPC(), caster, export_string, 0);
|
||||
}
|
||||
}
|
||||
if (caster != this) {
|
||||
parse->EventMob(EVENT_SPELL_BLOCKED, this, caster, f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4033,43 +3964,24 @@ bool Mob::SpellOnTarget(
|
||||
(spellOwner->IsClient() ? FilterPCSpells : FilterNPCSpells) /* EQ Filter Type: (8 or 9) */
|
||||
);
|
||||
|
||||
if (spelltar->IsNPC()) {
|
||||
if (parse->HasQuestSub(spelltar->GetNPCTypeID(), EVENT_CAST_ON)) {
|
||||
std::vector<std::any> args = { spelltar };
|
||||
const auto& export_string = fmt::format(
|
||||
std::vector<std::any> args = { spelltar };
|
||||
|
||||
parse->EventMob(
|
||||
EVENT_CAST_ON,
|
||||
spelltar,
|
||||
this,
|
||||
[&]() {
|
||||
return fmt::format(
|
||||
"{} {} {} {}",
|
||||
spell_id,
|
||||
GetID(),
|
||||
caster_level,
|
||||
target_id
|
||||
);
|
||||
parse->EventNPC(EVENT_CAST_ON, spelltar->CastToNPC(), this, export_string, 0, &args);
|
||||
}
|
||||
} else if (spelltar->IsClient()) {
|
||||
if (parse->PlayerHasQuestSub(EVENT_CAST_ON)) {
|
||||
std::vector<std::any> args = { spelltar };
|
||||
const auto& export_string = fmt::format(
|
||||
"{} {} {} {}",
|
||||
spell_id,
|
||||
GetID(),
|
||||
caster_level,
|
||||
target_id
|
||||
);
|
||||
parse->EventPlayer(EVENT_CAST_ON, spelltar->CastToClient(), export_string, 0, &args);
|
||||
}
|
||||
} else if (spelltar->IsBot()) {
|
||||
if (parse->BotHasQuestSub(EVENT_CAST_ON)) {
|
||||
std::vector<std::any> args = { spelltar };
|
||||
const auto& export_string = fmt::format(
|
||||
"{} {} {} {}",
|
||||
spell_id,
|
||||
GetID(),
|
||||
caster_level,
|
||||
target_id
|
||||
);
|
||||
parse->EventBot(EVENT_CAST_ON, spelltar->CastToBot(), this, export_string, 0, &args);
|
||||
}
|
||||
}
|
||||
},
|
||||
0,
|
||||
&args
|
||||
);
|
||||
|
||||
if (!DoCastingChecksOnTarget(false, spell_id, spelltar)) {
|
||||
safe_delete(action_packet);
|
||||
|
||||
Reference in New Issue
Block a user