2021-12-05 17:54:36 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include "RailActivatorComponent.h"
|
|
|
|
#include "CDClientManager.h"
|
|
|
|
#include "CDRailActivatorComponent.h"
|
|
|
|
#include "Entity.h"
|
|
|
|
#include "GameMessages.h"
|
|
|
|
#include "RebuildComponent.h"
|
|
|
|
#include "Game.h"
|
|
|
|
#include "dLogger.h"
|
2023-03-20 13:10:52 +00:00
|
|
|
#include "RenderComponent.h"
|
|
|
|
#include "EntityManager.h"
|
2023-05-02 22:39:21 +00:00
|
|
|
#include "eStateChangeType.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
RailActivatorComponent::RailActivatorComponent(Entity* parent, int32_t componentID) : Component(parent) {
|
|
|
|
m_ComponentID = componentID;
|
2023-03-17 14:36:21 +00:00
|
|
|
const auto tableData = CDClientManager::Instance().GetTable<CDRailActivatorComponentTable>()->GetEntryByID(componentID);;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
|
|
|
m_Path = parent->GetVar<std::u16string>(u"rail_path");
|
|
|
|
m_PathDirection = parent->GetVar<bool>(u"rail_path_direction");
|
|
|
|
m_PathStart = parent->GetVar<uint32_t>(u"rail_path_start");
|
|
|
|
|
|
|
|
m_StartSound = tableData.startSound;
|
|
|
|
m_loopSound = tableData.loopSound;
|
|
|
|
m_StopSound = tableData.stopSound;
|
|
|
|
|
|
|
|
m_StartAnimation = tableData.startAnimation;
|
|
|
|
m_LoopAnimation = tableData.loopAnimation;
|
|
|
|
m_StopAnimation = tableData.stopAnimation;
|
|
|
|
|
|
|
|
m_StartEffect = tableData.startEffectID;
|
|
|
|
m_LoopEffect = tableData.loopEffectID;
|
|
|
|
m_StopEffect = tableData.stopEffectID;
|
|
|
|
|
|
|
|
m_DamageImmune = parent->GetVar<bool>(u"rail_activator_damage_immune");
|
|
|
|
m_NoAggro = parent->GetVar<bool>(u"rail_no_aggro");
|
|
|
|
m_NotifyArrived = parent->GetVar<bool>(u"rail_notify_activator_arrived");
|
|
|
|
m_ShowNameBillboard = parent->GetVar<bool>(u"rail_show_name_billboard");
|
|
|
|
m_UseDB = parent->GetVar<bool>(u"rail_use_db");
|
|
|
|
m_CameraLocked = tableData.cameraLocked;
|
|
|
|
m_CollisionEnabled = tableData.playerCollision;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RailActivatorComponent::~RailActivatorComponent() = default;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void RailActivatorComponent::OnUse(Entity* originator) {
|
2023-06-07 01:59:53 +00:00
|
|
|
auto* rebuildComponent = m_OwningEntity->GetComponent<RebuildComponent>();
|
2023-05-02 22:39:21 +00:00
|
|
|
if (rebuildComponent != nullptr && rebuildComponent->GetState() != eRebuildState::COMPLETED)
|
2022-07-28 13:39:57 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (rebuildComponent != nullptr) {
|
|
|
|
// Don't want it to be destroyed while a player is using it
|
|
|
|
rebuildComponent->SetResetTime(rebuildComponent->GetResetTime() + 10.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_EntitiesOnRail.push_back(originator->GetObjectID());
|
|
|
|
|
|
|
|
// Start the initial effects
|
|
|
|
if (!m_StartEffect.second.empty()) {
|
|
|
|
GameMessages::SendPlayFXEffect(originator->GetObjectID(), m_StartEffect.first, m_StartEffect.second,
|
|
|
|
std::to_string(m_StartEffect.first));
|
|
|
|
}
|
2023-03-20 13:10:52 +00:00
|
|
|
|
|
|
|
float animationLength = 0.5f;
|
2022-07-28 13:39:57 +00:00
|
|
|
if (!m_StartAnimation.empty()) {
|
2023-03-20 13:10:52 +00:00
|
|
|
animationLength = RenderComponent::PlayAnimation(originator, m_StartAnimation);
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const auto originatorID = originator->GetObjectID();
|
|
|
|
|
2023-06-07 01:59:53 +00:00
|
|
|
m_OwningEntity->AddCallbackTimer(animationLength, [originatorID, this]() {
|
2022-07-28 13:39:57 +00:00
|
|
|
auto* originator = EntityManager::Instance()->GetEntity(originatorID);
|
|
|
|
|
|
|
|
if (originator == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GameMessages::SendStartRailMovement(originator->GetObjectID(), m_Path, m_StartSound,
|
|
|
|
m_loopSound, m_StopSound, originator->GetSystemAddress(),
|
|
|
|
m_PathStart, m_PathDirection, m_DamageImmune, m_NoAggro, m_NotifyArrived,
|
|
|
|
m_ShowNameBillboard, m_CameraLocked, m_CollisionEnabled, m_UseDB, m_ComponentID,
|
2023-06-07 01:59:53 +00:00
|
|
|
m_OwningEntity->GetObjectID());
|
2022-07-28 13:39:57 +00:00
|
|
|
});
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void RailActivatorComponent::OnRailMovementReady(Entity* originator) const {
|
|
|
|
// Stun the originator
|
2023-01-07 05:59:19 +00:00
|
|
|
GameMessages::SendSetStunned(originator->GetObjectID(), eStateChangeType::PUSH, originator->GetSystemAddress(), LWOOBJID_EMPTY,
|
2022-07-28 13:39:57 +00:00
|
|
|
true, true, true, true, true, true, true
|
|
|
|
);
|
|
|
|
|
|
|
|
if (std::find(m_EntitiesOnRail.begin(), m_EntitiesOnRail.end(), originator->GetObjectID()) != m_EntitiesOnRail.end()) {
|
|
|
|
// Stop the initial effects
|
|
|
|
if (!m_StartEffect.second.empty()) {
|
|
|
|
GameMessages::SendStopFXEffect(originator, false, std::to_string(m_StartEffect.first));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start the looping effects
|
|
|
|
if (!m_LoopEffect.second.empty()) {
|
|
|
|
GameMessages::SendPlayFXEffect(originator->GetObjectID(), m_LoopEffect.first, m_LoopEffect.second,
|
|
|
|
std::to_string(m_LoopEffect.first));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!m_LoopAnimation.empty()) {
|
2023-03-20 13:10:52 +00:00
|
|
|
RenderComponent::PlayAnimation(originator, m_LoopAnimation);
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GameMessages::SendSetRailMovement(originator->GetObjectID(), m_PathDirection, m_Path, m_PathStart,
|
|
|
|
originator->GetSystemAddress(), m_ComponentID,
|
2023-06-07 01:59:53 +00:00
|
|
|
m_OwningEntity->GetObjectID());
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void RailActivatorComponent::OnCancelRailMovement(Entity* originator) {
|
|
|
|
// Remove the stun from the originator
|
2023-01-07 05:59:19 +00:00
|
|
|
GameMessages::SendSetStunned(originator->GetObjectID(), eStateChangeType::POP, originator->GetSystemAddress(), LWOOBJID_EMPTY,
|
2022-07-28 13:39:57 +00:00
|
|
|
true, true, true, true, true, true, true
|
|
|
|
);
|
|
|
|
|
2023-06-07 01:59:53 +00:00
|
|
|
auto* rebuildComponent = m_OwningEntity->GetComponent<RebuildComponent>();
|
2022-07-28 13:39:57 +00:00
|
|
|
|
|
|
|
if (rebuildComponent != nullptr) {
|
|
|
|
// Set back reset time
|
|
|
|
rebuildComponent->SetResetTime(rebuildComponent->GetResetTime() - 10.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (std::find(m_EntitiesOnRail.begin(), m_EntitiesOnRail.end(), originator->GetObjectID()) != m_EntitiesOnRail.end()) {
|
|
|
|
// Stop the looping effects
|
|
|
|
if (!m_LoopEffect.second.empty()) {
|
|
|
|
GameMessages::SendStopFXEffect(originator, false, std::to_string(m_LoopEffect.first));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start the end effects
|
|
|
|
if (!m_StopEffect.second.empty()) {
|
|
|
|
GameMessages::SendPlayFXEffect(originator->GetObjectID(), m_StopEffect.first, m_StopEffect.second,
|
|
|
|
std::to_string(m_StopEffect.first));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!m_StopAnimation.empty()) {
|
2023-03-20 13:10:52 +00:00
|
|
|
RenderComponent::PlayAnimation(originator, m_StopAnimation);
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the player after they've signalled they're done railing
|
|
|
|
m_EntitiesOnRail.erase(std::remove(m_EntitiesOnRail.begin(), m_EntitiesOnRail.end(),
|
|
|
|
originator->GetObjectID()), m_EntitiesOnRail.end());
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|