2021-12-05 17:54:36 +00:00
|
|
|
#include "RebuildComponent.h"
|
|
|
|
#include "Entity.h"
|
|
|
|
#include "DestroyableComponent.h"
|
|
|
|
#include "GameMessages.h"
|
|
|
|
#include "EntityManager.h"
|
|
|
|
#include "Game.h"
|
|
|
|
#include "dLogger.h"
|
|
|
|
#include "CharacterComponent.h"
|
2022-07-05 06:00:10 +00:00
|
|
|
#include "MissionComponent.h"
|
|
|
|
#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 "PacketUtils.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"
|
|
|
|
|
|
|
|
RebuildComponent::RebuildComponent(Entity* entity) : Component(entity) {
|
|
|
|
std::u16string checkPreconditions = entity->GetVar<std::u16string>(u"CheckPrecondition");
|
|
|
|
|
|
|
|
if (!checkPreconditions.empty()) {
|
|
|
|
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);
|
2022-07-25 02:26:51 +00:00
|
|
|
if (positionAsVector.size() == 3 &&
|
2022-06-16 15:38:38 +00:00
|
|
|
GeneralUtils::TryParse(positionAsVector[0], m_ActivatorPosition.x) &&
|
2022-07-25 02:26:51 +00:00
|
|
|
GeneralUtils::TryParse(positionAsVector[1], m_ActivatorPosition.y) &&
|
2022-06-16 15:38:38 +00:00
|
|
|
GeneralUtils::TryParse(positionAsVector[2], m_ActivatorPosition.z)) {
|
2022-06-16 05:59:30 +00:00
|
|
|
} else {
|
2022-07-25 02:26:51 +00:00
|
|
|
Game::logger->Log("RebuildComponent", "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
|
|
|
}
|
|
|
|
|
|
|
|
RebuildComponent::~RebuildComponent() {
|
|
|
|
delete m_Precondition;
|
|
|
|
|
|
|
|
Entity* builder = GetBuilder();
|
|
|
|
if (builder) {
|
2023-05-02 22:39:21 +00:00
|
|
|
CancelRebuild(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();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RebuildComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
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) {
|
|
|
|
outBitStream->Write(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
outBitStream->Write(false);
|
|
|
|
|
|
|
|
outBitStream->Write(false);
|
|
|
|
}
|
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-05-02 22:39:21 +00:00
|
|
|
if (!m_StateDirty && m_State == eRebuildState::COMPLETED) {
|
2022-05-03 05:32:00 +00:00
|
|
|
outBitStream->Write0();
|
|
|
|
outBitStream->Write0();
|
|
|
|
return;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
// BEGIN Scripted Activity
|
|
|
|
outBitStream->Write1();
|
|
|
|
|
|
|
|
Entity* builder = GetBuilder();
|
|
|
|
|
|
|
|
if (builder) {
|
|
|
|
outBitStream->Write((uint32_t)1);
|
|
|
|
outBitStream->Write(builder->GetObjectID());
|
|
|
|
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
outBitStream->Write(0.0f);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
outBitStream->Write((uint32_t)0);
|
|
|
|
}
|
|
|
|
// END Scripted Activity
|
|
|
|
|
|
|
|
outBitStream->Write1();
|
|
|
|
|
2023-05-02 22:39:21 +00:00
|
|
|
outBitStream->Write(m_State);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
outBitStream->Write(m_ShowResetEffect);
|
|
|
|
outBitStream->Write(m_Activator != nullptr);
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
outBitStream->Write(m_Timer);
|
|
|
|
outBitStream->Write(m_TimerIncomplete);
|
|
|
|
|
|
|
|
if (bIsInitialUpdate) {
|
|
|
|
outBitStream->Write(false);
|
|
|
|
outBitStream->Write(m_ActivatorPosition);
|
|
|
|
outBitStream->Write(m_RepositionPlayer);
|
|
|
|
}
|
2022-05-03 05:32:00 +00:00
|
|
|
m_StateDirty = false;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RebuildComponent::Update(float deltaTime) {
|
|
|
|
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;
|
|
|
|
|
|
|
|
EntityManager::Instance()->SerializeEntity(m_Parent);
|
|
|
|
}*/
|
|
|
|
|
|
|
|
switch (m_State) {
|
2023-05-02 22:39:21 +00:00
|
|
|
case eRebuildState::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;
|
|
|
|
|
|
|
|
EntityManager::Instance()->SerializeEntity(m_Parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
ResetRebuild(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
break;
|
|
|
|
}
|
2023-05-02 22:39:21 +00:00
|
|
|
case eRebuildState::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) {
|
|
|
|
if (m_Timer >= m_ResetTime - 4.0f) {
|
|
|
|
if (!m_ShowResetEffect) {
|
|
|
|
m_ShowResetEffect = true;
|
|
|
|
|
|
|
|
EntityManager::Instance()->SerializeEntity(m_Parent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_Timer >= m_ResetTime) {
|
|
|
|
|
|
|
|
GameMessages::SendDieNoImplCode(m_Parent, LWOOBJID_EMPTY, LWOOBJID_EMPTY, eKillType::VIOLENT, u"", 0.0f, 0.0f, 0.0f, false, true);
|
|
|
|
|
|
|
|
ResetRebuild(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2023-05-02 22:39:21 +00:00
|
|
|
case eRebuildState::BUILDING:
|
2021-12-05 17:54:36 +00:00
|
|
|
{
|
|
|
|
Entity* builder = GetBuilder();
|
|
|
|
|
|
|
|
if (builder == nullptr) {
|
|
|
|
ResetRebuild(false);
|
|
|
|
|
|
|
|
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
|
|
|
int newImagination = destComp->GetImagination();
|
|
|
|
if (newImagination <= 0) {
|
|
|
|
CancelRebuild(builder, eQuickBuildFailReason::OUT_OF_IMAGINATION, true);
|
|
|
|
break;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-05-11 11:37:02 +00:00
|
|
|
++m_DrainedImagination;
|
|
|
|
--newImagination;
|
2021-12-05 17:54:36 +00:00
|
|
|
destComp->SetImagination(newImagination);
|
|
|
|
EntityManager::Instance()->SerializeEntity(builder);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_Timer >= m_CompleteTime && m_DrainedImagination >= m_TakeImagination) {
|
|
|
|
CompleteRebuild(builder);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2023-05-02 22:39:21 +00:00
|
|
|
case eRebuildState::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) {
|
|
|
|
if (m_TimerIncomplete >= m_TimeBeforeSmash - 4.0f) {
|
|
|
|
m_ShowResetEffect = true;
|
|
|
|
|
|
|
|
EntityManager::Instance()->SerializeEntity(m_Parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
ResetRebuild(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2023-05-02 22:39:21 +00:00
|
|
|
case eRebuildState::RESETTING: break;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RebuildComponent::OnUse(Entity* originator) {
|
2023-05-02 22:39:21 +00:00
|
|
|
if (GetBuilder() != nullptr || m_State == eRebuildState::COMPLETED) {
|
2021-12-05 17:54:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_Precondition != nullptr && !m_Precondition->Check(originator)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
StartRebuild(originator);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RebuildComponent::SpawnActivator() {
|
|
|
|
if (!m_SelfActivator || m_ActivatorPosition != NiPoint3::ZERO) {
|
|
|
|
if (!m_Activator) {
|
|
|
|
EntityInfo info;
|
|
|
|
|
|
|
|
info.lot = 6604;
|
|
|
|
info.spawnerID = m_Parent->GetObjectID();
|
|
|
|
info.pos = m_ActivatorPosition == NiPoint3::ZERO ? m_Parent->GetPosition() : m_ActivatorPosition;
|
|
|
|
|
|
|
|
m_Activator = EntityManager::Instance()->CreateEntity(info, nullptr, m_Parent);
|
|
|
|
if (m_Activator) {
|
|
|
|
m_ActivatorId = m_Activator->GetObjectID();
|
|
|
|
EntityManager::Instance()->ConstructEntity(m_Activator);
|
|
|
|
}
|
|
|
|
|
|
|
|
EntityManager::Instance()->SerializeEntity(m_Parent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RebuildComponent::DespawnActivator() {
|
|
|
|
if (m_Activator) {
|
|
|
|
EntityManager::Instance()->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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-25 02:26:51 +00:00
|
|
|
Entity* RebuildComponent::GetActivator() {
|
2021-12-05 17:54:36 +00:00
|
|
|
return EntityManager::Instance()->GetEntity(m_ActivatorId);
|
|
|
|
}
|
|
|
|
|
|
|
|
NiPoint3 RebuildComponent::GetActivatorPosition() {
|
|
|
|
return m_ActivatorPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
float RebuildComponent::GetResetTime() {
|
|
|
|
return m_ResetTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
float RebuildComponent::GetCompleteTime() {
|
|
|
|
return m_CompleteTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
int RebuildComponent::GetTakeImagination() {
|
|
|
|
return m_TakeImagination;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RebuildComponent::GetInterruptible() {
|
|
|
|
return m_Interruptible;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RebuildComponent::GetSelfActivator() {
|
|
|
|
return m_SelfActivator;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<int> RebuildComponent::GetCustomModules() {
|
|
|
|
return m_CustomModules;
|
|
|
|
}
|
|
|
|
|
|
|
|
int RebuildComponent::GetActivityId() {
|
|
|
|
return m_ActivityId;
|
|
|
|
}
|
|
|
|
|
|
|
|
int RebuildComponent::GetPostImaginationCost() {
|
|
|
|
return m_PostImaginationCost;
|
|
|
|
}
|
|
|
|
|
|
|
|
float RebuildComponent::GetTimeBeforeSmash() {
|
|
|
|
return m_TimeBeforeSmash;
|
|
|
|
}
|
|
|
|
|
|
|
|
eRebuildState RebuildComponent::GetState() {
|
|
|
|
return m_State;
|
|
|
|
}
|
|
|
|
|
|
|
|
Entity* RebuildComponent::GetBuilder() const {
|
|
|
|
auto* builder = EntityManager::Instance()->GetEntity(m_Builder);
|
|
|
|
|
|
|
|
return builder;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RebuildComponent::GetRepositionPlayer() const {
|
|
|
|
return m_RepositionPlayer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RebuildComponent::SetActivatorPosition(NiPoint3 value) {
|
|
|
|
m_ActivatorPosition = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RebuildComponent::SetResetTime(float value) {
|
|
|
|
m_ResetTime = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RebuildComponent::SetCompleteTime(float value) {
|
|
|
|
if (value < 0) {
|
|
|
|
m_CompleteTime = 4.5f;
|
|
|
|
} else {
|
|
|
|
m_CompleteTime = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RebuildComponent::SetTakeImagination(int value) {
|
|
|
|
m_TakeImagination = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RebuildComponent::SetInterruptible(bool value) {
|
|
|
|
m_Interruptible = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RebuildComponent::SetSelfActivator(bool value) {
|
|
|
|
m_SelfActivator = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RebuildComponent::SetCustomModules(std::vector<int> value) {
|
|
|
|
m_CustomModules = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RebuildComponent::SetActivityId(int value) {
|
|
|
|
m_ActivityId = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RebuildComponent::SetPostImaginationCost(int value) {
|
|
|
|
m_PostImaginationCost = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RebuildComponent::SetTimeBeforeSmash(float value) {
|
|
|
|
if (value < 0) {
|
|
|
|
m_TimeBeforeSmash = 10.0f;
|
|
|
|
} else {
|
|
|
|
m_TimeBeforeSmash = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RebuildComponent::SetRepositionPlayer(bool value) {
|
|
|
|
m_RepositionPlayer = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RebuildComponent::StartRebuild(Entity* user) {
|
2023-05-02 22:39:21 +00:00
|
|
|
if (m_State == eRebuildState::OPEN || m_State == eRebuildState::COMPLETED || m_State == eRebuildState::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
|
|
|
|
|
|
|
EntityManager::Instance()->SerializeEntity(user);
|
|
|
|
|
2023-05-02 22:39:21 +00:00
|
|
|
GameMessages::SendRebuildNotifyState(m_Parent, m_State, eRebuildState::BUILDING, user->GetObjectID());
|
|
|
|
GameMessages::SendEnableRebuild(m_Parent, true, false, false, eQuickBuildFailReason::NOT_GIVEN, 0.0f, user->GetObjectID());
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-05-02 22:39:21 +00:00
|
|
|
m_State = eRebuildState::BUILDING;
|
2022-05-03 05:32:00 +00:00
|
|
|
m_StateDirty = true;
|
2021-12-05 17:54:36 +00:00
|
|
|
EntityManager::Instance()->SerializeEntity(m_Parent);
|
|
|
|
|
|
|
|
auto* movingPlatform = m_Parent->GetComponent<MovingPlatformComponent>();
|
|
|
|
if (movingPlatform != nullptr) {
|
|
|
|
movingPlatform->OnRebuildInitilized();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto* script : CppScripts::GetEntityScripts(m_Parent)) {
|
|
|
|
script->OnRebuildStart(m_Parent, user);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Notify scripts and possible subscribers
|
|
|
|
for (auto* script : CppScripts::GetEntityScripts(m_Parent))
|
|
|
|
script->OnRebuildNotifyState(m_Parent, m_State);
|
|
|
|
for (const auto& cb : m_RebuildStateCallbacks)
|
|
|
|
cb(m_State);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RebuildComponent::CompleteRebuild(Entity* user) {
|
|
|
|
if (user == nullptr) {
|
|
|
|
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);
|
2021-12-05 17:54:36 +00:00
|
|
|
characterComponent->TrackRebuildComplete();
|
|
|
|
} else {
|
2022-07-25 02:26:51 +00:00
|
|
|
Game::logger->Log("RebuildComponent", "Some user tried to finish the rebuild but they didn't have a character somehow.");
|
2021-12-05 17:54:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
EntityManager::Instance()->SerializeEntity(user);
|
|
|
|
|
2023-05-02 22:39:21 +00:00
|
|
|
GameMessages::SendRebuildNotifyState(m_Parent, m_State, eRebuildState::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-05-02 22:39:21 +00:00
|
|
|
GameMessages::SendEnableRebuild(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-05-02 22:39:21 +00:00
|
|
|
m_State = eRebuildState::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;
|
|
|
|
|
|
|
|
EntityManager::Instance()->SerializeEntity(m_Parent);
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
|
|
|
// Set owner override so that entities smashed by this quickbuild will result in the builder getting rewards.
|
|
|
|
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
|
|
|
|
auto* member = EntityManager::Instance()->GetEntity(memberId);
|
|
|
|
if (member) {
|
|
|
|
auto* missionComponent = member->GetComponent<MissionComponent>();
|
|
|
|
if (missionComponent) missionComponent->Progress(eMissionTaskType::ACTIVITY, m_ActivityId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else{
|
|
|
|
auto* missionComponent = builder->GetComponent<MissionComponent>();
|
|
|
|
if (missionComponent) missionComponent->Progress(eMissionTaskType::ACTIVITY, m_ActivityId);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
2021-12-20 10:25:45 +00:00
|
|
|
LootGenerator::Instance().DropActivityLoot(builder, m_Parent, m_ActivityId, 1);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Notify scripts
|
|
|
|
for (auto* script : CppScripts::GetEntityScripts(m_Parent)) {
|
|
|
|
script->OnRebuildComplete(m_Parent, user);
|
|
|
|
script->OnRebuildNotifyState(m_Parent, m_State);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Notify subscribers
|
|
|
|
for (const auto& callback : m_RebuildStateCallbacks)
|
|
|
|
callback(m_State);
|
|
|
|
for (const auto& callback : m_RebuildCompleteCallbacks)
|
|
|
|
callback(user);
|
|
|
|
|
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) {
|
|
|
|
movingPlatform->OnCompleteRebuild();
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
|
|
|
void RebuildComponent::ResetRebuild(bool failed) {
|
|
|
|
Entity* builder = GetBuilder();
|
|
|
|
|
2023-05-02 22:39:21 +00:00
|
|
|
if (m_State == eRebuildState::BUILDING && builder) {
|
|
|
|
GameMessages::SendEnableRebuild(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-05-02 22:39:21 +00:00
|
|
|
GameMessages::SendRebuildNotifyState(m_Parent, m_State, eRebuildState::RESETTING, LWOOBJID_EMPTY);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-05-02 22:39:21 +00:00
|
|
|
m_State = eRebuildState::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
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
EntityManager::Instance()->SerializeEntity(m_Parent);
|
|
|
|
|
|
|
|
// Notify scripts and possible subscribers
|
|
|
|
for (auto* script : CppScripts::GetEntityScripts(m_Parent))
|
|
|
|
script->OnRebuildNotifyState(m_Parent, m_State);
|
|
|
|
for (const auto& cb : m_RebuildStateCallbacks)
|
|
|
|
cb(m_State);
|
|
|
|
|
|
|
|
m_Parent->ScheduleKillAfterUpdate();
|
|
|
|
|
|
|
|
if (m_Activator) {
|
|
|
|
m_Activator->ScheduleKillAfterUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-02 22:39:21 +00:00
|
|
|
void RebuildComponent::CancelRebuild(Entity* entity, eQuickBuildFailReason failReason, bool skipChecks) {
|
|
|
|
if (m_State != eRebuildState::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-05-02 22:39:21 +00:00
|
|
|
GameMessages::SendRebuildNotifyState(m_Parent, m_State, eRebuildState::INCOMPLETE, entityID);
|
2021-12-05 17:54:36 +00:00
|
|
|
GameMessages::SendEnableRebuild(m_Parent, false, true, false, failReason, m_Timer, entityID);
|
|
|
|
|
|
|
|
// 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-05-02 22:39:21 +00:00
|
|
|
m_State = eRebuildState::INCOMPLETE;
|
2022-05-03 05:32:00 +00:00
|
|
|
m_StateDirty = true;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
// Notify scripts and possible subscribers
|
|
|
|
for (auto* script : CppScripts::GetEntityScripts(m_Parent))
|
|
|
|
script->OnRebuildNotifyState(m_Parent, m_State);
|
|
|
|
for (const auto& cb : m_RebuildStateCallbacks)
|
|
|
|
cb(m_State);
|
|
|
|
|
|
|
|
EntityManager::Instance()->SerializeEntity(m_Parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (entity == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CharacterComponent* characterComponent = entity->GetComponent<CharacterComponent>();
|
|
|
|
if (characterComponent) {
|
2023-05-02 22:39:21 +00:00
|
|
|
characterComponent->SetCurrentActivity(eGameActivity::NONE);
|
2021-12-05 17:54:36 +00:00
|
|
|
EntityManager::Instance()->SerializeEntity(entity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RebuildComponent::AddRebuildCompleteCallback(const std::function<void(Entity* user)>& callback) {
|
|
|
|
m_RebuildCompleteCallbacks.push_back(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RebuildComponent::AddRebuildStateCallback(const std::function<void(eRebuildState state)>& callback) {
|
|
|
|
m_RebuildStateCallbacks.push_back(callback);
|
|
|
|
}
|