Revert "this commit may be kinda broke but I'm gonna push it to check something"

This reverts commit 071c022058.
This commit is contained in:
jadebenn 2024-04-20 17:32:19 -05:00
parent 071c022058
commit 7b223d1cc2
3 changed files with 102 additions and 102 deletions

View File

@ -85,7 +85,7 @@ PetComponent::PetComponent(Entity* parentEntity, uint32_t componentId)
m_MovementAI = nullptr;
m_ReadyToInteract = false;
m_State = PetAiState::SPAWN;
m_State = PetAiState::spawn;
SetIsHandlingInteraction(false);
std::string checkPreconditions = GeneralUtils::UTF16ToWTF8(parentEntity->GetVar<std::u16string>(u"CheckPrecondition"));
@ -139,76 +139,23 @@ void PetComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpd
void PetComponent::OnUse(Entity* originator) {
LOG_DEBUG("PET USE!");
if (!IsReadyToInteract()) return;
switch (m_Interaction.ability) {
case ePetAbilityType::DigAtPosition: // Treasure dig
StartInteractTreasureDig();
break;
if (IsReadyToInteract()) {
switch (m_Interaction.ability) {
case ePetAbilityType::DigAtPosition: // Treasure dig
StartInteractTreasureDig();
break;
case ePetAbilityType::JumpOnObject: // Bouncer
StartInteractBouncer();
break;
case ePetAbilityType::JumpOnObject: // Bouncer
StartInteractBouncer();
break;
default: // Pet taming minigame
StartTamingMinigame(originator);
break;
}
}
void PetComponent::Update(float deltaTime) {
// Update timers
m_TimerBounce -= deltaTime;
if (m_Timer > 0) {
m_Timer -= deltaTime;
return;
}
// Remove "left behind" pets and handle failing pet taming minigame
if (m_Owner != LWOOBJID_EMPTY) {
const Entity* const owner = GetOwner();
if (!owner) {
m_Parent->Kill();
return;
default:
break;
}
} else {
ClientFailTamingMinigame(); // TODO: This is not despawning the built model correctly
}
if (m_Flags.Has<PetFlag::SPAWNING>()) OnSpawn();
// Handle pet AI states
switch (m_State) {
case PetAiState::IDLE:
Wander();
break;
case PetAiState::FOLLOW:
OnFollow(deltaTime);
break;
case PetAiState::GO_TO_OBJ:
if (m_MovementAI->AtFinalWaypoint()) {
LOG_DEBUG("Reached object!");
m_MovementAI->Stop();
SetPetAiState(PetAiState::INTERACT);
} else {
m_Timer += 0.5f;
}
break;
case PetAiState::INTERACT:
OnInteract();
break;
default:
LOG_DEBUG("Unknown state: %d!", m_Flags);
break;
}
}
void PetComponent::StartTamingMinigame(Entity* originator) {
// The minigame logic beneath this comment should be rewritten... eventually
if (m_Owner != LWOOBJID_EMPTY) return;
if (m_Tamer != LWOOBJID_EMPTY) {
@ -220,6 +167,7 @@ void PetComponent::StartTamingMinigame(Entity* originator) {
}
auto* const inventoryComponent = originator->GetComponent<InventoryComponent>();
if (!inventoryComponent) return;
if (m_Preconditions.has_value() && !m_Preconditions->Check(originator, true)) return;
@ -238,7 +186,7 @@ void PetComponent::StartTamingMinigame(Entity* originator) {
std::string buildFile;
// It may make sense to move this minigame-specific logic into another file
if (cached == buildCache.cend()) {
if (cached == buildCache.end()) {
auto query = CDClientDatabase::CreatePreppedStmt(
"SELECT ValidPiecesLXF, PuzzleModelLot, Timelimit, NumValidPieces, imagCostPerBuild FROM TamingBuildPuzzles WHERE NPCLot = ?;");
query.bind(1, static_cast<int>(m_Parent->GetLOT()));
@ -278,9 +226,11 @@ void PetComponent::StartTamingMinigame(Entity* originator) {
}
const auto* const destroyableComponent = originator->GetComponent<DestroyableComponent>();
if (!destroyableComponent) return;
const auto imagination = destroyableComponent->GetImagination();
if (imagination < imaginationCost) return;
const auto& bricks = BrickDatabase::GetBricks(buildFile);
@ -293,11 +243,13 @@ void PetComponent::StartTamingMinigame(Entity* originator) {
}
const auto petPosition = m_Parent->GetPosition();
const auto originatorPosition = originator->GetPosition();
m_Parent->SetRotation(NiQuaternion::LookAt(petPosition, originatorPosition));
float interactionDistance = m_Parent->GetVar<float>(u"interaction_distance");
if (interactionDistance <= 0) {
interactionDistance = 15;
}
@ -365,6 +317,58 @@ void PetComponent::StartTamingMinigame(Entity* originator) {
m_Parent->GetScript()->OnNotifyPetTamingMinigame(m_Parent, originator, ePetTamingNotifyType::BEGIN);
}
void PetComponent::Update(float deltaTime) {
// Update timers
m_TimerBounce -= deltaTime;
if (m_Timer > 0) {
m_Timer -= deltaTime;
return;
}
// Remove "left behind" pets and handle failing pet taming minigame
if (m_Owner != LWOOBJID_EMPTY) {
const Entity* const owner = GetOwner();
if (!owner) {
m_Parent->Kill();
return;
}
} else {
ClientFailTamingMinigame(); // TODO: This is not despawning the built model correctly
}
if (m_Flags.Has<PetFlag::SPAWNING>()) OnSpawn();
// Handle pet AI states
switch (m_State) {
case PetAiState::idle:
Wander();
break;
case PetAiState::follow:
OnFollow(deltaTime);
break;
case PetAiState::goToObj:
if (m_MovementAI->AtFinalWaypoint()) {
LOG_DEBUG("Reached object!");
m_MovementAI->Stop();
SetPetAiState(PetAiState::interact);
} else {
m_Timer += 0.5f;
}
break;
case PetAiState::interact:
OnInteract();
break;
default:
LOG_DEBUG("Unknown state: %d!", m_Flags);
break;
}
}
void PetComponent::TryBuild(uint32_t numBricks, bool clientFailed) {
if (m_Tamer == LWOOBJID_EMPTY) return;
@ -624,7 +628,7 @@ void PetComponent::ClientExitTamingMinigame(bool voluntaryExit) {
void PetComponent::StartTimer() {
const auto& cached = buildCache.find(m_Parent->GetLOT());
if (cached == buildCache.cend()) {
if (cached == buildCache.end()) {
return;
}
@ -720,10 +724,10 @@ void PetComponent::OnSpawn() {
m_Parent->SetOwnerOverride(m_Owner);
m_MovementAI->SetMaxSpeed(m_PetInfo.sprintSpeed);
m_MovementAI->SetHaltDistance(m_FollowRadius);
SetPetAiState(PetAiState::FOLLOW);
SetPetAiState(PetAiState::follow);
} else {
m_Flags.Set<PetFlag::TAMEABLE>();
SetPetAiState(PetAiState::IDLE);
SetPetAiState(PetAiState::idle);
}
m_Flags.Set<PetFlag::IDLE>();
@ -744,7 +748,7 @@ void PetComponent::OnFollow(const float deltaTime) {
const LWOOBJID switchID = closestSwitch->GetParentEntity()->GetObjectID();
const float distance = Vector3::DistanceSquared(ownerPos, switchPos);
if (distance < 16 * 16) {
StartInteract(switchPos, PetInteractType::BOUNCER, switchID);
StartInteract(switchPos, PetInteractType::bouncer, switchID);
return;
}
}
@ -760,7 +764,7 @@ void PetComponent::OnFollow(const float deltaTime) {
const NiPoint3 treasurePos = closestTreasure->GetPosition();
const float distance = Vector3::DistanceSquared(ownerPos, treasurePos);
if (distance < 16 * 16) {
StartInteract(treasurePos, PetInteractType::TREASURE, m_Owner);
StartInteract(treasurePos, PetInteractType::treasure, m_Owner);
return;
}
}
@ -806,12 +810,12 @@ void PetComponent::OnInteract() {
}
switch (m_Interaction.type) {
case PetInteractType::BOUNCER:
case PetInteractType::bouncer:
if (IsReadyToInteract()) HandleInteractBouncer();
else SetupInteractBouncer();
break;
case PetInteractType::TREASURE:
case PetInteractType::treasure:
if (IsReadyToInteract()) HandleInteractTreasureDig();
else SetupInteractTreasureDig();
break;
@ -828,7 +832,7 @@ void PetComponent::StartInteract(const NiPoint3 position, const PetInteractType
m_Interaction.obj = interactID; // TODO: Check if this should be serialized for goToObj
m_Interaction.type = interactionType;
m_Interaction.ability = ePetAbilityType::GoToObject;
SetPetAiState(PetAiState::GO_TO_OBJ);
SetPetAiState(PetAiState::goToObj);
m_MovementAI->SetMaxSpeed(m_PetInfo.runSpeed);
m_MovementAI->SetHaltDistance(0.0f);
m_MovementAI->SetDestination(position);
@ -843,10 +847,11 @@ void PetComponent::StopInteract(bool bDontSerialize) {
constexpr auto petAbility = ePetAbilityType::Invalid;
m_Interaction.obj = LWOOBJID_EMPTY;
m_Interaction.type = PetInteractType::NONE;
m_Interaction.type = PetInteractType::none;
m_Interaction.ability = petAbility;
SetPetAiState(PetAiState::FOLLOW);
SetPetAiState(PetAiState::follow);
m_Flags.Reset<PetFlag::IDLE>();
SetIsReadyToInteract(false);
SetIsHandlingInteraction(false); // Needed?
m_MovementAI->SetMaxSpeed(m_PetInfo.sprintSpeed);
m_MovementAI->SetHaltDistance(m_FollowRadius);
@ -1165,7 +1170,7 @@ void PetComponent::Command(const NiPoint3& position, const LWOOBJID source, cons
GameMessages::SendPlayEmote(m_Parent->GetObjectID(), typeId, owner->GetObjectID(), UNASSIGNED_SYSTEM_ADDRESS);
} else if (commandType == 3) {
StopInteract(); // TODO: Verify this is necessary
SetPetAiState(PetAiState::FOLLOW);
SetPetAiState(PetAiState::follow);
} else if (commandType == 6) {
// TODO: Go to player
}

View File

@ -18,21 +18,21 @@
* The current state of the pet AI
*/
enum class PetAiState : uint8_t {
IDLE = 0, // Doing nothing
SPAWN, // Spawning into the world
FOLLOW, // Begin following
GO_TO_OBJ, // Go to object
INTERACT, // Interact with an object
DESPAWN // Despawning from world
idle = 0, // Doing nothing
spawn, // Spawning into the world
follow, // Begin following
goToObj, // Go to object
interact, // Interact with an object
despawn // Despawning from world
};
/*
* The type of object the pet is interacting with
*/
enum class PetInteractType : uint8_t {
NONE, // Not interacting
TREASURE, // Treasure dig
BOUNCER // Bouncer switch
none, // Not interacting
treasure, // Treasure dig
bouncer // Bouncer switch
};
/**
@ -113,11 +113,6 @@ public:
*/
void OnUse(Entity* originator) override;
/**
* Start the pet taming minigame
*/
void StartTamingMinigame(Entity* originator);
/**
* Attempts to complete the pet minigame by passing a list of bricks to build the minigame model.
* @param bricks the bricks to try to complete the minigame with
@ -401,7 +396,7 @@ private:
/**
* The type of object that the pet is currently interacting with (e.g. a treasure chest or switch)
*/
PetInteractType type = PetInteractType::NONE;
PetInteractType type = PetInteractType::none;
/**
* The interaction ability

View File

@ -41,25 +41,25 @@ TEST_F(PetTest, PlacementNewAddComponentTest) {
// Test getting initial status
ASSERT_EQ(petComponent->GetParent()->GetObjectID(), 15);
ASSERT_EQ(petComponent->GetPetAiState(), PetAiState::SPAWN);
ASSERT_EQ(petComponent->GetPetAiState(), PetAiState::spawn);
}
TEST_F(PetTest, PetAiState) {
const auto initialState = petComponent->GetPetAiState();
ASSERT_EQ(initialState, PetAiState::SPAWN);
ASSERT_EQ(initialState, PetAiState::spawn);
petComponent->SetPetAiState(PetAiState::FOLLOW);
ASSERT_EQ(PetAiState::FOLLOW, petComponent->GetPetAiState());
petComponent->SetPetAiState(PetAiState::follow);
ASSERT_EQ(PetAiState::follow, petComponent->GetPetAiState());
petComponent->SetPetAiState(PetAiState::IDLE);
ASSERT_EQ(PetAiState::IDLE, petComponent->GetPetAiState());
petComponent->SetPetAiState(PetAiState::idle);
ASSERT_EQ(PetAiState::idle, petComponent->GetPetAiState());
petComponent->SetPetAiState(PetAiState::INTERACT);
ASSERT_EQ(PetAiState::INTERACT, petComponent->GetPetAiState());
petComponent->SetPetAiState(PetAiState::interact);
ASSERT_EQ(PetAiState::interact, petComponent->GetPetAiState());
petComponent->SetPetAiState(PetAiState::DESPAWN);
ASSERT_EQ(PetAiState::DESPAWN, petComponent->GetPetAiState());
petComponent->SetPetAiState(PetAiState::despawn);
ASSERT_EQ(PetAiState::despawn, petComponent->GetPetAiState());
}
// Test the pet use logic