update loop cleanup

This commit is contained in:
jadebenn 2023-11-21 21:19:30 -06:00
parent 3f1468ebdf
commit e4b3e22570
2 changed files with 32 additions and 28 deletions

View File

@ -341,42 +341,18 @@ void PetComponent::Update(float deltaTime) {
} }
if (m_Owner == LWOOBJID_EMPTY) { if (m_Owner == LWOOBJID_EMPTY) {
if (m_Tamer != LWOOBJID_EMPTY) { UpdateUnowned(deltaTime);
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;
}
}
return; return;
} }
auto* owner = GetOwner(); auto* owner = GetOwner();
if (owner == nullptr) { if (!owner) {
m_Parent->Kill(); m_Parent->Kill();
return; return;
} }
m_MovementAI = m_Parent->GetComponent<MovementAIComponent>(); m_MovementAI = m_Parent->GetComponent<MovementAIComponent>();
if (m_MovementAI == nullptr) { if (!m_MovementAI) return;
return;
}
if (m_TresureTime > 0.0f) { //TODO: Find better trigger? if (m_TresureTime > 0.0f) { //TODO: Find better trigger?
InteractDig(deltaTime); InteractDig(deltaTime);
@ -404,7 +380,6 @@ void PetComponent::Update(float deltaTime) {
if (m_Timer > 0) { if (m_Timer > 0) {
m_Timer -= deltaTime; m_Timer -= deltaTime;
return; return;
} }
@ -468,6 +443,29 @@ skipTresure:
m_Timer = 1; 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) { void PetComponent::SetIsReadyToDig(bool isReady) {
if (isReady) { if (isReady) {
LOG("Dig state reached!"); LOG("Dig state reached!");

View File

@ -47,6 +47,12 @@ public:
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override; void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
void Update(float deltaTime) 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. * 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 * @param originator the entity that triggered the event