From 2e284eb2ce9d1f5a1f01746a8d1f50152f958238 Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Tue, 18 Apr 2023 12:48:03 -0500 Subject: [PATCH] Implement Timer handlers in triggers and ontimerdone trigger event (#1031) * Works, but AOE is broken * Address Feedback * fix typo --- dGame/Entity.cpp | 1 + dGame/dComponents/SkillComponent.cpp | 2 + dGame/dComponents/TriggerComponent.cpp | 40 +++++++--- dGame/dComponents/TriggerComponent.h | 2 + dScripts/ai/AG/AgJetEffectServer.cpp | 106 ++++++------------------- 5 files changed, 58 insertions(+), 93 deletions(-) diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index 683baaa2..595ab090 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -1232,6 +1232,7 @@ void Entity::Update(const float deltaTime) { for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) { script->OnTimerDone(this, timerName); } + TriggerEvent(eTriggerEventType::TIMER_DONE, this); } else { timerPosition++; } diff --git a/dGame/dComponents/SkillComponent.cpp b/dGame/dComponents/SkillComponent.cpp index ae0e82f0..dc7c16bd 100644 --- a/dGame/dComponents/SkillComponent.cpp +++ b/dGame/dComponents/SkillComponent.cpp @@ -260,6 +260,8 @@ SkillExecutionResult SkillComponent::CalculateBehavior(const uint32_t skillId, c context->caster = m_Parent->GetObjectID(); + context->skillID = skillId; + context->clientInitalized = clientInitalized; context->foundTarget = target != LWOOBJID_EMPTY || ignoreTarget || clientInitalized; diff --git a/dGame/dComponents/TriggerComponent.cpp b/dGame/dComponents/TriggerComponent.cpp index 0f241116..3f05d805 100644 --- a/dGame/dComponents/TriggerComponent.cpp +++ b/dGame/dComponents/TriggerComponent.cpp @@ -83,8 +83,12 @@ void TriggerComponent::HandleTriggerCommand(LUTriggers::Command* command, Entity case eTriggerCommandType::REPEL_OBJECT: HandleRepelObject(targetEntity, command->args); break; - case eTriggerCommandType::SET_TIMER: break; - case eTriggerCommandType::CANCEL_TIMER: break; + case eTriggerCommandType::SET_TIMER: + HandleSetTimer(targetEntity, argArray); + break; + case eTriggerCommandType::CANCEL_TIMER: + HandleCancelTimer(targetEntity, command->args); + break; case eTriggerCommandType::PLAY_CINEMATIC: HandlePlayCinematic(targetEntity, argArray); break; @@ -194,7 +198,7 @@ void TriggerComponent::HandleDestroyObject(Entity* targetEntity, std::string arg void TriggerComponent::HandleToggleTrigger(Entity* targetEntity, std::string args){ auto* triggerComponent = targetEntity->GetComponent(); if (!triggerComponent) { - Game::logger->Log("TriggerComponent::HandleToggleTrigger", "Trigger component not found!"); + Game::logger->LogDebug("TriggerComponent::HandleToggleTrigger", "Trigger component not found!"); return; } triggerComponent->SetTriggerEnabled(args == "1"); @@ -203,7 +207,7 @@ void TriggerComponent::HandleToggleTrigger(Entity* targetEntity, std::string arg void TriggerComponent::HandleResetRebuild(Entity* targetEntity, std::string args){ auto* rebuildComponent = targetEntity->GetComponent(); if (!rebuildComponent) { - Game::logger->Log("TriggerComponent::HandleResetRebuild", "Rebuild component not found!"); + Game::logger->LogDebug("TriggerComponent::HandleResetRebuild", "Rebuild component not found!"); return; } rebuildComponent->ResetRebuild(args == "1"); @@ -233,7 +237,7 @@ void TriggerComponent::HandleRotateObject(Entity* targetEntity, std::vector argArray){ auto* phantomPhysicsComponent = m_Parent->GetComponent(); if (!phantomPhysicsComponent) { - Game::logger->Log("TriggerComponent::HandlePushObject", "Phantom Physics component not found!"); + Game::logger->LogDebug("TriggerComponent::HandlePushObject", "Phantom Physics component not found!"); return; } phantomPhysicsComponent->SetPhysicsEffectActive(true); @@ -250,7 +254,7 @@ void TriggerComponent::HandlePushObject(Entity* targetEntity, std::vectorGetComponent(); if (!phantomPhysicsComponent) { - Game::logger->Log("TriggerComponent::HandleRepelObject", "Phantom Physics component not found!"); + Game::logger->LogDebug("TriggerComponent::HandleRepelObject", "Phantom Physics component not found!"); return; } float forceMultiplier; @@ -271,6 +275,20 @@ void TriggerComponent::HandleRepelObject(Entity* targetEntity, std::string args) EntityManager::Instance()->SerializeEntity(m_Parent); } +void TriggerComponent::HandleSetTimer(Entity* targetEntity, std::vector argArray){ + if (argArray.size() != 2) { + Game::logger->LogDebug("TriggerComponent::HandleSetTimer", "Not ehought variables!"); + return; + } + float time = 0.0; + GeneralUtils::TryParse(argArray.at(1), time); + m_Parent->AddTimer(argArray.at(0), time); +} + +void TriggerComponent::HandleCancelTimer(Entity* targetEntity, std::string args){ + m_Parent->CancelTimer(args); +} + void TriggerComponent::HandlePlayCinematic(Entity* targetEntity, std::vector argArray) { float leadIn = -1.0; auto wait = eEndBehavior::RETURN; @@ -300,7 +318,7 @@ void TriggerComponent::HandlePlayCinematic(Entity* targetEntity, std::vectorGetCharacter(); if (!character) { - Game::logger->Log("TriggerComponent::HandleToggleBBB", "Character was not found!"); + Game::logger->LogDebug("TriggerComponent::HandleToggleBBB", "Character was not found!"); return; } bool buildMode = !(character->GetBuildMode()); @@ -316,7 +334,7 @@ void TriggerComponent::HandleUpdateMission(Entity* targetEntity, std::vectorGetComponent(); if (!missionComponent){ - Game::logger->Log("TriggerComponent::HandleUpdateMission", "Mission component not found!"); + Game::logger->LogDebug("TriggerComponent::HandleUpdateMission", "Mission component not found!"); return; } missionComponent->Progress(eMissionTaskType::EXPLORE, 0, 0, argArray.at(4)); @@ -335,7 +353,7 @@ void TriggerComponent::HandlePlayEffect(Entity* targetEntity, std::vectorGetComponent(); if (!skillComponent) { - Game::logger->Log("TriggerComponent::HandleCastSkill", "Skill component not found!"); + Game::logger->LogDebug("TriggerComponent::HandleCastSkill", "Skill component not found!"); return; } uint32_t skillId; @@ -346,7 +364,7 @@ void TriggerComponent::HandleCastSkill(Entity* targetEntity, std::string args){ void TriggerComponent::HandleSetPhysicsVolumeEffect(Entity* targetEntity, std::vector argArray) { auto* phantomPhysicsComponent = targetEntity->GetComponent(); if (!phantomPhysicsComponent) { - Game::logger->Log("TriggerComponent::HandleSetPhysicsVolumeEffect", "Phantom Physics component not found!"); + Game::logger->LogDebug("TriggerComponent::HandleSetPhysicsVolumeEffect", "Phantom Physics component not found!"); return; } phantomPhysicsComponent->SetPhysicsEffectActive(true); @@ -381,7 +399,7 @@ void TriggerComponent::HandleSetPhysicsVolumeEffect(Entity* targetEntity, std::v void TriggerComponent::HandleSetPhysicsVolumeStatus(Entity* targetEntity, std::string args) { auto* phantomPhysicsComponent = targetEntity->GetComponent(); if (!phantomPhysicsComponent) { - Game::logger->Log("TriggerComponent::HandleSetPhysicsVolumeEffect", "Phantom Physics component not found!"); + Game::logger->LogDebug("TriggerComponent::HandleSetPhysicsVolumeEffect", "Phantom Physics component not found!"); return; } phantomPhysicsComponent->SetPhysicsEffectActive(args == "On"); diff --git a/dGame/dComponents/TriggerComponent.h b/dGame/dComponents/TriggerComponent.h index 317da00e..df65707f 100644 --- a/dGame/dComponents/TriggerComponent.h +++ b/dGame/dComponents/TriggerComponent.h @@ -30,6 +30,8 @@ private: void HandleRotateObject(Entity* targetEntity, std::vector argArray); void HandlePushObject(Entity* targetEntity, std::vector argArray); void HandleRepelObject(Entity* targetEntity, std::string args); + void HandleSetTimer(Entity* targetEntity, std::vector argArray); + void HandleCancelTimer(Entity* targetEntity, std::string args); void HandlePlayCinematic(Entity* targetEntity, std::vector argArray); void HandleToggleBBB(Entity* targetEntity, std::string args); void HandleUpdateMission(Entity* targetEntity, std::vector argArray); diff --git a/dScripts/ai/AG/AgJetEffectServer.cpp b/dScripts/ai/AG/AgJetEffectServer.cpp index 9546bc4d..1811d491 100644 --- a/dScripts/ai/AG/AgJetEffectServer.cpp +++ b/dScripts/ai/AG/AgJetEffectServer.cpp @@ -5,113 +5,55 @@ #include "eReplicaComponentType.h" void AgJetEffectServer::OnUse(Entity* self, Entity* user) { - if (inUse) { - return; - } - + if (inUse || !self->GetLOT() == 6859) return; GameMessages::SendNotifyClientObject( - self->GetObjectID(), - u"isInUse", - 0, - 0, - LWOOBJID_EMPTY, - "", - UNASSIGNED_SYSTEM_ADDRESS + self->GetObjectID(), u"toggleInUse", 1, 0, LWOOBJID_EMPTY, "", UNASSIGNED_SYSTEM_ADDRESS ); - inUse = true; auto entities = EntityManager::Instance()->GetEntitiesInGroup("Jet_FX"); - - if (entities.empty()) { - return; - } - - auto* effect = entities[0]; - - GameMessages::SendPlayFXEffect(effect, 641, u"create", "radarDish", LWOOBJID_EMPTY, 1, 1, true); - - self->AddTimer("radarDish", 2); - self->AddTimer("CineDone", 9); + if (entities.empty()) return; + GameMessages::SendPlayFXEffect(entities.at(0), 641, u"create", "radarDish", LWOOBJID_EMPTY, 1, 1, true); + self->AddTimer("radarDish", 2.0f); + self->AddTimer("PlayEffect", 2.5f); + self->AddTimer("CineDone", 7.5f + 5.0f); // 7.5f is time the cinematic takes to play } void AgJetEffectServer::OnRebuildComplete(Entity* self, Entity* target) { + if (self->GetLOT() != 6209) return; auto entities = EntityManager::Instance()->GetEntitiesInGroup("Jet_FX"); + if (entities.empty()) return; + GameMessages::SendPlayAnimation(entities.at(0), u"jetFX"); - if (entities.empty()) { - return; - } - - auto* effect = entities[0]; - - auto groups = self->GetGroups(); - - if (groups.empty()) { - return; - } - + // So we can give kill credit to person who build this builder = target->GetObjectID(); - const auto group = groups[0]; - - GameMessages::SendPlayAnimation(effect, u"jetFX"); - - self->AddTimer("PlayEffect", 2.5f); - - if (group == "Base_Radar") { - self->AddTimer("CineDone", 5); + auto groups = self->GetGroups(); + if (!groups.empty() && groups.at(0) == "Base_Radar") { + self->AddTimer("PlayEffect", 2.5f); + self->AddTimer("CineDone", 7.5f + 5.0f); // 7.5f is time the cinematic takes to play } } void AgJetEffectServer::OnTimerDone(Entity* self, std::string timerName) { if (timerName == "radarDish") { GameMessages::SendStopFXEffect(self, true, "radarDish"); - - return; - } - - if (timerName == "PlayEffect") { + } else if (timerName == "PlayEffect") { auto entities = EntityManager::Instance()->GetEntitiesInGroup("mortarMain"); + if (entities.empty()) return; - if (entities.empty()) { - return; - } - - const auto size = entities.size(); - - if (size == 0) { - return; - } - - const auto selected = GeneralUtils::GenerateRandomNumber(0, size - 1); - - auto* mortar = entities[selected]; - - Game::logger->Log("AgJetEffectServer", "Mortar (%i) (&d)", mortar->GetLOT(), mortar->HasComponent(eReplicaComponentType::SKILL)); + const auto selected = GeneralUtils::GenerateRandomNumber(0, entities.size() - 1); + auto* mortar = entities.at(selected); + // so we give proper credit to the builder for the kills from this skill mortar->SetOwnerOverride(builder); - SkillComponent* skillComponent; - if (!mortar->TryGetComponent(eReplicaComponentType::SKILL, skillComponent)) { - return; - } - - skillComponent->CalculateBehavior(318, 3727, LWOOBJID_EMPTY, true); - - return; - } - - if (timerName == "CineDone") { + auto* skillComponent = mortar->GetComponent(); + if (skillComponent) skillComponent->CastSkill(318); + } else if (timerName == "CineDone") { GameMessages::SendNotifyClientObject( - self->GetObjectID(), - u"toggleInUse", - -1, - 0, - LWOOBJID_EMPTY, - "", - UNASSIGNED_SYSTEM_ADDRESS + self->GetObjectID(), u"toggleInUse", -1, 0, LWOOBJID_EMPTY, "", UNASSIGNED_SYSTEM_ADDRESS ); - inUse = false; } }