From b91f84d8840f33bd4ea94286cf2cb2d7a8508efb Mon Sep 17 00:00:00 2001 From: David Markowitz Date: Sat, 10 Jun 2023 04:46:48 -0700 Subject: [PATCH] Collectible, Item, further re-implement initialize --- dGame/Entity.cpp | 283 +++++++++------------ dGame/Entity.h | 12 +- dGame/EntityInitializeOld.cc | 163 ++++++------ dGame/EntityManager.cpp | 15 +- dGame/dComponents/CMakeLists.txt | 2 + dGame/dComponents/CollectibleComponent.cpp | 11 + dGame/dComponents/CollectibleComponent.h | 22 ++ dGame/dComponents/ItemComponent.cpp | 5 + dGame/dComponents/ItemComponent.h | 15 ++ dGame/dGameMessages/GameMessages.cpp | 5 +- dGame/dMission/MissionTask.cpp | 6 +- 11 files changed, 285 insertions(+), 254 deletions(-) create mode 100644 dGame/dComponents/CollectibleComponent.cpp create mode 100644 dGame/dComponents/CollectibleComponent.h create mode 100644 dGame/dComponents/ItemComponent.cpp create mode 100644 dGame/dComponents/ItemComponent.h diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index 24321f85..522e53c4 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -53,6 +53,7 @@ #include "VendorComponent.h" #include "RocketLaunchpadControlComponent.h" #include "PropertyComponent.h" +#include "CollectibleComponent.h" #include "BaseCombatAIComponent.h" #include "PropertyManagementComponent.h" #include "PropertyVendorComponent.h" @@ -76,6 +77,7 @@ #include "eReplicaPacketType.h" #include "RacingStatsComponent.h" #include "MinigameControlComponent.h" +#include "ItemComponent.h" // Table includes #include "CDComponentsRegistryTable.h" @@ -130,7 +132,6 @@ Entity::Entity(const LWOOBJID& objectID, EntityInfo info, Entity* parentEntity) m_ParentEntity = parentEntity; m_Character = nullptr; m_GMLevel = eGameMasterLevel::CIVILIAN; - m_CollectibleID = 0; m_NetworkID = 0; m_Observers = 0; m_OwnerOverride = LWOOBJID_EMPTY; @@ -170,17 +171,40 @@ Entity::~Entity() { if (m_ParentEntity) m_ParentEntity->RemoveChild(this); } -void Entity::ApplyComponentWhitelist(TemplateComponents& components) { +void Entity::ApplyComponentWhitelist(TemplateComponents& components) const { const auto whitelistIndex = GetVar(u"componentWhitelist"); if (whitelistIndex < 0 || whitelistIndex >= m_ComponentWhitelists.size()) return; const auto& whitelist = m_ComponentWhitelists.at(whitelistIndex); 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(); - }); + }); 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(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() { // A few edge cases to tackle first const auto triggerInfo = GetVarAsString(u"trigger_id"); @@ -206,6 +230,8 @@ void Entity::Initialize() { auto* componentsRegistry = CDClientManager::Instance().GetTable(); TemplateComponents components = componentsRegistry->GetTemplateComponents(m_TemplateID); ApplyComponentWhitelist(components); + ApplyComponentBlacklist(components); + ApplyComponentConfig(components); for (const auto& [componentTemplate, componentId] : components) { switch (componentTemplate) { case eReplicaComponentType::CONTROLLABLE_PHYSICS: @@ -215,162 +241,87 @@ void Entity::Initialize() { AddComponent(); break; case eReplicaComponentType::SIMPLE_PHYSICS: + AddComponent(componentId); break; case eReplicaComponentType::CHARACTER: AddComponent(m_Character); AddComponent(); - break; - case eReplicaComponentType::SCRIPT: + AddComponent(); + AddComponent(); + AddComponent(); break; case eReplicaComponentType::BOUNCER: AddComponent(); break; - case eReplicaComponentType::DESTROYABLE: - break; - case eReplicaComponentType::GHOST: - break; case eReplicaComponentType::SKILL: AddComponent(); break; - case eReplicaComponentType::SPAWN: - break; case eReplicaComponentType::ITEM: - break; - case eReplicaComponentType::MODULAR_BUILD: - break; - case eReplicaComponentType::BUILD_CONTROLLER: - break; - case eReplicaComponentType::BUILD_ACTIVATOR: - break; - case eReplicaComponentType::ICON_ONLY: + AddComponent(); break; case eReplicaComponentType::VENDOR: AddComponent(); break; case eReplicaComponentType::INVENTORY: - break; - case eReplicaComponentType::PROJECTILE_PHYSICS: + AddComponent(); break; case eReplicaComponentType::SHOOTING_GALLERY: AddComponent(); break; case eReplicaComponentType::RIGID_BODY_PHANTOM_PHYSICS: - break; - case eReplicaComponentType::DROP_EFFECT: - break; - case eReplicaComponentType::CHEST: + AddComponent(); break; case eReplicaComponentType::COLLECTIBLE: - break; - case eReplicaComponentType::BLUEPRINT: + AddComponent(); break; case eReplicaComponentType::MOVING_PLATFORM: + AddComponent(GetVarAsString(u"attached_path")); break; case eReplicaComponentType::PET: AddComponent(componentId); break; - case eReplicaComponentType::PLATFORM_BOUNDARY: - break; - case eReplicaComponentType::MODULE: - break; - case eReplicaComponentType::JETPACKPAD: - break; case eReplicaComponentType::HAVOK_VEHICLE_PHYSICS: - break; - case eReplicaComponentType::MOVEMENT_AI: - break; - case eReplicaComponentType::EXHIBIT: - break; - case eReplicaComponentType::OVERHEAD_ICON: - break; - case eReplicaComponentType::PET_CONTROL: - break; - case eReplicaComponentType::MINIFIG: + AddComponent(); break; case eReplicaComponentType::PROPERTY: AddComponent(); break; - case eReplicaComponentType::PET_CREATOR: - break; - case eReplicaComponentType::MODEL_BUILDER: - break; case eReplicaComponentType::SCRIPTED_ACTIVITY: AddComponent(componentId); break; case eReplicaComponentType::PHANTOM_PHYSICS: - break; - case eReplicaComponentType::SPRINGPAD: + AddComponent(); break; case eReplicaComponentType::MODEL_BEHAVIOR: + AddComponent(); break; case eReplicaComponentType::PROPERTY_ENTRANCE: AddComponent(componentId); break; - case eReplicaComponentType::FX: - break; case eReplicaComponentType::PROPERTY_MANAGEMENT: AddComponent(); break; - case eReplicaComponentType::VEHICLE_PHYSICS: - break; - case eReplicaComponentType::PHYSICS_SYSTEM: - break; - case eReplicaComponentType::QUICK_BUILD: - break; case eReplicaComponentType::SWITCH: AddComponent(); break; case eReplicaComponentType::MINIGAME_CONTROL: AddComponent(); 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: AddComponent(componentId); break; case eReplicaComponentType::MODULE_ASSEMBLY: AddComponent(); break; - case eReplicaComponentType::SHOWCASE_MODEL_HANDLER: - break; - case eReplicaComponentType::RACING_MODULE: - break; - case eReplicaComponentType::GENERIC_ACTIVATOR: - break; case eReplicaComponentType::PROPERTY_VENDOR: AddComponent(); break; - case eReplicaComponentType::HF_LIGHT_DIRECTION_GADGET: - break; case eReplicaComponentType::ROCKET_LAUNCHPAD_CONTROL: - break; - case eReplicaComponentType::ROCKET_ANIMATION_CONTROL: - break; - case eReplicaComponentType::TRIGGER: - break; - case eReplicaComponentType::DROPPED_LOOT: + AddComponent(componentId); break; case eReplicaComponentType::RACING_CONTROL: AddComponent(); break; - case eReplicaComponentType::FACTION_TRIGGER: - break; case eReplicaComponentType::MISSION_OFFER: AddComponent(GetLOT()); break; @@ -380,92 +331,104 @@ void Entity::Initialize() { case eReplicaComponentType::LUP_EXHIBIT: AddComponent(); break; - case eReplicaComponentType::BBB: - break; case eReplicaComponentType::SOUND_TRIGGER: - break; - 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: + AddComponent(); break; case eReplicaComponentType::MULTI_ZONE_ENTRANCE: + AddComponent(); break; case eReplicaComponentType::BUFF: - break; - 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: + AddComponent(); break; case eReplicaComponentType::RAIL_ACTIVATOR: - break; - case eReplicaComponentType::ROLLER: - break; - case eReplicaComponentType::PLAYER_FORCED_MOVEMENT: - break; - case eReplicaComponentType::CRAFTING: + AddComponent(componentId); break; case eReplicaComponentType::POSSESSABLE: AddComponent(componentId); 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: AddComponent(); 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: - break; case eReplicaComponentType::CULLING_PLANE: - break; case eReplicaComponentType::NUMBER_OF_COMPONENTS: - break; case eReplicaComponentType::INVALID: default: Game::logger->Log("Entity", "blah %i %i", componentId, m_TemplateID); diff --git a/dGame/Entity.h b/dGame/Entity.h index 6337c52b..68f72966 100644 --- a/dGame/Entity.h +++ b/dGame/Entity.h @@ -57,8 +57,15 @@ public: explicit Entity(const LWOOBJID& objectID, EntityInfo info, Entity* parentEntity = nullptr); virtual ~Entity(); - void ApplyComponentWhitelist(TemplateComponents& components); + void ApplyComponentWhitelist(TemplateComponents& components) const; static const std::vector& 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(); bool operator==(const Entity& other) const; @@ -77,8 +84,6 @@ public: eGameMasterLevel GetGMLevel() const { return m_GMLevel; } void SetGMLevel(const eGameMasterLevel value); - const uint32_t GetCollectibleID() const { return m_CollectibleID; } - Entity* GetParentEntity() const { return m_ParentEntity; } const std::vector& GetGroups() { return m_Groups; }; @@ -317,7 +322,6 @@ protected: Entity* m_ParentEntity; //For spawners and the like std::vector m_ChildEntities; eGameMasterLevel m_GMLevel; - uint32_t m_CollectibleID; std::vector m_Groups; uint16_t m_NetworkID; std::vector> m_DieCallbacks; diff --git a/dGame/EntityInitializeOld.cc b/dGame/EntityInitializeOld.cc index 7facb0a8..84a2b839 100644 --- a/dGame/EntityInitializeOld.cc +++ b/dGame/EntityInitializeOld.cc @@ -1,4 +1,4 @@ -Entity::Initialize() { +// Entity::Initialize() { /** * Setup trigger */ @@ -33,7 +33,7 @@ Entity::Initialize() { * 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); // SimplePhysicsComponent* comp = new SimplePhysicsComponent(simplePhysicsComponentID, this); @@ -52,8 +52,8 @@ Entity::Initialize() { destroyableComponent->SetIsSmashable(true); // m_Components.insert(std::make_pair(eReplicaComponentType::DESTROYABLE, destroyableComponent)); // We have all our components. - return; - } + // return; + // } /** * 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. - bool markedAsPhantom = GetVar(u"markedAsPhantom"); + // bool markedAsPhantom = GetVar(u"markedAsPhantom"); - const auto simplePhysicsComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SIMPLE_PHYSICS); - if (!markedAsPhantom && simplePhysicsComponentID > 0) { - SimplePhysicsComponent* comp = new SimplePhysicsComponent(simplePhysicsComponentID, this); - m_Components.insert(std::make_pair(eReplicaComponentType::SIMPLE_PHYSICS, comp)); - } + // const auto simplePhysicsComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SIMPLE_PHYSICS); + // if (!markedAsPhantom && simplePhysicsComponentID > 0) { + // SimplePhysicsComponent* comp = new SimplePhysicsComponent(simplePhysicsComponentID, this); + // m_Components.insert(std::make_pair(eReplicaComponentType::SIMPLE_PHYSICS, comp)); + // } - if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RIGID_BODY_PHANTOM_PHYSICS) > 0) { - RigidbodyPhantomPhysicsComponent* comp = new RigidbodyPhantomPhysicsComponent(this); - m_Components.insert(std::make_pair(eReplicaComponentType::RIGID_BODY_PHANTOM_PHYSICS, comp)); - } + // if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RIGID_BODY_PHANTOM_PHYSICS) > 0) { + // RigidbodyPhantomPhysicsComponent* comp = new RigidbodyPhantomPhysicsComponent(this); + // m_Components.insert(std::make_pair(eReplicaComponentType::RIGID_BODY_PHANTOM_PHYSICS, comp)); + // } - if (markedAsPhantom || compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PHANTOM_PHYSICS) > 0) { - PhantomPhysicsComponent* phantomPhysics = new PhantomPhysicsComponent(this); + // if (markedAsPhantom || compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PHANTOM_PHYSICS) > 0) { + // PhantomPhysicsComponent* phantomPhysics = new PhantomPhysicsComponent(this); 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) { - VehiclePhysicsComponent* vehiclePhysicsComponent = new VehiclePhysicsComponent(this); - m_Components.insert(std::make_pair(eReplicaComponentType::VEHICLE_PHYSICS, vehiclePhysicsComponent)); + // 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); - } + // } - if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SOUND_TRIGGER, -1) != -1) { - auto* comp = new SoundTriggerComponent(this); - m_Components.insert(std::make_pair(eReplicaComponentType::SOUND_TRIGGER, comp)); - } + // if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SOUND_TRIGGER, -1) != -1) { + // auto* comp = new SoundTriggerComponent(this); + // m_Components.insert(std::make_pair(eReplicaComponentType::SOUND_TRIGGER, comp)); + // } //Also check for the collectible id: - m_CollectibleID = GetVarAs(u"collectible_id"); + // m_CollectibleID = GetVarAs(u"collectible_id"); - if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::BUFF) > 0) { - BuffComponent* comp = new BuffComponent(this); - m_Components.insert(std::make_pair(eReplicaComponentType::BUFF, comp)); - } + // if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::BUFF) > 0) { + // BuffComponent* comp = new BuffComponent(this); + // 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) { - m_Components.insert(std::make_pair(eReplicaComponentType::COLLECTIBLE, nullptr)); - } + // if (collectibleComponentID > 0) { + // m_Components.insert(std::make_pair(eReplicaComponentType::COLLECTIBLE, nullptr)); + // } /** * Multiple components require the destructible component. @@ -277,33 +277,33 @@ Entity::Initialize() { 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 - 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 - auto* levelComp = new LevelProgressionComponent(this); - levelComp->LoadFromXml(m_Character->GetXMLDoc()); - m_Components.insert(std::make_pair(eReplicaComponentType::LEVEL_PROGRESSION, levelComp)); + // auto* levelComp = new LevelProgressionComponent(this); + // levelComp->LoadFromXml(m_Character->GetXMLDoc()); + // 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); - charComp->LoadFromXml(m_Character->GetXMLDoc()); - m_Components.insert(std::make_pair(eReplicaComponentType::CHARACTER, charComp)); - } + // CharacterComponent* charComp = new CharacterComponent(this, m_Character); + // charComp->LoadFromXml(m_Character->GetXMLDoc()); + // m_Components.insert(std::make_pair(eReplicaComponentType::CHARACTER, charComp)); + // } - if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::INVENTORY) > 0 || m_Character) { - InventoryComponent* comp = nullptr; - if (m_Character) comp = new InventoryComponent(this, m_Character->GetXMLDoc()); - else comp = new InventoryComponent(this); - m_Components.insert(std::make_pair(eReplicaComponentType::INVENTORY, comp)); - } + // if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::INVENTORY) > 0 || m_Character) { + // InventoryComponent* comp = nullptr; + // if (m_Character) comp = new InventoryComponent(this, m_Character->GetXMLDoc()); + // else comp = new InventoryComponent(this); + // m_Components.insert(std::make_pair(eReplicaComponentType::INVENTORY, comp)); + // } // 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) { - auto comp = new RocketLaunchLupComponent(this); - m_Components.insert(std::make_pair(eReplicaComponentType::ROCKET_LAUNCH_LUP, comp)); - } + // if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::ROCKET_LAUNCH_LUP, -1) != -1) { + // auto comp = new RocketLaunchLupComponent(this); + // m_Components.insert(std::make_pair(eReplicaComponentType::ROCKET_LAUNCH_LUP, comp)); + // } /** * 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))); // } - if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MODEL, -1) != -1 && !GetComponent()) { - m_Components.insert(std::make_pair(eReplicaComponentType::MODEL, new ModelComponent(this))); + // if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MODEL, -1) != -1 && !GetComponent()) { + // 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); @@ -479,31 +479,31 @@ Entity::Initialize() { destroyableComponent->SetIsSmashable(true); m_Components.insert(std::make_pair(eReplicaComponentType::DESTROYABLE, destroyableComponent)); } - } + // } - PetComponent* petComponent; - if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::ITEM) > 0 && !TryGetComponent(eReplicaComponentType::PET, petComponent) && !HasComponent(eReplicaComponentType::MODEL)) { - m_Components.insert(std::make_pair(eReplicaComponentType::ITEM, nullptr)); - } + // PetComponent* petComponent; + // if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::ITEM) > 0 && !TryGetComponent(eReplicaComponentType::PET, petComponent) && !HasComponent(eReplicaComponentType::MODEL)) { + // m_Components.insert(std::make_pair(eReplicaComponentType::ITEM, nullptr)); + // } // Shooting gallery component // if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SHOOTING_GALLERY) > 0) { // m_Components.insert(std::make_pair(eReplicaComponentType::SHOOTING_GALLERY, new ShootingGalleryComponent(this))); // } - if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PROPERTY, -1) != -1) { - m_Components.insert(std::make_pair(eReplicaComponentType::PROPERTY, new PropertyComponent(this))); - } + // if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PROPERTY, -1) != -1) { + // m_Components.insert(std::make_pair(eReplicaComponentType::PROPERTY, new PropertyComponent(this))); + // } - const int rocketId = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::ROCKET_LAUNCH); - if ((rocketId > 0)) { - m_Components.insert(std::make_pair(eReplicaComponentType::ROCKET_LAUNCH, new RocketLaunchpadControlComponent(this, rocketId))); - } + // const int rocketId = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::ROCKET_LAUNCH); + // if ((rocketId > 0)) { + // m_Components.insert(std::make_pair(eReplicaComponentType::ROCKET_LAUNCH, new RocketLaunchpadControlComponent(this, rocketId))); + // } - const int32_t railComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RAIL_ACTIVATOR); - if (railComponentID > 0) { - m_Components.insert(std::make_pair(eReplicaComponentType::RAIL_ACTIVATOR, new RailActivatorComponent(this, railComponentID))); - } + // const int32_t railComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RAIL_ACTIVATOR); + // if (railComponentID > 0) { + // m_Components.insert(std::make_pair(eReplicaComponentType::RAIL_ACTIVATOR, new RailActivatorComponent(this, railComponentID))); + // } int movementAIID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MOVEMENT_AI); if (movementAIID > 0) { @@ -562,14 +562,15 @@ Entity::Initialize() { // 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 - int32_t movingPlatformComponentId = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MOVING_PLATFORM, -1); - if (movingPlatformComponentId >= 0) { - MovingPlatformComponent* plat = new MovingPlatformComponent(this, pathName); - m_Components.insert(std::make_pair(eReplicaComponentType::MOVING_PLATFORM, plat)); - } - } + // int32_t movingPlatformComponentId = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MOVING_PLATFORM, -1); + // if (movingPlatformComponentId >= 0) { + // MovingPlatformComponent* plat = new MovingPlatformComponent(this, pathName); + // m_Components.insert(std::make_pair(eReplicaComponentType::MOVING_PLATFORM, plat)); + // } + // } int proximityMonitorID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PROXIMITY_MONITOR); if (proximityMonitorID > 0) { @@ -637,4 +638,4 @@ no_ghosting: controllablePhysicsComponent->SetSpeedMultiplier(levelComponent->GetSpeedBase() / 500.0f); } } -} +// } diff --git a/dGame/EntityManager.cpp b/dGame/EntityManager.cpp index 511d7557..18602c89 100644 --- a/dGame/EntityManager.cpp +++ b/dGame/EntityManager.cpp @@ -24,6 +24,7 @@ #include "eGameMasterLevel.h" #include "eReplicaComponentType.h" #include "eReplicaPacketType.h" +#include "CollectibleComponent.h" EntityManager* EntityManager::m_Address = nullptr; @@ -518,16 +519,18 @@ void EntityManager::UpdateGhosting(Player* player) { entity->SetObservers(entity->GetObservers() - 1); } else if (!observed && ghostingDistanceMin > distance) { // Check collectables, don't construct if it has been collected - uint32_t collectionId = entity->GetCollectibleID(); + auto* collectibleComponent = entity->GetComponent(); + if (collectibleComponent) { + uint32_t collectionId = collectibleComponent->GetCollectibleId(); - if (collectionId != 0) { - collectionId = static_cast(collectionId) + static_cast(Game::server->GetZoneID() << 8); + if (collectionId != 0) { + collectionId = static_cast(collectionId) + static_cast(Game::server->GetZoneID() << 8); - if (missionComponent->HasCollectible(collectionId)) { - continue; + if (missionComponent->HasCollectible(collectionId)) { + continue; + } } } - player->ObserveEntity(id); ConstructEntity(entity, player->GetSystemAddress()); diff --git a/dGame/dComponents/CMakeLists.txt b/dGame/dComponents/CMakeLists.txt index a2ce6b1c..fd5fb676 100644 --- a/dGame/dComponents/CMakeLists.txt +++ b/dGame/dComponents/CMakeLists.txt @@ -3,10 +3,12 @@ set(DGAME_DCOMPONENTS_SOURCES "BaseCombatAIComponent.cpp" "BuffComponent.cpp" "BuildBorderComponent.cpp" "CharacterComponent.cpp" + "CollectibleComponent.cpp" "Component.cpp" "ControllablePhysicsComponent.cpp" "DestroyableComponent.cpp" "InventoryComponent.cpp" + "ItemComponent.cpp" "LevelProgressionComponent.cpp" "LUPExhibitComponent.cpp" "MinigameControlComponent.cpp" diff --git a/dGame/dComponents/CollectibleComponent.cpp b/dGame/dComponents/CollectibleComponent.cpp new file mode 100644 index 00000000..856f54f7 --- /dev/null +++ b/dGame/dComponents/CollectibleComponent.cpp @@ -0,0 +1,11 @@ +#include "CollectibleComponent.h" + +#include "Entity.h" + +CollectibleComponent::CollectibleComponent(Entity* parent) : Component(parent) { + +} + +void CollectibleComponent::Startup() { + m_CollectibleId = GetParentEntity()->GetVarAs(u"collectible_id"); +} diff --git a/dGame/dComponents/CollectibleComponent.h b/dGame/dComponents/CollectibleComponent.h new file mode 100644 index 00000000..eda6dd61 --- /dev/null +++ b/dGame/dComponents/CollectibleComponent.h @@ -0,0 +1,22 @@ +#ifndef __COLLECTIBLECOMPONENT__H__ +#define __COLLECTIBLECOMPONENT__H__ + +#include "Component.h" +#include "eReplicaComponentType.h" + +#include + +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__ diff --git a/dGame/dComponents/ItemComponent.cpp b/dGame/dComponents/ItemComponent.cpp new file mode 100644 index 00000000..af8608d0 --- /dev/null +++ b/dGame/dComponents/ItemComponent.cpp @@ -0,0 +1,5 @@ +#include "ItemComponent.h" + +ItemComponent::ItemComponent(Entity* parent) : Component(parent) { + +} diff --git a/dGame/dComponents/ItemComponent.h b/dGame/dComponents/ItemComponent.h new file mode 100644 index 00000000..6be074a4 --- /dev/null +++ b/dGame/dComponents/ItemComponent.h @@ -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__ diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index 3011de99..4f570acd 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -66,6 +66,7 @@ #include "InventoryComponent.h" #include "RocketLaunchpadControlComponent.h" #include "PropertyEntranceComponent.h" +#include "CollectibleComponent.h" #include "MovingPlatformComponent.h" #include "PetComponent.h" #include "ModuleAssemblyComponent.h" @@ -5264,7 +5265,9 @@ void GameMessages::HandleHasBeenCollected(RakNet::BitStream* inStream, Entity* e inStream->Read(playerID); Entity* player = EntityManager::Instance()->GetEntity(playerID); - if (!player || !entity || entity->GetCollectibleID() == 0) return; + if (!player || !entity) return; + auto* collectibleComponent = entity->GetComponent(); + if (!collectibleComponent || collectibleComponent->GetCollectibleId() == 0) return; auto* missionComponent = player->GetComponent(); if (missionComponent) { diff --git a/dGame/dMission/MissionTask.cpp b/dGame/dMission/MissionTask.cpp index 2a1042ae..fff59cea 100644 --- a/dGame/dMission/MissionTask.cpp +++ b/dGame/dMission/MissionTask.cpp @@ -15,6 +15,7 @@ #include "MissionComponent.h" #include "eMissionTaskType.h" #include "eReplicaComponentType.h" +#include "CollectibleComponent.h" MissionTask::MissionTask(Mission* mission, CDMissionTasks* info, uint32_t mask) { this->info = info; @@ -353,8 +354,9 @@ void MissionTask::Progress(int32_t value, LWOOBJID associate, const std::string& break; } - - collectionId = entity->GetCollectibleID(); + auto* collectibleComponent = entity->GetComponent(); + if (!collectibleComponent) break; + collectionId = collectibleComponent->GetCollectibleId(); collectionId = static_cast(collectionId) + static_cast(Game::server->GetZoneID() << 8);