Collectible, Item, further re-implement initialize

This commit is contained in:
David Markowitz 2023-06-10 04:46:48 -07:00
parent cebe3c732a
commit b91f84d884
11 changed files with 285 additions and 254 deletions

View File

@ -53,6 +53,7 @@
#include "VendorComponent.h" #include "VendorComponent.h"
#include "RocketLaunchpadControlComponent.h" #include "RocketLaunchpadControlComponent.h"
#include "PropertyComponent.h" #include "PropertyComponent.h"
#include "CollectibleComponent.h"
#include "BaseCombatAIComponent.h" #include "BaseCombatAIComponent.h"
#include "PropertyManagementComponent.h" #include "PropertyManagementComponent.h"
#include "PropertyVendorComponent.h" #include "PropertyVendorComponent.h"
@ -76,6 +77,7 @@
#include "eReplicaPacketType.h" #include "eReplicaPacketType.h"
#include "RacingStatsComponent.h" #include "RacingStatsComponent.h"
#include "MinigameControlComponent.h" #include "MinigameControlComponent.h"
#include "ItemComponent.h"
// Table includes // Table includes
#include "CDComponentsRegistryTable.h" #include "CDComponentsRegistryTable.h"
@ -130,7 +132,6 @@ Entity::Entity(const LWOOBJID& objectID, EntityInfo info, Entity* parentEntity)
m_ParentEntity = parentEntity; m_ParentEntity = parentEntity;
m_Character = nullptr; m_Character = nullptr;
m_GMLevel = eGameMasterLevel::CIVILIAN; m_GMLevel = eGameMasterLevel::CIVILIAN;
m_CollectibleID = 0;
m_NetworkID = 0; m_NetworkID = 0;
m_Observers = 0; m_Observers = 0;
m_OwnerOverride = LWOOBJID_EMPTY; m_OwnerOverride = LWOOBJID_EMPTY;
@ -170,17 +171,40 @@ Entity::~Entity() {
if (m_ParentEntity) m_ParentEntity->RemoveChild(this); if (m_ParentEntity) m_ParentEntity->RemoveChild(this);
} }
void Entity::ApplyComponentWhitelist(TemplateComponents& components) { void Entity::ApplyComponentWhitelist(TemplateComponents& components) const {
const auto whitelistIndex = GetVar<int32_t>(u"componentWhitelist"); const auto whitelistIndex = GetVar<int32_t>(u"componentWhitelist");
if (whitelistIndex < 0 || whitelistIndex >= m_ComponentWhitelists.size()) return; if (whitelistIndex < 0 || whitelistIndex >= m_ComponentWhitelists.size()) return;
const auto& whitelist = m_ComponentWhitelists.at(whitelistIndex); const auto& whitelist = m_ComponentWhitelists.at(whitelistIndex);
const auto endRange = std::remove_if(components.begin(), components.end(), [&whitelist](const auto& componentCandidate) { const auto endRange = std::remove_if(components.begin(), components.end(), [&whitelist](const auto& componentCandidate) {
return std::find(whitelist.begin(), whitelist.end(), componentCandidate.first) == whitelist.end(); return std::find(whitelist.begin(), whitelist.end(), componentCandidate.first) == whitelist.end();
}); });
components.erase(endRange, components.end()); components.erase(endRange, components.end());
} }
void Entity::ApplyComponentBlacklist(TemplateComponents& components) const {
bool hasPetComponent = std::find_if(components.begin(), components.end(), [](const auto& componentCandidate) {
return componentCandidate.first == eReplicaComponentType::PET;
}) != components.end();
if (hasPetComponent) {
auto toRemove = std::remove_if(components.begin(), components.end(), [](const auto& componentCandidate) {
return componentCandidate.first == eReplicaComponentType::MODEL_BEHAVIOR || componentCandidate.first == eReplicaComponentType::ITEM;
});
components.erase(toRemove, components.end());
}
}
void Entity::ApplyComponentConfig(TemplateComponents& components) const {
if (GetVar<bool>(u"markedAsPhantom")) {
auto toRemove = std::remove_if(components.begin(), components.end(), [](const auto& componentCandidate) {
return componentCandidate.first == eReplicaComponentType::SIMPLE_PHYSICS ||
componentCandidate.first == eReplicaComponentType::PHANTOM_PHYSICS; // Just make sure we dont have phantom physics already
});
components.erase(toRemove, components.end());
components.emplace_back(eReplicaComponentType::PHANTOM_PHYSICS, 0U);
}
}
void Entity::Initialize() { void Entity::Initialize() {
// A few edge cases to tackle first // A few edge cases to tackle first
const auto triggerInfo = GetVarAsString(u"trigger_id"); const auto triggerInfo = GetVarAsString(u"trigger_id");
@ -206,6 +230,8 @@ void Entity::Initialize() {
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);
ApplyComponentConfig(components);
for (const auto& [componentTemplate, componentId] : components) { for (const auto& [componentTemplate, componentId] : components) {
switch (componentTemplate) { switch (componentTemplate) {
case eReplicaComponentType::CONTROLLABLE_PHYSICS: case eReplicaComponentType::CONTROLLABLE_PHYSICS:
@ -215,162 +241,87 @@ void Entity::Initialize() {
AddComponent<RenderComponent>(); AddComponent<RenderComponent>();
break; break;
case eReplicaComponentType::SIMPLE_PHYSICS: case eReplicaComponentType::SIMPLE_PHYSICS:
AddComponent<SimplePhysicsComponent>(componentId);
break; break;
case eReplicaComponentType::CHARACTER: case eReplicaComponentType::CHARACTER:
AddComponent<CharacterComponent>(m_Character); AddComponent<CharacterComponent>(m_Character);
AddComponent<MissionComponent>(); AddComponent<MissionComponent>();
break; AddComponent<PossessorComponent>();
case eReplicaComponentType::SCRIPT: AddComponent<LevelProgressionComponent>();
AddComponent<PlayerForcedMovementComponent>();
break; break;
case eReplicaComponentType::BOUNCER: case eReplicaComponentType::BOUNCER:
AddComponent<BouncerComponent>(); AddComponent<BouncerComponent>();
break; break;
case eReplicaComponentType::DESTROYABLE:
break;
case eReplicaComponentType::GHOST:
break;
case eReplicaComponentType::SKILL: case eReplicaComponentType::SKILL:
AddComponent<SkillComponent>(); AddComponent<SkillComponent>();
break; break;
case eReplicaComponentType::SPAWN:
break;
case eReplicaComponentType::ITEM: case eReplicaComponentType::ITEM:
break; AddComponent<ItemComponent>();
case eReplicaComponentType::MODULAR_BUILD:
break;
case eReplicaComponentType::BUILD_CONTROLLER:
break;
case eReplicaComponentType::BUILD_ACTIVATOR:
break;
case eReplicaComponentType::ICON_ONLY:
break; break;
case eReplicaComponentType::VENDOR: case eReplicaComponentType::VENDOR:
AddComponent<VendorComponent>(); AddComponent<VendorComponent>();
break; break;
case eReplicaComponentType::INVENTORY: case eReplicaComponentType::INVENTORY:
break; AddComponent<InventoryComponent>();
case eReplicaComponentType::PROJECTILE_PHYSICS:
break; break;
case eReplicaComponentType::SHOOTING_GALLERY: case eReplicaComponentType::SHOOTING_GALLERY:
AddComponent<ShootingGalleryComponent>(); AddComponent<ShootingGalleryComponent>();
break; break;
case eReplicaComponentType::RIGID_BODY_PHANTOM_PHYSICS: case eReplicaComponentType::RIGID_BODY_PHANTOM_PHYSICS:
break; AddComponent<RigidbodyPhantomPhysicsComponent>();
case eReplicaComponentType::DROP_EFFECT:
break;
case eReplicaComponentType::CHEST:
break; break;
case eReplicaComponentType::COLLECTIBLE: case eReplicaComponentType::COLLECTIBLE:
break; AddComponent<CollectibleComponent>();
case eReplicaComponentType::BLUEPRINT:
break; break;
case eReplicaComponentType::MOVING_PLATFORM: case eReplicaComponentType::MOVING_PLATFORM:
AddComponent<MovingPlatformComponent>(GetVarAsString(u"attached_path"));
break; break;
case eReplicaComponentType::PET: case eReplicaComponentType::PET:
AddComponent<PetComponent>(componentId); AddComponent<PetComponent>(componentId);
break; break;
case eReplicaComponentType::PLATFORM_BOUNDARY:
break;
case eReplicaComponentType::MODULE:
break;
case eReplicaComponentType::JETPACKPAD:
break;
case eReplicaComponentType::HAVOK_VEHICLE_PHYSICS: case eReplicaComponentType::HAVOK_VEHICLE_PHYSICS:
break; AddComponent<HavokVehiclePhysicsComponent>();
case eReplicaComponentType::MOVEMENT_AI:
break;
case eReplicaComponentType::EXHIBIT:
break;
case eReplicaComponentType::OVERHEAD_ICON:
break;
case eReplicaComponentType::PET_CONTROL:
break;
case eReplicaComponentType::MINIFIG:
break; break;
case eReplicaComponentType::PROPERTY: case eReplicaComponentType::PROPERTY:
AddComponent<PropertyComponent>(); AddComponent<PropertyComponent>();
break; break;
case eReplicaComponentType::PET_CREATOR:
break;
case eReplicaComponentType::MODEL_BUILDER:
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:
break; AddComponent<PhantomPhysicsComponent>();
case eReplicaComponentType::SPRINGPAD:
break; break;
case eReplicaComponentType::MODEL_BEHAVIOR: case eReplicaComponentType::MODEL_BEHAVIOR:
AddComponent<ModelBehaviorComponent>();
break; break;
case eReplicaComponentType::PROPERTY_ENTRANCE: case eReplicaComponentType::PROPERTY_ENTRANCE:
AddComponent<PropertyEntranceComponent>(componentId); AddComponent<PropertyEntranceComponent>(componentId);
break; break;
case eReplicaComponentType::FX:
break;
case eReplicaComponentType::PROPERTY_MANAGEMENT: case eReplicaComponentType::PROPERTY_MANAGEMENT:
AddComponent<PropertyManagementComponent>(); AddComponent<PropertyManagementComponent>();
break; break;
case eReplicaComponentType::VEHICLE_PHYSICS:
break;
case eReplicaComponentType::PHYSICS_SYSTEM:
break;
case eReplicaComponentType::QUICK_BUILD:
break;
case eReplicaComponentType::SWITCH: case eReplicaComponentType::SWITCH:
AddComponent<SwitchComponent>(); AddComponent<SwitchComponent>();
break; break;
case eReplicaComponentType::MINIGAME_CONTROL: case eReplicaComponentType::MINIGAME_CONTROL:
AddComponent<MinigameControlComponent>(); AddComponent<MinigameControlComponent>();
break; break;
case eReplicaComponentType::CHANGLING_BUILD:
break;
case eReplicaComponentType::CHOICE_BUILD:
break;
case eReplicaComponentType::PACKAGE:
break;
case eReplicaComponentType::SOUND_REPEATER:
break;
case eReplicaComponentType::SOUND_AMBIENT_2D:
break;
case eReplicaComponentType::SOUND_AMBIENT_3D:
break;
case eReplicaComponentType::PRECONDITION:
break;
case eReplicaComponentType::FLAG:
break;
case eReplicaComponentType::CUSTOM_BUILD_ASSEMBLY:
break;
case eReplicaComponentType::BASE_COMBAT_AI: case eReplicaComponentType::BASE_COMBAT_AI:
AddComponent<BaseCombatAIComponent>(componentId); AddComponent<BaseCombatAIComponent>(componentId);
break; break;
case eReplicaComponentType::MODULE_ASSEMBLY: case eReplicaComponentType::MODULE_ASSEMBLY:
AddComponent<ModuleAssemblyComponent>(); AddComponent<ModuleAssemblyComponent>();
break; break;
case eReplicaComponentType::SHOWCASE_MODEL_HANDLER:
break;
case eReplicaComponentType::RACING_MODULE:
break;
case eReplicaComponentType::GENERIC_ACTIVATOR:
break;
case eReplicaComponentType::PROPERTY_VENDOR: case eReplicaComponentType::PROPERTY_VENDOR:
AddComponent<PropertyVendorComponent>(); AddComponent<PropertyVendorComponent>();
break; break;
case eReplicaComponentType::HF_LIGHT_DIRECTION_GADGET:
break;
case eReplicaComponentType::ROCKET_LAUNCHPAD_CONTROL: case eReplicaComponentType::ROCKET_LAUNCHPAD_CONTROL:
break; AddComponent<RocketLaunchpadControlComponent>(componentId);
case eReplicaComponentType::ROCKET_ANIMATION_CONTROL:
break;
case eReplicaComponentType::TRIGGER:
break;
case eReplicaComponentType::DROPPED_LOOT:
break; break;
case eReplicaComponentType::RACING_CONTROL: case eReplicaComponentType::RACING_CONTROL:
AddComponent<RacingControlComponent>(); AddComponent<RacingControlComponent>();
break; break;
case eReplicaComponentType::FACTION_TRIGGER:
break;
case eReplicaComponentType::MISSION_OFFER: case eReplicaComponentType::MISSION_OFFER:
AddComponent<MissionOfferComponent>(GetLOT()); AddComponent<MissionOfferComponent>(GetLOT());
break; break;
@ -380,92 +331,104 @@ void Entity::Initialize() {
case eReplicaComponentType::LUP_EXHIBIT: case eReplicaComponentType::LUP_EXHIBIT:
AddComponent<LUPExhibitComponent>(); AddComponent<LUPExhibitComponent>();
break; break;
case eReplicaComponentType::BBB:
break;
case eReplicaComponentType::SOUND_TRIGGER: case eReplicaComponentType::SOUND_TRIGGER:
break; AddComponent<SoundTriggerComponent>();
case eReplicaComponentType::PROXIMITY_MONITOR:
break;
case eReplicaComponentType::RACING_SOUND_TRIGGER:
break;
case eReplicaComponentType::CHAT_BUBBLE:
break;
case eReplicaComponentType::FRIENDS_LIST:
break;
case eReplicaComponentType::GUILD:
break;
case eReplicaComponentType::LOCAL_SYSTEM:
break;
case eReplicaComponentType::MISSION:
break;
case eReplicaComponentType::MUTABLE_MODEL_BEHAVIORS:
break;
case eReplicaComponentType::PATHFINDING:
break;
case eReplicaComponentType::PET_TAMING_CONTROL:
break;
case eReplicaComponentType::PROPERTY_EDITOR:
break;
case eReplicaComponentType::SKINNED_RENDER:
break;
case eReplicaComponentType::SLASH_COMMAND:
break;
case eReplicaComponentType::STATUS_EFFECT:
break;
case eReplicaComponentType::TEAMS:
break;
case eReplicaComponentType::TEXT_EFFECT:
break;
case eReplicaComponentType::TRADE:
break;
case eReplicaComponentType::USER_CONTROL:
break;
case eReplicaComponentType::IGNORE_LIST:
break; break;
case eReplicaComponentType::MULTI_ZONE_ENTRANCE: case eReplicaComponentType::MULTI_ZONE_ENTRANCE:
AddComponent<MultiZoneEntranceComponent>();
break; break;
case eReplicaComponentType::BUFF: case eReplicaComponentType::BUFF:
break; AddComponent<BuffComponent>();
case eReplicaComponentType::INTERACTION_MANAGER:
break;
case eReplicaComponentType::DONATION_VENDOR:
break;
case eReplicaComponentType::COMBAT_MEDIATOR:
break;
case eReplicaComponentType::ACHIEVEMENT_VENDOR:
break;
case eReplicaComponentType::GATE_RUSH_CONTROL:
break; break;
case eReplicaComponentType::RAIL_ACTIVATOR: case eReplicaComponentType::RAIL_ACTIVATOR:
break; AddComponent<RailActivatorComponent>(componentId);
case eReplicaComponentType::ROLLER:
break;
case eReplicaComponentType::PLAYER_FORCED_MOVEMENT:
break;
case eReplicaComponentType::CRAFTING:
break; break;
case eReplicaComponentType::POSSESSABLE: case eReplicaComponentType::POSSESSABLE:
AddComponent<PossessableComponent>(componentId); AddComponent<PossessableComponent>(componentId);
break; break;
case eReplicaComponentType::LEVEL_PROGRESSION:
break;
case eReplicaComponentType::POSSESSOR:
break;
case eReplicaComponentType::MOUNT_CONTROL:
break;
case eReplicaComponentType::UNKNOWN_112:
break;
case eReplicaComponentType::PROPERTY_PLAQUE:
break;
case eReplicaComponentType::BUILD_BORDER: case eReplicaComponentType::BUILD_BORDER:
AddComponent<BuildBorderComponent>(); AddComponent<BuildBorderComponent>();
break; break;
case eReplicaComponentType::SCRIPT:
case eReplicaComponentType::DESTROYABLE:
case eReplicaComponentType::GHOST:
case eReplicaComponentType::SPAWN:
case eReplicaComponentType::MODULAR_BUILD:
case eReplicaComponentType::BUILD_CONTROLLER:
case eReplicaComponentType::BUILD_ACTIVATOR:
case eReplicaComponentType::ICON_ONLY:
case eReplicaComponentType::PROJECTILE_PHYSICS:
case eReplicaComponentType::DROP_EFFECT:
case eReplicaComponentType::CHEST:
case eReplicaComponentType::BLUEPRINT:
case eReplicaComponentType::PLATFORM_BOUNDARY:
case eReplicaComponentType::MODULE:
case eReplicaComponentType::JETPACKPAD:
case eReplicaComponentType::MOVEMENT_AI:
case eReplicaComponentType::EXHIBIT:
case eReplicaComponentType::OVERHEAD_ICON:
case eReplicaComponentType::PET_CONTROL:
case eReplicaComponentType::MINIFIG:
case eReplicaComponentType::PET_CREATOR:
case eReplicaComponentType::MODEL_BUILDER:
case eReplicaComponentType::SPRINGPAD:
case eReplicaComponentType::FX:
case eReplicaComponentType::VEHICLE_PHYSICS:
case eReplicaComponentType::PHYSICS_SYSTEM:
case eReplicaComponentType::QUICK_BUILD:
case eReplicaComponentType::CHANGLING_BUILD:
case eReplicaComponentType::CHOICE_BUILD:
case eReplicaComponentType::PACKAGE:
case eReplicaComponentType::SOUND_REPEATER:
case eReplicaComponentType::SOUND_AMBIENT_2D:
case eReplicaComponentType::SOUND_AMBIENT_3D:
case eReplicaComponentType::PRECONDITION:
case eReplicaComponentType::FLAG:
case eReplicaComponentType::CUSTOM_BUILD_ASSEMBLY:
case eReplicaComponentType::SHOWCASE_MODEL_HANDLER:
case eReplicaComponentType::RACING_MODULE:
case eReplicaComponentType::GENERIC_ACTIVATOR:
case eReplicaComponentType::HF_LIGHT_DIRECTION_GADGET:
case eReplicaComponentType::ROCKET_ANIMATION_CONTROL:
case eReplicaComponentType::TRIGGER:
case eReplicaComponentType::DROPPED_LOOT:
case eReplicaComponentType::FACTION_TRIGGER:
case eReplicaComponentType::BBB:
case eReplicaComponentType::PROXIMITY_MONITOR:
case eReplicaComponentType::RACING_SOUND_TRIGGER:
case eReplicaComponentType::CHAT_BUBBLE:
case eReplicaComponentType::FRIENDS_LIST:
case eReplicaComponentType::GUILD:
case eReplicaComponentType::LOCAL_SYSTEM:
case eReplicaComponentType::MISSION:
case eReplicaComponentType::MUTABLE_MODEL_BEHAVIORS:
case eReplicaComponentType::PATHFINDING:
case eReplicaComponentType::PET_TAMING_CONTROL:
case eReplicaComponentType::PROPERTY_EDITOR:
case eReplicaComponentType::SKINNED_RENDER:
case eReplicaComponentType::SLASH_COMMAND:
case eReplicaComponentType::STATUS_EFFECT:
case eReplicaComponentType::TEAMS:
case eReplicaComponentType::TEXT_EFFECT:
case eReplicaComponentType::TRADE:
case eReplicaComponentType::USER_CONTROL:
case eReplicaComponentType::IGNORE_LIST:
case eReplicaComponentType::INTERACTION_MANAGER:
case eReplicaComponentType::DONATION_VENDOR:
case eReplicaComponentType::COMBAT_MEDIATOR:
case eReplicaComponentType::ACHIEVEMENT_VENDOR:
case eReplicaComponentType::GATE_RUSH_CONTROL:
case eReplicaComponentType::ROLLER:
case eReplicaComponentType::PLAYER_FORCED_MOVEMENT:
case eReplicaComponentType::CRAFTING:
case eReplicaComponentType::LEVEL_PROGRESSION:
case eReplicaComponentType::POSSESSOR:
case eReplicaComponentType::MOUNT_CONTROL:
case eReplicaComponentType::UNKNOWN_112:
case eReplicaComponentType::PROPERTY_PLAQUE:
case eReplicaComponentType::UNKNOWN_115: case eReplicaComponentType::UNKNOWN_115:
break;
case eReplicaComponentType::CULLING_PLANE: case eReplicaComponentType::CULLING_PLANE:
break;
case eReplicaComponentType::NUMBER_OF_COMPONENTS: case eReplicaComponentType::NUMBER_OF_COMPONENTS:
break;
case eReplicaComponentType::INVALID: case eReplicaComponentType::INVALID:
default: default:
Game::logger->Log("Entity", "blah %i %i", componentId, m_TemplateID); Game::logger->Log("Entity", "blah %i %i", componentId, m_TemplateID);

View File

@ -57,8 +57,15 @@ public:
explicit Entity(const LWOOBJID& objectID, EntityInfo info, Entity* parentEntity = nullptr); explicit Entity(const LWOOBJID& objectID, EntityInfo info, Entity* parentEntity = nullptr);
virtual ~Entity(); virtual ~Entity();
void ApplyComponentWhitelist(TemplateComponents& components); void ApplyComponentWhitelist(TemplateComponents& components) const;
static const std::vector<ComponentWhitelist>& GetComponentWhitelists() { return m_ComponentWhitelists; } static const std::vector<ComponentWhitelist>& GetComponentWhitelists() { return m_ComponentWhitelists; }
// There are some very very edge cases we need to take care of with what components
// are kept and removed. Here is where we take care of those cases.
void ApplyComponentBlacklist(TemplateComponents& components) const;
// For adding and removing components based on LDF keys
void ApplyComponentConfig(TemplateComponents& components) const;
virtual void Initialize(); virtual void Initialize();
bool operator==(const Entity& other) const; bool operator==(const Entity& other) const;
@ -77,8 +84,6 @@ public:
eGameMasterLevel GetGMLevel() const { return m_GMLevel; } eGameMasterLevel GetGMLevel() const { return m_GMLevel; }
void SetGMLevel(const eGameMasterLevel value); void SetGMLevel(const eGameMasterLevel value);
const uint32_t GetCollectibleID() const { return m_CollectibleID; }
Entity* GetParentEntity() const { return m_ParentEntity; } Entity* GetParentEntity() const { return m_ParentEntity; }
const std::vector<std::string>& GetGroups() { return m_Groups; }; const std::vector<std::string>& GetGroups() { return m_Groups; };
@ -317,7 +322,6 @@ protected:
Entity* m_ParentEntity; //For spawners and the like Entity* m_ParentEntity; //For spawners and the like
std::vector<Entity*> m_ChildEntities; std::vector<Entity*> m_ChildEntities;
eGameMasterLevel m_GMLevel; eGameMasterLevel m_GMLevel;
uint32_t m_CollectibleID;
std::vector<std::string> m_Groups; std::vector<std::string> m_Groups;
uint16_t m_NetworkID; uint16_t m_NetworkID;
std::vector<std::function<void()>> m_DieCallbacks; std::vector<std::function<void()>> m_DieCallbacks;

View File

@ -1,4 +1,4 @@
Entity::Initialize() { // Entity::Initialize() {
/** /**
* Setup trigger * Setup trigger
*/ */
@ -33,7 +33,7 @@ Entity::Initialize() {
* Special case for BBB models. They have components not corresponding to the registry. * Special case for BBB models. They have components not corresponding to the registry.
*/ */
if (m_TemplateID == 14) { // if (m_TemplateID == 14) {
// const auto simplePhysicsComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SIMPLE_PHYSICS); // const auto simplePhysicsComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SIMPLE_PHYSICS);
// SimplePhysicsComponent* comp = new SimplePhysicsComponent(simplePhysicsComponentID, this); // SimplePhysicsComponent* comp = new SimplePhysicsComponent(simplePhysicsComponentID, this);
@ -52,8 +52,8 @@ Entity::Initialize() {
destroyableComponent->SetIsSmashable(true); destroyableComponent->SetIsSmashable(true);
// m_Components.insert(std::make_pair(eReplicaComponentType::DESTROYABLE, destroyableComponent)); // m_Components.insert(std::make_pair(eReplicaComponentType::DESTROYABLE, destroyableComponent));
// We have all our components. // We have all our components.
return; // return;
} // }
/** /**
* Go through all the components and check if this entity has them. * Go through all the components and check if this entity has them.
@ -142,50 +142,50 @@ Entity::Initialize() {
// } // }
// If an entity is marked a phantom, simple physics is made into phantom phyics. // If an entity is marked a phantom, simple physics is made into phantom phyics.
bool markedAsPhantom = GetVar<bool>(u"markedAsPhantom"); // bool markedAsPhantom = GetVar<bool>(u"markedAsPhantom");
const auto simplePhysicsComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SIMPLE_PHYSICS); // const auto simplePhysicsComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SIMPLE_PHYSICS);
if (!markedAsPhantom && simplePhysicsComponentID > 0) { // if (!markedAsPhantom && simplePhysicsComponentID > 0) {
SimplePhysicsComponent* comp = new SimplePhysicsComponent(simplePhysicsComponentID, this); // SimplePhysicsComponent* comp = new SimplePhysicsComponent(simplePhysicsComponentID, this);
m_Components.insert(std::make_pair(eReplicaComponentType::SIMPLE_PHYSICS, comp)); // m_Components.insert(std::make_pair(eReplicaComponentType::SIMPLE_PHYSICS, comp));
} // }
if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RIGID_BODY_PHANTOM_PHYSICS) > 0) { // if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RIGID_BODY_PHANTOM_PHYSICS) > 0) {
RigidbodyPhantomPhysicsComponent* comp = new RigidbodyPhantomPhysicsComponent(this); // RigidbodyPhantomPhysicsComponent* comp = new RigidbodyPhantomPhysicsComponent(this);
m_Components.insert(std::make_pair(eReplicaComponentType::RIGID_BODY_PHANTOM_PHYSICS, comp)); // m_Components.insert(std::make_pair(eReplicaComponentType::RIGID_BODY_PHANTOM_PHYSICS, comp));
} // }
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) {
auto* comp = new SoundTriggerComponent(this); // auto* comp = new SoundTriggerComponent(this);
m_Components.insert(std::make_pair(eReplicaComponentType::SOUND_TRIGGER, comp)); // m_Components.insert(std::make_pair(eReplicaComponentType::SOUND_TRIGGER, comp));
} // }
//Also check for the collectible id: //Also check for the collectible id:
m_CollectibleID = GetVarAs<int32_t>(u"collectible_id"); // m_CollectibleID = GetVarAs<int32_t>(u"collectible_id");
if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::BUFF) > 0) { // if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::BUFF) > 0) {
BuffComponent* comp = new BuffComponent(this); // BuffComponent* comp = new BuffComponent(this);
m_Components.insert(std::make_pair(eReplicaComponentType::BUFF, comp)); // m_Components.insert(std::make_pair(eReplicaComponentType::BUFF, comp));
} // }
int collectibleComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::COLLECTIBLE); // int collectibleComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::COLLECTIBLE);
if (collectibleComponentID > 0) { // if (collectibleComponentID > 0) {
m_Components.insert(std::make_pair(eReplicaComponentType::COLLECTIBLE, nullptr)); // m_Components.insert(std::make_pair(eReplicaComponentType::COLLECTIBLE, nullptr));
} // }
/** /**
* Multiple components require the destructible component. * Multiple components require the destructible component.
@ -277,33 +277,33 @@ Entity::Initialize() {
m_Components.insert(std::make_pair(eReplicaComponentType::DESTROYABLE, comp)); m_Components.insert(std::make_pair(eReplicaComponentType::DESTROYABLE, comp));
} }
if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::CHARACTER) > 0 || m_Character) { // if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::CHARACTER) > 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
m_Components.insert(std::make_pair(eReplicaComponentType::POSSESSOR, new PossessorComponent(this))); // m_Components.insert(std::make_pair(eReplicaComponentType::POSSESSOR, new PossessorComponent(this)));
// load in the xml for the level // load in the xml for the level
auto* levelComp = new LevelProgressionComponent(this); // auto* levelComp = new LevelProgressionComponent(this);
levelComp->LoadFromXml(m_Character->GetXMLDoc()); // levelComp->LoadFromXml(m_Character->GetXMLDoc());
m_Components.insert(std::make_pair(eReplicaComponentType::LEVEL_PROGRESSION, levelComp)); // m_Components.insert(std::make_pair(eReplicaComponentType::LEVEL_PROGRESSION, levelComp));
m_Components.insert(std::make_pair(eReplicaComponentType::PLAYER_FORCED_MOVEMENT, new PlayerForcedMovementComponent(this))); // m_Components.insert(std::make_pair(eReplicaComponentType::PLAYER_FORCED_MOVEMENT, new PlayerForcedMovementComponent(this)));
CharacterComponent* charComp = new CharacterComponent(this, m_Character); // CharacterComponent* charComp = new CharacterComponent(this, m_Character);
charComp->LoadFromXml(m_Character->GetXMLDoc()); // charComp->LoadFromXml(m_Character->GetXMLDoc());
m_Components.insert(std::make_pair(eReplicaComponentType::CHARACTER, charComp)); // m_Components.insert(std::make_pair(eReplicaComponentType::CHARACTER, charComp));
} // }
if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::INVENTORY) > 0 || m_Character) { // if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::INVENTORY) > 0 || m_Character) {
InventoryComponent* comp = nullptr; // InventoryComponent* comp = nullptr;
if (m_Character) comp = new InventoryComponent(this, m_Character->GetXMLDoc()); // if (m_Character) comp = new InventoryComponent(this, m_Character->GetXMLDoc());
else comp = new InventoryComponent(this); // else comp = new InventoryComponent(this);
m_Components.insert(std::make_pair(eReplicaComponentType::INVENTORY, comp)); // m_Components.insert(std::make_pair(eReplicaComponentType::INVENTORY, comp));
} // }
// if this component exists, then we initialize it. it's value is always 0 // if this component exists, then we initialize it. it's value is always 0
if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::ROCKET_LAUNCH_LUP, -1) != -1) { // if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::ROCKET_LAUNCH_LUP, -1) != -1) {
auto comp = new RocketLaunchLupComponent(this); // auto comp = new RocketLaunchLupComponent(this);
m_Components.insert(std::make_pair(eReplicaComponentType::ROCKET_LAUNCH_LUP, comp)); // m_Components.insert(std::make_pair(eReplicaComponentType::ROCKET_LAUNCH_LUP, comp));
} // }
/** /**
* This is a bit of a mess * This is a bit of a mess
@ -469,8 +469,8 @@ Entity::Initialize() {
// m_Components.insert(std::make_pair(eReplicaComponentType::SCRIPTED_ACTIVITY, new ScriptedActivityComponent(this, scriptedActivityID))); // m_Components.insert(std::make_pair(eReplicaComponentType::SCRIPTED_ACTIVITY, new ScriptedActivityComponent(this, scriptedActivityID)));
// } // }
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);
@ -479,31 +479,31 @@ Entity::Initialize() {
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;
if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::ITEM) > 0 && !TryGetComponent(eReplicaComponentType::PET, petComponent) && !HasComponent(eReplicaComponentType::MODEL)) { // if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::ITEM) > 0 && !TryGetComponent(eReplicaComponentType::PET, petComponent) && !HasComponent(eReplicaComponentType::MODEL)) {
m_Components.insert(std::make_pair(eReplicaComponentType::ITEM, nullptr)); // m_Components.insert(std::make_pair(eReplicaComponentType::ITEM, nullptr));
} // }
// Shooting gallery component // Shooting gallery component
// if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SHOOTING_GALLERY) > 0) { // if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SHOOTING_GALLERY) > 0) {
// m_Components.insert(std::make_pair(eReplicaComponentType::SHOOTING_GALLERY, new ShootingGalleryComponent(this))); // m_Components.insert(std::make_pair(eReplicaComponentType::SHOOTING_GALLERY, new ShootingGalleryComponent(this)));
// } // }
if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PROPERTY, -1) != -1) { // if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PROPERTY, -1) != -1) {
m_Components.insert(std::make_pair(eReplicaComponentType::PROPERTY, new PropertyComponent(this))); // m_Components.insert(std::make_pair(eReplicaComponentType::PROPERTY, new PropertyComponent(this)));
} // }
const int rocketId = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::ROCKET_LAUNCH); // const int rocketId = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::ROCKET_LAUNCH);
if ((rocketId > 0)) { // if ((rocketId > 0)) {
m_Components.insert(std::make_pair(eReplicaComponentType::ROCKET_LAUNCH, new RocketLaunchpadControlComponent(this, rocketId))); // m_Components.insert(std::make_pair(eReplicaComponentType::ROCKET_LAUNCH, new RocketLaunchpadControlComponent(this, rocketId)));
} // }
const int32_t railComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RAIL_ACTIVATOR); // const int32_t railComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RAIL_ACTIVATOR);
if (railComponentID > 0) { // if (railComponentID > 0) {
m_Components.insert(std::make_pair(eReplicaComponentType::RAIL_ACTIVATOR, new RailActivatorComponent(this, railComponentID))); // m_Components.insert(std::make_pair(eReplicaComponentType::RAIL_ACTIVATOR, new RailActivatorComponent(this, railComponentID)));
} // }
int movementAIID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MOVEMENT_AI); int movementAIID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MOVEMENT_AI);
if (movementAIID > 0) { if (movementAIID > 0) {
@ -562,14 +562,15 @@ Entity::Initialize() {
// TODO: create movementAIcomp and set path // TODO: create movementAIcomp and set path
} }
}*/ }*/
} else { }
// else {
// else we still need to setup moving platform if it has a moving platform comp but no path // else we still need to setup moving platform if it has a moving platform comp but no path
int32_t movingPlatformComponentId = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MOVING_PLATFORM, -1); // int32_t movingPlatformComponentId = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MOVING_PLATFORM, -1);
if (movingPlatformComponentId >= 0) { // if (movingPlatformComponentId >= 0) {
MovingPlatformComponent* plat = new MovingPlatformComponent(this, pathName); // MovingPlatformComponent* plat = new MovingPlatformComponent(this, pathName);
m_Components.insert(std::make_pair(eReplicaComponentType::MOVING_PLATFORM, plat)); // m_Components.insert(std::make_pair(eReplicaComponentType::MOVING_PLATFORM, plat));
} // }
} // }
int proximityMonitorID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PROXIMITY_MONITOR); int proximityMonitorID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PROXIMITY_MONITOR);
if (proximityMonitorID > 0) { if (proximityMonitorID > 0) {
@ -637,4 +638,4 @@ no_ghosting:
controllablePhysicsComponent->SetSpeedMultiplier(levelComponent->GetSpeedBase() / 500.0f); controllablePhysicsComponent->SetSpeedMultiplier(levelComponent->GetSpeedBase() / 500.0f);
} }
} }
} // }

View File

@ -24,6 +24,7 @@
#include "eGameMasterLevel.h" #include "eGameMasterLevel.h"
#include "eReplicaComponentType.h" #include "eReplicaComponentType.h"
#include "eReplicaPacketType.h" #include "eReplicaPacketType.h"
#include "CollectibleComponent.h"
EntityManager* EntityManager::m_Address = nullptr; EntityManager* EntityManager::m_Address = nullptr;
@ -518,16 +519,18 @@ void EntityManager::UpdateGhosting(Player* player) {
entity->SetObservers(entity->GetObservers() - 1); entity->SetObservers(entity->GetObservers() - 1);
} else if (!observed && ghostingDistanceMin > distance) { } else if (!observed && ghostingDistanceMin > distance) {
// Check collectables, don't construct if it has been collected // Check collectables, don't construct if it has been collected
uint32_t collectionId = entity->GetCollectibleID(); auto* collectibleComponent = entity->GetComponent<CollectibleComponent>();
if (collectibleComponent) {
uint32_t collectionId = collectibleComponent->GetCollectibleId();
if (collectionId != 0) { if (collectionId != 0) {
collectionId = static_cast<uint32_t>(collectionId) + static_cast<uint32_t>(Game::server->GetZoneID() << 8); collectionId = static_cast<uint32_t>(collectionId) + static_cast<uint32_t>(Game::server->GetZoneID() << 8);
if (missionComponent->HasCollectible(collectionId)) { if (missionComponent->HasCollectible(collectionId)) {
continue; continue;
}
} }
} }
player->ObserveEntity(id); player->ObserveEntity(id);
ConstructEntity(entity, player->GetSystemAddress()); ConstructEntity(entity, player->GetSystemAddress());

View File

@ -3,10 +3,12 @@ set(DGAME_DCOMPONENTS_SOURCES "BaseCombatAIComponent.cpp"
"BuffComponent.cpp" "BuffComponent.cpp"
"BuildBorderComponent.cpp" "BuildBorderComponent.cpp"
"CharacterComponent.cpp" "CharacterComponent.cpp"
"CollectibleComponent.cpp"
"Component.cpp" "Component.cpp"
"ControllablePhysicsComponent.cpp" "ControllablePhysicsComponent.cpp"
"DestroyableComponent.cpp" "DestroyableComponent.cpp"
"InventoryComponent.cpp" "InventoryComponent.cpp"
"ItemComponent.cpp"
"LevelProgressionComponent.cpp" "LevelProgressionComponent.cpp"
"LUPExhibitComponent.cpp" "LUPExhibitComponent.cpp"
"MinigameControlComponent.cpp" "MinigameControlComponent.cpp"

View File

@ -0,0 +1,11 @@
#include "CollectibleComponent.h"
#include "Entity.h"
CollectibleComponent::CollectibleComponent(Entity* parent) : Component(parent) {
}
void CollectibleComponent::Startup() {
m_CollectibleId = GetParentEntity()->GetVarAs<int32_t>(u"collectible_id");
}

View File

@ -0,0 +1,22 @@
#ifndef __COLLECTIBLECOMPONENT__H__
#define __COLLECTIBLECOMPONENT__H__
#include "Component.h"
#include "eReplicaComponentType.h"
#include <cstdint>
class CollectibleComponent : public Component {
public:
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::COLLECTIBLE;
CollectibleComponent(Entity* parent);
void Startup() override;
uint32_t GetCollectibleId() const { return m_CollectibleId; }
private:
uint32_t m_CollectibleId;
};
#endif //!__COLLECTIBLECOMPONENT__H__

View File

@ -0,0 +1,5 @@
#include "ItemComponent.h"
ItemComponent::ItemComponent(Entity* parent) : Component(parent) {
}

View File

@ -0,0 +1,15 @@
#ifndef __ITEMCOMPONENT__H__
#define __ITEMCOMPONENT__H__
#include "Component.h"
#include "eReplicaComponentType.h"
class Entity;
class ItemComponent : public Component {
public:
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::ITEM;
ItemComponent(Entity* parent);
};
#endif //!__ITEMCOMPONENT__H__

View File

@ -66,6 +66,7 @@
#include "InventoryComponent.h" #include "InventoryComponent.h"
#include "RocketLaunchpadControlComponent.h" #include "RocketLaunchpadControlComponent.h"
#include "PropertyEntranceComponent.h" #include "PropertyEntranceComponent.h"
#include "CollectibleComponent.h"
#include "MovingPlatformComponent.h" #include "MovingPlatformComponent.h"
#include "PetComponent.h" #include "PetComponent.h"
#include "ModuleAssemblyComponent.h" #include "ModuleAssemblyComponent.h"
@ -5264,7 +5265,9 @@ void GameMessages::HandleHasBeenCollected(RakNet::BitStream* inStream, Entity* e
inStream->Read(playerID); inStream->Read(playerID);
Entity* player = EntityManager::Instance()->GetEntity(playerID); Entity* player = EntityManager::Instance()->GetEntity(playerID);
if (!player || !entity || entity->GetCollectibleID() == 0) return; if (!player || !entity) return;
auto* collectibleComponent = entity->GetComponent<CollectibleComponent>();
if (!collectibleComponent || collectibleComponent->GetCollectibleId() == 0) return;
auto* missionComponent = player->GetComponent<MissionComponent>(); auto* missionComponent = player->GetComponent<MissionComponent>();
if (missionComponent) { if (missionComponent) {

View File

@ -15,6 +15,7 @@
#include "MissionComponent.h" #include "MissionComponent.h"
#include "eMissionTaskType.h" #include "eMissionTaskType.h"
#include "eReplicaComponentType.h" #include "eReplicaComponentType.h"
#include "CollectibleComponent.h"
MissionTask::MissionTask(Mission* mission, CDMissionTasks* info, uint32_t mask) { MissionTask::MissionTask(Mission* mission, CDMissionTasks* info, uint32_t mask) {
this->info = info; this->info = info;
@ -353,8 +354,9 @@ void MissionTask::Progress(int32_t value, LWOOBJID associate, const std::string&
break; break;
} }
auto* collectibleComponent = entity->GetComponent<CollectibleComponent>();
collectionId = entity->GetCollectibleID(); if (!collectibleComponent) break;
collectionId = collectibleComponent->GetCollectibleId();
collectionId = static_cast<uint32_t>(collectionId) + static_cast<uint32_t>(Game::server->GetZoneID() << 8); collectionId = static_cast<uint32_t>(collectionId) + static_cast<uint32_t>(Game::server->GetZoneID() << 8);