diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index 91a13dda..4b234341 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -1662,11 +1662,9 @@ void Entity::PickupItem(const LWOOBJID& objectID) const { auto* const skillsTable = CDClientManager::GetTable(); const auto skills = skillsTable->Query([&info](CDObjectSkills entry) {return (entry.objectTemplate == info.lot); }); for (const auto& skill : skills) { - auto* skillComponent = GetComponent(); + const auto [skillComponent, missionComponent] = GetComponentsMut(); if (skillComponent) skillComponent->CastSkill(skill.skillID, GetObjectID(), GetObjectID(), skill.castOnType, NiQuaternion(0, 0, 0, 0)); - auto* missionComponent = GetComponent(); - if (missionComponent != nullptr) { missionComponent->Progress(eMissionTaskType::POWERUP, skill.skillID); } diff --git a/dGame/Entity.h b/dGame/Entity.h index 43b3fe1a..5f5d1976 100644 --- a/dGame/Entity.h +++ b/dGame/Entity.h @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -161,6 +162,12 @@ public: template T* GetComponent() const; + template + auto GetComponents() const; + + template + auto GetComponentsMut() const; + template bool TryGetComponent(eReplicaComponentType componentId, T*& component) const; @@ -579,3 +586,13 @@ inline ComponentType* Entity::AddComponent(VaArgs... args) { // To allow a static cast here instead of a dynamic one. return dynamic_cast(componentToReturn); } + +template +auto Entity::GetComponents() const { + return GetComponentsMut(); +} + +template +auto Entity::GetComponentsMut() const { + return std::tuple{GetComponent()...}; +} diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index 0d25774f..61061771 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -6165,12 +6165,9 @@ void GameMessages::HandleRemoveDonationItem(RakNet::BitStream& inStream, Entity* } void GameMessages::HandleConfirmDonationOnPlayer(RakNet::BitStream& inStream, Entity* entity) { - auto* inventoryComponent = entity->GetComponent(); - if (!inventoryComponent) return; - auto* missionComponent = entity->GetComponent(); - if (!missionComponent) return; - auto* characterComponent = entity->GetComponent(); - if (!characterComponent || !characterComponent->GetCurrentInteracting()) return; + const auto [inventoryComponent, missionComponent, characterComponent] = entity->GetComponentsMut(); + if (!inventoryComponent || !missionComponent || !characterComponent || !characterComponent->GetCurrentInteracting()) return; + auto* donationEntity = Game::entityManager->GetEntity(characterComponent->GetCurrentInteracting()); if (!donationEntity) return; auto* donationVendorComponent = donationEntity->GetComponent();