From 4caed08ce4634c3b90b8da3a2eed13f2890b270f Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Sat, 13 Apr 2024 01:32:42 -0500 Subject: [PATCH] WIP --- dGame/Entity.cpp | 4 +-- dGame/dComponents/CMakeLists.txt | 1 - dGame/dComponents/InventoryComponent.cpp | 26 ++++++++++++------- dGame/dComponents/ItemComponent.cpp | 12 +++++++++ .../dComponents/MiniGameControlComponent.cpp | 5 ---- dGame/dComponents/MiniGameControlComponent.h | 8 +++--- .../dComponents/ShootingGalleryComponent.cpp | 26 ++++++------------- dGame/dComponents/ShootingGalleryComponent.h | 14 +++------- dGame/dComponents/SkillComponent.cpp | 26 +++++++++++++++++++ .../ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp | 2 +- 10 files changed, 73 insertions(+), 51 deletions(-) delete mode 100644 dGame/dComponents/MiniGameControlComponent.cpp diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index 00ad8471..3508fc60 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -254,7 +254,7 @@ void Entity::Initialize() { } if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MINI_GAME_CONTROL) > 0) { - AddComponent(); + AddComponent(m_TemplateID); } uint32_t possessableComponentId = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::POSSESSABLE); @@ -666,7 +666,7 @@ void Entity::Initialize() { // Shooting gallery component if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SHOOTING_GALLERY) > 0) { - AddComponent(); + AddComponent(m_TemplateID); } if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PROPERTY, -1) != -1) { diff --git a/dGame/dComponents/CMakeLists.txt b/dGame/dComponents/CMakeLists.txt index c60e135f..bf136912 100644 --- a/dGame/dComponents/CMakeLists.txt +++ b/dGame/dComponents/CMakeLists.txt @@ -47,7 +47,6 @@ set(DGAME_DCOMPONENTS_SOURCES "TriggerComponent.cpp" "HavokVehiclePhysicsComponent.cpp" "VendorComponent.cpp" - "MiniGameControlComponent.cpp" "ScriptComponent.cpp" ) diff --git a/dGame/dComponents/InventoryComponent.cpp b/dGame/dComponents/InventoryComponent.cpp index 8af7fb34..ec38aea2 100644 --- a/dGame/dComponents/InventoryComponent.cpp +++ b/dGame/dComponents/InventoryComponent.cpp @@ -696,22 +696,20 @@ void InventoryComponent::UpdateXml(tinyxml2::XMLDocument& document) { } void InventoryComponent::Serialize(RakNet::BitStream& outBitStream, const bool bIsInitialUpdate) { + // LWOInventoryComponent_EquippedItem + outBitStream.Write(bIsInitialUpdate || m_Dirty); if (bIsInitialUpdate || m_Dirty) { - outBitStream.Write(true); - outBitStream.Write(m_Equipped.size()); for (const auto& pair : m_Equipped) { const auto item = pair.second; - if (bIsInitialUpdate) { - AddItemSkills(item.lot); - } + if (bIsInitialUpdate) AddItemSkills(item.lot); outBitStream.Write(item.id); outBitStream.Write(item.lot); - outBitStream.Write0(); + outBitStream.Write0(); // subkey outBitStream.Write(item.count > 0); if (item.count > 0) outBitStream.Write(item.count); @@ -719,7 +717,7 @@ void InventoryComponent::Serialize(RakNet::BitStream& outBitStream, const bool b outBitStream.Write(item.slot != 0); if (item.slot != 0) outBitStream.Write(item.slot); - outBitStream.Write0(); + outBitStream.Write0(); // inventory type bool flag = !item.config.empty(); outBitStream.Write(flag); @@ -746,11 +744,21 @@ void InventoryComponent::Serialize(RakNet::BitStream& outBitStream, const bool b } m_Dirty = false; - } else { - outBitStream.Write(false); } + // EquippedModelTransform outBitStream.Write(false); + /* + outBitStream.Write(bIsInitialUpdate || m_Dirty); // Same dirty or different? + if (bIsInitialUpdate || m_Dirty) { + outBitStream.Write(m_Equipped.size()); // Equiped models? + for (const auto& [location, item] : m_Equipped) { + outBitStream.Write(item.id); + outBitStream.Write(item.pos); + outBitStream.Write(item.rot); + } + } + */ } void InventoryComponent::Update(float deltaTime) { diff --git a/dGame/dComponents/ItemComponent.cpp b/dGame/dComponents/ItemComponent.cpp index 799cd935..bcc76b4c 100644 --- a/dGame/dComponents/ItemComponent.cpp +++ b/dGame/dComponents/ItemComponent.cpp @@ -2,4 +2,16 @@ void ItemComponent::Serialize(RakNet::BitStream& outBitStream, bool isConstruction) { outBitStream.Write0(); + /* + outBitStream.Write(isConstruction || m_Dirty); // Same dirty or different? + if (isConstruction || m_Dirty) { + outBitStream.Write(m_parent->GetObjectID()); + outBitStream.Write(moderationStatus); + outBitStream.Write(!description.empty()); + if (!description.empty()) { + outBitStream.Write(description.size()); + outBitStream.Write(description) // u16string + } + } + */ } diff --git a/dGame/dComponents/MiniGameControlComponent.cpp b/dGame/dComponents/MiniGameControlComponent.cpp deleted file mode 100644 index 088ee354..00000000 --- a/dGame/dComponents/MiniGameControlComponent.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "MiniGameControlComponent.h" - -void MiniGameControlComponent::Serialize(RakNet::BitStream& outBitStream, bool isConstruction) { - outBitStream.Write(0x40000000); -} diff --git a/dGame/dComponents/MiniGameControlComponent.h b/dGame/dComponents/MiniGameControlComponent.h index 2cd9ac6a..a1b568a0 100644 --- a/dGame/dComponents/MiniGameControlComponent.h +++ b/dGame/dComponents/MiniGameControlComponent.h @@ -1,15 +1,13 @@ #ifndef __MINIGAMECONTROLCOMPONENT__H__ #define __MINIGAMECONTROLCOMPONENT__H__ -#include "Component.h" +#include "ActivityComponent.h" #include "eReplicaComponentType.h" -class MiniGameControlComponent final : public Component { +class MiniGameControlComponent final : public ActivityComponent { public: static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::MINI_GAME_CONTROL; - - MiniGameControlComponent(Entity* parent) : Component(parent) {} - void Serialize(RakNet::BitStream& outBitStream, bool isConstruction); + MiniGameControlComponent(Entity* parent, LOT lot) : ActivityComponent(parent, lot) {} }; #endif //!__MINIGAMECONTROLCOMPONENT__H__ diff --git a/dGame/dComponents/ShootingGalleryComponent.cpp b/dGame/dComponents/ShootingGalleryComponent.cpp index 20665a01..1f1e213f 100644 --- a/dGame/dComponents/ShootingGalleryComponent.cpp +++ b/dGame/dComponents/ShootingGalleryComponent.cpp @@ -2,11 +2,6 @@ #include "EntityManager.h" #include "ScriptedActivityComponent.h" -ShootingGalleryComponent::ShootingGalleryComponent(Entity* parent) : Component(parent) { -} - -ShootingGalleryComponent::~ShootingGalleryComponent() = default; - void ShootingGalleryComponent::SetStaticParams(const StaticShootingGalleryParams& params) { m_StaticParams = params; } @@ -17,20 +12,15 @@ void ShootingGalleryComponent::SetDynamicParams(const DynamicShootingGalleryPara Game::entityManager->SerializeEntity(m_Parent); } -void ShootingGalleryComponent::Serialize(RakNet::BitStream& outBitStream, bool isInitialUpdate) { - // Start ScriptedActivityComponent - outBitStream.Write(true); - if (m_CurrentPlayerID == LWOOBJID_EMPTY) { - outBitStream.Write(0); - } else { - outBitStream.Write(1); - outBitStream.Write(m_CurrentPlayerID); - for (size_t i = 0; i < 10; i++) { - outBitStream.Write(0.0f); - } +void ShootingGalleryComponent::SetCurrentPlayerID(LWOOBJID playerID) { + m_CurrentPlayerID = playerID; + m_Dirty = true; + AddActivityPlayerData(playerID); +}; - } - // End ScriptedActivityComponent + +void ShootingGalleryComponent::Serialize(RakNet::BitStream& outBitStream, bool isInitialUpdate) { + ActivityComponent::Serialize(outBitStream, isInitialUpdate); if (isInitialUpdate) { outBitStream.Write(m_StaticParams.cameraPosition.GetX()); diff --git a/dGame/dComponents/ShootingGalleryComponent.h b/dGame/dComponents/ShootingGalleryComponent.h index 9382d87e..eae301b1 100644 --- a/dGame/dComponents/ShootingGalleryComponent.h +++ b/dGame/dComponents/ShootingGalleryComponent.h @@ -2,7 +2,7 @@ #include "dCommonVars.h" #include "NiPoint3.h" #include "Entity.h" -#include "Component.h" +#include "ActivityComponent.h" #include "eReplicaComponentType.h" /** @@ -71,12 +71,11 @@ struct StaticShootingGalleryParams { * A very ancient component that was used to guide shooting galleries, it's still kind of used but a lot of logic is * also in the related scripts. */ -class ShootingGalleryComponent final : public Component { +class ShootingGalleryComponent final : public ActivityComponent { public: static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::SHOOTING_GALLERY; - explicit ShootingGalleryComponent(Entity* parent); - ~ShootingGalleryComponent(); + explicit ShootingGalleryComponent(Entity* parent, LOT lot) : ActivityComponent(parent, lot) {} void Serialize(RakNet::BitStream& outBitStream, bool isInitialUpdate) override; /** @@ -107,13 +106,8 @@ public: * Sets the entity that's currently playing the shooting gallery * @param playerID the entity to set */ - void SetCurrentPlayerID(LWOOBJID playerID) { m_CurrentPlayerID = playerID; m_Dirty = true; }; + void SetCurrentPlayerID(LWOOBJID playerID); - /** - * Returns the player that's currently playing the shooting gallery - * @return the player that's currently playing the shooting gallery - */ - LWOOBJID GetCurrentPlayerID() const { return m_CurrentPlayerID; }; private: /** diff --git a/dGame/dComponents/SkillComponent.cpp b/dGame/dComponents/SkillComponent.cpp index 8460032c..df5a6e98 100644 --- a/dGame/dComponents/SkillComponent.cpp +++ b/dGame/dComponents/SkillComponent.cpp @@ -486,6 +486,32 @@ SkillComponent::~SkillComponent() { void SkillComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) { if (bIsInitialUpdate) outBitStream.Write0(); + /* + outBitStream.Write(bIsInitialUpdate && !m_managedBehaviors.empty()); + if (bIsInitialUpdate && !m_managedBehaviors.empty()) { + outBitStream.Write(m_managedBehaviors.size()); + for (const auto& [id, skill] : m_managedBehaviors) { + outBitStream.Write(skill.skillUID); + outBitStream.Write(skill.skillID); + outBitStream.Write(skill.cast_type); + outBitStream.Write(skill.cancel_type); + outBitStream.Write(skill.behavior_count); + for (auto& index : skill.behavior_count) { + outBitStream.Write(unknown_1); + outBitStream.Write(action); + outBitStream.Write(wait_time_ms); + outBitStream.Write(template_id); + outBitStream.Write(casterObjId); + outBitStream.Write(originatorObjId); + outBitStream.Write(targetObjId); + outBitStream.Write(usedMouse); + outBitStream.Write(cooldown); + outBitStream.Write(charge_time); + outBitStream.Write(imagination_cost); + } + } + } + */ } /// diff --git a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp index 56f5b257..3cd61ce8 100644 --- a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp +++ b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp @@ -90,7 +90,7 @@ void SGCannon::OnActivityStateChangeRequest(Entity* self, LWOOBJID senderID, int auto* shootingGalleryComponent = self->GetComponent(); if (shootingGalleryComponent != nullptr) { - shootingGalleryComponent->SetCurrentPlayerID(player->GetObjectID()); + shootingGalleryComponent->AddActivityPlayerData(player->GetObjectID()); LOG("Setting player ID");