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 "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<int32_t>(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<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() {
// 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<CDComponentsRegistryTable>();
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<RenderComponent>();
break;
case eReplicaComponentType::SIMPLE_PHYSICS:
AddComponent<SimplePhysicsComponent>(componentId);
break;
case eReplicaComponentType::CHARACTER:
AddComponent<CharacterComponent>(m_Character);
AddComponent<MissionComponent>();
break;
case eReplicaComponentType::SCRIPT:
AddComponent<PossessorComponent>();
AddComponent<LevelProgressionComponent>();
AddComponent<PlayerForcedMovementComponent>();
break;
case eReplicaComponentType::BOUNCER:
AddComponent<BouncerComponent>();
break;
case eReplicaComponentType::DESTROYABLE:
break;
case eReplicaComponentType::GHOST:
break;
case eReplicaComponentType::SKILL:
AddComponent<SkillComponent>();
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<ItemComponent>();
break;
case eReplicaComponentType::VENDOR:
AddComponent<VendorComponent>();
break;
case eReplicaComponentType::INVENTORY:
break;
case eReplicaComponentType::PROJECTILE_PHYSICS:
AddComponent<InventoryComponent>();
break;
case eReplicaComponentType::SHOOTING_GALLERY:
AddComponent<ShootingGalleryComponent>();
break;
case eReplicaComponentType::RIGID_BODY_PHANTOM_PHYSICS:
break;
case eReplicaComponentType::DROP_EFFECT:
break;
case eReplicaComponentType::CHEST:
AddComponent<RigidbodyPhantomPhysicsComponent>();
break;
case eReplicaComponentType::COLLECTIBLE:
break;
case eReplicaComponentType::BLUEPRINT:
AddComponent<CollectibleComponent>();
break;
case eReplicaComponentType::MOVING_PLATFORM:
AddComponent<MovingPlatformComponent>(GetVarAsString(u"attached_path"));
break;
case eReplicaComponentType::PET:
AddComponent<PetComponent>(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<HavokVehiclePhysicsComponent>();
break;
case eReplicaComponentType::PROPERTY:
AddComponent<PropertyComponent>();
break;
case eReplicaComponentType::PET_CREATOR:
break;
case eReplicaComponentType::MODEL_BUILDER:
break;
case eReplicaComponentType::SCRIPTED_ACTIVITY:
AddComponent<ScriptedActivityComponent>(componentId);
break;
case eReplicaComponentType::PHANTOM_PHYSICS:
break;
case eReplicaComponentType::SPRINGPAD:
AddComponent<PhantomPhysicsComponent>();
break;
case eReplicaComponentType::MODEL_BEHAVIOR:
AddComponent<ModelBehaviorComponent>();
break;
case eReplicaComponentType::PROPERTY_ENTRANCE:
AddComponent<PropertyEntranceComponent>(componentId);
break;
case eReplicaComponentType::FX:
break;
case eReplicaComponentType::PROPERTY_MANAGEMENT:
AddComponent<PropertyManagementComponent>();
break;
case eReplicaComponentType::VEHICLE_PHYSICS:
break;
case eReplicaComponentType::PHYSICS_SYSTEM:
break;
case eReplicaComponentType::QUICK_BUILD:
break;
case eReplicaComponentType::SWITCH:
AddComponent<SwitchComponent>();
break;
case eReplicaComponentType::MINIGAME_CONTROL:
AddComponent<MinigameControlComponent>();
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<BaseCombatAIComponent>(componentId);
break;
case eReplicaComponentType::MODULE_ASSEMBLY:
AddComponent<ModuleAssemblyComponent>();
break;
case eReplicaComponentType::SHOWCASE_MODEL_HANDLER:
break;
case eReplicaComponentType::RACING_MODULE:
break;
case eReplicaComponentType::GENERIC_ACTIVATOR:
break;
case eReplicaComponentType::PROPERTY_VENDOR:
AddComponent<PropertyVendorComponent>();
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<RocketLaunchpadControlComponent>(componentId);
break;
case eReplicaComponentType::RACING_CONTROL:
AddComponent<RacingControlComponent>();
break;
case eReplicaComponentType::FACTION_TRIGGER:
break;
case eReplicaComponentType::MISSION_OFFER:
AddComponent<MissionOfferComponent>(GetLOT());
break;
@ -380,92 +331,104 @@ void Entity::Initialize() {
case eReplicaComponentType::LUP_EXHIBIT:
AddComponent<LUPExhibitComponent>();
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<SoundTriggerComponent>();
break;
case eReplicaComponentType::MULTI_ZONE_ENTRANCE:
AddComponent<MultiZoneEntranceComponent>();
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<BuffComponent>();
break;
case eReplicaComponentType::RAIL_ACTIVATOR:
break;
case eReplicaComponentType::ROLLER:
break;
case eReplicaComponentType::PLAYER_FORCED_MOVEMENT:
break;
case eReplicaComponentType::CRAFTING:
AddComponent<RailActivatorComponent>(componentId);
break;
case eReplicaComponentType::POSSESSABLE:
AddComponent<PossessableComponent>(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<BuildBorderComponent>();
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);

View File

@ -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<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();
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<std::string>& GetGroups() { return m_Groups; };
@ -317,7 +322,6 @@ protected:
Entity* m_ParentEntity; //For spawners and the like
std::vector<Entity*> m_ChildEntities;
eGameMasterLevel m_GMLevel;
uint32_t m_CollectibleID;
std::vector<std::string> m_Groups;
uint16_t m_NetworkID;
std::vector<std::function<void()>> m_DieCallbacks;

View File

@ -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<bool>(u"markedAsPhantom");
// bool markedAsPhantom = GetVar<bool>(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<int32_t>(u"collectible_id");
// m_CollectibleID = GetVarAs<int32_t>(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<PetComponent>()) {
m_Components.insert(std::make_pair(eReplicaComponentType::MODEL, new ModelComponent(this)));
// if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MODEL, -1) != -1 && !GetComponent<PetComponent>()) {
// m_Components.insert(std::make_pair(eReplicaComponentType::MODEL, new ModelComponent(this)));
if (m_Components.find(eReplicaComponentType::DESTROYABLE) == m_Components.end()) {
auto destroyableComponent = new DestroyableComponent(this);
destroyableComponent->SetHealth(1);
@ -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);
}
}
}
// }

View File

@ -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<CollectibleComponent>();
if (collectibleComponent) {
uint32_t collectionId = collectibleComponent->GetCollectibleId();
if (collectionId != 0) {
collectionId = static_cast<uint32_t>(collectionId) + static_cast<uint32_t>(Game::server->GetZoneID() << 8);
if (collectionId != 0) {
collectionId = static_cast<uint32_t>(collectionId) + static_cast<uint32_t>(Game::server->GetZoneID() << 8);
if (missionComponent->HasCollectible(collectionId)) {
continue;
if (missionComponent->HasCollectible(collectionId)) {
continue;
}
}
}
player->ObserveEntity(id);
ConstructEntity(entity, player->GetSystemAddress());

View File

@ -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"

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 "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<CollectibleComponent>();
if (!collectibleComponent || collectibleComponent->GetCollectibleId() == 0) return;
auto* missionComponent = player->GetComponent<MissionComponent>();
if (missionComponent) {

View File

@ -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<CollectibleComponent>();
if (!collectibleComponent) break;
collectionId = collectibleComponent->GetCollectibleId();
collectionId = static_cast<uint32_t>(collectionId) + static_cast<uint32_t>(Game::server->GetZoneID() << 8);