mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-20 10:45:27 +00:00
refactor(component): proximity monitor and movement AI load their own rows
The ProximityMonitorComponent row's radii and the MovementAIComponent row (with the level's wanderRadius over it) move out of Entity::Initialize into each component's LoadDataFromTemplate / LoadConfigData. Same components and bytes for every LOT. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -470,47 +470,14 @@ void Entity::Initialize() {
|
|||||||
}
|
}
|
||||||
case eReplicaComponentType::PROXIMITY_MONITOR: {
|
case eReplicaComponentType::PROXIMITY_MONITOR: {
|
||||||
const auto proximityMonitorID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PROXIMITY_MONITOR);
|
const auto proximityMonitorID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PROXIMITY_MONITOR);
|
||||||
if (proximityMonitorID > 0) {
|
if (proximityMonitorID > 0) AddComponent<ProximityMonitorComponent>(proximityMonitorID);
|
||||||
auto* const proxCompTable = CDClientManager::GetTable<CDProximityMonitorComponentTable>();
|
|
||||||
const auto proxCompData = proxCompTable->Query([proximityMonitorID](const CDProximityMonitorComponent& entry) { return (entry.id == proximityMonitorID); });
|
|
||||||
if (proxCompData.size() > 0) {
|
|
||||||
// "small,large"; one value (LOT 9833: "4") is both
|
|
||||||
const auto radii = GeneralUtils::SplitString(proxCompData[0].Proximities, ',');
|
|
||||||
const auto small = radii.empty() ? std::nullopt : GeneralUtils::TryParse<int32_t>(radii[0]);
|
|
||||||
const auto large = radii.size() > 1 ? GeneralUtils::TryParse<int32_t>(radii[1]) : small;
|
|
||||||
if (small && large) AddComponent<ProximityMonitorComponent>(proximityMonitorID, *small, *large);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case eReplicaComponentType::MOVEMENT_AI: {
|
case eReplicaComponentType::MOVEMENT_AI: {
|
||||||
const int movementAIID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MOVEMENT_AI);
|
const int movementAIID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MOVEMENT_AI);
|
||||||
if (movementAIID > 0) {
|
if (movementAIID > 0) {
|
||||||
CDMovementAIComponentTable* moveAITable = CDClientManager::GetTable<CDMovementAIComponentTable>();
|
// Its row and the level's wanderRadius load in the component
|
||||||
std::vector<CDMovementAIComponent> moveAIComp = moveAITable->Query([=](CDMovementAIComponent entry) {return (entry.id == movementAIID); });
|
AddComponent<MovementAIComponent>(movementAIID, MovementAIInfo{});
|
||||||
|
|
||||||
if (moveAIComp.size() > 0) {
|
|
||||||
MovementAIInfo moveInfo{
|
|
||||||
.movementType = moveAIComp[0].MovementType,
|
|
||||||
.wanderRadius = moveAIComp[0].WanderRadius,
|
|
||||||
.wanderSpeed = moveAIComp[0].WanderSpeed,
|
|
||||||
.wanderChance = moveAIComp[0].WanderChance,
|
|
||||||
.wanderDelayMin = moveAIComp[0].WanderDelayMin,
|
|
||||||
.wanderDelayMax = moveAIComp[0].WanderDelayMax,
|
|
||||||
};
|
|
||||||
|
|
||||||
const bool useWanderDB = GetVar<bool>(u"usewanderdb");
|
|
||||||
|
|
||||||
if (!useWanderDB) {
|
|
||||||
const auto wanderOverride = GetVarAs<float>(u"wanderRadius");
|
|
||||||
|
|
||||||
if (wanderOverride != 0.0f) {
|
|
||||||
moveInfo.wanderRadius = wanderOverride;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
AddComponent<MovementAIComponent>(movementAIID, moveInfo);
|
|
||||||
}
|
|
||||||
} else if (petComponentID > 0 || combatAiID > 0 && BaseCombatAIComponent::TetherSpeedOf(combatAiID) > 0) {
|
} else if (petComponentID > 0 || combatAiID > 0 && BaseCombatAIComponent::TetherSpeedOf(combatAiID) > 0) {
|
||||||
MovementAIInfo moveInfo{
|
MovementAIInfo moveInfo{
|
||||||
.movementType = "",
|
.movementType = "",
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
#include "MovementAIComponent.h"
|
#include "MovementAIComponent.h"
|
||||||
|
#include "CDClientManager.h"
|
||||||
|
#include "CDMovementAIComponentTable.h"
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
@@ -46,11 +48,6 @@ MovementAIComponent::MovementAIComponent(Entity* parent, const int32_t component
|
|||||||
|
|
||||||
m_BaseCombatAI = m_Parent->GetComponent<BaseCombatAIComponent>();
|
m_BaseCombatAI = m_Parent->GetComponent<BaseCombatAIComponent>();
|
||||||
|
|
||||||
//Try and fix the insane values:
|
|
||||||
if (m_Info.wanderRadius > 5.0f) m_Info.wanderRadius *= 0.5f;
|
|
||||||
if (m_Info.wanderRadius > 8.0f) m_Info.wanderRadius = 8.0f;
|
|
||||||
if (m_Info.wanderSpeed > 0.5f) m_Info.wanderSpeed *= 0.5f;
|
|
||||||
|
|
||||||
m_BaseSpeed = GetBaseSpeed(m_Parent->GetLOT());
|
m_BaseSpeed = GetBaseSpeed(m_Parent->GetLOT());
|
||||||
|
|
||||||
m_NextWaypoint = m_Parent->GetPosition();
|
m_NextWaypoint = m_Parent->GetPosition();
|
||||||
@@ -73,7 +70,33 @@ MovementAIComponent::MovementAIComponent(Entity* parent, const int32_t component
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The level config: the attached path
|
// The level config: the attached path
|
||||||
|
// The MovementAIComponent row (an object made without one gets its info from the constructor)
|
||||||
|
void MovementAIComponent::LoadDataFromTemplate() {
|
||||||
|
if (m_ComponentID <= 0) return;
|
||||||
|
const auto componentID = m_ComponentID;
|
||||||
|
const auto moveAIComp = CDClientManager::GetTable<CDMovementAIComponentTable>()->Query([componentID](const CDMovementAIComponent& entry) { return (entry.id == componentID); });
|
||||||
|
if (moveAIComp.empty()) return;
|
||||||
|
|
||||||
|
m_Info.movementType = moveAIComp[0].MovementType;
|
||||||
|
m_Info.wanderRadius = moveAIComp[0].WanderRadius;
|
||||||
|
m_Info.wanderSpeed = moveAIComp[0].WanderSpeed;
|
||||||
|
m_Info.wanderChance = moveAIComp[0].WanderChance;
|
||||||
|
m_Info.wanderDelayMin = moveAIComp[0].WanderDelayMin;
|
||||||
|
m_Info.wanderDelayMax = moveAIComp[0].WanderDelayMax;
|
||||||
|
}
|
||||||
|
|
||||||
void MovementAIComponent::LoadConfigData() {
|
void MovementAIComponent::LoadConfigData() {
|
||||||
|
// The level's wanderRadius over the row's, unless usewanderdb
|
||||||
|
if (m_ComponentID > 0 && !m_Parent->GetVar<bool>(u"usewanderdb")) {
|
||||||
|
const auto wanderOverride = m_Parent->GetVarAs<float>(u"wanderRadius");
|
||||||
|
if (wanderOverride != 0.0f) m_Info.wanderRadius = wanderOverride;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Try and fix the insane values:
|
||||||
|
if (m_Info.wanderRadius > 5.0f) m_Info.wanderRadius *= 0.5f;
|
||||||
|
if (m_Info.wanderRadius > 8.0f) m_Info.wanderRadius = 8.0f;
|
||||||
|
if (m_Info.wanderSpeed > 0.5f) m_Info.wanderSpeed *= 0.5f;
|
||||||
|
|
||||||
SetPath(m_Parent->GetVarAsString(u"attached_path"));
|
SetPath(m_Parent->GetVarAsString(u"attached_path"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ public:
|
|||||||
|
|
||||||
MovementAIComponent(Entity* parentEntity, const int32_t componentID, MovementAIInfo info);
|
MovementAIComponent(Entity* parentEntity, const int32_t componentID, MovementAIInfo info);
|
||||||
|
|
||||||
|
void LoadDataFromTemplate() override;
|
||||||
void LoadConfigData() override;
|
void LoadConfigData() override;
|
||||||
|
|
||||||
void SetPath(const std::string pathName);
|
void SetPath(const std::string pathName);
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
#include "ProximityMonitorComponent.h"
|
#include "ProximityMonitorComponent.h"
|
||||||
|
#include "CDClientManager.h"
|
||||||
|
#include "CDProximityMonitorComponentTable.h"
|
||||||
#include "GameMessages.h"
|
#include "GameMessages.h"
|
||||||
#include "dZoneManager.h"
|
#include "dZoneManager.h"
|
||||||
#include "ControllablePhysicsComponent.h"
|
#include "ControllablePhysicsComponent.h"
|
||||||
@@ -17,6 +19,22 @@ ProximityMonitorComponent::ProximityMonitorComponent(Entity* parent, const int32
|
|||||||
RegisterMsg(&ProximityMonitorComponent::OnGetObjectReportInfo);
|
RegisterMsg(&ProximityMonitorComponent::OnGetObjectReportInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The ProximityMonitorComponent row's radii, "small,large" (one value, as LOT 9833's "4", is both): the rocket
|
||||||
|
// launch radii
|
||||||
|
void ProximityMonitorComponent::LoadDataFromTemplate() {
|
||||||
|
if (m_ComponentID <= 0) return;
|
||||||
|
const auto componentID = m_ComponentID;
|
||||||
|
const auto proxCompData = CDClientManager::GetTable<CDProximityMonitorComponentTable>()->Query([componentID](const CDProximityMonitorComponent& entry) { return (entry.id == componentID); });
|
||||||
|
if (proxCompData.empty()) return;
|
||||||
|
|
||||||
|
const auto radii = GeneralUtils::SplitString(proxCompData[0].Proximities, ',');
|
||||||
|
const auto small = radii.empty() ? std::nullopt : GeneralUtils::TryParse<int32_t>(radii[0]);
|
||||||
|
const auto large = radii.size() > 1 ? GeneralUtils::TryParse<int32_t>(radii[1]) : small;
|
||||||
|
if (!small || !large) return;
|
||||||
|
SetProximityRadius(*small, "rocketSmall");
|
||||||
|
SetProximityRadius(*large, "rocketLarge");
|
||||||
|
}
|
||||||
|
|
||||||
ProximityMonitorComponent::~ProximityMonitorComponent() {
|
ProximityMonitorComponent::~ProximityMonitorComponent() {
|
||||||
for (const auto& en : m_ProximitiesData) {
|
for (const auto& en : m_ProximitiesData) {
|
||||||
if (!en.second) continue;
|
if (!en.second) continue;
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ public:
|
|||||||
|
|
||||||
ProximityMonitorComponent(Entity* parentEntity, const int32_t componentID, int smallRadius = -1, int largeRadius = -1);
|
ProximityMonitorComponent(Entity* parentEntity, const int32_t componentID, int smallRadius = -1, int largeRadius = -1);
|
||||||
~ProximityMonitorComponent() override;
|
~ProximityMonitorComponent() override;
|
||||||
|
|
||||||
|
void LoadDataFromTemplate() override;
|
||||||
void Run(float deltaTime) override;
|
void Run(float deltaTime) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user