From a449e5323b6e5869129fcbf95329baf80f708d55 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sun, 3 Mar 2024 19:02:11 -0600 Subject: [PATCH] delete unused functions and update documentation --- dGame/dComponents/PetComponent.cpp | 129 ++++++++++------------- dGame/dComponents/PetComponent.h | 6 +- dGame/dUtilities/SlashCommandHandler.cpp | 12 +-- dScripts/02_server/Pets/DamagingPets.cpp | 8 +- docs/Commands.md | 4 + 5 files changed, 72 insertions(+), 87 deletions(-) diff --git a/dGame/dComponents/PetComponent.cpp b/dGame/dComponents/PetComponent.cpp index 48634f4b..db7bbc17 100644 --- a/dGame/dComponents/PetComponent.cpp +++ b/dGame/dComponents/PetComponent.cpp @@ -175,20 +175,20 @@ void PetComponent::OnUse(Entity* originator) { if (m_Owner != LWOOBJID_EMPTY) return; if (m_Tamer != LWOOBJID_EMPTY) { - auto* tamer = Game::entityManager->GetEntity(m_Tamer); + const auto* const tamer = Game::entityManager->GetEntity(m_Tamer); if (tamer != nullptr) return; m_Tamer = LWOOBJID_EMPTY; } - auto* inventoryComponent = originator->GetComponent(); + auto* const inventoryComponent = originator->GetComponent(); - if (inventoryComponent == nullptr) return; + if (!inventoryComponent) return; if (m_Preconditions != nullptr && !m_Preconditions->Check(originator, true)) return; - auto* movementAIComponent = m_Parent->GetComponent(); + auto* const movementAIComponent = m_Parent->GetComponent(); if (movementAIComponent != nullptr) { movementAIComponent->Stop(); @@ -240,11 +240,11 @@ void PetComponent::OnUse(Entity* originator) { imaginationCost = cached->second.imaginationCost; } - auto* destroyableComponent = originator->GetComponent(); + const auto* const destroyableComponent = originator->GetComponent(); - if (destroyableComponent == nullptr) return; + if (!destroyableComponent) return; - auto imagination = destroyableComponent->GetImagination(); + const auto imagination = destroyableComponent->GetImagination(); if (imagination < imaginationCost) return; @@ -257,9 +257,9 @@ void PetComponent::OnUse(Entity* originator) { return; } - auto petPosition = m_Parent->GetPosition(); + const auto petPosition = m_Parent->GetPosition(); - auto originatorPosition = originator->GetPosition(); + const auto originatorPosition = originator->GetPosition(); m_Parent->SetRotation(NiQuaternion::LookAt(petPosition, originatorPosition)); @@ -295,7 +295,7 @@ void PetComponent::OnUse(Entity* originator) { } - auto rotation = NiQuaternion::LookAt(position, petPosition); + const auto rotation = NiQuaternion::LookAt(position, petPosition); GameMessages::SendNotifyPetTamingMinigame( originator->GetObjectID(), @@ -345,21 +345,13 @@ void PetComponent::Update(float deltaTime) { // Remove "left behind" pets if (m_Owner != LWOOBJID_EMPTY) { - Entity* owner = GetOwner(); + const Entity* const owner = GetOwner(); if (!owner) { m_Parent->Kill(); return; } } - /*START_BITMASK_SWITCH(m_Flags) { - case TAMEABLE: - break; - - default: - LOG_DEBUG("Triggered default case!"); - }*/ - if (HasFlag(SPAWNING)) OnSpawn(); // Handle pet AI states @@ -417,9 +409,9 @@ void PetComponent::UpdateUnowned(float deltaTime) { //TODO: CURRENTLY UNUSED void PetComponent::TryBuild(uint32_t numBricks, bool clientFailed) { if (m_Tamer == LWOOBJID_EMPTY) return; - auto* tamer = Game::entityManager->GetEntity(m_Tamer); + auto* const tamer = Game::entityManager->GetEntity(m_Tamer); - if (tamer == nullptr) { + if (!tamer) { m_Tamer = LWOOBJID_EMPTY; return; @@ -429,9 +421,9 @@ void PetComponent::TryBuild(uint32_t numBricks, bool clientFailed) { if (cached == buildCache.end()) return; - auto* destroyableComponent = tamer->GetComponent(); + auto* const destroyableComponent = tamer->GetComponent(); - if (destroyableComponent == nullptr) return; + if (!destroyableComponent) return; auto imagination = destroyableComponent->GetImagination(); @@ -457,9 +449,9 @@ void PetComponent::TryBuild(uint32_t numBricks, bool clientFailed) { void PetComponent::NotifyTamingBuildSuccess(NiPoint3 position) { if (m_Tamer == LWOOBJID_EMPTY) return; - auto* tamer = Game::entityManager->GetEntity(m_Tamer); + auto* const tamer = Game::entityManager->GetEntity(m_Tamer); - if (tamer == nullptr) { + if (!tamer) { m_Tamer = LWOOBJID_EMPTY; return; @@ -480,7 +472,7 @@ void PetComponent::NotifyTamingBuildSuccess(NiPoint3 position) { info.rot = NiQuaternionConstant::IDENTITY; info.spawnerID = tamer->GetObjectID(); - auto* modelEntity = Game::entityManager->CreateEntity(info); + auto* const modelEntity = Game::entityManager->CreateEntity(info); m_ModelId = modelEntity->GetObjectID(); @@ -490,7 +482,7 @@ void PetComponent::NotifyTamingBuildSuccess(NiPoint3 position) { GameMessages::SendPetResponse(m_Tamer, m_Parent->GetObjectID(), 0, 10, 0, tamer->GetSystemAddress()); - auto* inventoryComponent = tamer->GetComponent(); + auto* const inventoryComponent = tamer->GetComponent(); if (!inventoryComponent) return; LWOOBJID petSubKey = ObjectIDManager::GenerateRandomObjectID(); @@ -511,7 +503,7 @@ void PetComponent::NotifyTamingBuildSuccess(NiPoint3 position) { inventoryComponent->AddItem(m_Parent->GetLOT(), 1, eLootSourceType::ACTIVITY, eInventoryType::MODELS, {}, LWOOBJID_EMPTY, true, false, petSubKey); - auto* item = inventoryComponent->FindItemBySubKey(petSubKey, MODELS); + auto* const item = inventoryComponent->FindItemBySubKey(petSubKey, MODELS); if (!item) return; DatabasePet databasePet{}; @@ -543,15 +535,15 @@ void PetComponent::NotifyTamingBuildSuccess(NiPoint3 position) { tamer->GetCharacter()->SetPlayerFlag(petFlags.at(m_Parent->GetLOT()), true); } - auto* missionComponent = tamer->GetComponent(); + auto* const missionComponent = tamer->GetComponent(); if (missionComponent != nullptr) { missionComponent->Progress(eMissionTaskType::PET_TAMING, m_Parent->GetLOT()); } - SetOnlyFlag(IDLE); // SetStatus(1); + SetOnlyFlag(IDLE); - auto* characterComponent = tamer->GetComponent(); + auto* const characterComponent = tamer->GetComponent(); if (characterComponent != nullptr) { characterComponent->UpdatePlayerStatistic(PetsTamed); } @@ -617,7 +609,7 @@ void PetComponent::RequestSetPetName(std::u16string name) { GameMessages::SendTerminateInteraction(m_Tamer, eTerminateType::FROM_INTERACTION, m_Parent->GetObjectID()); - auto* modelEntity = Game::entityManager->GetEntity(m_ModelId); + auto* const modelEntity = Game::entityManager->GetEntity(m_ModelId); if (modelEntity != nullptr) { modelEntity->Smash(m_Tamer); @@ -636,9 +628,9 @@ void PetComponent::RequestSetPetName(std::u16string name) { void PetComponent::ClientExitTamingMinigame(bool voluntaryExit) { if (m_Tamer == LWOOBJID_EMPTY) return; - auto* tamer = Game::entityManager->GetEntity(m_Tamer); + auto* const tamer = Game::entityManager->GetEntity(m_Tamer); - if (tamer == nullptr) { + if (!tamer) { m_Tamer = LWOOBJID_EMPTY; return; @@ -687,9 +679,9 @@ void PetComponent::StartTimer() { void PetComponent::ClientFailTamingMinigame() { if (m_Tamer == LWOOBJID_EMPTY) return; - auto* tamer = Game::entityManager->GetEntity(m_Tamer); + auto* const tamer = Game::entityManager->GetEntity(m_Tamer); - if (tamer == nullptr) { + if (!tamer) { m_Tamer = LWOOBJID_EMPTY; return; @@ -806,11 +798,11 @@ void PetComponent::OnFollow(const float deltaTime) { } // Determine if the "Lost Tags" mission has been completed and digging has been unlocked - auto* missionComponent = owner->GetComponent(); + const auto* const missionComponent = owner->GetComponent(); if (!missionComponent) return; const bool digUnlocked = missionComponent->GetMissionState(842) == eMissionState::COMPLETE; - Entity* closestTreasure = PetDigServer::GetClosestTresure(ownerPos); + const Entity* closestTreasure = PetDigServer::GetClosestTresure(ownerPos); const bool nonDragonForBone = closestTreasure->GetLOT() == 12192 && m_Parent->GetLOT() != 13067; if (!nonDragonForBone && closestTreasure != nullptr && digUnlocked) { const NiPoint3 treasurePos = closestTreasure->GetPosition(); @@ -893,7 +885,7 @@ void PetComponent::StartInteract(const NiPoint3& position, const PetInteractType } void PetComponent::StopInteract(bool bDontSerialize) { - Entity* owner = GetOwner(); + Entity* const owner = GetOwner(); if (!owner) return; const auto petAbility = ePetAbilityType::Invalid; @@ -917,7 +909,7 @@ void PetComponent::StopInteract(bool bDontSerialize) { } void PetComponent::SetupInteractBouncer() { - const auto* owner = GetOwner(); + const auto* const owner = GetOwner(); if (!owner) return; LOG_DEBUG("Setting up bouncer interaction!"); @@ -941,10 +933,10 @@ void PetComponent::SetupInteractBouncer() { } void PetComponent::StartInteractBouncer() { - Entity* user = GetOwner(); + Entity* const user = GetOwner(); if (IsHandlingInteraction() || !user) return; - auto* destroyableComponent = user->GetComponent(); + auto* const destroyableComponent = user->GetComponent(); if (!destroyableComponent) return; auto imagination = destroyableComponent->GetImagination(); @@ -1018,10 +1010,10 @@ void PetComponent::SetupInteractTreasureDig() { } void PetComponent::StartInteractTreasureDig() { - Entity* user = GetOwner(); + Entity* const user = GetOwner(); if (IsHandlingInteraction() || !user) return; - auto* destroyableComponent = user->GetComponent(); + auto* const destroyableComponent = user->GetComponent(); if (!destroyableComponent) return; auto imagination = destroyableComponent->GetImagination(); @@ -1077,7 +1069,7 @@ void PetComponent::Activate(Item* item, bool registerPet, bool fromTaming) { // m_ItemId = item->GetId(); m_DatabaseId = item->GetSubKey(); - auto* inventoryComponent = item->GetInventory()->GetComponent(); + auto* const inventoryComponent = item->GetInventory()->GetComponent(); if (inventoryComponent == nullptr) return; @@ -1085,10 +1077,10 @@ void PetComponent::Activate(Item* item, bool registerPet, bool fromTaming) { // m_Owner = inventoryComponent->GetParent()->GetObjectID(); - auto* owner = GetOwner(); + auto* const owner = GetOwner(); - if (owner == nullptr) return; - SetFlag(SPAWNING); //SetStatus(PetFlag::SPAWNING); + if (!owner) return; + SetFlag(SPAWNING); auto databaseData = inventoryComponent->GetDatabasePet(m_DatabaseId); @@ -1119,7 +1111,7 @@ void PetComponent::Activate(Item* item, bool registerPet, bool fromTaming) { // GameMessages::SendMarkInventoryItemAsActive(m_Owner, true, eUnequippableActiveType::PET, m_ItemId, GetOwner()->GetSystemAddress()); - activePets[m_Owner] = m_Parent->GetObjectID(); + activePets.emplace(m_Owner, m_Parent->GetObjectID()); Game::entityManager->SerializeEntity(m_Parent); @@ -1137,16 +1129,16 @@ void PetComponent::Activate(Item* item, bool registerPet, bool fromTaming) { // void PetComponent::AddDrainImaginationTimer(Item* item, bool fromTaming) { if (Game::config->GetValue("pets_take_imagination") != "1") return; - auto playerInventory = item->GetInventory(); + const auto* const playerInventory = item->GetInventory(); if (!playerInventory) return; - auto playerInventoryComponent = playerInventory->GetComponent(); + const auto* const playerInventoryComponent = playerInventory->GetComponent(); if (!playerInventoryComponent) return; - auto playerEntity = playerInventoryComponent->GetParent(); + const auto* const playerEntity = playerInventoryComponent->GetParent(); if (!playerEntity) return; - auto playerDestroyableComponent = playerEntity->GetComponent(); + auto* const playerDestroyableComponent = playerEntity->GetComponent(); if (!playerDestroyableComponent) return; // Drain by 1 when you summon pet or when this method is called, but not when we have just tamed this pet. @@ -1181,9 +1173,9 @@ void PetComponent::Deactivate() { m_Parent->Kill(); - auto* owner = GetOwner(); + const auto* const owner = GetOwner(); - if (owner == nullptr) return; + if (!owner) return; GameMessages::SendAddPetToPlayer(m_Owner, 0, u"", LWOOBJID_EMPTY, LOT_NULL, owner->GetSystemAddress()); @@ -1195,23 +1187,21 @@ void PetComponent::Deactivate() { } void PetComponent::Release() { - auto* inventoryComponent = GetOwner()->GetComponent(); + auto* const inventoryComponent = GetOwner()->GetComponent(); - if (inventoryComponent == nullptr) { - return; - } + if (!inventoryComponent) return; Deactivate(); inventoryComponent->RemoveDatabasePet(m_DatabaseId); - auto* item = inventoryComponent->FindItemBySubKey(m_DatabaseId); + auto* const item = inventoryComponent->FindItemBySubKey(m_DatabaseId); item->SetCount(0, false, false); } void PetComponent::Command(const NiPoint3& position, const LWOOBJID source, const int32_t commandType, const int32_t typeId, const bool overrideObey) { - auto* owner = GetOwner(); + auto* const owner = GetOwner(); if (!owner) return; if (commandType == 1) { @@ -1254,10 +1244,6 @@ LWOOBJID PetComponent::GetItemId() const { return m_ItemId; } -uint32_t PetComponent::GetStatus() const { - return m_Flags; -} - ePetAbilityType PetComponent::GetAbility() const { return m_Ability; } @@ -1266,11 +1252,6 @@ void PetComponent::SetInteraction(LWOOBJID value) { m_Interaction = value; } -void PetComponent::SetStatus(uint32_t value) { - m_Flags = value; - LOG_DEBUG("Pet status set to: %x", m_Flags); -} - void PetComponent::SetAbility(ePetAbilityType value) { m_Ability = value; } @@ -1282,9 +1263,9 @@ PetComponent* PetComponent::GetTamingPet(LWOOBJID tamer) { return nullptr; } - auto* entity = Game::entityManager->GetEntity(pair->second); + auto* const entity = Game::entityManager->GetEntity(pair->second); - if (entity == nullptr) { + if (!entity) { currentActivities.erase(tamer); return nullptr; @@ -1300,9 +1281,9 @@ PetComponent* PetComponent::GetActivePet(LWOOBJID owner) { return nullptr; } - auto* entity = Game::entityManager->GetEntity(pair->second); + auto* const entity = Game::entityManager->GetEntity(pair->second); - if (entity == nullptr) { + if (!entity) { activePets.erase(owner); return nullptr; diff --git a/dGame/dComponents/PetComponent.h b/dGame/dComponents/PetComponent.h index 001faa1e..d8b08b73 100644 --- a/dGame/dComponents/PetComponent.h +++ b/dGame/dComponents/PetComponent.h @@ -38,6 +38,7 @@ enum PetInteractType : uint8_t { enum PetFlag : uint32_t { NONE, IDLE = 1 << 0, //0x01 - Seems to be "idle," which the game doesn't differentiate from "follow" + UNKNOWN2 = 1 << 1, //0x02, UNKNOWN4 = 1 << 2, //0x04 - FOLLOWING(?) BEING_TAMED = 1 << 4, //0x10, NOT_WAITING = 1 << 5, //0x20, @@ -297,13 +298,13 @@ public: * bit map * @return the status of this pet */ - uint32_t GetStatus() const; + /*uint32_t GetStatus() const;*/ /** * Sets the current status of the pet * @param value the current status of the pet to set */ - void SetStatus(uint32_t value); + /*void SetStatus(uint32_t value);*/ /** * Returns an ability the pet may perform, currently unused @@ -585,7 +586,6 @@ private: /** * Pet information loaded from the CDClientDatabase - * TODO: Switch to a reference when safe to do so */ CDPetComponent m_PetInfo; }; diff --git a/dGame/dUtilities/SlashCommandHandler.cpp b/dGame/dUtilities/SlashCommandHandler.cpp index b989a4f1..f4f71675 100644 --- a/dGame/dUtilities/SlashCommandHandler.cpp +++ b/dGame/dUtilities/SlashCommandHandler.cpp @@ -710,17 +710,18 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit } // Pet status utility - if (chatCommand == "setpetstatus" && entity->GetGMLevel() >= eGameMasterLevel::DEVELOPER) { + if (chatCommand == "setpetflag" && entity->GetGMLevel() >= eGameMasterLevel::DEVELOPER) { if (args.size() == 0) { ChatPackets::SendSystemMessage(sysAddr, u"Too few arguments!"); return; } - const auto petStatus = GeneralUtils::TryParse(args[0]); - if (!petStatus) { + const auto petFlagInput = GeneralUtils::TryParse>(args[0]); + if (!petFlagInput) { ChatPackets::SendSystemMessage(sysAddr, u"Invalid pet status!"); return; } + const PetFlag petFlag = static_cast(1 << petFlagInput.value()); // Determine if player has a pet summoned auto* petComponent = PetComponent::GetActivePet(entity->GetObjectID()); @@ -729,10 +730,9 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit return; } - petComponent->SetStatus(petStatus.value()); - //Game::entityManager->SerializeEntity(petComponent->GetParentEntity()); + petComponent->SetFlag(petFlag); - std::u16string msg = u"Set pet status to " + (GeneralUtils::to_u16string(petStatus.value())); + std::u16string msg = u"Set pet flag to " + (GeneralUtils::to_u16string(petFlag)); ChatPackets::SendSystemMessage(sysAddr, msg); } diff --git a/dScripts/02_server/Pets/DamagingPets.cpp b/dScripts/02_server/Pets/DamagingPets.cpp index 6fd8c560..2702fa78 100644 --- a/dScripts/02_server/Pets/DamagingPets.cpp +++ b/dScripts/02_server/Pets/DamagingPets.cpp @@ -74,13 +74,13 @@ void DamagingPets::OnTimerDone(Entity* self, std::string message) { } void DamagingPets::MakeUntamable(Entity* self) { - auto* petComponent = self->GetComponent(); + auto* const petComponent = self->GetComponent(); // If the pet is currently not being tamed, make it hostile - if (petComponent != nullptr && petComponent->GetStatus() != 5) { + if (petComponent != nullptr && !petComponent->HasFlag(PetFlag::NOT_WAITING)) { self->SetNetworkVar(u"bIAmTamable", false); self->SetVar(u"IsEvil", true); - petComponent->SetStatus(1); + petComponent->SetFlag(PetFlag::IDLE); auto* combatAIComponent = self->GetComponent(); if (combatAIComponent != nullptr) { @@ -110,7 +110,7 @@ void DamagingPets::ClearEffects(Entity* self) { auto* petComponent = self->GetComponent(); if (petComponent != nullptr) { - petComponent->SetStatus(67108866); + petComponent->SetFlag(PetFlag::TAMEABLE, PetFlag::UNKNOWN2); } auto* combatAIComponent = self->GetComponent(); diff --git a/docs/Commands.md b/docs/Commands.md index d485847f..265ab60d 100644 --- a/docs/Commands.md +++ b/docs/Commands.md @@ -97,6 +97,10 @@ These commands are primarily for development and testing. The usage of many of t |setcontrolscheme|`/setcontrolscheme `|Sets the character control scheme to the specified number.|8| |setcurrency|`/setcurrency `|Sets your coins.|8| |setflag|`/setflag (value) `|Sets the given inventory or health flag to the given value, where value can be one of "on" or "off". If no value is given, by default this adds the flag to your character (equivalent of calling `/setflag on `).|8| +|setpetaccel|`/setpetaccel (value) `|Sets the acceleration of the owner's pet to the given value.|8| +|setpetflag|`/setpetflag (value) `|Sets the pet flag to the given value, where the value is one of the bitshift values specified in the PetFlags enum.|8| +|setpetmaxspeed|`/setpetmaxspeed (value) `|Sets the maximum speed of the owner's pet to the given value.|8| +|setpethalt|`/setpethalt (value) `|Sets the halting distance of the owner's pet to the given value.|8| |setinventorysize|`/setinventorysize (inventory)` or
`/setinvsize (inventory)`|Sets your inventory size to the given size. If `inventory` is provided, the number or string will be used to set that inventory to the requested size. Alias: `/setinvsize`|8| |setuistate|`/setuistate `|Changes UI state.|8| |spawn|`/spawn `|Spawns an object at your location by id.|8|