mirror of
https://github.com/EQEmu/Server.git
synced 2026-06-10 23:20:25 +00:00
[Quest API] Add Lua handlers for zone controller events (#2514)
This cleans up some of the NPC::Death event dispatch code. Adds handlers for EVENT_SPAWN_ZONE and EVENT_DEATH_ZONE used by zone controller and fixes the death handler exports which were incorrect.
This commit is contained in:
+28
-66
@@ -2318,52 +2318,37 @@ bool NPC::Death(Mob* killer_mob, int64 damage, uint16 spell, EQ::skills::SkillTy
|
||||
LogCombat("Fatal blow dealt by [{}] with [{}] damage, spell [{}], skill [{}]",
|
||||
((killer_mob) ? (killer_mob->GetName()) : ("[nullptr]")), damage, spell, attack_skill);
|
||||
|
||||
Mob *oos = nullptr;
|
||||
if (killer_mob) {
|
||||
oos = killer_mob->GetOwnerOrSelf();
|
||||
std::string export_string = fmt::format(
|
||||
"{} {} {} {}",
|
||||
killer_mob->GetID(),
|
||||
damage,
|
||||
spell,
|
||||
static_cast<int>(attack_skill)
|
||||
);
|
||||
if (parse->EventNPC(EVENT_DEATH, this, oos, export_string, 0) != 0) {
|
||||
if (GetHP() < 0) {
|
||||
SetHP(0);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Mob* oos = killer_mob ? killer_mob->GetOwnerOrSelf() : nullptr;
|
||||
|
||||
if ((killer_mob->IsClient() || killer_mob->IsBot()) && (spell != SPELL_UNKNOWN) && damage > 0) {
|
||||
char val1[20] = { 0 };
|
||||
std::string export_string = fmt::format(
|
||||
"{} {} {} {}",
|
||||
killer_mob ? killer_mob->GetID() : 0,
|
||||
damage,
|
||||
spell,
|
||||
static_cast<int>(attack_skill)
|
||||
);
|
||||
|
||||
entity_list.MessageCloseString(
|
||||
this, /* Sender */
|
||||
false, /* Skip Sender */
|
||||
RuleI(Range, DamageMessages),
|
||||
Chat::NonMelee, /* 283 */
|
||||
HIT_NON_MELEE, /* %1 hit %2 for %3 points of non-melee damage. */
|
||||
killer_mob->GetCleanName(), /* Message1 */
|
||||
GetCleanName(), /* Message2 */
|
||||
ConvertArray(damage, val1) /* Message3 */
|
||||
);
|
||||
// todo: multiple attacks causes this to fire multiple times (DoAttackRounds, DoMain/OffHandAttackRounds, DoRiposte, spells?)
|
||||
if (parse->EventNPC(EVENT_DEATH, this, oos, export_string, 0) != 0) {
|
||||
if (GetHP() < 0) {
|
||||
SetHP(0);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
std::string export_string = fmt::format(
|
||||
"{} {} {} {}",
|
||||
0,
|
||||
damage,
|
||||
spell,
|
||||
static_cast<int>(attack_skill)
|
||||
|
||||
if (killer_mob && (killer_mob->IsClient() || killer_mob->IsBot()) && (spell != SPELL_UNKNOWN) && damage > 0) {
|
||||
char val1[20] = { 0 };
|
||||
|
||||
entity_list.MessageCloseString(
|
||||
this, /* Sender */
|
||||
false, /* Skip Sender */
|
||||
RuleI(Range, DamageMessages),
|
||||
Chat::NonMelee, /* 283 */
|
||||
HIT_NON_MELEE, /* %1 hit %2 for %3 points of non-melee damage. */
|
||||
killer_mob->GetCleanName(), /* Message1 */
|
||||
GetCleanName(), /* Message2 */
|
||||
ConvertArray(damage, val1) /* Message3 */
|
||||
);
|
||||
if (parse->EventNPC(EVENT_DEATH, this, nullptr, export_string, 0) != 0) {
|
||||
if (GetHP() < 0) {
|
||||
SetHP(0);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (IsEngaged()) {
|
||||
@@ -2752,35 +2737,12 @@ bool NPC::Death(Mob* killer_mob, int64 damage, uint16 spell, EQ::skills::SkillTy
|
||||
|
||||
entity_list.UpdateFindableNPCState(this, true);
|
||||
|
||||
std::string export_string = fmt::format(
|
||||
"{} {} {} {}",
|
||||
killer_mob ? killer_mob->GetID() : 0,
|
||||
damage,
|
||||
spell,
|
||||
static_cast<int>(attack_skill)
|
||||
);
|
||||
parse->EventNPC(EVENT_DEATH_COMPLETE, this, oos, export_string, 0);
|
||||
combat_record.Stop();
|
||||
|
||||
/* Zone controller process EVENT_DEATH_ZONE (Death events) */
|
||||
if (RuleB(Zone, UseZoneController)) {
|
||||
auto controller = entity_list.GetNPCByNPCTypeID(ZONE_CONTROLLER_NPC_ID);
|
||||
if (controller && GetNPCTypeID() != ZONE_CONTROLLER_NPC_ID) {
|
||||
export_string = fmt::format(
|
||||
"{} {} {} {} {} {:.2f} {:.2f} {:.2f} {:.2f}",
|
||||
killer_mob ? killer_mob->GetID() : 0,
|
||||
damage,
|
||||
spell,
|
||||
static_cast<int>(attack_skill),
|
||||
GetNPCTypeID(),
|
||||
GetX(),
|
||||
GetY(),
|
||||
GetZ(),
|
||||
GetHeading()
|
||||
);
|
||||
parse->EventNPC(EVENT_DEATH_ZONE, controller, nullptr, export_string, 0);
|
||||
}
|
||||
}
|
||||
std::vector<std::any> args = { this };
|
||||
DispatchZoneControllerEvent(EVENT_DEATH_ZONE, oos, export_string, 0, &args);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user