From 70e0cd6f93dfe1ee4996039171acbf610ae46982 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Tue, 13 Feb 2024 20:59:35 -0600 Subject: [PATCH] more merge --- dGame/dComponents/PetComponent.cpp | 13 +++-- dGame/dUtilities/SlashCommandHandler.cpp | 69 ++++++++++-------------- 2 files changed, 34 insertions(+), 48 deletions(-) diff --git a/dGame/dComponents/PetComponent.cpp b/dGame/dComponents/PetComponent.cpp index 111aa895..48634f4b 100644 --- a/dGame/dComponents/PetComponent.cpp +++ b/dGame/dComponents/PetComponent.cpp @@ -767,7 +767,7 @@ void PetComponent::Wander() { void PetComponent::OnSpawn() { m_MovementAI = m_Parent->GetComponent(); - if (m_StartPosition == NiPoint3::ZERO) { + if (m_StartPosition == NiPoint3Constant::ZERO) { m_StartPosition = m_Parent->GetPosition(); } @@ -982,7 +982,7 @@ void PetComponent::HandleInteractBouncer() { const auto bouncerId = bouncerComp->GetParentEntity()->GetObjectID(); bouncerComp->SetPetBouncerEnabled(true); - GameMessages::SendRequestClientBounce(bouncerId, this->GetOwnerId(), NiPoint3::ZERO, NiPoint3::ZERO, bouncerId, true, false, UNASSIGNED_SYSTEM_ADDRESS); //TODO: Check packet captures!! + GameMessages::SendRequestClientBounce(bouncerId, this->GetOwnerId(), NiPoint3Constant::ZERO, NiPoint3Constant::ZERO, bouncerId, true, false, UNASSIGNED_SYSTEM_ADDRESS); //TODO: Check packet captures!! bouncerComp->SetPetBouncerEnabled(false); RenderComponent::PlayAnimation(petSwitchEntity, u"up"); }); @@ -990,7 +990,7 @@ void PetComponent::HandleInteractBouncer() { RenderComponent::PlayAnimation(petSwitchEntity, u"launch"); //u"engaged"); //TODO: Check if the timing on this is right // TODO: Need to freeze player movement until the bounce begins! - Command(NiPoint3::ZERO, LWOOBJID_EMPTY, 1, PetEmote::ActivateSwitch, true); // Plays 'jump on switch' animation + Command(NiPoint3Constant::ZERO, LWOOBJID_EMPTY, 1, PetEmote::ActivateSwitch, true); // Plays 'jump on switch' animation StopInteract(); } m_Timer += 0.5f; @@ -1043,7 +1043,7 @@ void PetComponent::StartInteractTreasureDig() { LOG_DEBUG("StartInteractTreasureDig() m_Flags = %d", m_Flags); Game::entityManager->SerializeEntity(m_Parent); - Command(NiPoint3::ZERO, LWOOBJID_EMPTY, 1, PetEmote::DigTreasure, true); // Plays 'dig' animation + Command(NiPoint3Constant::ZERO, LWOOBJID_EMPTY, 1, PetEmote::DigTreasure, true); // Plays 'dig' animation m_Timer = 2.0f; } @@ -1064,7 +1064,7 @@ void PetComponent::HandleInteractTreasureDig() { } if (m_TimerBounce <= 0.0f) { - Command(NiPoint3::ZERO, LWOOBJID_EMPTY, 1, PetEmote::Bounce, true); // Plays 'bounce' animation + Command(NiPoint3Constant::ZERO, LWOOBJID_EMPTY, 1, PetEmote::Bounce, true); // Plays 'bounce' animation m_TimerBounce = 1.0f; } @@ -1153,7 +1153,6 @@ void PetComponent::AddDrainImaginationTimer(Item* item, bool fromTaming) { if (!fromTaming) playerDestroyableComponent->Imagine(-1); // Set this to a variable so when this is called back from the player the timer doesn't fire off. - m_Parent->AddCallbackTimer(m_PetInfo.imaginationDrainRate, [playerDestroyableComponent, this, item]() { m_Parent->AddCallbackTimer(m_PetInfo.imaginationDrainRate, [playerDestroyableComponent, this, item]() { if (!playerDestroyableComponent) { LOG("No petComponent and/or no playerDestroyableComponent"); @@ -1230,7 +1229,7 @@ void PetComponent::Command(const NiPoint3& position, const LWOOBJID source, cons } // Add movement functionality - if (position != NiPoint3::ZERO) { + if (position != NiPoint3Constant::ZERO) { m_MovementAI->SetDestination(position); } } diff --git a/dGame/dUtilities/SlashCommandHandler.cpp b/dGame/dUtilities/SlashCommandHandler.cpp index d96a330e..b989a4f1 100644 --- a/dGame/dUtilities/SlashCommandHandler.cpp +++ b/dGame/dUtilities/SlashCommandHandler.cpp @@ -716,8 +716,8 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit return; } - uint32_t petStatus; - if (!GeneralUtils::TryParse(args[0], petStatus)) { + const auto petStatus = GeneralUtils::TryParse(args[0]); + if (!petStatus) { ChatPackets::SendSystemMessage(sysAddr, u"Invalid pet status!"); return; } @@ -729,10 +729,10 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit return; } - petComponent->SetStatus(petStatus); + petComponent->SetStatus(petStatus.value()); //Game::entityManager->SerializeEntity(petComponent->GetParentEntity()); - std::u16string msg = u"Set pet status to " + (GeneralUtils::to_u16string(petStatus)); + std::u16string msg = u"Set pet status to " + (GeneralUtils::to_u16string(petStatus.value())); ChatPackets::SendSystemMessage(sysAddr, msg); } @@ -743,14 +743,14 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit return; } - int32_t commandType; - if (!GeneralUtils::TryParse(args[0+3], commandType)) { + const auto commandType = GeneralUtils::TryParse(args[0+3]); + if (!commandType) { ChatPackets::SendSystemMessage(sysAddr, u"Invalid command type!"); return; } - int32_t typeId; - if (!GeneralUtils::TryParse(args[1+3], typeId)) { + const auto typeId = GeneralUtils::TryParse(args[1+3]); + if (!typeId) { ChatPackets::SendSystemMessage(sysAddr, u"Invalid command type id!"); return; } @@ -763,29 +763,16 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit } //Determine the positional coordinates - NiPoint3 commandPos{}; - float x, y, z; - if (!GeneralUtils::TryParse(args[0], x)) { - ChatPackets::SendSystemMessage(sysAddr, u"Invalid x."); - return; - } - - if (!GeneralUtils::TryParse(args[1], y)) { - ChatPackets::SendSystemMessage(sysAddr, u"Invalid y."); - return; - } - - if (!GeneralUtils::TryParse(args[2], z)) { - ChatPackets::SendSystemMessage(sysAddr, u"Invalid z."); + //NiPoint3 commandPos{}; + //float x, y, z; + const auto commandPos = GeneralUtils::TryParse(args[0], args[1], args[2]); + if (!commandPos) { + ChatPackets::SendSystemMessage(sysAddr, u"Invalid position."); return; } // Set command position - commandPos.SetX(x); - commandPos.SetY(y); - commandPos.SetZ(z); - - petComponent->Command(commandPos, entity->GetObjectID(), commandType, typeId, true); + petComponent->Command(commandPos.value(), entity->GetObjectID(), commandType.value(), typeId.value(), true); } // Pet speed utility @@ -795,8 +782,8 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit return; } - float petMaxSpeed; - if (!GeneralUtils::TryParse(args[0], petMaxSpeed)) { + const auto petMaxSpeed = GeneralUtils::TryParse(args[0]); + if (!petMaxSpeed) { ChatPackets::SendSystemMessage(sysAddr, u"Invalid speed!"); return; } @@ -811,9 +798,9 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit auto* movementAIComponent = petComponent->GetParentEntity()->GetComponent(); if (!movementAIComponent) return; - movementAIComponent->SetMaxSpeed(petMaxSpeed); + movementAIComponent->SetMaxSpeed(petMaxSpeed.value()); - std::u16string msg = u"Set pet max speed to " + (GeneralUtils::to_u16string(petMaxSpeed)); + std::u16string msg = u"Set pet max speed to " + (GeneralUtils::to_u16string(petMaxSpeed.value())); ChatPackets::SendSystemMessage(sysAddr, msg); } @@ -824,25 +811,25 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit return; } - float petAccel; - if (!GeneralUtils::TryParse(args[0], petAccel)) { + const auto petAccel = GeneralUtils::TryParse(args[0]); + if (!petAccel) { ChatPackets::SendSystemMessage(sysAddr, u"Invalid acceleration!"); return; } // Determine if player has a pet summoned - auto* petComponent = PetComponent::GetActivePet(entity->GetObjectID()); + auto* const petComponent = PetComponent::GetActivePet(entity->GetObjectID()); if (!petComponent) { ChatPackets::SendSystemMessage(sysAddr, u"No active pet found!"); return; } - auto* movementAIComponent = petComponent->GetParentEntity()->GetComponent(); + auto* const movementAIComponent = petComponent->GetParentEntity()->GetComponent(); if (!movementAIComponent) return; - movementAIComponent->SetAcceleration(petAccel); + movementAIComponent->SetAcceleration(petAccel.value()); - std::u16string msg = u"Set pet acceleration to " + (GeneralUtils::to_u16string(petAccel)); + std::u16string msg = u"Set pet acceleration to " + GeneralUtils::to_u16string(petAccel.value()); ChatPackets::SendSystemMessage(sysAddr, msg); } @@ -853,8 +840,8 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit return; } - float petHaltDistance; - if (!GeneralUtils::TryParse(args[0], petHaltDistance)) { + const auto petHaltDistance = GeneralUtils::TryParse(args[0]); + if (!petHaltDistance) { ChatPackets::SendSystemMessage(sysAddr, u"Invalid halt distance!"); return; } @@ -869,9 +856,9 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit auto* movementAIComponent = petComponent->GetParentEntity()->GetComponent(); if (!movementAIComponent) return; - movementAIComponent->SetHaltDistance(petHaltDistance); + movementAIComponent->SetHaltDistance(petHaltDistance.value()); - std::u16string msg = u"Set pet halt distance to " + (GeneralUtils::to_u16string(petHaltDistance)); + std::u16string msg = u"Set pet halt distance to " + GeneralUtils::to_u16string(petHaltDistance.value()); ChatPackets::SendSystemMessage(sysAddr, msg); }