Merge pull request #493 from EmosewaMC/ugh

Pets no longer cause client hitches in Nimbus Station and Forbidden Valley
This commit is contained in:
David Markowitz 2022-04-11 14:35:57 -07:00 committed by GitHub
commit e92cdc4f14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 89 deletions

View File

@ -231,7 +231,8 @@ void Entity::Initialize()
m_Components.insert(std::make_pair(COMPONENT_TYPE_RACING_STATS, nullptr));
}
if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_ITEM) > 0) {
PetComponent* petComponent;
if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_ITEM) > 0 && !TryGetComponent(COMPONENT_TYPE_PET, petComponent)) {
m_Components.insert(std::make_pair(COMPONENT_TYPE_ITEM, nullptr));
}

View File

@ -81,7 +81,7 @@ void PetComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpd
{
const bool tamed = m_Owner != LWOOBJID_EMPTY;
outBitStream->Write1(); // Dirty?
outBitStream->Write1(); // Always serialize as dirty for now
outBitStream->Write<uint32_t>(static_cast<unsigned int>(m_Status));
outBitStream->Write<uint32_t>(static_cast<uint32_t>(tamed ? m_Ability : PetAbilityType::Invalid)); // Something with the overhead icon?
@ -263,29 +263,12 @@ void PetComponent::OnUse(Entity* originator)
auto position = originatorPosition;
NiPoint3 forward = NiQuaternion::LookAt(m_Parent->GetPosition(), originator->GetPosition()).GetForwardVector(); //m_Parent->GetRotation().GetForwardVector();
NiPoint3 forward = NiQuaternion::LookAt(m_Parent->GetPosition(), originator->GetPosition()).GetForwardVector();
forward.y = 0;
if (dpWorld::Instance().IsLoaded())
{
/*
if (interactionDistance > 2)
{
interactionDistance -= 1;
}
*/
NiPoint3 attempt = petPosition + forward * interactionDistance;
/*
float deg = std::atan2(petPosition.z - originatorPosition.z, petPosition.x - originatorPosition.x); //* 180 / M_PI;
auto position = NiPoint3(
petPosition.x + interactionDistance * std::cos(-deg),
petPosition.y,
petPosition.z + interactionDistance * std::sin(-deg)
);
*/
float y = dpWorld::Instance().GetHeightAtPoint(attempt);
@ -309,8 +292,6 @@ void PetComponent::OnUse(Entity* originator)
auto rotation = NiQuaternion::LookAt(position, petPosition);
//GameMessages::SendTeleport(originator->GetObjectID(), position, rotation, originator->GetSystemAddress(), true);
GameMessages::SendNotifyPetTamingMinigame(
originator->GetObjectID(),
@ -532,14 +513,12 @@ void PetComponent::Update(float deltaTime)
m_Timer = 1;
}
void PetComponent::TryBuild(std::vector<Brick>& bricks, bool clientFailed)
{
void PetComponent::TryBuild(uint32_t numBricks, bool clientFailed) {
if (m_Tamer == LWOOBJID_EMPTY) return;
auto* tamer = EntityManager::Instance()->GetEntity(m_Tamer);
if (tamer == nullptr)
{
if (tamer == nullptr) {
m_Tamer = LWOOBJID_EMPTY;
return;
@ -547,19 +526,11 @@ void PetComponent::TryBuild(std::vector<Brick>& bricks, bool clientFailed)
const auto& cached = buildCache.find(m_Parent->GetLOT());
if (cached == buildCache.end())
{
GameMessages::SendPetTamingTryBuildResult(m_Tamer, false, 0, tamer->GetSystemAddress());
return;
}
if (cached == buildCache.end()) return;
auto* destroyableComponent = tamer->GetComponent<DestroyableComponent>();
if (destroyableComponent == nullptr)
{
return;
}
if (destroyableComponent == nullptr) return;
auto imagination = destroyableComponent->GetImagination();
@ -569,59 +540,17 @@ void PetComponent::TryBuild(std::vector<Brick>& bricks, bool clientFailed)
EntityManager::Instance()->SerializeEntity(tamer);
const auto& trueBricks = BrickDatabase::Instance()->GetBricks(cached->second.buildFile);
if (trueBricks.empty() || bricks.empty())
{
GameMessages::SendPetTamingTryBuildResult(m_Tamer, false, 0, tamer->GetSystemAddress());
return;
}
auto* brickIDTable = CDClientManager::Instance()->GetTable<CDBrickIDTableTable>("BrickIDTable");
int32_t correct = 0;
for (const auto& brick : bricks)
{
const auto brickEntries = brickIDTable->Query([brick](const CDBrickIDTable& entry)
{
return entry.NDObjectID == brick.designerID;
});
if (brickEntries.empty())
{
continue;
}
const auto designerID = brickEntries[0].LEGOBrickID;
for (const auto& trueBrick : trueBricks)
{
if (designerID == trueBrick.designerID && brick.materialID == trueBrick.materialID)
{
correct++;
break;
}
}
}
const auto success = correct >= cached->second.numValidPieces;
GameMessages::SendPetTamingTryBuildResult(m_Tamer, success, correct, tamer->GetSystemAddress());
if (!success)
{
if (imagination < cached->second.imaginationCost)
{
if (clientFailed) {
if (imagination < cached->second.imaginationCost) {
ClientFailTamingMinigame();
}
}
else
{
} else {
m_Timer = 0;
}
if (numBricks == 0) return;
GameMessages::SendPetTamingTryBuildResult(m_Tamer, !clientFailed, numBricks, tamer->GetSystemAddress());
}
void PetComponent::NotifyTamingBuildSuccess(NiPoint3 position)
@ -727,7 +656,6 @@ void PetComponent::NotifyTamingBuildSuccess(NiPoint3 position)
if (missionComponent != nullptr)
{
//missionComponent->ForceProgress(506, 768, 1, false);
missionComponent->Progress(MissionTaskType::MISSION_TASK_TYPE_PET_TAMING, m_Parent->GetLOT());
}

View File

@ -39,7 +39,7 @@ public:
* @param bricks the bricks to try to complete the minigame with
* @param clientFailed unused
*/
void TryBuild(std::vector<Brick>& bricks, bool clientFailed);
void TryBuild(uint32_t numBricks, bool clientFailed);
/**
* Handles a notification from the client regarding the completion of the pet minigame, adding the pet to their

View File

@ -3676,7 +3676,7 @@ void GameMessages::HandlePetTamingTryBuild(RakNet::BitStream* inStream, Entity*
return;
}
petComponent->TryBuild(bricks, clientFailed);
petComponent->TryBuild(bricks.size(), clientFailed);
}
void GameMessages::HandleNotifyTamingBuildSuccess(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr)