From 9e7ef8c4eea710981624d6ebf094277bfbc56aa2 Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Mon, 25 Nov 2024 20:55:50 -0800 Subject: [PATCH] fix: Player activated switches (#1655) --- dGame/Entity.cpp | 5 ----- dGame/dComponents/PetComponent.cpp | 2 +- dGame/dComponents/SwitchComponent.cpp | 20 ++++++++++++++++++++ dGame/dComponents/SwitchComponent.h | 3 +++ 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index 8066ce61..54629888 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -1351,11 +1351,6 @@ void Entity::OnCollisionPhantom(const LWOOBJID otherEntity) { callback(other); } - SwitchComponent* switchComp = GetComponent(); - if (switchComp) { - switchComp->EntityEnter(other); - } - TriggerEvent(eTriggerEventType::ENTER, other); // POI system diff --git a/dGame/dComponents/PetComponent.cpp b/dGame/dComponents/PetComponent.cpp index 4e34db25..c2783a15 100644 --- a/dGame/dComponents/PetComponent.cpp +++ b/dGame/dComponents/PetComponent.cpp @@ -381,7 +381,7 @@ void PetComponent::Update(float deltaTime) { float distance = Vector3::DistanceSquared(position, switchPosition); if (distance < 3 * 3) { m_Interaction = closestSwitch->GetParentEntity()->GetObjectID(); - closestSwitch->EntityEnter(m_Parent); + closestSwitch->OnUse(m_Parent); } else if (distance < 20 * 20) { haltDistance = 1; diff --git a/dGame/dComponents/SwitchComponent.cpp b/dGame/dComponents/SwitchComponent.cpp index e6ad6d00..cb13cc7f 100644 --- a/dGame/dComponents/SwitchComponent.cpp +++ b/dGame/dComponents/SwitchComponent.cpp @@ -2,6 +2,7 @@ #include "EntityManager.h" #include "eTriggerEventType.h" #include "RenderComponent.h" +#include "DestroyableComponent.h" std::vector SwitchComponent::petSwitches; @@ -11,6 +12,13 @@ SwitchComponent::SwitchComponent(Entity* parent) : Component(parent) { m_ResetTime = m_Parent->GetVarAs(u"switch_reset_time"); m_QuickBuild = m_Parent->GetComponent(); + + const auto factions = GeneralUtils::SplitString(m_Parent->GetVar(u"respond_to_faction"), u':'); + for (const auto& faction : factions) { + auto factionID = GeneralUtils::TryParse(GeneralUtils::UTF16ToWTF8(faction)); + if (!factionID) continue; + m_FactionsToRespondTo.push_back(factionID.value()); + } } SwitchComponent::~SwitchComponent() { @@ -25,6 +33,17 @@ void SwitchComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitial outBitStream.Write(m_Active); } +void SwitchComponent::OnUse(Entity* originator) { + const auto* const destroyableComponent = originator->GetComponent(); + if (!destroyableComponent) return; + for (const auto faction : m_FactionsToRespondTo) { + if (destroyableComponent->HasFaction(faction)) { + EntityEnter(originator); + break; + } + } +} + void SwitchComponent::SetActive(bool active) { m_Active = active; @@ -63,6 +82,7 @@ void SwitchComponent::EntityEnter(Entity* entity) { RenderComponent::PlayAnimation(m_Parent, u"engaged"); m_PetBouncer->SetPetBouncerEnabled(true); } else { + GameMessages::SendKnockback(entity->GetObjectID(), m_Parent->GetObjectID(), m_Parent->GetObjectID(), 0.0f, NiPoint3(0.0f, 17.0f, 0.0f)); Game::entityManager->SerializeEntity(m_Parent); } diff --git a/dGame/dComponents/SwitchComponent.h b/dGame/dComponents/SwitchComponent.h index 862e5719..49819481 100644 --- a/dGame/dComponents/SwitchComponent.h +++ b/dGame/dComponents/SwitchComponent.h @@ -22,6 +22,7 @@ public: ~SwitchComponent() override; void Update(float deltaTime) override; + void OnUse(Entity* originator) override; Entity* GetParentEntity() const; @@ -101,6 +102,8 @@ private: * Attached pet bouncer */ BouncerComponent* m_PetBouncer = nullptr; + + std::vector m_FactionsToRespondTo{}; }; #endif // SWITCHCOMPONENT_H