refactor(entity): components are made in the client's load order

Entity::Initialize walks ComponentOrderVector::Initialize's list (0x0101f8e0) as ObjectLoader2::DoObjectComponentLoad does; ids a component needs from a later one come from the registry; the trigger is added after the walk. All 15,962 LOTs get the same components as before (LoaderSnapshotTest).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-10-01 06:17:06 -05:00
parent 9c4d14173e
commit b2192e158c
3 changed files with 656 additions and 540 deletions

View File

@@ -211,6 +211,17 @@ Entity::~Entity() {
} }
} }
namespace {
// The order the client makes an object's components in (ComponentOrderVector::Initialize 0x0101f8e0, walked by
// ObjectLoader2::DoObjectComponentLoad 0x0105ebb0; crafting 107 only for game versions above 999)
constexpr auto ClientComponentLoadOrder = [] {
constexpr std::array<uint32_t, 79> types{ 108, 24, 61, 1, 18, 47, 46, 30, 20, 3, 40, 7, 35, 4, 106, 110, 111, 26, 17, 78, 31, 5, 9, 60, 10, 11, 12, 114, 28, 13, 14, 48, 73, 16, 100, 102, 19, 105, 39, 23, 25, 51, 52, 53, 27, 66, 116, 32, 75, 36, 113, 42, 43, 97, 45, 104, 6, 41, 49, 50, 38, 54, 22, 62, 29, 2, 55, 56, 77, 79, 59, 64, 65, 67, 68, 72, 71, 103, 76 };
std::array<eReplicaComponentType, types.size()> order{};
for (size_t i = 0; i < types.size(); i++) order[i] = static_cast<eReplicaComponentType>(types[i]);
return order;
}();
}
void Entity::Initialize() { void Entity::Initialize() {
RegisterMsg(&Entity::MsgRequestServerObjectInfo); RegisterMsg(&Entity::MsgRequestServerObjectInfo);
RegisterMsg(&Entity::MsgDropClientLoot); RegisterMsg(&Entity::MsgDropClientLoot);
@@ -218,14 +229,6 @@ void Entity::Initialize() {
RegisterMsg(&Entity::MsgPickupItem); RegisterMsg(&Entity::MsgPickupItem);
RegisterMsg(&Entity::MsgChildRemoved); RegisterMsg(&Entity::MsgChildRemoved);
RegisterMsg(&Entity::MsgGetFlag); RegisterMsg(&Entity::MsgGetFlag);
/**
* Setup trigger
*/
const auto triggerInfo = GetVarAsString(u"trigger_id");
if (!triggerInfo.empty()) AddComponent<TriggerComponent>(-1, triggerInfo);
/** /**
* Setup groups * Setup groups
*/ */
@@ -273,55 +276,42 @@ void Entity::Initialize() {
} }
/** /**
* Go through all the components and check if this entity has them. * Player components (the client makes them with the character, not from the registry)
*
* Not all components are implemented. Some are represented by a nullptr, as they hold no data.
*/ */
if (m_Character && m_Character->GetParentUser()) { if (m_Character && m_Character->GetParentUser()) {
AddComponent<MissionComponent>(-1)->LoadFromXml(m_Character->GetXMLDoc()); AddComponent<MissionComponent>(-1)->LoadFromXml(m_Character->GetXMLDoc());
} }
/**
* The components in the client's load order (ObjectLoader2::DoObjectComponentLoad 0x0105ebb0 walks
* ComponentOrderVector::Initialize 0x0101f8e0's list): a component that looks at another one finds it made when the
* client's does. Ids a component needs from a later one come from the registry.
*/
const auto petComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PET); const auto petComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PET);
if (petComponentID > 0) { const auto collectibleComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::COLLECTIBLE);
AddComponent<PetComponent>(petComponentID); const auto combatAiID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::BASE_COMBAT_AI);
} // A race car's destroyable has 60 imagination
const bool isRacingCar = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RACING_STATS) > 0;
const auto minigameControlID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MINI_GAME_CONTROL); // If an entity is marked a phantom, simple physics is made into phantom phyics.
if (minigameControlID > 0) { const bool markedAsPhantom = GetVar<bool>(u"markedAsPhantom");
AddComponent<MiniGameControlComponent>(minigameControlID);
}
for (const auto type : ClientComponentLoadOrder) {
switch (type) {
case eReplicaComponentType::POSSESSABLE: {
const auto possessableComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::POSSESSABLE); const auto possessableComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::POSSESSABLE);
if (possessableComponentID > 0) { if (possessableComponentID > 0) {
AddComponent<PossessableComponent>(possessableComponentID); AddComponent<PossessableComponent>(possessableComponentID);
} }
break;
}
case eReplicaComponentType::MODULE_ASSEMBLY: {
const auto moduleAssemblyID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MODULE_ASSEMBLY); const auto moduleAssemblyID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MODULE_ASSEMBLY);
if (moduleAssemblyID > 0) { if (moduleAssemblyID > 0) {
AddComponent<ModuleAssemblyComponent>(moduleAssemblyID); AddComponent<ModuleAssemblyComponent>(moduleAssemblyID);
} }
break;
const auto racingStatsID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RACING_STATS);
if (racingStatsID > 0) {
AddComponent<RacingStatsComponent>(racingStatsID);
} }
case eReplicaComponentType::CONTROLLABLE_PHYSICS: {
const auto lupExhibitID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::LUP_EXHIBIT, -1);
if (lupExhibitID >= 0) {
AddComponent<LUPExhibitComponent>(lupExhibitID);
}
const auto racingControlID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RACING_CONTROL);
if (racingControlID > 0) {
AddComponent<RacingControlComponent>(racingControlID);
}
const auto propertyEntranceComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PROPERTY_ENTRANCE);
if (propertyEntranceComponentID > 0) {
AddComponent<PropertyEntranceComponent>(propertyEntranceComponentID);
}
const auto controllablePhysicsComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::CONTROLLABLE_PHYSICS); const auto controllablePhysicsComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::CONTROLLABLE_PHYSICS);
if (controllablePhysicsComponentID > 0) { if (controllablePhysicsComponentID > 0) {
auto* controllablePhysics = AddComponent<ControllablePhysicsComponent>(controllablePhysicsComponentID); auto* controllablePhysics = AddComponent<ControllablePhysicsComponent>(controllablePhysicsComponentID);
@@ -359,46 +349,39 @@ void Entity::Initialize() {
controllablePhysics->SetRotation(m_DefaultRotation); controllablePhysics->SetRotation(m_DefaultRotation);
} }
} }
break;
// If an entity is marked a phantom, simple physics is made into phantom phyics.
const bool markedAsPhantom = GetVar<bool>(u"markedAsPhantom");
const auto simplePhysicsComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SIMPLE_PHYSICS);
if (!markedAsPhantom && simplePhysicsComponentID > 0) {
AddComponent<SimplePhysicsComponent>(simplePhysicsComponentID);
} }
case eReplicaComponentType::HAVOK_VEHICLE_PHYSICS: {
const auto rigidBodyPhantomPhysicsComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RIGID_BODY_PHANTOM_PHYSICS);
if (rigidBodyPhantomPhysicsComponentID > 0) {
AddComponent<RigidbodyPhantomPhysicsComponent>(rigidBodyPhantomPhysicsComponentID);
}
const auto phantomPhysicsComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PHANTOM_PHYSICS);
if (markedAsPhantom || phantomPhysicsComponentID > 0) {
AddComponent<PhantomPhysicsComponent>(phantomPhysicsComponentID)->SetPhysicsEffectActive(false);
}
const auto havokVehiclePhysicsComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::HAVOK_VEHICLE_PHYSICS); const auto havokVehiclePhysicsComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::HAVOK_VEHICLE_PHYSICS);
if (havokVehiclePhysicsComponentID > 0) { if (havokVehiclePhysicsComponentID > 0) {
auto* havokVehiclePhysicsComponent = AddComponent<HavokVehiclePhysicsComponent>(havokVehiclePhysicsComponentID); auto* havokVehiclePhysicsComponent = AddComponent<HavokVehiclePhysicsComponent>(havokVehiclePhysicsComponentID);
havokVehiclePhysicsComponent->SetPosition(m_DefaultPosition); havokVehiclePhysicsComponent->SetPosition(m_DefaultPosition);
havokVehiclePhysicsComponent->SetRotation(m_DefaultRotation); havokVehiclePhysicsComponent->SetRotation(m_DefaultRotation);
} }
break;
const auto soundTriggerID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SOUND_TRIGGER, -1);
const auto racingSoundTriggerID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RACING_SOUND_TRIGGER, -1);
if (soundTriggerID > -1) {
AddComponent<SoundTriggerComponent>(soundTriggerID);
} else if (racingSoundTriggerID > -1) {
AddComponent<RacingSoundTriggerComponent>(racingSoundTriggerID);
} }
case eReplicaComponentType::RIGID_BODY_PHANTOM_PHYSICS: {
const auto collectibleComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::COLLECTIBLE); const auto rigidBodyPhantomPhysicsComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RIGID_BODY_PHANTOM_PHYSICS);
if (rigidBodyPhantomPhysicsComponentID > 0) {
if (collectibleComponentID > 0) { AddComponent<RigidbodyPhantomPhysicsComponent>(rigidBodyPhantomPhysicsComponentID);
AddComponent<CollectibleComponent>(collectibleComponentID, GetVarAs<int32_t>(u"collectible_id"));
} }
break;
}
case eReplicaComponentType::SIMPLE_PHYSICS: {
const auto simplePhysicsComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SIMPLE_PHYSICS);
if (!markedAsPhantom && simplePhysicsComponentID > 0) {
AddComponent<SimplePhysicsComponent>(simplePhysicsComponentID);
}
break;
}
case eReplicaComponentType::PHANTOM_PHYSICS: {
const auto phantomPhysicsComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PHANTOM_PHYSICS);
if (markedAsPhantom || phantomPhysicsComponentID > 0) {
AddComponent<PhantomPhysicsComponent>(phantomPhysicsComponentID)->SetPhysicsEffectActive(false);
}
break;
}
case eReplicaComponentType::DESTROYABLE: {
/** /**
* The destroyable component. The client makes one (with a buff component in front of it) for a DESTROYABLE * The destroyable component. The client makes one (with a buff component in front of it) for a DESTROYABLE
* registry entry, whose id is the DestructibleComponent row. Collectibles and smashable (is_smashable) objects * registry entry, whose id is the DestructibleComponent row. Collectibles and smashable (is_smashable) objects
@@ -424,7 +407,7 @@ void Entity::Initialize() {
if (componentID > 0) { if (componentID > 0) {
if (!destCompData.empty()) { if (!destCompData.empty()) {
if (HasComponent(eReplicaComponentType::RACING_STATS)) { if (isRacingCar) {
destCompData[0].imagination = 60; destCompData[0].imagination = 60;
} }
@@ -471,8 +454,8 @@ void Entity::Initialize() {
comp->AddFaction(6); //Smashables comp->AddFaction(6); //Smashables
// A race car has 60 imagination, other entities defaults to 0. // A race car has 60 imagination, other entities defaults to 0.
comp->SetImagination(HasComponent(eReplicaComponentType::RACING_STATS) ? 60 : 0); comp->SetImagination(isRacingCar ? 60 : 0);
comp->SetMaxImagination(HasComponent(eReplicaComponentType::RACING_STATS) ? 60 : 0); comp->SetMaxImagination(isRacingCar ? 60 : 0);
} }
} }
@@ -492,7 +475,9 @@ void Entity::Initialize() {
Loot::CacheMatrix(levelLootMatrix.value()); Loot::CacheMatrix(levelLootMatrix.value());
} }
} }
break;
}
case eReplicaComponentType::CHARACTER: {
const auto characterID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::CHARACTER); const auto characterID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::CHARACTER);
if (characterID > 0 || m_Character) { if (characterID > 0 || m_Character) {
// Character Component always has a possessor, level, and forced movement components // Character Component always has a possessor, level, and forced movement components
@@ -508,17 +493,79 @@ void Entity::Initialize() {
AddComponent<GhostComponent>(characterID)->LoadFromXml(m_Character->GetXMLDoc()); AddComponent<GhostComponent>(characterID)->LoadFromXml(m_Character->GetXMLDoc());
} }
break;
}
case eReplicaComponentType::PET: {
if (petComponentID > 0) {
AddComponent<PetComponent>(petComponentID);
}
break;
}
case eReplicaComponentType::INVENTORY: {
const auto inventoryID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::INVENTORY); const auto inventoryID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::INVENTORY);
if (inventoryID > 0 || m_Character) { if (inventoryID > 0 || m_Character) {
AddComponent<InventoryComponent>(inventoryID); AddComponent<InventoryComponent>(inventoryID);
} }
// if this component exists, then we initialize it. it's value is always 0 break;
const auto multiZoneEntranceID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MULTI_ZONE_ENTRANCE, -1); }
if (multiZoneEntranceID > -1) { case eReplicaComponentType::PROXIMITY_MONITOR: {
AddComponent<MultiZoneEntranceComponent>(multiZoneEntranceID); const auto proximityMonitorID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PROXIMITY_MONITOR);
if (proximityMonitorID > 0) {
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;
}
case eReplicaComponentType::MOVEMENT_AI: {
const int movementAIID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MOVEMENT_AI);
if (movementAIID > 0) {
CDMovementAIComponentTable* moveAITable = CDClientManager::GetTable<CDMovementAIComponentTable>();
std::vector<CDMovementAIComponent> moveAIComp = moveAITable->Query([=](CDMovementAIComponent entry) {return (entry.id == movementAIID); });
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) {
MovementAIInfo moveInfo{
.movementType = "",
.wanderRadius = 16,
.wanderSpeed = 2.5f,
.wanderChance = 0,
.wanderDelayMin = 2,
.wanderDelayMax = 5,
};
AddComponent<MovementAIComponent>(-1, moveInfo);
}
break;
}
case eReplicaComponentType::SCRIPT: {
/** /**
* This is a bit of a mess * This is a bit of a mess
* yep i aint touching this * yep i aint touching this
@@ -582,18 +629,40 @@ void Entity::Initialize() {
AddComponent<ScriptComponent>(zoneScriptID, zoneScriptData.script_name, true, false); AddComponent<ScriptComponent>(zoneScriptID, zoneScriptData.script_name, true, false);
} }
} }
break;
}
case eReplicaComponentType::SKILL: {
const auto skillID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SKILL, -1); const auto skillID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SKILL, -1);
if (skillID > -1 || m_Character) { if (skillID > -1 || m_Character) {
auto* const skillComponent = AddComponent<SkillComponent>(skillID); auto* const skillComponent = AddComponent<SkillComponent>(skillID);
if (m_Character) skillComponent->LoadFromXml(m_Character->GetXMLDoc()); if (m_Character) skillComponent->LoadFromXml(m_Character->GetXMLDoc());
} }
break;
const auto combatAiID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::BASE_COMBAT_AI); }
case eReplicaComponentType::BASE_COMBAT_AI: {
if (combatAiID > 0) { if (combatAiID > 0) {
AddComponent<BaseCombatAIComponent>(combatAiID); AddComponent<BaseCombatAIComponent>(combatAiID);
} }
break;
}
case eReplicaComponentType::ITEM: {
PetComponent* petComponent{};
const auto itemID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::ITEM);
// The model (42) comes later in the client's order: a model without a pet has no item component
const bool hasModel = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MODEL, -1) > -1 && petComponentID <= 0;
if (itemID > 0 && !TryGetComponent(eReplicaComponentType::PET, petComponent) && !hasModel) {
AddComponent<ItemComponent>(itemID);
}
break;
}
case eReplicaComponentType::BUILD_BORDER: {
const auto buildBorderID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::BUILD_BORDER, -1);
if (buildBorderID > -1) {
AddComponent<BuildBorderComponent>(buildBorderID);
}
break;
}
case eReplicaComponentType::QUICK_BUILD: {
const auto quickBuildComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::QUICK_BUILD); const auto quickBuildComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::QUICK_BUILD);
if (quickBuildComponentID > 0) { if (quickBuildComponentID > 0) {
auto* const quickBuildComponent = AddComponent<QuickBuildComponent>(quickBuildComponentID); auto* const quickBuildComponent = AddComponent<QuickBuildComponent>(quickBuildComponentID);
@@ -642,12 +711,16 @@ void Entity::Initialize() {
} }
} }
} }
break;
const auto switchID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SWITCH, -1);
if (switchID > -1) {
AddComponent<SwitchComponent>(switchID);
} }
case eReplicaComponentType::MISSION_OFFER: {
const auto missionOfferComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MISSION_OFFER, -1);
if (missionOfferComponentID > -1 || m_Character) {
AddComponent<MissionOfferComponent>(missionOfferComponentID);
}
break;
}
case eReplicaComponentType::VENDOR: {
const auto vendorID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::VENDOR); const auto vendorID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::VENDOR);
const auto donationVendorID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::DONATION_VENDOR, -1); const auto donationVendorID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::DONATION_VENDOR, -1);
const auto achievementVendorID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::ACHIEVEMENT_VENDOR, -1); const auto achievementVendorID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::ACHIEVEMENT_VENDOR, -1);
@@ -658,122 +731,32 @@ void Entity::Initialize() {
} else if (achievementVendorID > -1) { } else if (achievementVendorID > -1) {
AddComponent<AchievementVendorComponent>(achievementVendorID); AddComponent<AchievementVendorComponent>(achievementVendorID);
} }
break;
const auto propertyVendorID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PROPERTY_VENDOR, -1);
if (propertyVendorID > -1) {
AddComponent<PropertyVendorComponent>(propertyVendorID);
} }
case eReplicaComponentType::SHOOTING_GALLERY: {
const auto propertyManagementID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PROPERTY_MANAGEMENT, -1);
if (propertyManagementID > -1) {
AddComponent<PropertyManagementComponent>(propertyManagementID);
}
const auto bouncerID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::BOUNCER, -1);
if (bouncerID > -1) { // you have to determine it like this because all bouncers have a componentID of 0
AddComponent<BouncerComponent>(bouncerID);
}
const auto renderComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RENDER);
if ((renderComponentID > 0 && m_TemplateID != 2365) || m_Character) {
AddComponent<RenderComponent>(renderComponentID);
}
const auto missionOfferComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MISSION_OFFER, -1);
if (missionOfferComponentID > -1 || m_Character) {
AddComponent<MissionOfferComponent>(missionOfferComponentID);
}
const auto buildBorderID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::BUILD_BORDER, -1);
if (buildBorderID > -1) {
AddComponent<BuildBorderComponent>(buildBorderID);
}
// Scripted activity component
const auto scriptedActivityID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SCRIPTED_ACTIVITY, -1);
if (scriptedActivityID > -1) {
AddComponent<ScriptedActivityComponent>(scriptedActivityID);
}
const auto modelID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MODEL, -1);
if (modelID > -1 && !GetComponent<PetComponent>()) {
AddComponent<ModelComponent>(modelID)->LoadBehaviors();
if (!HasComponent(eReplicaComponentType::DESTROYABLE)) {
auto* const destroyableComponent = AddComponent<DestroyableComponent>(-1);
destroyableComponent->SetHealth(1);
destroyableComponent->SetMaxHealth(1.0f);
destroyableComponent->SetFaction(-1, true);
destroyableComponent->SetIsSmashable(true);
}
}
PetComponent* petComponent{};
const auto itemID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::ITEM);
if (itemID > 0 && !TryGetComponent(eReplicaComponentType::PET, petComponent) && !HasComponent(eReplicaComponentType::MODEL)) {
AddComponent<ItemComponent>(itemID);
}
// Shooting gallery component // Shooting gallery component
const auto shootingGalleryComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SHOOTING_GALLERY); const auto shootingGalleryComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SHOOTING_GALLERY);
if (shootingGalleryComponentID > 0) { if (shootingGalleryComponentID > 0) {
AddComponent<ShootingGalleryComponent>(shootingGalleryComponentID); AddComponent<ShootingGalleryComponent>(shootingGalleryComponentID);
} }
break;
const auto propertyID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PROPERTY, -1);
if (propertyID > -1) {
AddComponent<PropertyComponent>(propertyID);
} }
case eReplicaComponentType::SCRIPTED_ACTIVITY: {
const auto rocketID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::ROCKET_LAUNCH); // Scripted activity component
if ((rocketID > 0)) { const auto scriptedActivityID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SCRIPTED_ACTIVITY, -1);
AddComponent<RocketLaunchpadControlComponent>(rocketID); if (scriptedActivityID > -1) {
AddComponent<ScriptedActivityComponent>(scriptedActivityID);
} }
break;
const auto railComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RAIL_ACTIVATOR);
if (railComponentID > 0) {
AddComponent<RailActivatorComponent>(railComponentID);
} }
case eReplicaComponentType::COLLECTIBLE: {
const int movementAIID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MOVEMENT_AI); if (collectibleComponentID > 0) {
if (movementAIID > 0) { AddComponent<CollectibleComponent>(collectibleComponentID, GetVarAs<int32_t>(u"collectible_id"));
CDMovementAIComponentTable* moveAITable = CDClientManager::GetTable<CDMovementAIComponentTable>();
std::vector<CDMovementAIComponent> moveAIComp = moveAITable->Query([=](CDMovementAIComponent entry) {return (entry.id == movementAIID); });
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;
} }
break;
} }
case eReplicaComponentType::MOVING_PLATFORM: {
AddComponent<MovementAIComponent>(movementAIID, moveInfo);
}
} else if (petComponentID > 0 || combatAiID > 0 && GetComponent<BaseCombatAIComponent>()->GetTetherSpeed() > 0) {
MovementAIInfo moveInfo{
.movementType = "",
.wanderRadius = 16,
.wanderSpeed = 2.5f,
.wanderChance = 0,
.wanderDelayMin = 2,
.wanderDelayMax = 5,
};
AddComponent<MovementAIComponent>(-1, moveInfo);
}
const std::string pathName = GetVarAsString(u"attached_path"); const std::string pathName = GetVarAsString(u"attached_path");
const Path* const path = Game::zoneManager->GetZone()->GetPath(pathName); const Path* const path = Game::zoneManager->GetZone()->GetPath(pathName);
@@ -807,20 +790,143 @@ void Entity::Initialize() {
AddComponent<MovingPlatformComponent>(movingPlatformComponentID, pathName); AddComponent<MovingPlatformComponent>(movingPlatformComponentID, pathName);
} }
} }
break;
}
case eReplicaComponentType::LUP_EXHIBIT: {
const auto lupExhibitID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::LUP_EXHIBIT, -1);
if (lupExhibitID >= 0) {
AddComponent<LUPExhibitComponent>(lupExhibitID);
}
break;
}
case eReplicaComponentType::PROPERTY: {
const auto propertyID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PROPERTY, -1);
if (propertyID > -1) {
AddComponent<PropertyComponent>(propertyID);
}
break;
}
case eReplicaComponentType::MODEL: {
const auto modelID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MODEL, -1);
if (modelID > -1 && !GetComponent<PetComponent>()) {
AddComponent<ModelComponent>(modelID)->LoadBehaviors();
if (!HasComponent(eReplicaComponentType::DESTROYABLE)) {
auto* const destroyableComponent = AddComponent<DestroyableComponent>(-1);
destroyableComponent->SetHealth(1);
destroyableComponent->SetMaxHealth(1.0f);
destroyableComponent->SetFaction(-1, true);
destroyableComponent->SetIsSmashable(true);
}
}
break;
}
case eReplicaComponentType::PROPERTY_ENTRANCE: {
const auto propertyEntranceComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PROPERTY_ENTRANCE);
if (propertyEntranceComponentID > 0) {
AddComponent<PropertyEntranceComponent>(propertyEntranceComponentID);
}
break;
}
case eReplicaComponentType::MULTI_ZONE_ENTRANCE: {
// if this component exists, then we initialize it. it's value is always 0
const auto multiZoneEntranceID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MULTI_ZONE_ENTRANCE, -1);
if (multiZoneEntranceID > -1) {
AddComponent<MultiZoneEntranceComponent>(multiZoneEntranceID);
}
break;
}
case eReplicaComponentType::PROPERTY_MANAGEMENT: {
const auto propertyManagementID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PROPERTY_MANAGEMENT, -1);
if (propertyManagementID > -1) {
AddComponent<PropertyManagementComponent>(propertyManagementID);
}
break;
}
case eReplicaComponentType::RAIL_ACTIVATOR: {
const auto railComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RAIL_ACTIVATOR);
if (railComponentID > 0) {
AddComponent<RailActivatorComponent>(railComponentID);
}
break;
}
case eReplicaComponentType::BOUNCER: {
const auto bouncerID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::BOUNCER, -1);
if (bouncerID > -1) { // you have to determine it like this because all bouncers have a componentID of 0
AddComponent<BouncerComponent>(bouncerID);
}
break;
}
case eReplicaComponentType::SWITCH: {
const auto switchID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SWITCH, -1);
if (switchID > -1) {
AddComponent<SwitchComponent>(switchID);
}
break;
}
case eReplicaComponentType::MINI_GAME_CONTROL: {
const auto minigameControlID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MINI_GAME_CONTROL);
if (minigameControlID > 0) {
AddComponent<MiniGameControlComponent>(minigameControlID);
}
break;
}
case eReplicaComponentType::RENDER: {
const auto renderComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RENDER);
if ((renderComponentID > 0 && m_TemplateID != 2365) || m_Character) {
AddComponent<RenderComponent>(renderComponentID);
}
break;
}
case eReplicaComponentType::SOUND_TRIGGER: {
const auto soundTriggerID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SOUND_TRIGGER, -1);
const auto racingSoundTriggerID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RACING_SOUND_TRIGGER, -1);
if (soundTriggerID > -1) {
AddComponent<SoundTriggerComponent>(soundTriggerID);
} else if (racingSoundTriggerID > -1) {
AddComponent<RacingSoundTriggerComponent>(racingSoundTriggerID);
}
break;
}
case eReplicaComponentType::PROPERTY_VENDOR: {
const auto propertyVendorID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PROPERTY_VENDOR, -1);
if (propertyVendorID > -1) {
AddComponent<PropertyVendorComponent>(propertyVendorID);
}
break;
}
case eReplicaComponentType::ROCKET_LAUNCH: {
const auto rocketID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::ROCKET_LAUNCH);
if ((rocketID > 0)) {
AddComponent<RocketLaunchpadControlComponent>(rocketID);
}
break;
}
case eReplicaComponentType::RACING_CONTROL: {
const auto racingControlID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RACING_CONTROL);
if (racingControlID > 0) {
AddComponent<RacingControlComponent>(racingControlID);
}
break;
}
default:
break;
}
}
const auto proximityMonitorID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PROXIMITY_MONITOR); /**
if (proximityMonitorID > 0) { * Components DLU has that the client's load order doesn't make
auto* const proxCompTable = CDClientManager::GetTable<CDProximityMonitorComponentTable>(); */
const auto proxCompData = proxCompTable->Query([proximityMonitorID](const CDProximityMonitorComponent& entry) { return (entry.id == proximityMonitorID); }); const auto racingStatsID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RACING_STATS);
if (proxCompData.size() > 0) { if (racingStatsID > 0) {
// "small,large"; one value (LOT 9833: "4") is both AddComponent<RacingStatsComponent>(racingStatsID);
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);
}
} }
/**
* Added after the walk, as the client does (DoObjectComponentLoad): the trigger from the level config
*/
const auto triggerInfo = GetVarAsString(u"trigger_id");
if (!triggerInfo.empty()) AddComponent<TriggerComponent>(-1, triggerInfo);
// Hacky way to trigger these when the object has had a chance to get constructed // Hacky way to trigger these when the object has had a chance to get constructed
AddCallbackTimer(0, [this]() { AddCallbackTimer(0, [this]() {
this->GetScript()->OnStartup(this); this->GetScript()->OnStartup(this);

View File

@@ -40,6 +40,13 @@ namespace {
constexpr float DEFAULT_BODY_RADIUS = 1.7f; constexpr float DEFAULT_BODY_RADIUS = 1.7f;
} }
float BaseCombatAIComponent::TetherSpeedOf(const int32_t componentID) {
auto query = CDClientDatabase::CreatePreppedStmt("SELECT tetherSpeed FROM BaseCombatAIComponent WHERE id = ?;");
query.bind(1, static_cast<int>(componentID));
auto result = query.execQuery();
return !result.eof() && !result.fieldIsNull("tetherSpeed") ? result.getFloatField("tetherSpeed") : 4.0f;
}
BaseCombatAIComponent::BaseCombatAIComponent(Entity* parent, const int32_t componentID) : Component(parent, componentID) { BaseCombatAIComponent::BaseCombatAIComponent(Entity* parent, const int32_t componentID) : Component(parent, componentID) {
RegisterMsg(&BaseCombatAIComponent::MsgGetObjectReportInfo); RegisterMsg(&BaseCombatAIComponent::MsgGetObjectReportInfo);
m_Target = LWOOBJID_EMPTY; m_Target = LWOOBJID_EMPTY;

View File

@@ -52,6 +52,9 @@ public:
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::BASE_COMBAT_AI; static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::BASE_COMBAT_AI;
BaseCombatAIComponent(Entity* parentEntity, int32_t componentID); BaseCombatAIComponent(Entity* parentEntity, int32_t componentID);
// The tether speed a BaseCombatAIComponent row gives (4 without one), before the component exists
static float TetherSpeedOf(int32_t componentID);
~BaseCombatAIComponent() override; ~BaseCombatAIComponent() override;
void Update(float deltaTime) override; void Update(float deltaTime) override;