Implement Timer handlers in triggers and ontimerdone trigger event (#1031)

* Works, but AOE is broken

* Address Feedback

* fix typo
This commit is contained in:
Aaron Kimbrell 2023-04-18 12:48:03 -05:00 committed by GitHub
parent da6ca82ae2
commit 2e284eb2ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 58 additions and 93 deletions

View File

@ -1232,6 +1232,7 @@ void Entity::Update(const float deltaTime) {
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) { for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
script->OnTimerDone(this, timerName); script->OnTimerDone(this, timerName);
} }
TriggerEvent(eTriggerEventType::TIMER_DONE, this);
} else { } else {
timerPosition++; timerPosition++;
} }

View File

@ -260,6 +260,8 @@ SkillExecutionResult SkillComponent::CalculateBehavior(const uint32_t skillId, c
context->caster = m_Parent->GetObjectID(); context->caster = m_Parent->GetObjectID();
context->skillID = skillId;
context->clientInitalized = clientInitalized; context->clientInitalized = clientInitalized;
context->foundTarget = target != LWOOBJID_EMPTY || ignoreTarget || clientInitalized; context->foundTarget = target != LWOOBJID_EMPTY || ignoreTarget || clientInitalized;

View File

@ -83,8 +83,12 @@ void TriggerComponent::HandleTriggerCommand(LUTriggers::Command* command, Entity
case eTriggerCommandType::REPEL_OBJECT: case eTriggerCommandType::REPEL_OBJECT:
HandleRepelObject(targetEntity, command->args); HandleRepelObject(targetEntity, command->args);
break; break;
case eTriggerCommandType::SET_TIMER: break; case eTriggerCommandType::SET_TIMER:
case eTriggerCommandType::CANCEL_TIMER: break; HandleSetTimer(targetEntity, argArray);
break;
case eTriggerCommandType::CANCEL_TIMER:
HandleCancelTimer(targetEntity, command->args);
break;
case eTriggerCommandType::PLAY_CINEMATIC: case eTriggerCommandType::PLAY_CINEMATIC:
HandlePlayCinematic(targetEntity, argArray); HandlePlayCinematic(targetEntity, argArray);
break; break;
@ -194,7 +198,7 @@ void TriggerComponent::HandleDestroyObject(Entity* targetEntity, std::string arg
void TriggerComponent::HandleToggleTrigger(Entity* targetEntity, std::string args){ void TriggerComponent::HandleToggleTrigger(Entity* targetEntity, std::string args){
auto* triggerComponent = targetEntity->GetComponent<TriggerComponent>(); auto* triggerComponent = targetEntity->GetComponent<TriggerComponent>();
if (!triggerComponent) { if (!triggerComponent) {
Game::logger->Log("TriggerComponent::HandleToggleTrigger", "Trigger component not found!"); Game::logger->LogDebug("TriggerComponent::HandleToggleTrigger", "Trigger component not found!");
return; return;
} }
triggerComponent->SetTriggerEnabled(args == "1"); triggerComponent->SetTriggerEnabled(args == "1");
@ -203,7 +207,7 @@ void TriggerComponent::HandleToggleTrigger(Entity* targetEntity, std::string arg
void TriggerComponent::HandleResetRebuild(Entity* targetEntity, std::string args){ void TriggerComponent::HandleResetRebuild(Entity* targetEntity, std::string args){
auto* rebuildComponent = targetEntity->GetComponent<RebuildComponent>(); auto* rebuildComponent = targetEntity->GetComponent<RebuildComponent>();
if (!rebuildComponent) { if (!rebuildComponent) {
Game::logger->Log("TriggerComponent::HandleResetRebuild", "Rebuild component not found!"); Game::logger->LogDebug("TriggerComponent::HandleResetRebuild", "Rebuild component not found!");
return; return;
} }
rebuildComponent->ResetRebuild(args == "1"); rebuildComponent->ResetRebuild(args == "1");
@ -233,7 +237,7 @@ void TriggerComponent::HandleRotateObject(Entity* targetEntity, std::vector<std:
void TriggerComponent::HandlePushObject(Entity* targetEntity, std::vector<std::string> argArray){ void TriggerComponent::HandlePushObject(Entity* targetEntity, std::vector<std::string> argArray){
auto* phantomPhysicsComponent = m_Parent->GetComponent<PhantomPhysicsComponent>(); auto* phantomPhysicsComponent = m_Parent->GetComponent<PhantomPhysicsComponent>();
if (!phantomPhysicsComponent) { if (!phantomPhysicsComponent) {
Game::logger->Log("TriggerComponent::HandlePushObject", "Phantom Physics component not found!"); Game::logger->LogDebug("TriggerComponent::HandlePushObject", "Phantom Physics component not found!");
return; return;
} }
phantomPhysicsComponent->SetPhysicsEffectActive(true); phantomPhysicsComponent->SetPhysicsEffectActive(true);
@ -250,7 +254,7 @@ void TriggerComponent::HandlePushObject(Entity* targetEntity, std::vector<std::s
void TriggerComponent::HandleRepelObject(Entity* targetEntity, std::string args){ void TriggerComponent::HandleRepelObject(Entity* targetEntity, std::string args){
auto* phantomPhysicsComponent = m_Parent->GetComponent<PhantomPhysicsComponent>(); auto* phantomPhysicsComponent = m_Parent->GetComponent<PhantomPhysicsComponent>();
if (!phantomPhysicsComponent) { if (!phantomPhysicsComponent) {
Game::logger->Log("TriggerComponent::HandleRepelObject", "Phantom Physics component not found!"); Game::logger->LogDebug("TriggerComponent::HandleRepelObject", "Phantom Physics component not found!");
return; return;
} }
float forceMultiplier; float forceMultiplier;
@ -271,6 +275,20 @@ void TriggerComponent::HandleRepelObject(Entity* targetEntity, std::string args)
EntityManager::Instance()->SerializeEntity(m_Parent); EntityManager::Instance()->SerializeEntity(m_Parent);
} }
void TriggerComponent::HandleSetTimer(Entity* targetEntity, std::vector<std::string> argArray){
if (argArray.size() != 2) {
Game::logger->LogDebug("TriggerComponent::HandleSetTimer", "Not ehought variables!");
return;
}
float time = 0.0;
GeneralUtils::TryParse<float>(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<std::string> argArray) { void TriggerComponent::HandlePlayCinematic(Entity* targetEntity, std::vector<std::string> argArray) {
float leadIn = -1.0; float leadIn = -1.0;
auto wait = eEndBehavior::RETURN; auto wait = eEndBehavior::RETURN;
@ -300,7 +318,7 @@ void TriggerComponent::HandlePlayCinematic(Entity* targetEntity, std::vector<std
void TriggerComponent::HandleToggleBBB(Entity* targetEntity, std::string args) { void TriggerComponent::HandleToggleBBB(Entity* targetEntity, std::string args) {
auto* character = targetEntity->GetCharacter(); auto* character = targetEntity->GetCharacter();
if (!character) { if (!character) {
Game::logger->Log("TriggerComponent::HandleToggleBBB", "Character was not found!"); Game::logger->LogDebug("TriggerComponent::HandleToggleBBB", "Character was not found!");
return; return;
} }
bool buildMode = !(character->GetBuildMode()); bool buildMode = !(character->GetBuildMode());
@ -316,7 +334,7 @@ void TriggerComponent::HandleUpdateMission(Entity* targetEntity, std::vector<std
if (argArray.at(0) != "exploretask") return; if (argArray.at(0) != "exploretask") return;
MissionComponent* missionComponent = targetEntity->GetComponent<MissionComponent>(); MissionComponent* missionComponent = targetEntity->GetComponent<MissionComponent>();
if (!missionComponent){ if (!missionComponent){
Game::logger->Log("TriggerComponent::HandleUpdateMission", "Mission component not found!"); Game::logger->LogDebug("TriggerComponent::HandleUpdateMission", "Mission component not found!");
return; return;
} }
missionComponent->Progress(eMissionTaskType::EXPLORE, 0, 0, argArray.at(4)); missionComponent->Progress(eMissionTaskType::EXPLORE, 0, 0, argArray.at(4));
@ -335,7 +353,7 @@ void TriggerComponent::HandlePlayEffect(Entity* targetEntity, std::vector<std::s
void TriggerComponent::HandleCastSkill(Entity* targetEntity, std::string args){ void TriggerComponent::HandleCastSkill(Entity* targetEntity, std::string args){
auto* skillComponent = targetEntity->GetComponent<SkillComponent>(); auto* skillComponent = targetEntity->GetComponent<SkillComponent>();
if (!skillComponent) { if (!skillComponent) {
Game::logger->Log("TriggerComponent::HandleCastSkill", "Skill component not found!"); Game::logger->LogDebug("TriggerComponent::HandleCastSkill", "Skill component not found!");
return; return;
} }
uint32_t skillId; uint32_t skillId;
@ -346,7 +364,7 @@ void TriggerComponent::HandleCastSkill(Entity* targetEntity, std::string args){
void TriggerComponent::HandleSetPhysicsVolumeEffect(Entity* targetEntity, std::vector<std::string> argArray) { void TriggerComponent::HandleSetPhysicsVolumeEffect(Entity* targetEntity, std::vector<std::string> argArray) {
auto* phantomPhysicsComponent = targetEntity->GetComponent<PhantomPhysicsComponent>(); auto* phantomPhysicsComponent = targetEntity->GetComponent<PhantomPhysicsComponent>();
if (!phantomPhysicsComponent) { if (!phantomPhysicsComponent) {
Game::logger->Log("TriggerComponent::HandleSetPhysicsVolumeEffect", "Phantom Physics component not found!"); Game::logger->LogDebug("TriggerComponent::HandleSetPhysicsVolumeEffect", "Phantom Physics component not found!");
return; return;
} }
phantomPhysicsComponent->SetPhysicsEffectActive(true); phantomPhysicsComponent->SetPhysicsEffectActive(true);
@ -381,7 +399,7 @@ void TriggerComponent::HandleSetPhysicsVolumeEffect(Entity* targetEntity, std::v
void TriggerComponent::HandleSetPhysicsVolumeStatus(Entity* targetEntity, std::string args) { void TriggerComponent::HandleSetPhysicsVolumeStatus(Entity* targetEntity, std::string args) {
auto* phantomPhysicsComponent = targetEntity->GetComponent<PhantomPhysicsComponent>(); auto* phantomPhysicsComponent = targetEntity->GetComponent<PhantomPhysicsComponent>();
if (!phantomPhysicsComponent) { if (!phantomPhysicsComponent) {
Game::logger->Log("TriggerComponent::HandleSetPhysicsVolumeEffect", "Phantom Physics component not found!"); Game::logger->LogDebug("TriggerComponent::HandleSetPhysicsVolumeEffect", "Phantom Physics component not found!");
return; return;
} }
phantomPhysicsComponent->SetPhysicsEffectActive(args == "On"); phantomPhysicsComponent->SetPhysicsEffectActive(args == "On");

View File

@ -30,6 +30,8 @@ private:
void HandleRotateObject(Entity* targetEntity, std::vector<std::string> argArray); void HandleRotateObject(Entity* targetEntity, std::vector<std::string> argArray);
void HandlePushObject(Entity* targetEntity, std::vector<std::string> argArray); void HandlePushObject(Entity* targetEntity, std::vector<std::string> argArray);
void HandleRepelObject(Entity* targetEntity, std::string args); void HandleRepelObject(Entity* targetEntity, std::string args);
void HandleSetTimer(Entity* targetEntity, std::vector<std::string> argArray);
void HandleCancelTimer(Entity* targetEntity, std::string args);
void HandlePlayCinematic(Entity* targetEntity, std::vector<std::string> argArray); void HandlePlayCinematic(Entity* targetEntity, std::vector<std::string> argArray);
void HandleToggleBBB(Entity* targetEntity, std::string args); void HandleToggleBBB(Entity* targetEntity, std::string args);
void HandleUpdateMission(Entity* targetEntity, std::vector<std::string> argArray); void HandleUpdateMission(Entity* targetEntity, std::vector<std::string> argArray);

View File

@ -5,113 +5,55 @@
#include "eReplicaComponentType.h" #include "eReplicaComponentType.h"
void AgJetEffectServer::OnUse(Entity* self, Entity* user) { void AgJetEffectServer::OnUse(Entity* self, Entity* user) {
if (inUse) { if (inUse || !self->GetLOT() == 6859) return;
return;
}
GameMessages::SendNotifyClientObject( GameMessages::SendNotifyClientObject(
self->GetObjectID(), self->GetObjectID(), u"toggleInUse", 1, 0, LWOOBJID_EMPTY, "", UNASSIGNED_SYSTEM_ADDRESS
u"isInUse",
0,
0,
LWOOBJID_EMPTY,
"",
UNASSIGNED_SYSTEM_ADDRESS
); );
inUse = true; inUse = true;
auto entities = EntityManager::Instance()->GetEntitiesInGroup("Jet_FX"); auto entities = EntityManager::Instance()->GetEntitiesInGroup("Jet_FX");
if (entities.empty()) return;
if (entities.empty()) { GameMessages::SendPlayFXEffect(entities.at(0), 641, u"create", "radarDish", LWOOBJID_EMPTY, 1, 1, true);
return; 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
auto* effect = entities[0];
GameMessages::SendPlayFXEffect(effect, 641, u"create", "radarDish", LWOOBJID_EMPTY, 1, 1, true);
self->AddTimer("radarDish", 2);
self->AddTimer("CineDone", 9);
} }
void AgJetEffectServer::OnRebuildComplete(Entity* self, Entity* target) { void AgJetEffectServer::OnRebuildComplete(Entity* self, Entity* target) {
if (self->GetLOT() != 6209) return;
auto entities = EntityManager::Instance()->GetEntitiesInGroup("Jet_FX"); auto entities = EntityManager::Instance()->GetEntitiesInGroup("Jet_FX");
if (entities.empty()) return;
GameMessages::SendPlayAnimation(entities.at(0), u"jetFX");
if (entities.empty()) { // So we can give kill credit to person who build this
return;
}
auto* effect = entities[0];
auto groups = self->GetGroups();
if (groups.empty()) {
return;
}
builder = target->GetObjectID(); builder = target->GetObjectID();
const auto group = groups[0]; auto groups = self->GetGroups();
if (!groups.empty() && groups.at(0) == "Base_Radar") {
GameMessages::SendPlayAnimation(effect, u"jetFX");
self->AddTimer("PlayEffect", 2.5f); self->AddTimer("PlayEffect", 2.5f);
self->AddTimer("CineDone", 7.5f + 5.0f); // 7.5f is time the cinematic takes to play
if (group == "Base_Radar") {
self->AddTimer("CineDone", 5);
} }
} }
void AgJetEffectServer::OnTimerDone(Entity* self, std::string timerName) { void AgJetEffectServer::OnTimerDone(Entity* self, std::string timerName) {
if (timerName == "radarDish") { if (timerName == "radarDish") {
GameMessages::SendStopFXEffect(self, true, "radarDish"); GameMessages::SendStopFXEffect(self, true, "radarDish");
} else if (timerName == "PlayEffect") {
return;
}
if (timerName == "PlayEffect") {
auto entities = EntityManager::Instance()->GetEntitiesInGroup("mortarMain"); auto entities = EntityManager::Instance()->GetEntitiesInGroup("mortarMain");
if (entities.empty()) return;
if (entities.empty()) { const auto selected = GeneralUtils::GenerateRandomNumber<int>(0, entities.size() - 1);
return; auto* mortar = entities.at(selected);
}
const auto size = entities.size();
if (size == 0) {
return;
}
const auto selected = GeneralUtils::GenerateRandomNumber<int>(0, size - 1);
auto* mortar = entities[selected];
Game::logger->Log("AgJetEffectServer", "Mortar (%i) (&d)", mortar->GetLOT(), mortar->HasComponent(eReplicaComponentType::SKILL));
// so we give proper credit to the builder for the kills from this skill
mortar->SetOwnerOverride(builder); mortar->SetOwnerOverride(builder);
SkillComponent* skillComponent; auto* skillComponent = mortar->GetComponent<SkillComponent>();
if (!mortar->TryGetComponent(eReplicaComponentType::SKILL, skillComponent)) { if (skillComponent) skillComponent->CastSkill(318);
return; } else if (timerName == "CineDone") {
}
skillComponent->CalculateBehavior(318, 3727, LWOOBJID_EMPTY, true);
return;
}
if (timerName == "CineDone") {
GameMessages::SendNotifyClientObject( GameMessages::SendNotifyClientObject(
self->GetObjectID(), self->GetObjectID(), u"toggleInUse", -1, 0, LWOOBJID_EMPTY, "", UNASSIGNED_SYSTEM_ADDRESS
u"toggleInUse",
-1,
0,
LWOOBJID_EMPTY,
"",
UNASSIGNED_SYSTEM_ADDRESS
); );
inUse = false; inUse = false;
} }
} }