[Quest API] (Performance) Check event EVENT_LANGUAGE_SKILL_UP, EVENT_SKILL_UP, or EVENT_USE_SKILL exist before export and execute (#2894)

* [Quest API] Optionally parse EVENT_LANGUAGE_SKILL_UP, EVENT_SKILL_UP, and EVENT_USE_SKILL

- Optionally parse these events instead of always doing so.

* Cleanup
This commit is contained in:
Alex King 2023-02-13 00:30:48 -05:00 committed by GitHub
parent 3d6b0e5f74
commit 3474c00e7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 59 additions and 34 deletions

View File

@ -1451,12 +1451,15 @@ void Mob::DoAttack(Mob *other, DamageHitInfo &hit, ExtraAttackOptions *opts, boo
}
if (IsBot()) {
const auto export_string = fmt::format(
"{} {}",
hit.skill,
GetSkill(hit.skill)
);
parse->EventBot(EVENT_USE_SKILL, CastToBot(), nullptr, export_string, 0);
if (parse->BotHasQuestSub(EVENT_USE_SKILL)) {
const auto& export_string = fmt::format(
"{} {}",
hit.skill,
GetSkill(hit.skill)
);
parse->EventBot(EVENT_USE_SKILL, CastToBot(), nullptr, export_string, 0);
}
}
}
}

View File

@ -2508,22 +2508,35 @@ uint64 Client::GetAllMoney() {
}
bool Client::CheckIncreaseSkill(EQ::skills::SkillType skillid, Mob *against_who, int chancemodi) {
if (IsDead() || IsUnconscious())
if (IsDead() || IsUnconscious()) {
return false;
if (IsAIControlled()) // no skillups while chamred =p
}
if (IsAIControlled()) { // no skillups while chamred =p
return false;
if (against_who != nullptr && against_who->IsCorpse()) // no skillups on corpses
}
if (against_who && against_who->IsCorpse()) { // no skillups on corpses
return false;
if (skillid > EQ::skills::HIGHEST_SKILL)
}
if (skillid > EQ::skills::HIGHEST_SKILL) {
return false;
int skillval = GetRawSkill(skillid);
int maxskill = GetMaxSkillAfterSpecializationRules(skillid, MaxSkill(skillid));
std::string export_string = fmt::format(
"{} {}",
skillid,
skillval
);
parse->EventPlayer(EVENT_USE_SKILL, this, export_string, 0);
}
auto skillval = GetRawSkill(skillid);
auto maxskill = GetMaxSkillAfterSpecializationRules(skillid, MaxSkill(skillid));
if (parse->PlayerHasQuestSub(EVENT_USE_SKILL)) {
const auto& export_string = fmt::format(
"{} {}",
skillid,
skillval
);
parse->EventPlayer(EVENT_USE_SKILL, this, export_string, 0);
}
if (against_who) {
if (
against_who->GetSpecialAbility(IMMUNE_AGGRO) ||
@ -2557,25 +2570,29 @@ bool Client::CheckIncreaseSkill(EQ::skills::SkillType skillid, Mob *against_who,
if(zone->random.Real(0, 99) < Chance)
{
SetSkill(skillid, GetRawSkill(skillid) + 1);
std::string export_string = fmt::format(
"{} {} {} {}",
skillid,
skillval+1,
maxskill,
0
);
parse->EventPlayer(EVENT_SKILL_UP, this, export_string, 0);
if (player_event_logs.IsEventEnabled(PlayerEvent::SKILL_UP)) {
auto e = PlayerEvent::SkillUpEvent{
.skill_id = static_cast<uint32>(skillid),
.value = (skillval + 1),
.value = static_cast<int>((skillval + 1)),
.max_skill = static_cast<int16>(maxskill),
.against_who = (against_who) ? against_who->GetCleanName() : GetCleanName(),
};
RecordPlayerEventLog(PlayerEvent::SKILL_UP, e);
}
if (parse->PlayerHasQuestSub(EVENT_SKILL_UP)) {
const auto& export_string = fmt::format(
"{} {} {} {}",
skillid,
skillval + 1,
maxskill,
0
);
parse->EventPlayer(EVENT_SKILL_UP, this, export_string, 0);
}
LogSkills("Skill [{}] at value [{}] successfully gain with [{}] chance (mod [{}])", skillid, skillval, Chance, chancemodi);
return true;
} else {
@ -2603,13 +2620,18 @@ void Client::CheckLanguageSkillIncrease(uint8 langid, uint8 TeacherSkill) {
if(zone->random.Real(0,100) < Chance) { // if they make the roll
IncreaseLanguageSkill(langid); // increase the language skill by 1
std::string export_string = fmt::format(
"{} {} {}",
langid,
LangSkill + 1,
100
);
parse->EventPlayer(EVENT_LANGUAGE_SKILL_UP, this, export_string, 0);
if (parse->PlayerHasQuestSub(EVENT_LANGUAGE_SKILL_UP)) {
const auto& export_string = fmt::format(
"{} {} {}",
langid,
LangSkill + 1,
100
);
parse->EventPlayer(EVENT_LANGUAGE_SKILL_UP, this, export_string, 0);
}
LogSkills("Language [{}] at value [{}] successfully gain with [{}] % chance", langid, LangSkill, Chance);
}
else