mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-12-25 23:13:35 +00:00
Quickbuild and Destroyable reintegration
This commit is contained in:
parent
77dc6ff312
commit
5f139c75e0
@ -218,19 +218,15 @@ void Entity::Initialize() {
|
||||
|
||||
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>();
|
||||
TemplateComponents components = componentsRegistry->GetTemplateComponents(m_TemplateID);
|
||||
ApplyComponentWhitelist(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) {
|
||||
switch (componentTemplate) {
|
||||
case eReplicaComponentType::CONTROLLABLE_PHYSICS:
|
||||
@ -250,8 +246,7 @@ void Entity::Initialize() {
|
||||
AddComponent<PlayerForcedMovementComponent>();
|
||||
break;
|
||||
case eReplicaComponentType::SCRIPT: {
|
||||
auto script = ScriptComponent::GetScriptName(this, componentId);
|
||||
if (!script.empty()) AddComponent<ScriptComponent>(script);
|
||||
AddComponent<ScriptComponent>(ScriptComponent::GetScriptName(this, componentId));
|
||||
if (m_TemplateID == ZONE_CONTROL_LOT) {
|
||||
const auto zoneScript = ScriptComponent::GetZoneScriptName(componentId);
|
||||
if (!zoneScript.empty()) AddComponent<ScriptComponent>(zoneScript);
|
||||
@ -262,7 +257,7 @@ void Entity::Initialize() {
|
||||
AddComponent<BouncerComponent>();
|
||||
break;
|
||||
case eReplicaComponentType::DESTROYABLE:
|
||||
AddComponent<DestroyableComponent>();
|
||||
if (HasComponent(eReplicaComponentType::DESTROYABLE)) AddComponent<DestroyableComponent>();
|
||||
break;
|
||||
case eReplicaComponentType::SKILL:
|
||||
AddComponent<SkillComponent>();
|
||||
@ -284,7 +279,7 @@ void Entity::Initialize() {
|
||||
break;
|
||||
case eReplicaComponentType::COLLECTIBLE:
|
||||
AddComponent<CollectibleComponent>();
|
||||
AddComponent<DestroyableComponent>();
|
||||
if (HasComponent(eReplicaComponentType::DESTROYABLE)) AddComponent<DestroyableComponent>();
|
||||
break;
|
||||
case eReplicaComponentType::MOVING_PLATFORM:
|
||||
AddComponent<MovingPlatformComponent>(GetVarAsString(u"attached_path"));
|
||||
@ -292,21 +287,38 @@ void Entity::Initialize() {
|
||||
case eReplicaComponentType::PET:
|
||||
AddComponent<PetComponent>(componentId);
|
||||
break;
|
||||
case eReplicaComponentType::HAVOK_VEHICLE_PHYSICS:
|
||||
AddComponent<HavokVehiclePhysicsComponent>();
|
||||
case eReplicaComponentType::HAVOK_VEHICLE_PHYSICS: {
|
||||
auto* havokVehiclePhysicsComponent = AddComponent<HavokVehiclePhysicsComponent>();
|
||||
if (havokVehiclePhysicsComponent) {
|
||||
havokVehiclePhysicsComponent->SetPosition(m_DefaultPosition);
|
||||
havokVehiclePhysicsComponent->SetRotation(m_DefaultRotation);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case eReplicaComponentType::PROPERTY:
|
||||
AddComponent<PropertyComponent>();
|
||||
break;
|
||||
case eReplicaComponentType::SCRIPTED_ACTIVITY:
|
||||
AddComponent<ScriptedActivityComponent>(componentId);
|
||||
break;
|
||||
case eReplicaComponentType::PHANTOM_PHYSICS:
|
||||
AddComponent<PhantomPhysicsComponent>();
|
||||
case eReplicaComponentType::PHANTOM_PHYSICS: {
|
||||
auto* phantomPhysicsComponent = AddComponent<PhantomPhysicsComponent>();
|
||||
if (phantomPhysicsComponent) phantomPhysicsComponent->SetPhysicsEffectActive(false);
|
||||
break;
|
||||
case eReplicaComponentType::MODEL_BEHAVIOR:
|
||||
}
|
||||
case eReplicaComponentType::MODEL_BEHAVIOR: {
|
||||
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;
|
||||
}
|
||||
case eReplicaComponentType::PROPERTY_ENTRANCE:
|
||||
AddComponent<PropertyEntranceComponent>(componentId);
|
||||
break;
|
||||
@ -314,8 +326,8 @@ void Entity::Initialize() {
|
||||
AddComponent<PropertyManagementComponent>();
|
||||
break;
|
||||
case eReplicaComponentType::QUICK_BUILD:
|
||||
AddComponent<QuickBuildComponent>();
|
||||
AddComponent<DestroyableComponent>();
|
||||
AddComponent<QuickBuildComponent>(componentId);
|
||||
if (HasComponent(eReplicaComponentType::DESTROYABLE)) AddComponent<DestroyableComponent>();
|
||||
break;
|
||||
case eReplicaComponentType::SWITCH:
|
||||
AddComponent<SwitchComponent>();
|
||||
|
@ -4,6 +4,7 @@
|
||||
#error "Include Entity.h instead of Entity.tpp"
|
||||
#endif
|
||||
|
||||
// Access definitions
|
||||
template <typename Cmpt>
|
||||
Cmpt* Entity::GetComponent() const {
|
||||
const auto& componentItr = this->m_Components.find(Cmpt::ComponentType);
|
||||
|
@ -157,15 +157,15 @@ Entity::Initialize() {
|
||||
|
||||
// if (markedAsPhantom || compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PHANTOM_PHYSICS) > 0) {
|
||||
// PhantomPhysicsComponent* phantomPhysics = new PhantomPhysicsComponent(this);
|
||||
phantomPhysics->SetPhysicsEffectActive(false);
|
||||
// phantomPhysics->SetPhysicsEffectActive(false);
|
||||
// m_Components.insert(std::make_pair(eReplicaComponentType::PHANTOM_PHYSICS, phantomPhysics));
|
||||
// }
|
||||
|
||||
// if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::VEHICLE_PHYSICS) > 0) {
|
||||
// VehiclePhysicsComponent* vehiclePhysicsComponent = new VehiclePhysicsComponent(this);
|
||||
// m_Components.insert(std::make_pair(eReplicaComponentType::VEHICLE_PHYSICS, vehiclePhysicsComponent));
|
||||
vehiclePhysicsComponent->SetPosition(m_DefaultPosition);
|
||||
vehiclePhysicsComponent->SetRotation(m_DefaultRotation);
|
||||
// vehiclePhysicsComponent->SetPosition(m_DefaultPosition);
|
||||
// vehiclePhysicsComponent->SetRotation(m_DefaultRotation);
|
||||
// }
|
||||
|
||||
// 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));
|
||||
// }
|
||||
|
||||
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);
|
||||
// m_Components.insert(std::make_pair(eReplicaComponentType::QUICK_BUILD, comp));
|
||||
|
||||
CDRebuildComponentTable* rebCompTable = CDClientManager::Instance().GetTable<CDRebuildComponentTable>();
|
||||
std::vector<CDRebuildComponent> rebCompData = rebCompTable->Query([=](CDRebuildComponent entry) { return (entry.id == quickBuildComponentID); });
|
||||
// CDRebuildComponentTable* rebCompTable = CDClientManager::Instance().GetTable<CDRebuildComponentTable>();
|
||||
// std::vector<CDRebuildComponent> rebCompData = rebCompTable->Query([=](CDRebuildComponent entry) { return (entry.id == quickBuildComponentID); });
|
||||
|
||||
if (rebCompData.size() > 0) {
|
||||
comp->SetResetTime(rebCompData[0].reset_time);
|
||||
comp->SetCompleteTime(rebCompData[0].complete_time);
|
||||
comp->SetTakeImagination(rebCompData[0].take_imagination);
|
||||
comp->SetInterruptible(rebCompData[0].interruptible);
|
||||
comp->SetSelfActivator(rebCompData[0].self_activator);
|
||||
comp->SetActivityId(rebCompData[0].activityID);
|
||||
comp->SetPostImaginationCost(rebCompData[0].post_imagination_cost);
|
||||
comp->SetTimeBeforeSmash(rebCompData[0].time_before_smash);
|
||||
// if (rebCompData.size() > 0) {
|
||||
// comp->SetResetTime(rebCompData[0].reset_time);
|
||||
// comp->SetCompleteTime(rebCompData[0].complete_time);
|
||||
// comp->SetTakeImagination(rebCompData[0].take_imagination);
|
||||
// comp->SetInterruptible(rebCompData[0].interruptible);
|
||||
// comp->SetSelfActivator(rebCompData[0].self_activator);
|
||||
// comp->SetActivityId(rebCompData[0].activityID);
|
||||
// comp->SetPostImaginationCost(rebCompData[0].post_imagination_cost);
|
||||
// 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) {
|
||||
comp->SetResetTime(rebuildResetTime);
|
||||
// if (rebuildResetTime != 0.0f) {
|
||||
// comp->SetResetTime(rebuildResetTime);
|
||||
|
||||
if (m_TemplateID == 9483) // Look away!
|
||||
{
|
||||
comp->SetResetTime(comp->GetResetTime() + 25);
|
||||
}
|
||||
}
|
||||
// if (m_TemplateID == 9483) // Look away!
|
||||
// {
|
||||
// comp->SetResetTime(comp->GetResetTime() + 25);
|
||||
// }
|
||||
// }
|
||||
|
||||
const auto activityID = GetVar<int32_t>(u"activityID");
|
||||
// const auto activityID = GetVar<int32_t>(u"activityID");
|
||||
|
||||
if (activityID > 0) {
|
||||
comp->SetActivityId(activityID);
|
||||
}
|
||||
// if (activityID > 0) {
|
||||
// comp->SetActivityId(activityID);
|
||||
// }
|
||||
|
||||
const auto compTime = GetVar<float>(u"compTime");
|
||||
// const auto compTime = GetVar<float>(u"compTime");
|
||||
|
||||
if (compTime > 0) {
|
||||
comp->SetCompleteTime(compTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
// if (compTime > 0) {
|
||||
// comp->SetCompleteTime(compTime);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SWITCH, -1) != -1) {
|
||||
// SwitchComponent* comp = new SwitchComponent(this);
|
||||
@ -471,14 +471,14 @@ Entity::Initialize() {
|
||||
|
||||
// if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MODEL, -1) != -1 && !GetComponent<PetComponent>()) {
|
||||
// m_Components.insert(std::make_pair(eReplicaComponentType::MODEL, new ModelComponent(this)));
|
||||
if (m_Components.find(eReplicaComponentType::DESTROYABLE) == m_Components.end()) {
|
||||
auto destroyableComponent = new DestroyableComponent(this);
|
||||
destroyableComponent->SetHealth(1);
|
||||
destroyableComponent->SetMaxHealth(1.0f);
|
||||
destroyableComponent->SetFaction(-1, true);
|
||||
destroyableComponent->SetIsSmashable(true);
|
||||
m_Components.insert(std::make_pair(eReplicaComponentType::DESTROYABLE, destroyableComponent));
|
||||
}
|
||||
// if (m_Components.find(eReplicaComponentType::DESTROYABLE) == m_Components.end()) {
|
||||
// auto destroyableComponent = new DestroyableComponent(this);
|
||||
// destroyableComponent->SetHealth(1);
|
||||
// destroyableComponent->SetMaxHealth(1.0f);
|
||||
// destroyableComponent->SetFaction(-1, true);
|
||||
// destroyableComponent->SetIsSmashable(true);
|
||||
// m_Components.insert(std::make_pair(eReplicaComponentType::DESTROYABLE, destroyableComponent));
|
||||
// }
|
||||
// }
|
||||
|
||||
// PetComponent* petComponent;
|
||||
|
@ -21,10 +21,12 @@
|
||||
#include "Loot.h"
|
||||
#include "TeamManager.h"
|
||||
#include "RenderComponent.h"
|
||||
#include "CDRebuildComponentTable.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");
|
||||
|
||||
if (!checkPreconditions.empty()) {
|
||||
@ -57,6 +59,42 @@ QuickBuildComponent::~QuickBuildComponent() {
|
||||
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) {
|
||||
if (!m_ParentEntity->GetComponent<DestroyableComponent>()) {
|
||||
if (bIsInitialUpdate) {
|
||||
@ -482,7 +520,7 @@ void QuickBuildComponent::CompleteRebuild(Entity* user) {
|
||||
if (missionComponent) missionComponent->Progress(eMissionTaskType::ACTIVITY, m_ActivityId);
|
||||
}
|
||||
}
|
||||
} else{
|
||||
} else {
|
||||
auto* missionComponent = builder->GetComponent<MissionComponent>();
|
||||
if (missionComponent) missionComponent->Progress(eMissionTaskType::ACTIVITY, m_ActivityId);
|
||||
}
|
||||
|
@ -24,11 +24,13 @@ class QuickBuildComponent : public Component {
|
||||
public:
|
||||
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::QUICK_BUILD;
|
||||
|
||||
QuickBuildComponent(Entity* entity);
|
||||
QuickBuildComponent(Entity* entity, uint32_t componentId = 0);
|
||||
~QuickBuildComponent() override;
|
||||
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
|
||||
void Update(float deltaTime) override;
|
||||
void LoadTemplateData() override;
|
||||
void LoadConfigData() override;
|
||||
|
||||
/**
|
||||
* Handles a OnUse event from some entity, initiating the quick build
|
||||
@ -349,6 +351,8 @@ private:
|
||||
*/
|
||||
PreconditionExpression* m_Precondition = nullptr;
|
||||
|
||||
uint32_t m_ComponentId = 0;
|
||||
|
||||
/**
|
||||
* Starts the rebuild for a certain entity
|
||||
* @param user the entity to start the rebuild
|
||||
|
@ -312,11 +312,8 @@
|
||||
#include "WildNinjaSensei.h"
|
||||
#include "WildNinjaBricks.h"
|
||||
|
||||
//Big bad global bc this is a namespace and not a class:
|
||||
InvalidScript* invalidToReturn = new InvalidScript();
|
||||
std::map<std::string, CppScripts::Script*> m_Scripts;
|
||||
|
||||
// yeah sorry darwin ill fix the global later
|
||||
InvalidScript* CppScripts::invalidToReturn = new InvalidScript();
|
||||
std::map<std::string, CppScripts::Script*> CppScripts::m_Scripts;
|
||||
|
||||
CppScripts::Script* CppScripts::GetScript(Entity* parent, const std::string& scriptName) {
|
||||
Script* script;
|
||||
|
@ -7,11 +7,15 @@
|
||||
class User;
|
||||
class Entity;
|
||||
class NiPoint3;
|
||||
class InvalidScript;
|
||||
enum class eMissionState : int32_t;
|
||||
enum class ePetTamingNotifyType : uint32_t;
|
||||
enum class eRebuildState : uint32_t;
|
||||
|
||||
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.
|
||||
*
|
||||
@ -357,7 +361,7 @@ namespace CppScripts {
|
||||
* @param player the player to remove
|
||||
* @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);
|
||||
|
Loading…
Reference in New Issue
Block a user