From 57a1c05e98c3869164bb98e24a7c5ad480a699a0 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Tue, 21 Nov 2023 21:19:30 -0600 Subject: [PATCH] update loop cleanup --- dGame/dComponents/PetComponent.cpp | 54 ++++++++++++++---------------- dGame/dComponents/PetComponent.h | 6 ++++ 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/dGame/dComponents/PetComponent.cpp b/dGame/dComponents/PetComponent.cpp index f979def4..de5a7ef3 100644 --- a/dGame/dComponents/PetComponent.cpp +++ b/dGame/dComponents/PetComponent.cpp @@ -341,42 +341,18 @@ void PetComponent::Update(float deltaTime) { } if (m_Owner == LWOOBJID_EMPTY) { - if (m_Tamer != LWOOBJID_EMPTY) { - if (m_Timer > 0) { - m_Timer -= deltaTime; - - if (m_Timer <= 0) { - m_Timer = 0; - - ClientFailTamingMinigame(); - } - } - } else { - if (m_Timer > 0) { - m_Timer -= deltaTime; - - if (m_Timer <= 0) { - Wander(); - Game::entityManager->SerializeEntity(m_Parent); - } - } else { - m_Timer = 5; - } - } - + UpdateUnowned(deltaTime); return; } auto* owner = GetOwner(); - if (owner == nullptr) { + if (!owner) { m_Parent->Kill(); return; } m_MovementAI = m_Parent->GetComponent(); - if (m_MovementAI == nullptr) { - return; - } + if (!m_MovementAI) return; if (m_TresureTime > 0.0f) { //TODO: Find better trigger? InteractDig(deltaTime); @@ -404,7 +380,6 @@ void PetComponent::Update(float deltaTime) { if (m_Timer > 0) { m_Timer -= deltaTime; - return; } @@ -468,6 +443,29 @@ skipTresure: m_Timer = 1; } +void PetComponent::UpdateUnowned(float deltaTime) { + if (m_Tamer != LWOOBJID_EMPTY) { + if (m_Timer > 0) { + m_Timer -= deltaTime; + + if (m_Timer <= 0) { + m_Timer = 0; + + ClientFailTamingMinigame(); + } + } + } + else { + if (m_Timer > 0) { + m_Timer -= deltaTime; + + if (m_Timer <= 0) Wander(); + } else { + m_Timer = 5; + } + } +} + void PetComponent::SetIsReadyToDig(bool isReady) { if (isReady) { LOG("Dig state reached!"); diff --git a/dGame/dComponents/PetComponent.h b/dGame/dComponents/PetComponent.h index 4ec0ef29..57f4a01f 100644 --- a/dGame/dComponents/PetComponent.h +++ b/dGame/dComponents/PetComponent.h @@ -47,6 +47,12 @@ public: void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override; void Update(float deltaTime) override; + /** + * Handles updates for unowned pets + * @param deltaTime time since last update + */ + void UpdateUnowned(float deltaTime); + /** * Handles an OnUse event from another entity, initializing the pet taming minigame if this pet is untamed. * @param originator the entity that triggered the event