Quickbuild and Destroyable reintegration

This commit is contained in:
David Markowitz 2023-06-11 04:37:53 -07:00
parent 77dc6ff312
commit 5f139c75e0
7 changed files with 126 additions and 70 deletions

View File

@ -218,19 +218,15 @@ void Entity::Initialize() {
if (m_ParentEntity) m_ParentEntity->AddChild(this); if (m_ParentEntity) m_ParentEntity->AddChild(this);
// Brick-by-Brick models don't have all their components in the registry for some reason? Might have to be related to using ldf keys for physics
if (GetLOT() == 14) {
AddComponent<SimplePhysicsComponent>(4246);
AddComponent<ModelBehaviorComponent>();
AddComponent<RenderComponent>();
AddComponent<DestroyableComponent>();
return;
}
auto* componentsRegistry = CDClientManager::Instance().GetTable<CDComponentsRegistryTable>(); auto* componentsRegistry = CDClientManager::Instance().GetTable<CDComponentsRegistryTable>();
TemplateComponents components = componentsRegistry->GetTemplateComponents(m_TemplateID); TemplateComponents components = componentsRegistry->GetTemplateComponents(m_TemplateID);
ApplyComponentWhitelist(components); ApplyComponentWhitelist(components);
ApplyComponentBlacklist(components); ApplyComponentBlacklist(components);
// Brick-by-Brick models use custom physics depending on _something_ but the client uses 4246 as the simple
// physics component id and 4247 for phantom physics. We'll just use the simple physics component for now
// since we dont know what the phantom physics are for at the moment.
if (GetLOT() == 14) components.emplace_back(eReplicaComponentType::SIMPLE_PHYSICS, 4246U);
for (const auto& [componentTemplate, componentId] : components) { for (const auto& [componentTemplate, componentId] : components) {
switch (componentTemplate) { switch (componentTemplate) {
case eReplicaComponentType::CONTROLLABLE_PHYSICS: case eReplicaComponentType::CONTROLLABLE_PHYSICS:
@ -250,8 +246,7 @@ void Entity::Initialize() {
AddComponent<PlayerForcedMovementComponent>(); AddComponent<PlayerForcedMovementComponent>();
break; break;
case eReplicaComponentType::SCRIPT: { case eReplicaComponentType::SCRIPT: {
auto script = ScriptComponent::GetScriptName(this, componentId); AddComponent<ScriptComponent>(ScriptComponent::GetScriptName(this, componentId));
if (!script.empty()) AddComponent<ScriptComponent>(script);
if (m_TemplateID == ZONE_CONTROL_LOT) { if (m_TemplateID == ZONE_CONTROL_LOT) {
const auto zoneScript = ScriptComponent::GetZoneScriptName(componentId); const auto zoneScript = ScriptComponent::GetZoneScriptName(componentId);
if (!zoneScript.empty()) AddComponent<ScriptComponent>(zoneScript); if (!zoneScript.empty()) AddComponent<ScriptComponent>(zoneScript);
@ -262,7 +257,7 @@ void Entity::Initialize() {
AddComponent<BouncerComponent>(); AddComponent<BouncerComponent>();
break; break;
case eReplicaComponentType::DESTROYABLE: case eReplicaComponentType::DESTROYABLE:
AddComponent<DestroyableComponent>(); if (HasComponent(eReplicaComponentType::DESTROYABLE)) AddComponent<DestroyableComponent>();
break; break;
case eReplicaComponentType::SKILL: case eReplicaComponentType::SKILL:
AddComponent<SkillComponent>(); AddComponent<SkillComponent>();
@ -284,7 +279,7 @@ void Entity::Initialize() {
break; break;
case eReplicaComponentType::COLLECTIBLE: case eReplicaComponentType::COLLECTIBLE:
AddComponent<CollectibleComponent>(); AddComponent<CollectibleComponent>();
AddComponent<DestroyableComponent>(); if (HasComponent(eReplicaComponentType::DESTROYABLE)) AddComponent<DestroyableComponent>();
break; break;
case eReplicaComponentType::MOVING_PLATFORM: case eReplicaComponentType::MOVING_PLATFORM:
AddComponent<MovingPlatformComponent>(GetVarAsString(u"attached_path")); AddComponent<MovingPlatformComponent>(GetVarAsString(u"attached_path"));
@ -292,21 +287,38 @@ void Entity::Initialize() {
case eReplicaComponentType::PET: case eReplicaComponentType::PET:
AddComponent<PetComponent>(componentId); AddComponent<PetComponent>(componentId);
break; break;
case eReplicaComponentType::HAVOK_VEHICLE_PHYSICS: case eReplicaComponentType::HAVOK_VEHICLE_PHYSICS: {
AddComponent<HavokVehiclePhysicsComponent>(); auto* havokVehiclePhysicsComponent = AddComponent<HavokVehiclePhysicsComponent>();
if (havokVehiclePhysicsComponent) {
havokVehiclePhysicsComponent->SetPosition(m_DefaultPosition);
havokVehiclePhysicsComponent->SetRotation(m_DefaultRotation);
}
break; break;
}
case eReplicaComponentType::PROPERTY: case eReplicaComponentType::PROPERTY:
AddComponent<PropertyComponent>(); AddComponent<PropertyComponent>();
break; break;
case eReplicaComponentType::SCRIPTED_ACTIVITY: case eReplicaComponentType::SCRIPTED_ACTIVITY:
AddComponent<ScriptedActivityComponent>(componentId); AddComponent<ScriptedActivityComponent>(componentId);
break; break;
case eReplicaComponentType::PHANTOM_PHYSICS: case eReplicaComponentType::PHANTOM_PHYSICS: {
AddComponent<PhantomPhysicsComponent>(); auto* phantomPhysicsComponent = AddComponent<PhantomPhysicsComponent>();
if (phantomPhysicsComponent) phantomPhysicsComponent->SetPhysicsEffectActive(false);
break; break;
case eReplicaComponentType::MODEL_BEHAVIOR: }
case eReplicaComponentType::MODEL_BEHAVIOR: {
AddComponent<ModelBehaviorComponent>(); AddComponent<ModelBehaviorComponent>();
if (HasComponent(eReplicaComponentType::DESTROYABLE)) {
auto* destroyableComponent = AddComponent<DestroyableComponent>();
if (destroyableComponent) {
destroyableComponent->SetHealth(1);
destroyableComponent->SetMaxHealth(1.0f);
destroyableComponent->SetFaction(-1, true);
destroyableComponent->SetIsSmashable(true);
}
}
break; break;
}
case eReplicaComponentType::PROPERTY_ENTRANCE: case eReplicaComponentType::PROPERTY_ENTRANCE:
AddComponent<PropertyEntranceComponent>(componentId); AddComponent<PropertyEntranceComponent>(componentId);
break; break;
@ -314,8 +326,8 @@ void Entity::Initialize() {
AddComponent<PropertyManagementComponent>(); AddComponent<PropertyManagementComponent>();
break; break;
case eReplicaComponentType::QUICK_BUILD: case eReplicaComponentType::QUICK_BUILD:
AddComponent<QuickBuildComponent>(); AddComponent<QuickBuildComponent>(componentId);
AddComponent<DestroyableComponent>(); if (HasComponent(eReplicaComponentType::DESTROYABLE)) AddComponent<DestroyableComponent>();
break; break;
case eReplicaComponentType::SWITCH: case eReplicaComponentType::SWITCH:
AddComponent<SwitchComponent>(); AddComponent<SwitchComponent>();

View File

@ -4,6 +4,7 @@
#error "Include Entity.h instead of Entity.tpp" #error "Include Entity.h instead of Entity.tpp"
#endif #endif
// Access definitions
template <typename Cmpt> template <typename Cmpt>
Cmpt* Entity::GetComponent() const { Cmpt* Entity::GetComponent() const {
const auto& componentItr = this->m_Components.find(Cmpt::ComponentType); const auto& componentItr = this->m_Components.find(Cmpt::ComponentType);

View File

@ -157,15 +157,15 @@ Entity::Initialize() {
// if (markedAsPhantom || compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PHANTOM_PHYSICS) > 0) { // if (markedAsPhantom || compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PHANTOM_PHYSICS) > 0) {
// PhantomPhysicsComponent* phantomPhysics = new PhantomPhysicsComponent(this); // PhantomPhysicsComponent* phantomPhysics = new PhantomPhysicsComponent(this);
phantomPhysics->SetPhysicsEffectActive(false); // phantomPhysics->SetPhysicsEffectActive(false);
// m_Components.insert(std::make_pair(eReplicaComponentType::PHANTOM_PHYSICS, phantomPhysics)); // m_Components.insert(std::make_pair(eReplicaComponentType::PHANTOM_PHYSICS, phantomPhysics));
// } // }
// if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::VEHICLE_PHYSICS) > 0) { // if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::VEHICLE_PHYSICS) > 0) {
// VehiclePhysicsComponent* vehiclePhysicsComponent = new VehiclePhysicsComponent(this); // VehiclePhysicsComponent* vehiclePhysicsComponent = new VehiclePhysicsComponent(this);
// m_Components.insert(std::make_pair(eReplicaComponentType::VEHICLE_PHYSICS, vehiclePhysicsComponent)); // m_Components.insert(std::make_pair(eReplicaComponentType::VEHICLE_PHYSICS, vehiclePhysicsComponent));
vehiclePhysicsComponent->SetPosition(m_DefaultPosition); // vehiclePhysicsComponent->SetPosition(m_DefaultPosition);
vehiclePhysicsComponent->SetRotation(m_DefaultRotation); // vehiclePhysicsComponent->SetRotation(m_DefaultRotation);
// } // }
// if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SOUND_TRIGGER, -1) != -1) { // if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SOUND_TRIGGER, -1) != -1) {
@ -382,47 +382,47 @@ Entity::Initialize() {
// m_Components.insert(std::make_pair(eReplicaComponentType::BASE_COMBAT_AI, comp)); // m_Components.insert(std::make_pair(eReplicaComponentType::BASE_COMBAT_AI, comp));
// } // }
if (int componentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::QUICK_BUILD) > 0) { // if (int componentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::QUICK_BUILD) > 0) {
// QuickBuildComponent* comp = new QuickBuildComponent(this); // QuickBuildComponent* comp = new QuickBuildComponent(this);
// m_Components.insert(std::make_pair(eReplicaComponentType::QUICK_BUILD, comp)); // m_Components.insert(std::make_pair(eReplicaComponentType::QUICK_BUILD, comp));
CDRebuildComponentTable* rebCompTable = CDClientManager::Instance().GetTable<CDRebuildComponentTable>(); // CDRebuildComponentTable* rebCompTable = CDClientManager::Instance().GetTable<CDRebuildComponentTable>();
std::vector<CDRebuildComponent> rebCompData = rebCompTable->Query([=](CDRebuildComponent entry) { return (entry.id == quickBuildComponentID); }); // std::vector<CDRebuildComponent> rebCompData = rebCompTable->Query([=](CDRebuildComponent entry) { return (entry.id == quickBuildComponentID); });
if (rebCompData.size() > 0) { // if (rebCompData.size() > 0) {
comp->SetResetTime(rebCompData[0].reset_time); // comp->SetResetTime(rebCompData[0].reset_time);
comp->SetCompleteTime(rebCompData[0].complete_time); // comp->SetCompleteTime(rebCompData[0].complete_time);
comp->SetTakeImagination(rebCompData[0].take_imagination); // comp->SetTakeImagination(rebCompData[0].take_imagination);
comp->SetInterruptible(rebCompData[0].interruptible); // comp->SetInterruptible(rebCompData[0].interruptible);
comp->SetSelfActivator(rebCompData[0].self_activator); // comp->SetSelfActivator(rebCompData[0].self_activator);
comp->SetActivityId(rebCompData[0].activityID); // comp->SetActivityId(rebCompData[0].activityID);
comp->SetPostImaginationCost(rebCompData[0].post_imagination_cost); // comp->SetPostImaginationCost(rebCompData[0].post_imagination_cost);
comp->SetTimeBeforeSmash(rebCompData[0].time_before_smash); // comp->SetTimeBeforeSmash(rebCompData[0].time_before_smash);
const auto rebuildResetTime = GetVar<float>(u"rebuild_reset_time"); // const auto rebuildResetTime = GetVar<float>(u"rebuild_reset_time");
if (rebuildResetTime != 0.0f) { // if (rebuildResetTime != 0.0f) {
comp->SetResetTime(rebuildResetTime); // comp->SetResetTime(rebuildResetTime);
if (m_TemplateID == 9483) // Look away! // if (m_TemplateID == 9483) // Look away!
{ // {
comp->SetResetTime(comp->GetResetTime() + 25); // comp->SetResetTime(comp->GetResetTime() + 25);
} // }
} // }
const auto activityID = GetVar<int32_t>(u"activityID"); // const auto activityID = GetVar<int32_t>(u"activityID");
if (activityID > 0) { // if (activityID > 0) {
comp->SetActivityId(activityID); // comp->SetActivityId(activityID);
} // }
const auto compTime = GetVar<float>(u"compTime"); // const auto compTime = GetVar<float>(u"compTime");
if (compTime > 0) { // if (compTime > 0) {
comp->SetCompleteTime(compTime); // comp->SetCompleteTime(compTime);
} // }
} // }
} // }
// if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SWITCH, -1) != -1) { // if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SWITCH, -1) != -1) {
// SwitchComponent* comp = new SwitchComponent(this); // SwitchComponent* comp = new SwitchComponent(this);
@ -471,14 +471,14 @@ Entity::Initialize() {
// if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MODEL, -1) != -1 && !GetComponent<PetComponent>()) { // if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MODEL, -1) != -1 && !GetComponent<PetComponent>()) {
// m_Components.insert(std::make_pair(eReplicaComponentType::MODEL, new ModelComponent(this))); // m_Components.insert(std::make_pair(eReplicaComponentType::MODEL, new ModelComponent(this)));
if (m_Components.find(eReplicaComponentType::DESTROYABLE) == m_Components.end()) { // if (m_Components.find(eReplicaComponentType::DESTROYABLE) == m_Components.end()) {
auto destroyableComponent = new DestroyableComponent(this); // auto destroyableComponent = new DestroyableComponent(this);
destroyableComponent->SetHealth(1); // destroyableComponent->SetHealth(1);
destroyableComponent->SetMaxHealth(1.0f); // destroyableComponent->SetMaxHealth(1.0f);
destroyableComponent->SetFaction(-1, true); // destroyableComponent->SetFaction(-1, true);
destroyableComponent->SetIsSmashable(true); // destroyableComponent->SetIsSmashable(true);
m_Components.insert(std::make_pair(eReplicaComponentType::DESTROYABLE, destroyableComponent)); // m_Components.insert(std::make_pair(eReplicaComponentType::DESTROYABLE, destroyableComponent));
} // }
// } // }
// PetComponent* petComponent; // PetComponent* petComponent;

View File

@ -21,10 +21,12 @@
#include "Loot.h" #include "Loot.h"
#include "TeamManager.h" #include "TeamManager.h"
#include "RenderComponent.h" #include "RenderComponent.h"
#include "CDRebuildComponentTable.h"
#include "CppScripts.h" #include "CppScripts.h"
QuickBuildComponent::QuickBuildComponent(Entity* entity) : Component(entity) { QuickBuildComponent::QuickBuildComponent(Entity* entity, uint32_t componentId) : Component(entity) {
m_ComponentId = componentId;
std::u16string checkPreconditions = entity->GetVar<std::u16string>(u"CheckPrecondition"); std::u16string checkPreconditions = entity->GetVar<std::u16string>(u"CheckPrecondition");
if (!checkPreconditions.empty()) { if (!checkPreconditions.empty()) {
@ -57,6 +59,42 @@ QuickBuildComponent::~QuickBuildComponent() {
DespawnActivator(); DespawnActivator();
} }
void QuickBuildComponent::LoadConfigData() {
const auto rebuildResetTime = m_ParentEntity->GetVar<float>(u"rebuild_reset_time");
if (rebuildResetTime != 0.0f) {
SetResetTime(rebuildResetTime);
if (m_ParentEntity->GetLOT() == 9483) // Look away!
{
SetResetTime(GetResetTime() + 25);
}
}
const auto activityID = m_ParentEntity->GetVar<int32_t>(u"activityID");
if (activityID > 0) SetActivityId(activityID);
const auto compTime = m_ParentEntity->GetVar<float>(u"compTime");
if (compTime > 0) SetCompleteTime(compTime);
}
void QuickBuildComponent::LoadTemplateData() {
auto* rebCompTable = CDClientManager::Instance().GetTable<CDRebuildComponentTable>();
std::vector<CDRebuildComponent> rebCompData = rebCompTable->Query([this](CDRebuildComponent entry) { return (entry.id == this->m_ComponentId); });
if (rebCompData.empty()) return;
const auto& quickbuildData = rebCompData.at(0);
SetResetTime(quickbuildData.reset_time);
SetCompleteTime(quickbuildData.complete_time);
SetTakeImagination(quickbuildData.take_imagination);
SetInterruptible(quickbuildData.interruptible);
SetSelfActivator(quickbuildData.self_activator);
SetActivityId(quickbuildData.activityID);
SetPostImaginationCost(quickbuildData.post_imagination_cost);
SetTimeBeforeSmash(quickbuildData.time_before_smash);
}
void QuickBuildComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) { void QuickBuildComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
if (!m_ParentEntity->GetComponent<DestroyableComponent>()) { if (!m_ParentEntity->GetComponent<DestroyableComponent>()) {
if (bIsInitialUpdate) { if (bIsInitialUpdate) {
@ -482,7 +520,7 @@ void QuickBuildComponent::CompleteRebuild(Entity* user) {
if (missionComponent) missionComponent->Progress(eMissionTaskType::ACTIVITY, m_ActivityId); if (missionComponent) missionComponent->Progress(eMissionTaskType::ACTIVITY, m_ActivityId);
} }
} }
} else{ } else {
auto* missionComponent = builder->GetComponent<MissionComponent>(); auto* missionComponent = builder->GetComponent<MissionComponent>();
if (missionComponent) missionComponent->Progress(eMissionTaskType::ACTIVITY, m_ActivityId); if (missionComponent) missionComponent->Progress(eMissionTaskType::ACTIVITY, m_ActivityId);
} }

View File

@ -24,11 +24,13 @@ class QuickBuildComponent : public Component {
public: public:
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::QUICK_BUILD; inline static const eReplicaComponentType ComponentType = eReplicaComponentType::QUICK_BUILD;
QuickBuildComponent(Entity* entity); QuickBuildComponent(Entity* entity, uint32_t componentId = 0);
~QuickBuildComponent() override; ~QuickBuildComponent() override;
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags); void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
void Update(float deltaTime) override; void Update(float deltaTime) override;
void LoadTemplateData() override;
void LoadConfigData() override;
/** /**
* Handles a OnUse event from some entity, initiating the quick build * Handles a OnUse event from some entity, initiating the quick build
@ -349,6 +351,8 @@ private:
*/ */
PreconditionExpression* m_Precondition = nullptr; PreconditionExpression* m_Precondition = nullptr;
uint32_t m_ComponentId = 0;
/** /**
* Starts the rebuild for a certain entity * Starts the rebuild for a certain entity
* @param user the entity to start the rebuild * @param user the entity to start the rebuild

View File

@ -312,11 +312,8 @@
#include "WildNinjaSensei.h" #include "WildNinjaSensei.h"
#include "WildNinjaBricks.h" #include "WildNinjaBricks.h"
//Big bad global bc this is a namespace and not a class: InvalidScript* CppScripts::invalidToReturn = new InvalidScript();
InvalidScript* invalidToReturn = new InvalidScript(); std::map<std::string, CppScripts::Script*> CppScripts::m_Scripts;
std::map<std::string, CppScripts::Script*> m_Scripts;
// yeah sorry darwin ill fix the global later
CppScripts::Script* CppScripts::GetScript(Entity* parent, const std::string& scriptName) { CppScripts::Script* CppScripts::GetScript(Entity* parent, const std::string& scriptName) {
Script* script; Script* script;

View File

@ -7,11 +7,15 @@
class User; class User;
class Entity; class Entity;
class NiPoint3; class NiPoint3;
class InvalidScript;
enum class eMissionState : int32_t; enum class eMissionState : int32_t;
enum class ePetTamingNotifyType : uint32_t; enum class ePetTamingNotifyType : uint32_t;
enum class eRebuildState : uint32_t; enum class eRebuildState : uint32_t;
namespace CppScripts { namespace CppScripts {
extern InvalidScript* invalidToReturn;
extern std::map<std::string, CppScripts::Script*> m_Scripts;
/** /**
* Base class for all scripts. Includes virtual methods to be overridden to handle LUA equivelent events. * Base class for all scripts. Includes virtual methods to be overridden to handle LUA equivelent events.
* *
@ -357,7 +361,7 @@ namespace CppScripts {
* @param player the player to remove * @param player the player to remove
* @param canceled if it was done via the cancel button * @param canceled if it was done via the cancel button
*/ */
virtual void OnRequestActivityExit(Entity* sender, LWOOBJID player, bool canceled){}; virtual void OnRequestActivityExit(Entity* sender, LWOOBJID player, bool canceled) {};
}; };
Script* GetScript(Entity* parent, const std::string& scriptName); Script* GetScript(Entity* parent, const std::string& scriptName);