From a55162775e1d13d2e137e1942b1f1d05fb3f0438 Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Tue, 28 Jun 2022 23:17:45 -0700 Subject: [PATCH] Address incorrect stun played by growl speakers (#605) Add the FireFirstSkillonStartup script to allow for scripts that use this to function. Add comments Fix QB Stunner scripts Use SetVar for variable Remember that variables for scripts need to be stored in the entity since a script can be used across multiple entities. Remove unused variable Specify Unsigned Int Start skill asap, not next tick --- dScripts/QbEnemyStunner.cpp | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/dScripts/QbEnemyStunner.cpp b/dScripts/QbEnemyStunner.cpp index ba089844..9f0cb8fc 100644 --- a/dScripts/QbEnemyStunner.cpp +++ b/dScripts/QbEnemyStunner.cpp @@ -13,16 +13,32 @@ void QbEnemyStunner::OnRebuildComplete(Entity* self, Entity* target) destroyable->SetFaction(115); } - auto* skillComponent = self->GetComponent(); + auto skillComponent = self->GetComponent(); + if (!skillComponent) return; - if (skillComponent != nullptr) - { - skillComponent->CalculateBehavior(499, 6095, LWOOBJID_EMPTY); + // Get the skill IDs of this object. + CDObjectSkillsTable* skillsTable = CDClientManager::Instance()->GetTable("ObjectSkills"); + auto skills = skillsTable->Query([=](CDObjectSkills entry) {return (entry.objectTemplate == self->GetLOT()); }); + std::map skillBehaviorMap; + // For each skill, cast it with the associated behavior ID. + for (auto skill : skills) { + CDSkillBehaviorTable* skillBehaviorTable = CDClientManager::Instance()->GetTable("SkillBehavior"); + CDSkillBehavior behaviorData = skillBehaviorTable->GetSkillByID(skill.skillID); + + skillBehaviorMap.insert(std::make_pair(skill.skillID, behaviorData.behaviorID)); } - self->AddTimer("TickTime", 1); + // If there are no skills found, insert a default skill to use. + if (skillBehaviorMap.size() == 0) { + skillBehaviorMap.insert(std::make_pair(499U, 6095U)); + } + + // Start all skills associated with the object next tick + self->AddTimer("TickTime", 0); self->AddTimer("PlayEffect", 20); + + self->SetVar>(u"skillBehaviorMap", skillBehaviorMap); } void QbEnemyStunner::OnTimerDone(Entity* self, std::string timerName) @@ -45,9 +61,16 @@ void QbEnemyStunner::OnTimerDone(Entity* self, std::string timerName) if (skillComponent != nullptr) { - skillComponent->CalculateBehavior(499, 6095, LWOOBJID_EMPTY); + auto skillBehaviorMap = self->GetVar>(u"skillBehaviorMap"); + if (skillBehaviorMap.size() == 0) { + // Should no skills have been found, default to the mermaid stunner + skillComponent->CalculateBehavior(499U, 6095U, LWOOBJID_EMPTY); + } else { + for (auto pair : skillBehaviorMap) { + skillComponent->CalculateBehavior(pair.first, pair.second, LWOOBJID_EMPTY); + } + } } - self->AddTimer("TickTime", 1); } }