2023-12-29 04:24:30 +00:00
|
|
|
#include "QuickBuildComponent.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "Entity.h"
|
|
|
|
#include "DestroyableComponent.h"
|
|
|
|
#include "GameMessages.h"
|
|
|
|
#include "EntityManager.h"
|
|
|
|
#include "Game.h"
|
2023-10-21 23:31:55 +00:00
|
|
|
#include "Logger.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "CharacterComponent.h"
|
2022-07-05 06:00:10 +00:00
|
|
|
#include "MissionComponent.h"
|
2023-01-22 23:38:47 +00:00
|
|
|
#include "eMissionTaskType.h"
|
2023-03-25 10:26:39 +00:00
|
|
|
#include "eTriggerEventType.h"
|
2023-05-02 22:39:21 +00:00
|
|
|
#include "eQuickBuildFailReason.h"
|
|
|
|
#include "eTerminateType.h"
|
|
|
|
#include "eGameActivity.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
#include "dServer.h"
|
|
|
|
#include "Spawner.h"
|
|
|
|
#include "MovingPlatformComponent.h"
|
|
|
|
#include "Preconditions.h"
|
2023-01-07 05:17:05 +00:00
|
|
|
#include "Loot.h"
|
2022-12-22 13:24:59 +00:00
|
|
|
#include "TeamManager.h"
|
2023-03-20 13:10:52 +00:00
|
|
|
#include "RenderComponent.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
#include "CppScripts.h"
|
|
|
|
|
2024-02-10 19:44:40 +00:00
|
|
|
QuickBuildComponent::QuickBuildComponent(Entity* const entity) : Component{ entity } {
|
2021-12-05 17:54:36 +00:00
|
|
|
std::u16string checkPreconditions = entity->GetVar<std::u16string>(u"CheckPrecondition");
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (!checkPreconditions.empty()) {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_Precondition = new PreconditionExpression(GeneralUtils::UTF16ToWTF8(checkPreconditions));
|
|
|
|
}
|
2022-06-16 05:59:30 +00:00
|
|
|
|
2022-06-16 06:04:03 +00:00
|
|
|
// Should a setting that has the build activator position exist, fetch that setting here and parse it for position.
|
2022-06-16 15:38:38 +00:00
|
|
|
// It is assumed that the user who sets this setting uses the correct character delimiter (character 31 or in hex 0x1F)
|
|
|
|
auto positionAsVector = GeneralUtils::SplitString(m_Parent->GetVarAsString(u"rebuild_activators"), 0x1F);
|
2024-02-10 11:05:25 +00:00
|
|
|
const auto activatorPositionValid = GeneralUtils::TryParse<NiPoint3>(positionAsVector);
|
|
|
|
if (positionAsVector.size() == 3 && activatorPositionValid) {
|
|
|
|
m_ActivatorPosition = activatorPositionValid.value();
|
2022-06-16 05:59:30 +00:00
|
|
|
} else {
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("Failed to find activator position for lot %i. Defaulting to parents position.", m_Parent->GetLOT());
|
2022-06-16 05:59:30 +00:00
|
|
|
m_ActivatorPosition = m_Parent->GetPosition();
|
|
|
|
}
|
2022-06-16 15:38:38 +00:00
|
|
|
|
2022-06-16 05:59:30 +00:00
|
|
|
SpawnActivator();
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2023-12-29 04:24:30 +00:00
|
|
|
QuickBuildComponent::~QuickBuildComponent() {
|
2021-12-05 17:54:36 +00:00
|
|
|
delete m_Precondition;
|
|
|
|
|
|
|
|
Entity* builder = GetBuilder();
|
|
|
|
if (builder) {
|
2023-12-29 04:24:30 +00:00
|
|
|
CancelQuickBuild(builder, eQuickBuildFailReason::BUILD_ENDED, true);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
DespawnActivator();
|
|
|
|
}
|
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
void QuickBuildComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
|
2023-03-04 07:16:37 +00:00
|
|
|
if (m_Parent->GetComponent(eReplicaComponentType::DESTROYABLE) == nullptr) {
|
2021-12-05 17:54:36 +00:00
|
|
|
if (bIsInitialUpdate) {
|
2024-02-27 07:25:44 +00:00
|
|
|
outBitStream.Write(false);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
outBitStream.Write(false);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
outBitStream.Write(false);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
2022-07-25 02:26:51 +00:00
|
|
|
// If build state is completed and we've already serialized once in the completed state,
|
2022-05-03 05:32:00 +00:00
|
|
|
// don't serializing this component anymore as this will cause the build to jump again.
|
|
|
|
// If state changes, serialization will begin again.
|
2023-12-29 04:24:30 +00:00
|
|
|
if (!m_StateDirty && m_State == eQuickBuildState::COMPLETED) {
|
2024-02-27 07:25:44 +00:00
|
|
|
outBitStream.Write0();
|
|
|
|
outBitStream.Write0();
|
2022-05-03 05:32:00 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
// BEGIN Scripted Activity
|
2024-02-27 07:25:44 +00:00
|
|
|
outBitStream.Write1();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
Entity* builder = GetBuilder();
|
|
|
|
|
|
|
|
if (builder) {
|
2024-02-27 07:25:44 +00:00
|
|
|
outBitStream.Write<uint32_t>(1);
|
|
|
|
outBitStream.Write(builder->GetObjectID());
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < 10; i++) {
|
2024-02-27 07:25:44 +00:00
|
|
|
outBitStream.Write(0.0f);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
} else {
|
2024-02-27 07:25:44 +00:00
|
|
|
outBitStream.Write<uint32_t>(0);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
// END Scripted Activity
|
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
outBitStream.Write1();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
outBitStream.Write(m_State);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
outBitStream.Write(m_ShowResetEffect);
|
|
|
|
outBitStream.Write(m_Activator != nullptr);
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
outBitStream.Write(m_Timer);
|
|
|
|
outBitStream.Write(m_TimerIncomplete);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (bIsInitialUpdate) {
|
2024-02-27 07:25:44 +00:00
|
|
|
outBitStream.Write(false);
|
|
|
|
outBitStream.Write(m_ActivatorPosition);
|
|
|
|
outBitStream.Write(m_RepositionPlayer);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
2022-05-03 05:32:00 +00:00
|
|
|
m_StateDirty = false;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2023-12-29 04:24:30 +00:00
|
|
|
void QuickBuildComponent::Update(float deltaTime) {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_Activator = GetActivator();
|
|
|
|
|
|
|
|
// Serialize the quickbuild every so often, fixes the odd bug where the quickbuild is not buildable
|
|
|
|
/*if (m_SoftTimer > 0.0f) {
|
|
|
|
m_SoftTimer -= deltaTime;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_SoftTimer = 5.0f;
|
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->SerializeEntity(m_Parent);
|
2021-12-05 17:54:36 +00:00
|
|
|
}*/
|
|
|
|
|
|
|
|
switch (m_State) {
|
2023-12-29 04:24:30 +00:00
|
|
|
case eQuickBuildState::OPEN: {
|
2021-12-05 17:54:36 +00:00
|
|
|
SpawnActivator();
|
|
|
|
m_TimeBeforeDrain = 0;
|
|
|
|
|
|
|
|
auto* spawner = m_Parent->GetSpawner();
|
|
|
|
const bool isSmashGroup = spawner != nullptr ? spawner->GetIsSpawnSmashGroup() : false;
|
|
|
|
|
|
|
|
if (isSmashGroup) {
|
|
|
|
m_TimerIncomplete += deltaTime;
|
|
|
|
|
|
|
|
// For reset times < 0 this has to be handled manually
|
|
|
|
if (m_TimeBeforeSmash > 0) {
|
|
|
|
if (m_TimerIncomplete >= m_TimeBeforeSmash - 4.0f) {
|
|
|
|
m_ShowResetEffect = true;
|
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->SerializeEntity(m_Parent);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_TimerIncomplete >= m_TimeBeforeSmash) {
|
|
|
|
m_Builder = LWOOBJID_EMPTY;
|
|
|
|
|
|
|
|
GameMessages::SendDieNoImplCode(m_Parent, LWOOBJID_EMPTY, LWOOBJID_EMPTY, eKillType::VIOLENT, u"", 0.0f, 0.0f, 0.0f, false, true);
|
|
|
|
|
2023-12-29 04:24:30 +00:00
|
|
|
ResetQuickBuild(false);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
break;
|
|
|
|
}
|
2023-12-29 04:24:30 +00:00
|
|
|
case eQuickBuildState::COMPLETED: {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_Timer += deltaTime;
|
|
|
|
|
|
|
|
// For reset times < 0 this has to be handled manually
|
|
|
|
if (m_ResetTime > 0) {
|
2022-07-28 13:39:57 +00:00
|
|
|
if (m_Timer >= m_ResetTime - 4.0f) {
|
|
|
|
if (!m_ShowResetEffect) {
|
|
|
|
m_ShowResetEffect = true;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->SerializeEntity(m_Parent);
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (m_Timer >= m_ResetTime) {
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
GameMessages::SendDieNoImplCode(m_Parent, LWOOBJID_EMPTY, LWOOBJID_EMPTY, eKillType::VIOLENT, u"", 0.0f, 0.0f, 0.0f, false, true);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-12-29 04:24:30 +00:00
|
|
|
ResetQuickBuild(false);
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2023-12-29 04:24:30 +00:00
|
|
|
case eQuickBuildState::BUILDING:
|
2021-12-05 17:54:36 +00:00
|
|
|
{
|
|
|
|
Entity* builder = GetBuilder();
|
|
|
|
|
2023-08-04 02:37:27 +00:00
|
|
|
if (!builder) {
|
2023-12-29 04:24:30 +00:00
|
|
|
ResetQuickBuild(false);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_TimeBeforeDrain -= deltaTime;
|
|
|
|
m_Timer += deltaTime;
|
|
|
|
m_TimerIncomplete = 0;
|
|
|
|
m_ShowResetEffect = false;
|
|
|
|
|
|
|
|
if (m_TimeBeforeDrain <= 0.0f) {
|
|
|
|
m_TimeBeforeDrain = m_CompleteTime / static_cast<float>(m_TakeImagination);
|
|
|
|
|
|
|
|
DestroyableComponent* destComp = builder->GetComponent<DestroyableComponent>();
|
|
|
|
if (!destComp) break;
|
|
|
|
|
2023-05-11 11:37:02 +00:00
|
|
|
++m_DrainedImagination;
|
2023-12-17 01:35:16 +00:00
|
|
|
const int32_t imaginationCostRemaining = m_TakeImagination - m_DrainedImagination;
|
|
|
|
|
|
|
|
const int32_t newImagination = destComp->GetImagination() - 1;
|
2021-12-05 17:54:36 +00:00
|
|
|
destComp->SetImagination(newImagination);
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->SerializeEntity(builder);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-12-17 01:35:16 +00:00
|
|
|
if (newImagination <= 0 && imaginationCostRemaining > 0) {
|
2023-12-29 04:24:30 +00:00
|
|
|
CancelQuickBuild(builder, eQuickBuildFailReason::OUT_OF_IMAGINATION, true);
|
2023-08-04 02:37:27 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_Timer >= m_CompleteTime && m_DrainedImagination >= m_TakeImagination) {
|
2023-12-29 04:24:30 +00:00
|
|
|
CompleteQuickBuild(builder);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2023-12-29 04:24:30 +00:00
|
|
|
case eQuickBuildState::INCOMPLETE: {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_TimerIncomplete += deltaTime;
|
|
|
|
|
|
|
|
// For reset times < 0 this has to be handled manually
|
|
|
|
if (m_TimeBeforeSmash > 0) {
|
2022-07-28 13:39:57 +00:00
|
|
|
if (m_TimerIncomplete >= m_TimeBeforeSmash - 4.0f) {
|
|
|
|
m_ShowResetEffect = true;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->SerializeEntity(m_Parent);
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (m_TimerIncomplete >= m_TimeBeforeSmash) {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_Builder = LWOOBJID_EMPTY;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
GameMessages::SendDieNoImplCode(m_Parent, LWOOBJID_EMPTY, LWOOBJID_EMPTY, eKillType::VIOLENT, u"", 0.0f, 0.0f, 0.0f, false, true);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-12-29 04:24:30 +00:00
|
|
|
ResetQuickBuild(false);
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2023-12-29 04:24:30 +00:00
|
|
|
case eQuickBuildState::RESETTING: break;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-29 04:24:30 +00:00
|
|
|
void QuickBuildComponent::OnUse(Entity* originator) {
|
|
|
|
if (GetBuilder() != nullptr || m_State == eQuickBuildState::COMPLETED) {
|
2021-12-05 17:54:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_Precondition != nullptr && !m_Precondition->Check(originator)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-12-29 04:24:30 +00:00
|
|
|
StartQuickBuild(originator);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2023-12-29 04:24:30 +00:00
|
|
|
void QuickBuildComponent::SpawnActivator() {
|
2024-01-29 07:53:12 +00:00
|
|
|
if (!m_SelfActivator || m_ActivatorPosition != NiPoint3Constant::ZERO) {
|
2021-12-05 17:54:36 +00:00
|
|
|
if (!m_Activator) {
|
|
|
|
EntityInfo info;
|
|
|
|
|
|
|
|
info.lot = 6604;
|
|
|
|
info.spawnerID = m_Parent->GetObjectID();
|
2024-01-29 07:53:12 +00:00
|
|
|
info.pos = m_ActivatorPosition == NiPoint3Constant::ZERO ? m_Parent->GetPosition() : m_ActivatorPosition;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
m_Activator = Game::entityManager->CreateEntity(info, nullptr, m_Parent);
|
2021-12-05 17:54:36 +00:00
|
|
|
if (m_Activator) {
|
|
|
|
m_ActivatorId = m_Activator->GetObjectID();
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->ConstructEntity(m_Activator);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->SerializeEntity(m_Parent);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-29 04:24:30 +00:00
|
|
|
void QuickBuildComponent::DespawnActivator() {
|
2021-12-05 17:54:36 +00:00
|
|
|
if (m_Activator) {
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->DestructEntity(m_Activator);
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
m_Activator->ScheduleKillAfterUpdate();
|
|
|
|
|
|
|
|
m_Activator = nullptr;
|
|
|
|
|
|
|
|
m_ActivatorId = LWOOBJID_EMPTY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-10 19:44:40 +00:00
|
|
|
Entity* QuickBuildComponent::GetActivator() const {
|
2023-07-15 20:56:33 +00:00
|
|
|
return Game::entityManager->GetEntity(m_ActivatorId);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2024-02-10 19:44:40 +00:00
|
|
|
NiPoint3 QuickBuildComponent::GetActivatorPosition() const noexcept {
|
2021-12-05 17:54:36 +00:00
|
|
|
return m_ActivatorPosition;
|
|
|
|
}
|
|
|
|
|
2024-02-10 19:44:40 +00:00
|
|
|
float QuickBuildComponent::GetResetTime() const noexcept {
|
2021-12-05 17:54:36 +00:00
|
|
|
return m_ResetTime;
|
|
|
|
}
|
|
|
|
|
2024-02-10 19:44:40 +00:00
|
|
|
float QuickBuildComponent::GetCompleteTime() const noexcept {
|
2021-12-05 17:54:36 +00:00
|
|
|
return m_CompleteTime;
|
|
|
|
}
|
|
|
|
|
2024-02-10 19:44:40 +00:00
|
|
|
int32_t QuickBuildComponent::GetTakeImagination() const noexcept {
|
2021-12-05 17:54:36 +00:00
|
|
|
return m_TakeImagination;
|
|
|
|
}
|
|
|
|
|
2024-02-10 19:44:40 +00:00
|
|
|
bool QuickBuildComponent::GetInterruptible() const noexcept {
|
2021-12-05 17:54:36 +00:00
|
|
|
return m_Interruptible;
|
|
|
|
}
|
|
|
|
|
2024-02-10 19:44:40 +00:00
|
|
|
bool QuickBuildComponent::GetSelfActivator() const noexcept {
|
2021-12-05 17:54:36 +00:00
|
|
|
return m_SelfActivator;
|
|
|
|
}
|
|
|
|
|
2024-02-10 19:44:40 +00:00
|
|
|
std::vector<int32_t> QuickBuildComponent::GetCustomModules() const noexcept {
|
2021-12-05 17:54:36 +00:00
|
|
|
return m_CustomModules;
|
|
|
|
}
|
|
|
|
|
2024-02-10 19:44:40 +00:00
|
|
|
int32_t QuickBuildComponent::GetActivityId() const noexcept {
|
2021-12-05 17:54:36 +00:00
|
|
|
return m_ActivityId;
|
|
|
|
}
|
|
|
|
|
2024-02-10 19:44:40 +00:00
|
|
|
int32_t QuickBuildComponent::GetPostImaginationCost() const noexcept {
|
2021-12-05 17:54:36 +00:00
|
|
|
return m_PostImaginationCost;
|
|
|
|
}
|
|
|
|
|
2024-02-10 19:44:40 +00:00
|
|
|
float QuickBuildComponent::GetTimeBeforeSmash() const noexcept {
|
2021-12-05 17:54:36 +00:00
|
|
|
return m_TimeBeforeSmash;
|
|
|
|
}
|
|
|
|
|
2024-02-10 11:05:25 +00:00
|
|
|
eQuickBuildState QuickBuildComponent::GetState() const noexcept {
|
2021-12-05 17:54:36 +00:00
|
|
|
return m_State;
|
|
|
|
}
|
|
|
|
|
2023-12-29 04:24:30 +00:00
|
|
|
Entity* QuickBuildComponent::GetBuilder() const {
|
2024-02-10 19:44:40 +00:00
|
|
|
auto* const builder = Game::entityManager->GetEntity(m_Builder);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
return builder;
|
|
|
|
}
|
|
|
|
|
2024-02-10 19:44:40 +00:00
|
|
|
bool QuickBuildComponent::GetRepositionPlayer() const noexcept {
|
2021-12-05 17:54:36 +00:00
|
|
|
return m_RepositionPlayer;
|
|
|
|
}
|
|
|
|
|
2024-02-10 19:44:40 +00:00
|
|
|
void QuickBuildComponent::SetActivatorPosition(const NiPoint3& value) noexcept {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_ActivatorPosition = value;
|
|
|
|
}
|
|
|
|
|
2024-02-10 19:44:40 +00:00
|
|
|
void QuickBuildComponent::SetResetTime(const float value) noexcept {
|
2022-07-28 13:39:57 +00:00
|
|
|
m_ResetTime = value;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2024-02-10 19:44:40 +00:00
|
|
|
void QuickBuildComponent::SetCompleteTime(const float value) noexcept {
|
2021-12-05 17:54:36 +00:00
|
|
|
if (value < 0) {
|
|
|
|
m_CompleteTime = 4.5f;
|
2022-07-28 13:39:57 +00:00
|
|
|
} else {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_CompleteTime = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-10 19:44:40 +00:00
|
|
|
void QuickBuildComponent::SetTakeImagination(const int32_t value) noexcept {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_TakeImagination = value;
|
|
|
|
}
|
|
|
|
|
2024-02-10 19:44:40 +00:00
|
|
|
void QuickBuildComponent::SetInterruptible(const bool value) noexcept {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_Interruptible = value;
|
|
|
|
}
|
|
|
|
|
2024-02-10 19:44:40 +00:00
|
|
|
void QuickBuildComponent::SetSelfActivator(const bool value) noexcept {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_SelfActivator = value;
|
|
|
|
}
|
|
|
|
|
2024-02-10 19:44:40 +00:00
|
|
|
void QuickBuildComponent::SetCustomModules(const std::vector<int32_t>& value) noexcept {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_CustomModules = value;
|
|
|
|
}
|
|
|
|
|
2024-02-10 19:44:40 +00:00
|
|
|
void QuickBuildComponent::SetActivityId(const int32_t value) noexcept {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_ActivityId = value;
|
|
|
|
}
|
|
|
|
|
2024-02-10 19:44:40 +00:00
|
|
|
void QuickBuildComponent::SetPostImaginationCost(const int32_t value) noexcept {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_PostImaginationCost = value;
|
|
|
|
}
|
|
|
|
|
2024-02-10 19:44:40 +00:00
|
|
|
void QuickBuildComponent::SetTimeBeforeSmash(const float value) noexcept {
|
2021-12-05 17:54:36 +00:00
|
|
|
if (value < 0) {
|
|
|
|
m_TimeBeforeSmash = 10.0f;
|
2022-07-28 13:39:57 +00:00
|
|
|
} else {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_TimeBeforeSmash = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-10 19:44:40 +00:00
|
|
|
void QuickBuildComponent::SetRepositionPlayer(const bool value) noexcept {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_RepositionPlayer = value;
|
|
|
|
}
|
|
|
|
|
2024-02-10 19:44:40 +00:00
|
|
|
void QuickBuildComponent::StartQuickBuild(Entity* const user) {
|
2023-12-29 04:24:30 +00:00
|
|
|
if (m_State == eQuickBuildState::OPEN || m_State == eQuickBuildState::COMPLETED || m_State == eQuickBuildState::INCOMPLETE) {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_Builder = user->GetObjectID();
|
|
|
|
|
|
|
|
auto* character = user->GetComponent<CharacterComponent>();
|
2023-05-02 22:39:21 +00:00
|
|
|
character->SetCurrentActivity(eGameActivity::QUICKBUILDING);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->SerializeEntity(user);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-12-29 04:24:30 +00:00
|
|
|
GameMessages::SendQuickBuildNotifyState(m_Parent, m_State, eQuickBuildState::BUILDING, user->GetObjectID());
|
|
|
|
GameMessages::SendEnableQuickBuild(m_Parent, true, false, false, eQuickBuildFailReason::NOT_GIVEN, 0.0f, user->GetObjectID());
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-12-29 04:24:30 +00:00
|
|
|
m_State = eQuickBuildState::BUILDING;
|
2022-05-03 05:32:00 +00:00
|
|
|
m_StateDirty = true;
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->SerializeEntity(m_Parent);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
auto* movingPlatform = m_Parent->GetComponent<MovingPlatformComponent>();
|
|
|
|
if (movingPlatform != nullptr) {
|
2023-12-29 04:24:30 +00:00
|
|
|
movingPlatform->OnQuickBuildInitilized();
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (auto* script : CppScripts::GetEntityScripts(m_Parent)) {
|
2023-12-29 04:24:30 +00:00
|
|
|
script->OnQuickBuildStart(m_Parent, user);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
// Notify scripts and possible subscribers
|
|
|
|
for (auto* script : CppScripts::GetEntityScripts(m_Parent))
|
2023-12-29 04:24:30 +00:00
|
|
|
script->OnQuickBuildNotifyState(m_Parent, m_State);
|
|
|
|
for (const auto& cb : m_QuickBuildStateCallbacks)
|
2022-07-28 13:39:57 +00:00
|
|
|
cb(m_State);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-10 19:44:40 +00:00
|
|
|
void QuickBuildComponent::CompleteQuickBuild(Entity* const user) {
|
|
|
|
if (!user) return;
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
auto* characterComponent = user->GetComponent<CharacterComponent>();
|
|
|
|
if (characterComponent != nullptr) {
|
2023-05-02 22:39:21 +00:00
|
|
|
characterComponent->SetCurrentActivity(eGameActivity::NONE);
|
2023-12-29 04:24:30 +00:00
|
|
|
characterComponent->TrackQuickBuildComplete();
|
2021-12-05 17:54:36 +00:00
|
|
|
} else {
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("Some user tried to finish the rebuild but they didn't have a character somehow.");
|
2021-12-05 17:54:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->SerializeEntity(user);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-12-29 04:24:30 +00:00
|
|
|
GameMessages::SendQuickBuildNotifyState(m_Parent, m_State, eQuickBuildState::COMPLETED, user->GetObjectID());
|
2022-04-01 11:14:15 +00:00
|
|
|
GameMessages::SendPlayFXEffect(m_Parent, 507, u"create", "BrickFadeUpVisCompleteEffect", LWOOBJID_EMPTY, 0.4f, 1.0f, true);
|
2023-12-29 04:24:30 +00:00
|
|
|
GameMessages::SendEnableQuickBuild(m_Parent, false, false, true, eQuickBuildFailReason::NOT_GIVEN, m_ResetTime, user->GetObjectID());
|
2022-04-01 11:14:15 +00:00
|
|
|
GameMessages::SendTerminateInteraction(user->GetObjectID(), eTerminateType::FROM_INTERACTION, m_Parent->GetObjectID());
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-12-29 04:24:30 +00:00
|
|
|
m_State = eQuickBuildState::COMPLETED;
|
2022-05-03 05:32:00 +00:00
|
|
|
m_StateDirty = true;
|
2021-12-05 17:54:36 +00:00
|
|
|
m_Timer = 0.0f;
|
|
|
|
m_DrainedImagination = 0;
|
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->SerializeEntity(m_Parent);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
// Removes extra item requirements, isn't live accurate.
|
|
|
|
// In live, all items were removed at the start of the quickbuild, then returned if it was cancelled.
|
|
|
|
// TODO: fix?
|
|
|
|
if (m_Precondition != nullptr) {
|
|
|
|
m_Precondition->Check(user, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
DespawnActivator();
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
// Set owner override so that entities smashed by this quickbuild will result in the builder getting rewards.
|
2021-12-05 17:54:36 +00:00
|
|
|
m_Parent->SetOwnerOverride(user->GetObjectID());
|
|
|
|
|
|
|
|
auto* builder = GetBuilder();
|
|
|
|
|
2022-12-22 13:24:59 +00:00
|
|
|
if (builder) {
|
|
|
|
auto* team = TeamManager::Instance()->GetTeam(builder->GetObjectID());
|
|
|
|
if (team) {
|
|
|
|
for (const auto memberId : team->members) { // progress missions for all team members
|
2023-07-15 20:56:33 +00:00
|
|
|
auto* member = Game::entityManager->GetEntity(memberId);
|
2022-12-22 13:24:59 +00:00
|
|
|
if (member) {
|
|
|
|
auto* missionComponent = member->GetComponent<MissionComponent>();
|
2023-01-22 23:38:47 +00:00
|
|
|
if (missionComponent) missionComponent->Progress(eMissionTaskType::ACTIVITY, m_ActivityId);
|
2022-12-22 13:24:59 +00:00
|
|
|
}
|
|
|
|
}
|
2023-08-04 02:37:27 +00:00
|
|
|
} else {
|
2022-12-22 13:24:59 +00:00
|
|
|
auto* missionComponent = builder->GetComponent<MissionComponent>();
|
2023-01-22 23:38:47 +00:00
|
|
|
if (missionComponent) missionComponent->Progress(eMissionTaskType::ACTIVITY, m_ActivityId);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
2023-10-09 20:33:22 +00:00
|
|
|
Loot::DropActivityLoot(builder, m_Parent, m_ActivityId, 1);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Notify scripts
|
|
|
|
for (auto* script : CppScripts::GetEntityScripts(m_Parent)) {
|
2023-12-29 04:24:30 +00:00
|
|
|
script->OnQuickBuildComplete(m_Parent, user);
|
|
|
|
script->OnQuickBuildNotifyState(m_Parent, m_State);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Notify subscribers
|
2023-12-29 04:24:30 +00:00
|
|
|
for (const auto& callback : m_QuickBuildStateCallbacks)
|
2022-07-28 13:39:57 +00:00
|
|
|
callback(m_State);
|
2023-12-29 04:24:30 +00:00
|
|
|
for (const auto& callback : m_QuickBuildCompleteCallbacks)
|
2022-07-28 13:39:57 +00:00
|
|
|
callback(user);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-03-25 10:26:39 +00:00
|
|
|
m_Parent->TriggerEvent(eTriggerEventType::REBUILD_COMPLETE, user);
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
auto* movingPlatform = m_Parent->GetComponent<MovingPlatformComponent>();
|
|
|
|
if (movingPlatform != nullptr) {
|
2023-12-29 04:24:30 +00:00
|
|
|
movingPlatform->OnCompleteQuickBuild();
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set flag
|
|
|
|
auto* character = user->GetCharacter();
|
|
|
|
|
|
|
|
if (character != nullptr) {
|
|
|
|
const auto flagNumber = m_Parent->GetVar<int32_t>(u"quickbuild_single_build_player_flag");
|
|
|
|
|
|
|
|
if (flagNumber != 0) {
|
|
|
|
character->SetPlayerFlag(flagNumber, true);
|
|
|
|
}
|
|
|
|
}
|
2023-03-20 13:10:52 +00:00
|
|
|
RenderComponent::PlayAnimation(user, u"rebuild-celebrate", 1.09f);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2024-02-10 19:44:40 +00:00
|
|
|
void QuickBuildComponent::ResetQuickBuild(const bool failed) {
|
2021-12-05 17:54:36 +00:00
|
|
|
Entity* builder = GetBuilder();
|
|
|
|
|
2023-12-29 04:24:30 +00:00
|
|
|
if (m_State == eQuickBuildState::BUILDING && builder) {
|
|
|
|
GameMessages::SendEnableQuickBuild(m_Parent, false, false, failed, eQuickBuildFailReason::NOT_GIVEN, m_ResetTime, builder->GetObjectID());
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (failed) {
|
2023-03-20 13:10:52 +00:00
|
|
|
RenderComponent::PlayAnimation(builder, u"rebuild-fail");
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-29 04:24:30 +00:00
|
|
|
GameMessages::SendQuickBuildNotifyState(m_Parent, m_State, eQuickBuildState::RESETTING, LWOOBJID_EMPTY);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-12-29 04:24:30 +00:00
|
|
|
m_State = eQuickBuildState::RESETTING;
|
2022-05-03 05:32:00 +00:00
|
|
|
m_StateDirty = true;
|
2021-12-05 17:54:36 +00:00
|
|
|
m_Timer = 0.0f;
|
|
|
|
m_TimerIncomplete = 0.0f;
|
|
|
|
m_ShowResetEffect = false;
|
|
|
|
m_DrainedImagination = 0;
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->SerializeEntity(m_Parent);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
// Notify scripts and possible subscribers
|
|
|
|
for (auto* script : CppScripts::GetEntityScripts(m_Parent))
|
2023-12-29 04:24:30 +00:00
|
|
|
script->OnQuickBuildNotifyState(m_Parent, m_State);
|
|
|
|
for (const auto& cb : m_QuickBuildStateCallbacks)
|
2022-07-28 13:39:57 +00:00
|
|
|
cb(m_State);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
m_Parent->ScheduleKillAfterUpdate();
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (m_Activator) {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_Activator->ScheduleKillAfterUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-10 19:44:40 +00:00
|
|
|
void QuickBuildComponent::CancelQuickBuild(Entity* const entity, const eQuickBuildFailReason failReason, const bool skipChecks) {
|
2023-12-29 04:24:30 +00:00
|
|
|
if (m_State != eQuickBuildState::COMPLETED || skipChecks) {
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
m_Builder = LWOOBJID_EMPTY;
|
|
|
|
|
|
|
|
const auto entityID = entity != nullptr ? entity->GetObjectID() : LWOOBJID_EMPTY;
|
|
|
|
|
|
|
|
// Notify the client that a state has changed
|
2023-12-29 04:24:30 +00:00
|
|
|
GameMessages::SendQuickBuildNotifyState(m_Parent, m_State, eQuickBuildState::INCOMPLETE, entityID);
|
|
|
|
GameMessages::SendEnableQuickBuild(m_Parent, false, true, false, failReason, m_Timer, entityID);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
// Now terminate any interaction with the rebuild
|
|
|
|
GameMessages::SendTerminateInteraction(entityID, eTerminateType::FROM_INTERACTION, m_Parent->GetObjectID());
|
|
|
|
GameMessages::SendTerminateInteraction(m_Parent->GetObjectID(), eTerminateType::FROM_INTERACTION, m_Parent->GetObjectID());
|
|
|
|
|
|
|
|
// Now update the component itself
|
2023-12-29 04:24:30 +00:00
|
|
|
m_State = eQuickBuildState::INCOMPLETE;
|
2022-05-03 05:32:00 +00:00
|
|
|
m_StateDirty = true;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
// Notify scripts and possible subscribers
|
|
|
|
for (auto* script : CppScripts::GetEntityScripts(m_Parent))
|
2023-12-29 04:24:30 +00:00
|
|
|
script->OnQuickBuildNotifyState(m_Parent, m_State);
|
|
|
|
for (const auto& cb : m_QuickBuildStateCallbacks)
|
2022-07-28 13:39:57 +00:00
|
|
|
cb(m_State);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->SerializeEntity(m_Parent);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2024-02-10 19:44:40 +00:00
|
|
|
if (!entity) return;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
CharacterComponent* characterComponent = entity->GetComponent<CharacterComponent>();
|
|
|
|
if (characterComponent) {
|
2023-05-02 22:39:21 +00:00
|
|
|
characterComponent->SetCurrentActivity(eGameActivity::NONE);
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->SerializeEntity(entity);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-29 04:24:30 +00:00
|
|
|
void QuickBuildComponent::AddQuickBuildCompleteCallback(const std::function<void(Entity* user)>& callback) {
|
|
|
|
m_QuickBuildCompleteCallbacks.push_back(callback);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2023-12-29 04:24:30 +00:00
|
|
|
void QuickBuildComponent::AddQuickBuildStateCallback(const std::function<void(eQuickBuildState state)>& callback) {
|
|
|
|
m_QuickBuildStateCallbacks.push_back(callback);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|