mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-02 10:53:44 +00:00
Live sent the player ModifyPlayerZoneStatistic(set false, value 1, the current map) for "QuickBuildsCompleted" (227) after a quickbuild's EnableRebuild and for "AchievementsCompleted" (186) at the end of an achievement's completion. DLU counted both server side (they are saved and shown at the next load) but never told the client, so the zone summary only caught up after a zone change. The client counts enemies, coins and bricks itself and sends those to the server. Check: complete a quickbuild and an achievement, then open the zone summary (passport / map zone stats) without changing zones: both counts went up by one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
680 lines
21 KiB
C++
680 lines
21 KiB
C++
#include "QuickBuildComponent.h"
|
|
#include "Entity.h"
|
|
#include "DestroyableComponent.h"
|
|
#include "GameMessages.h"
|
|
#include "EffectsMessages.h"
|
|
#include "CombatMessages.h"
|
|
#include "ObjectMessages.h"
|
|
#include "QuickBuildMessages.h"
|
|
#include "EntityManager.h"
|
|
#include "Game.h"
|
|
#include "Logger.h"
|
|
#include "CharacterComponent.h"
|
|
#include "MissionComponent.h"
|
|
#include "eMissionTaskType.h"
|
|
#include "eTriggerEventType.h"
|
|
#include "eQuickBuildFailReason.h"
|
|
#include "eTerminateType.h"
|
|
#include "eGameActivity.h"
|
|
|
|
#include "dServer.h"
|
|
#include "Spawner.h"
|
|
#include "MovingPlatformComponent.h"
|
|
#include "Preconditions.h"
|
|
#include "Loot.h"
|
|
#include "TeamManager.h"
|
|
#include "RenderComponent.h"
|
|
|
|
#include "CppScripts.h"
|
|
#include "StringifiedEnum.h"
|
|
#include "Amf3.h"
|
|
#include "EconomyLedger.h"
|
|
|
|
QuickBuildComponent::QuickBuildComponent(Entity* const entity, const int32_t componentID) : Component{ entity, componentID } {
|
|
std::u16string checkPreconditions = entity->GetVar<std::u16string>(u"CheckPrecondition");
|
|
|
|
if (!checkPreconditions.empty()) {
|
|
m_Precondition = new PreconditionExpression(GeneralUtils::UTF16ToWTF8(checkPreconditions));
|
|
}
|
|
|
|
// Should a setting that has the build activator position exist, fetch that setting here and parse it for position.
|
|
// 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);
|
|
const auto activatorPositionValid = GeneralUtils::TryParse<NiPoint3>(positionAsVector);
|
|
if (positionAsVector.size() == 3 && activatorPositionValid) {
|
|
m_ActivatorPosition = activatorPositionValid.value();
|
|
} else {
|
|
LOG("Failed to find activator position for lot %i. Defaulting to parents position.", m_Parent->GetLOT());
|
|
m_ActivatorPosition = m_Parent->GetPosition();
|
|
}
|
|
|
|
SpawnActivator();
|
|
RegisterMsg(&QuickBuildComponent::OnGetObjectReportInfo);
|
|
}
|
|
|
|
QuickBuildComponent::~QuickBuildComponent() {
|
|
delete m_Precondition;
|
|
|
|
Entity* builder = GetBuilder();
|
|
if (builder) {
|
|
CancelQuickBuild(builder, eQuickBuildFailReason::BUILD_ENDED, true);
|
|
}
|
|
|
|
DespawnActivator();
|
|
}
|
|
|
|
void QuickBuildComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
|
|
if (m_Parent->GetComponent(eReplicaComponentType::DESTROYABLE) == nullptr) {
|
|
if (bIsInitialUpdate) {
|
|
outBitStream.Write(false);
|
|
}
|
|
|
|
outBitStream.Write(false);
|
|
|
|
outBitStream.Write(false);
|
|
}
|
|
|
|
// 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.Write(m_StateDirty || bIsInitialUpdate);
|
|
if (m_StateDirty || bIsInitialUpdate) {
|
|
outBitStream.Write(m_State);
|
|
|
|
outBitStream.Write(m_ShowResetEffect);
|
|
outBitStream.Write(m_Activator != nullptr);
|
|
|
|
outBitStream.Write(m_Timer);
|
|
outBitStream.Write(m_TimerIncomplete);
|
|
|
|
if (bIsInitialUpdate) {
|
|
outBitStream.Write(false); // IsChoiceBuild
|
|
outBitStream.Write(m_ActivatorPosition);
|
|
outBitStream.Write(m_RepositionPlayer);
|
|
}
|
|
m_StateDirty = false;
|
|
}
|
|
}
|
|
|
|
void QuickBuildComponent::Update(float deltaTime) {
|
|
SetActivator(GetActivator());
|
|
|
|
switch (m_State) {
|
|
case eQuickBuildState::OPEN: {
|
|
SpawnActivator();
|
|
m_TimeBeforeDrain = 0;
|
|
|
|
auto* spawner = m_Parent->GetSpawner();
|
|
const bool isSmashGroup = spawner != nullptr ? spawner->GetIsSpawnSmashGroup() : false;
|
|
|
|
if (isSmashGroup) {
|
|
ModifyIncompleteTimer(deltaTime);
|
|
|
|
// For reset times < 0 this has to be handled manually
|
|
if (m_TimeBeforeSmash > 0) {
|
|
if (m_TimerIncomplete >= m_TimeBeforeSmash - 4.0f && !m_ShowResetEffect) {
|
|
SetShowResetEffect(true);
|
|
|
|
Game::entityManager->SerializeEntity(m_Parent);
|
|
}
|
|
|
|
if (m_TimerIncomplete >= m_TimeBeforeSmash) {
|
|
m_Builder = LWOOBJID_EMPTY;
|
|
|
|
GameMessages::Die die;
|
|
die.target = m_Parent->GetObjectID();
|
|
die.bClientDeath = false;
|
|
die.bSpawnLoot = true;
|
|
die.killerID = LWOOBJID_EMPTY;
|
|
die.Send(UNASSIGNED_SYSTEM_ADDRESS);
|
|
|
|
ResetQuickBuild(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
break;
|
|
}
|
|
case eQuickBuildState::COMPLETED: {
|
|
ModifyTimer(deltaTime);
|
|
|
|
// For reset times < 0 this has to be handled manually
|
|
if (m_ResetTime > 0) {
|
|
if (m_Timer >= m_ResetTime - 4.0f && !m_ShowResetEffect) {
|
|
SetShowResetEffect(true);
|
|
|
|
Game::entityManager->SerializeEntity(m_Parent);
|
|
}
|
|
|
|
if (m_Timer >= m_ResetTime) {
|
|
|
|
GameMessages::Die die;
|
|
die.target = m_Parent->GetObjectID();
|
|
die.bClientDeath = false;
|
|
die.bSpawnLoot = true;
|
|
die.directionRelative_Force = 7.0f;
|
|
die.killerID = LWOOBJID_EMPTY;
|
|
die.Send(UNASSIGNED_SYSTEM_ADDRESS);
|
|
|
|
ResetQuickBuild(false);
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
case eQuickBuildState::BUILDING:
|
|
{
|
|
Entity* builder = GetBuilder();
|
|
|
|
if (!builder) {
|
|
ResetQuickBuild(false);
|
|
|
|
return;
|
|
}
|
|
|
|
m_TimeBeforeDrain -= deltaTime;
|
|
ModifyTimer(deltaTime);
|
|
SetIncompleteTimer(0.0f);
|
|
SetShowResetEffect(false);
|
|
|
|
if (m_TimeBeforeDrain <= 0.0f) {
|
|
m_TimeBeforeDrain = m_CompleteTime / static_cast<float>(m_TakeImagination);
|
|
|
|
DestroyableComponent* destComp = builder->GetComponent<DestroyableComponent>();
|
|
if (!destComp) break;
|
|
|
|
++m_DrainedImagination;
|
|
const int32_t imaginationCostRemaining = m_TakeImagination - m_DrainedImagination;
|
|
|
|
const int32_t newImagination = destComp->GetImagination() - 1;
|
|
destComp->SetImagination(newImagination);
|
|
Game::entityManager->SerializeEntity(builder);
|
|
|
|
if (newImagination <= 0 && imaginationCostRemaining > 0) {
|
|
CancelQuickBuild(builder, eQuickBuildFailReason::OUT_OF_IMAGINATION, true);
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (m_Timer >= m_CompleteTime && m_DrainedImagination >= m_TakeImagination) {
|
|
CompleteQuickBuild(builder);
|
|
}
|
|
|
|
break;
|
|
}
|
|
case eQuickBuildState::INCOMPLETE: {
|
|
ModifyIncompleteTimer(deltaTime);
|
|
|
|
// For reset times < 0 this has to be handled manually
|
|
if (m_TimeBeforeSmash > 0) {
|
|
if (m_TimerIncomplete >= m_TimeBeforeSmash - 4.0f && !m_ShowResetEffect) {
|
|
SetShowResetEffect(true);
|
|
|
|
Game::entityManager->SerializeEntity(m_Parent);
|
|
}
|
|
|
|
if (m_TimerIncomplete >= m_TimeBeforeSmash) {
|
|
m_Builder = LWOOBJID_EMPTY;
|
|
|
|
GameMessages::Die die;
|
|
die.target = m_Parent->GetObjectID();
|
|
die.bClientDeath = false;
|
|
die.bSpawnLoot = true;
|
|
die.killerID = LWOOBJID_EMPTY;
|
|
die.Send(UNASSIGNED_SYSTEM_ADDRESS);
|
|
|
|
ResetQuickBuild(false);
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
case eQuickBuildState::RESETTING: break;
|
|
}
|
|
}
|
|
|
|
void QuickBuildComponent::OnUse(Entity* originator) {
|
|
if (GetBuilder() != nullptr || m_State == eQuickBuildState::COMPLETED) {
|
|
return;
|
|
}
|
|
|
|
if (m_Precondition != nullptr && !m_Precondition->Check(originator)) {
|
|
return;
|
|
}
|
|
|
|
StartQuickBuild(originator);
|
|
}
|
|
|
|
void QuickBuildComponent::SpawnActivator() {
|
|
if (!m_SelfActivator || m_ActivatorPosition != NiPoint3Constant::ZERO) {
|
|
if (!m_Activator) {
|
|
EntityInfo info;
|
|
|
|
info.lot = 6604;
|
|
info.spawnerID = m_Parent->GetObjectID();
|
|
info.pos = m_ActivatorPosition == NiPoint3Constant::ZERO ? m_Parent->GetPosition() : m_ActivatorPosition;
|
|
|
|
SetActivator(Game::entityManager->CreateEntity(info, nullptr, m_Parent));
|
|
if (m_Activator) {
|
|
m_ActivatorId = m_Activator->GetObjectID();
|
|
Game::entityManager->ConstructEntity(m_Activator);
|
|
}
|
|
|
|
Game::entityManager->SerializeEntity(m_Parent);
|
|
}
|
|
}
|
|
}
|
|
|
|
void QuickBuildComponent::DespawnActivator() {
|
|
if (m_Activator) {
|
|
Game::entityManager->DestructEntity(m_Activator);
|
|
|
|
m_Activator->ScheduleKillAfterUpdate();
|
|
|
|
SetActivator(nullptr);
|
|
|
|
m_ActivatorId = LWOOBJID_EMPTY;
|
|
}
|
|
}
|
|
|
|
Entity* QuickBuildComponent::GetActivator() const {
|
|
return Game::entityManager->GetEntity(m_ActivatorId);
|
|
}
|
|
|
|
NiPoint3 QuickBuildComponent::GetActivatorPosition() const noexcept {
|
|
return m_ActivatorPosition;
|
|
}
|
|
|
|
float QuickBuildComponent::GetResetTime() const noexcept {
|
|
return m_ResetTime;
|
|
}
|
|
|
|
float QuickBuildComponent::GetCompleteTime() const noexcept {
|
|
return m_CompleteTime;
|
|
}
|
|
|
|
int32_t QuickBuildComponent::GetTakeImagination() const noexcept {
|
|
return m_TakeImagination;
|
|
}
|
|
|
|
bool QuickBuildComponent::GetInterruptible() const noexcept {
|
|
return m_Interruptible;
|
|
}
|
|
|
|
bool QuickBuildComponent::GetSelfActivator() const noexcept {
|
|
return m_SelfActivator;
|
|
}
|
|
|
|
std::vector<int32_t> QuickBuildComponent::GetCustomModules() const noexcept {
|
|
return m_CustomModules;
|
|
}
|
|
|
|
int32_t QuickBuildComponent::GetActivityId() const noexcept {
|
|
return m_ActivityId;
|
|
}
|
|
|
|
int32_t QuickBuildComponent::GetPostImaginationCost() const noexcept {
|
|
return m_PostImaginationCost;
|
|
}
|
|
|
|
float QuickBuildComponent::GetTimeBeforeSmash() const noexcept {
|
|
return m_TimeBeforeSmash;
|
|
}
|
|
|
|
eQuickBuildState QuickBuildComponent::GetState() const noexcept {
|
|
return m_State;
|
|
}
|
|
|
|
Entity* QuickBuildComponent::GetBuilder() const {
|
|
auto* const builder = Game::entityManager->GetEntity(m_Builder);
|
|
|
|
return builder;
|
|
}
|
|
|
|
bool QuickBuildComponent::GetRepositionPlayer() const noexcept {
|
|
return m_RepositionPlayer;
|
|
}
|
|
|
|
void QuickBuildComponent::SetActivatorPosition(const NiPoint3& value) noexcept {
|
|
m_ActivatorPosition = value;
|
|
}
|
|
|
|
void QuickBuildComponent::SetResetTime(const float value) noexcept {
|
|
m_ResetTime = value;
|
|
}
|
|
|
|
void QuickBuildComponent::SetCompleteTime(const float value) noexcept {
|
|
if (value < 0) {
|
|
m_CompleteTime = 4.5f;
|
|
} else {
|
|
m_CompleteTime = value;
|
|
}
|
|
}
|
|
|
|
void QuickBuildComponent::SetTakeImagination(const int32_t value) noexcept {
|
|
m_TakeImagination = value;
|
|
}
|
|
|
|
void QuickBuildComponent::SetInterruptible(const bool value) noexcept {
|
|
m_Interruptible = value;
|
|
}
|
|
|
|
void QuickBuildComponent::SetSelfActivator(const bool value) noexcept {
|
|
m_SelfActivator = value;
|
|
}
|
|
|
|
void QuickBuildComponent::SetCustomModules(const std::vector<int32_t>& value) noexcept {
|
|
m_CustomModules = value;
|
|
}
|
|
|
|
void QuickBuildComponent::SetActivityId(const int32_t value) noexcept {
|
|
m_ActivityId = value;
|
|
}
|
|
|
|
void QuickBuildComponent::SetPostImaginationCost(const int32_t value) noexcept {
|
|
m_PostImaginationCost = value;
|
|
}
|
|
|
|
void QuickBuildComponent::SetTimeBeforeSmash(const float value) noexcept {
|
|
if (value < 0) {
|
|
m_TimeBeforeSmash = 10.0f;
|
|
} else {
|
|
m_TimeBeforeSmash = value;
|
|
}
|
|
}
|
|
|
|
void QuickBuildComponent::SetRepositionPlayer(const bool value) noexcept {
|
|
m_RepositionPlayer = value;
|
|
}
|
|
|
|
void QuickBuildComponent::StartQuickBuild(Entity* const user) {
|
|
if (m_State == eQuickBuildState::OPEN || m_State == eQuickBuildState::COMPLETED || m_State == eQuickBuildState::INCOMPLETE) {
|
|
m_Builder = user->GetObjectID();
|
|
|
|
auto* character = user->GetComponent<CharacterComponent>();
|
|
if (character) character->SetCurrentActivity(eGameActivity::QUICKBUILDING);
|
|
|
|
Game::entityManager->SerializeEntity(user);
|
|
|
|
GameMessages::RebuildNotifyState notifyState;
|
|
notifyState.target = m_Parent->GetObjectID();
|
|
notifyState.prevState = m_State;
|
|
notifyState.state = eQuickBuildState::BUILDING;
|
|
notifyState.player = user->GetObjectID();
|
|
notifyState.Send(UNASSIGNED_SYSTEM_ADDRESS);
|
|
GameMessages::EnableRebuild enableRebuild;
|
|
enableRebuild.target = m_Parent->GetObjectID();
|
|
enableRebuild.bEnable = true;
|
|
enableRebuild.bFail = false;
|
|
enableRebuild.bSuccess = false;
|
|
enableRebuild.eFailReason = eQuickBuildFailReason::NOT_GIVEN;
|
|
enableRebuild.fDuration = 0.0f;
|
|
enableRebuild.user = user->GetObjectID();
|
|
enableRebuild.Send(UNASSIGNED_SYSTEM_ADDRESS);
|
|
|
|
SetState(eQuickBuildState::BUILDING);
|
|
Game::entityManager->SerializeEntity(m_Parent);
|
|
|
|
auto* movingPlatform = m_Parent->GetComponent<MovingPlatformComponent>();
|
|
if (movingPlatform != nullptr) {
|
|
movingPlatform->OnQuickBuildInitilized();
|
|
}
|
|
|
|
auto* script = m_Parent->GetScript();
|
|
script->OnQuickBuildStart(m_Parent, user);
|
|
|
|
// Notify scripts and possible subscribers
|
|
script->OnQuickBuildNotifyState(m_Parent, m_State);
|
|
for (const auto& cb : m_QuickBuildStateCallbacks)
|
|
cb(m_State);
|
|
}
|
|
}
|
|
|
|
void QuickBuildComponent::CompleteQuickBuild(Entity* const user) {
|
|
if (!user) return;
|
|
|
|
auto* characterComponent = user->GetComponent<CharacterComponent>();
|
|
if (characterComponent != nullptr) {
|
|
characterComponent->SetCurrentActivity(eGameActivity::NONE);
|
|
EconomyLedger::RecordMapEvent(IEconomyLedger::eMapEvent::QUICKBUILDS_COMPLETED, m_Parent->GetLOT(), m_Parent->GetPosition(), 1, user);
|
|
} else {
|
|
LOG("Some user tried to finish the rebuild but they didn't have a character somehow.");
|
|
return;
|
|
}
|
|
|
|
Game::entityManager->SerializeEntity(user);
|
|
|
|
GameMessages::RebuildNotifyState notifyState;
|
|
notifyState.target = m_Parent->GetObjectID();
|
|
notifyState.prevState = m_State;
|
|
notifyState.state = eQuickBuildState::COMPLETED;
|
|
notifyState.player = user->GetObjectID();
|
|
notifyState.Send(UNASSIGNED_SYSTEM_ADDRESS);
|
|
GameMessages::PlayFXEffect fx(m_Parent->GetObjectID(), 507, u"create", "BrickFadeUpVisCompleteEffect");
|
|
fx.priority = 0.4f;
|
|
fx.Send(UNASSIGNED_SYSTEM_ADDRESS);
|
|
// Live: RebuildNotifyState(Completed), the effect, then QuickBuildsCompleted, then EnableRebuild
|
|
characterComponent->TrackQuickBuildComplete();
|
|
GameMessages::EnableRebuild enableRebuild;
|
|
enableRebuild.target = m_Parent->GetObjectID();
|
|
enableRebuild.bEnable = false;
|
|
enableRebuild.bFail = false;
|
|
enableRebuild.bSuccess = true;
|
|
enableRebuild.eFailReason = eQuickBuildFailReason::NOT_GIVEN;
|
|
// Live sent no duration on success (744 of 744); cancels carry the time spent building.
|
|
enableRebuild.fDuration = 0.0f;
|
|
enableRebuild.user = user->GetObjectID();
|
|
enableRebuild.Send(UNASSIGNED_SYSTEM_ADDRESS);
|
|
characterComponent->SendZoneStatisticIncrement(u"QuickBuildsCompleted");
|
|
GameMessages::TerminateInteraction(user->GetObjectID(), eTerminateType::FROM_INTERACTION, m_Parent->GetObjectID()).Send(UNASSIGNED_SYSTEM_ADDRESS);
|
|
|
|
|
|
SetState(eQuickBuildState::COMPLETED);
|
|
SetTimer(0.0f);
|
|
m_DrainedImagination = 0;
|
|
|
|
Game::entityManager->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();
|
|
|
|
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 = Game::entityManager->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);
|
|
}
|
|
Loot::DropActivityLoot(builder, m_Parent->GetObjectID(), m_ActivityId, 1);
|
|
}
|
|
|
|
// Notify scripts
|
|
auto* script = m_Parent->GetScript();
|
|
script->OnQuickBuildComplete(m_Parent, user);
|
|
script->OnQuickBuildNotifyState(m_Parent, m_State);
|
|
|
|
// Notify subscribers
|
|
for (const auto& callback : m_QuickBuildStateCallbacks)
|
|
callback(m_State);
|
|
for (const auto& callback : m_QuickBuildCompleteCallbacks)
|
|
callback(user);
|
|
|
|
m_Parent->TriggerEvent(eTriggerEventType::REBUILD_COMPLETE, user);
|
|
|
|
auto* movingPlatform = m_Parent->GetComponent<MovingPlatformComponent>();
|
|
if (movingPlatform != nullptr) {
|
|
movingPlatform->OnCompleteQuickBuild();
|
|
}
|
|
|
|
// 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);
|
|
}
|
|
}
|
|
RenderComponent::PlayAnimation(user, u"rebuild-celebrate", 1.09f);
|
|
}
|
|
|
|
void QuickBuildComponent::ResetQuickBuild(const bool failed) {
|
|
Entity* builder = GetBuilder();
|
|
|
|
if (m_State == eQuickBuildState::BUILDING && builder) {
|
|
GameMessages::EnableRebuild enableRebuild;
|
|
enableRebuild.target = m_Parent->GetObjectID();
|
|
enableRebuild.bEnable = false;
|
|
enableRebuild.bFail = false;
|
|
enableRebuild.bSuccess = failed;
|
|
enableRebuild.eFailReason = eQuickBuildFailReason::NOT_GIVEN;
|
|
enableRebuild.fDuration = m_ResetTime;
|
|
enableRebuild.user = builder->GetObjectID();
|
|
enableRebuild.Send(UNASSIGNED_SYSTEM_ADDRESS);
|
|
|
|
if (failed) {
|
|
RenderComponent::PlayAnimation(builder, u"rebuild-fail");
|
|
}
|
|
}
|
|
|
|
GameMessages::RebuildNotifyState notifyState;
|
|
notifyState.target = m_Parent->GetObjectID();
|
|
notifyState.prevState = m_State;
|
|
notifyState.state = eQuickBuildState::RESETTING;
|
|
notifyState.player = LWOOBJID_EMPTY;
|
|
notifyState.Send(UNASSIGNED_SYSTEM_ADDRESS);
|
|
|
|
SetState(eQuickBuildState::RESETTING);
|
|
SetTimer(0.0f);
|
|
SetIncompleteTimer(0.0f);
|
|
SetShowResetEffect(false);
|
|
m_DrainedImagination = 0;
|
|
|
|
Game::entityManager->SerializeEntity(m_Parent);
|
|
|
|
// Notify scripts and possible subscribers
|
|
m_Parent->GetScript()->OnQuickBuildNotifyState(m_Parent, m_State);
|
|
for (const auto& cb : m_QuickBuildStateCallbacks)
|
|
cb(m_State);
|
|
|
|
m_Parent->ScheduleKillAfterUpdate();
|
|
|
|
if (m_Activator) {
|
|
m_Activator->ScheduleKillAfterUpdate();
|
|
}
|
|
}
|
|
|
|
void QuickBuildComponent::CancelQuickBuild(Entity* const entity, const eQuickBuildFailReason failReason, const bool skipChecks) {
|
|
if (m_State != eQuickBuildState::COMPLETED || skipChecks) {
|
|
|
|
m_Builder = LWOOBJID_EMPTY;
|
|
|
|
const auto entityID = entity != nullptr ? entity->GetObjectID() : LWOOBJID_EMPTY;
|
|
|
|
// Notify the client that a state has changed
|
|
GameMessages::RebuildNotifyState notifyState;
|
|
notifyState.target = m_Parent->GetObjectID();
|
|
notifyState.prevState = m_State;
|
|
notifyState.state = eQuickBuildState::INCOMPLETE;
|
|
notifyState.player = entityID;
|
|
notifyState.Send(UNASSIGNED_SYSTEM_ADDRESS);
|
|
GameMessages::EnableRebuild enableRebuild;
|
|
enableRebuild.target = m_Parent->GetObjectID();
|
|
enableRebuild.bEnable = false;
|
|
enableRebuild.bFail = true;
|
|
enableRebuild.bSuccess = false;
|
|
enableRebuild.eFailReason = failReason;
|
|
enableRebuild.fDuration = m_Timer;
|
|
enableRebuild.user = entityID;
|
|
enableRebuild.Send(UNASSIGNED_SYSTEM_ADDRESS);
|
|
|
|
// Now terminate any interaction with the rebuild
|
|
GameMessages::TerminateInteraction(entityID, eTerminateType::FROM_INTERACTION, m_Parent->GetObjectID()).Send(UNASSIGNED_SYSTEM_ADDRESS);
|
|
GameMessages::TerminateInteraction(m_Parent->GetObjectID(), eTerminateType::FROM_INTERACTION, m_Parent->GetObjectID()).Send(UNASSIGNED_SYSTEM_ADDRESS);
|
|
|
|
// Now update the component itself
|
|
SetState(eQuickBuildState::INCOMPLETE);
|
|
|
|
// Notify scripts and possible subscribers
|
|
m_Parent->GetScript()->OnQuickBuildNotifyState(m_Parent, m_State);
|
|
for (const auto& cb : m_QuickBuildStateCallbacks)
|
|
cb(m_State);
|
|
|
|
Game::entityManager->SerializeEntity(m_Parent);
|
|
}
|
|
|
|
if (!entity) return;
|
|
|
|
CharacterComponent* characterComponent = entity->GetComponent<CharacterComponent>();
|
|
if (characterComponent) {
|
|
characterComponent->SetCurrentActivity(eGameActivity::NONE);
|
|
Game::entityManager->SerializeEntity(entity);
|
|
}
|
|
}
|
|
|
|
void QuickBuildComponent::AddQuickBuildCompleteCallback(const std::function<void(Entity* user)>& callback) {
|
|
m_QuickBuildCompleteCallbacks.push_back(callback);
|
|
}
|
|
|
|
void QuickBuildComponent::AddQuickBuildStateCallback(const std::function<void(eQuickBuildState state)>& callback) {
|
|
m_QuickBuildStateCallbacks.push_back(callback);
|
|
}
|
|
|
|
bool QuickBuildComponent::OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo) {
|
|
auto& quickbuild = reportInfo.info->PushDebug("Quick Build");
|
|
quickbuild.PushDebug<AMFStringValue>("State") = StringifiedEnum::ToString(m_State).data();
|
|
quickbuild.PushDebug<AMFDoubleValue>("Timer") = m_Timer;
|
|
quickbuild.PushDebug<AMFDoubleValue>("Timer Incomplete") = m_TimerIncomplete;
|
|
quickbuild.PushDebug("Activator Position").PushDebug(m_ActivatorPosition);
|
|
quickbuild.PushDebug<AMFStringValue>("Activator ID", "LWOOBJID") = std::to_string(m_ActivatorId);
|
|
quickbuild.PushDebug<AMFBoolValue>("Show Reset Effect") = m_ShowResetEffect;
|
|
quickbuild.PushDebug<AMFDoubleValue>("Taken") = m_Taken;
|
|
quickbuild.PushDebug<AMFDoubleValue>("Reset Time") = m_ResetTime;
|
|
quickbuild.PushDebug<AMFDoubleValue>("Complete Time") = m_CompleteTime;
|
|
quickbuild.PushDebug<AMFIntValue>("Take Imagination") = m_TakeImagination;
|
|
quickbuild.PushDebug<AMFBoolValue>("Interruptible") = m_Interruptible;
|
|
quickbuild.PushDebug<AMFBoolValue>("Self Activator") = m_SelfActivator;
|
|
auto& modules = quickbuild.PushDebug("Custom Modules");
|
|
for (const auto cmodule : m_CustomModules) modules.PushDebug<AMFIntValue>("Module") = cmodule;
|
|
quickbuild.PushDebug<AMFIntValue>("Activity Id") = m_ActivityId;
|
|
quickbuild.PushDebug<AMFIntValue>("Post Imagination Cost") = m_PostImaginationCost;
|
|
quickbuild.PushDebug<AMFDoubleValue>("Time Before Smash") = m_TimeBeforeSmash;
|
|
quickbuild.PushDebug<AMFDoubleValue>("Time Before Drain") = m_TimeBeforeDrain;
|
|
quickbuild.PushDebug<AMFIntValue>("Drained Imagination") = m_DrainedImagination;
|
|
quickbuild.PushDebug<AMFBoolValue>("Reposition Player") = m_RepositionPlayer;
|
|
quickbuild.PushDebug<AMFDoubleValue>("Soft Timer") = m_SoftTimer;
|
|
quickbuild.PushDebug<AMFStringValue>("Builder", "LWOOBJID") = std::to_string(m_Builder);
|
|
return true;
|
|
}
|