2021-12-05 17:54:36 +00:00
|
|
|
#ifndef REBUILDCOMPONENT_H
|
|
|
|
#define REBUILDCOMPONENT_H
|
|
|
|
|
|
|
|
#include <BitStream.h>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include "dCommonVars.h"
|
|
|
|
#include "NiPoint3.h"
|
|
|
|
#include "ScriptedActivityComponent.h"
|
|
|
|
#include "Preconditions.h"
|
|
|
|
#include "Component.h"
|
2023-03-04 07:16:37 +00:00
|
|
|
#include "eReplicaComponentType.h"
|
2023-05-02 22:39:21 +00:00
|
|
|
#include "eRebuildState.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
class Entity;
|
2023-05-02 22:39:21 +00:00
|
|
|
enum class eQuickBuildFailReason : uint32_t;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Component that handles entities that can be built into other entities using the quick build mechanic. Generally
|
|
|
|
* consists of an activator that shows a popup and then the actual entity that the bricks are built into. Note
|
|
|
|
* that quick builds are also scripted activities so this shared some logic with the ScriptedActivityComponent.
|
|
|
|
*/
|
|
|
|
class RebuildComponent : public Component {
|
|
|
|
public:
|
2023-03-04 07:16:37 +00:00
|
|
|
static const eReplicaComponentType ComponentType = eReplicaComponentType::QUICK_BUILD;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
RebuildComponent(Entity* entity);
|
|
|
|
~RebuildComponent() override;
|
|
|
|
|
|
|
|
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
|
|
|
|
void Update(float deltaTime) override;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Handles a OnUse event from some entity, initiating the quick build
|
|
|
|
* @param originator the entity that triggered the event
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
void OnUse(Entity* originator) override;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Spawns the activator that can be used to initiate the rebuild
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
void SpawnActivator();
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Despawns the activiator that can be used to initiate the rebuild
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
void DespawnActivator();
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Returns the entity that acts as the activator for this rebuild
|
|
|
|
* @return the entity that acts as the activator for this rebuild
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
Entity* GetActivator();
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Returns the spawn position of the activator for this rebuild, if any
|
|
|
|
* @return the spawn position of the activator for this rebuild, if any
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
NiPoint3 GetActivatorPosition();
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Sets the spawn position for the activator of this rebuild
|
|
|
|
* @param value the spawn position to set for the activator
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
void SetActivatorPosition(NiPoint3 value);
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Returns the time it takes for the rebuild to reset after being built
|
|
|
|
* @return the time it takes for the rebuild to reset after being built
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
float GetResetTime();
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Sets the time it takes for the rebuild to reset after being built
|
|
|
|
* @param value the reset time to set
|
|
|
|
*/
|
|
|
|
void SetResetTime(float value);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Returns the time it takes to complete the rebuild
|
|
|
|
* @return the time it takes to complete the rebuild
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
float GetCompleteTime();
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Sets the time it takes to complete the rebuild
|
|
|
|
* @param value the completion time to set
|
|
|
|
*/
|
|
|
|
void SetCompleteTime(float value);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Returns the imagination that's taken when completing the rebuild
|
|
|
|
* @return the imagination that's taken when completing the rebuild
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
int GetTakeImagination();
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Sets the imagination that's taken when completing the rebuild
|
|
|
|
* @param value the imagination deduction to set
|
|
|
|
*/
|
|
|
|
void SetTakeImagination(int value);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Returns if the rebuild can be interrupted, currently unused
|
|
|
|
* @return if the rebuild can be interrupted
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
bool GetInterruptible();
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Sets whether or not the rebuild can be interrupted, currently unused
|
|
|
|
* @param value true if the rebuild may be interrupted, false otherwise
|
|
|
|
*/
|
|
|
|
void SetInterruptible(bool value);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Returns whether or not this entity contains a built-in activator
|
|
|
|
* @return whether or not this entity contains a built-in activator
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
bool GetSelfActivator();
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Sets whether or not this entity contains a built-in activator. If set to false this will spawn activators on
|
|
|
|
* each new rebuild.
|
|
|
|
* @param value whether or not this entity contains a built-in activator
|
|
|
|
*/
|
|
|
|
void SetSelfActivator(bool value);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Currently unused
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
std::vector<int> GetCustomModules();
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Currently unused
|
|
|
|
*/
|
|
|
|
void SetCustomModules(std::vector<int> value);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Returns the activity ID for participating in this rebuild
|
|
|
|
* @return the activity ID for participating in this rebuild
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
int GetActivityId();
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Sets the activity ID for participating in this rebuild
|
|
|
|
* @param value the activity ID to set
|
|
|
|
*/
|
|
|
|
void SetActivityId(int value);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Currently unused
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
int GetPostImaginationCost();
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Currently unused
|
|
|
|
*/
|
|
|
|
void SetPostImaginationCost(int value);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Returns the time it takes for an incomplete rebuild to be smashed automatically
|
|
|
|
* @return the time it takes for an incomplete rebuild to be smashed automatically
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
float GetTimeBeforeSmash();
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Sets the time it takes for an incomplete rebuild to be smashed automatically
|
|
|
|
* @param value the time to set
|
|
|
|
*/
|
|
|
|
void SetTimeBeforeSmash(float value);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Returns the current rebuild state
|
|
|
|
* @return the current rebuild state
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
eRebuildState GetState();
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Returns the player that is currently building this rebuild
|
|
|
|
* @return the player that is currently building this rebuild
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
Entity* GetBuilder() const;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Returns whether or not the player is repositioned when initiating the rebuild
|
|
|
|
* @return whether or not the player is repositioned when initiating the rebuild
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
bool GetRepositionPlayer() const;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Sets whether or not the player is repositioned when initiating the rebuild
|
|
|
|
* @param value whether or not the player is repositioned when initiating the rebuild
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
void SetRepositionPlayer(bool value);
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Adds a callback that is called when the rebuild is completed
|
|
|
|
* @param callback the callback to add
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
void AddRebuildCompleteCallback(const std::function<void(Entity* user)>& callback);
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Adds a callback when the rebuild state is updated
|
|
|
|
* @param callback the callback to add
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
void AddRebuildStateCallback(const std::function<void(eRebuildState state)>& callback);
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Resets the rebuild
|
|
|
|
* @param failed whether or not the player failed to complete the rebuild, triggers an extra animation
|
|
|
|
*/
|
|
|
|
void ResetRebuild(bool failed);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cancels the rebuild if it wasn't completed
|
|
|
|
* @param builder the player that's currently building
|
|
|
|
* @param failReason the reason the rebuild was cancelled
|
|
|
|
* @param skipChecks whether or not to skip the check for the rebuild not being completed
|
|
|
|
*/
|
2023-05-02 22:39:21 +00:00
|
|
|
void CancelRebuild(Entity* builder, eQuickBuildFailReason failReason, bool skipChecks = false);
|
2021-12-05 17:54:36 +00:00
|
|
|
private:
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Whether or not the quickbuild state has been changed since we last serialized it.
|
|
|
|
*/
|
|
|
|
bool m_StateDirty = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The state the rebuild is currently in
|
|
|
|
*/
|
2023-05-02 22:39:21 +00:00
|
|
|
eRebuildState m_State = eRebuildState::OPEN;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* The time that has passed since initiating the rebuild
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
float m_Timer = 0;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* The time that has passed before completing the rebuild
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
float m_TimerIncomplete = 0;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* The position that the rebuild activator is spawned at
|
|
|
|
*/
|
2022-05-03 05:32:00 +00:00
|
|
|
NiPoint3 m_ActivatorPosition = NiPoint3::ZERO;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* The entity that represents the rebuild activator
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
Entity* m_Activator = nullptr;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* The ID of the entity that represents the rebuild activator
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
LWOOBJID m_ActivatorId = LWOOBJID_EMPTY;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Triggers the blinking that indicates that the rebuild is resetting
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
bool m_ShowResetEffect = false;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Currently unused
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
float m_Taken = 0;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* The callbacks that are called when the rebuild is completed
|
|
|
|
*/
|
|
|
|
std::vector<std::function<void(Entity* user)>> m_RebuildCompleteCallbacks{};
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* The callbacks that are called when the rebuild state is updated
|
|
|
|
*/
|
|
|
|
std::vector<std::function<void(eRebuildState state)>> m_RebuildStateCallbacks{};
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* The time it takes for the rebuild to reset after being completed
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
float m_ResetTime = 0;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* The time it takes to complete the rebuild
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
float m_CompleteTime = 0;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* The imagination that's deducted when compeleting the rebuild
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
int m_TakeImagination = 0;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Currently unused
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
bool m_Interruptible = false;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Whether or not this rebuild entity also has an activator attached. If not a new one will be spawned
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
bool m_SelfActivator = false;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Currently unused
|
|
|
|
*/
|
|
|
|
std::vector<int> m_CustomModules{};
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* The activity ID that players partake in when doing this rebuild
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
int m_ActivityId = 0;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Currently unused
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
int m_PostImaginationCost = 0;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* The time it takes for the rebuild to reset when it's not completed yet
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
float m_TimeBeforeSmash = 0;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* The time it takes to drain imagination
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
float m_TimeBeforeDrain = 0;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* The amount of imagination that was drained when building this rebuild
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
int m_DrainedImagination = 0;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Whether to reposition the player or not when building
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
bool m_RepositionPlayer = true;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Currently unused
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
float m_SoftTimer = 0;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* The ID of the entity that's currently building the rebuild
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
LWOOBJID m_Builder = LWOOBJID_EMPTY;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Preconditions to be met before being able to start the rebuild
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
PreconditionExpression* m_Precondition = nullptr;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Starts the rebuild for a certain entity
|
|
|
|
* @param user the entity to start the rebuild
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
void StartRebuild(Entity* user);
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Completes the rebuild for an entity, dropping loot and despawning the activator
|
|
|
|
* @param user the entity that completed the rebuild
|
|
|
|
*/
|
2021-12-05 17:54:36 +00:00
|
|
|
void CompleteRebuild(Entity* user);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // REBUILDCOMPONENT_H
|