2021-12-05 17:54:36 +00:00
|
|
|
#include "BouncerComponent.h"
|
|
|
|
|
|
|
|
#include "EntityManager.h"
|
|
|
|
#include "dZoneManager.h"
|
|
|
|
#include "SwitchComponent.h"
|
|
|
|
#include "Game.h"
|
2023-10-21 23:31:55 +00:00
|
|
|
#include "Logger.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "GameMessages.h"
|
2024-01-05 12:33:52 +00:00
|
|
|
#include "BitStream.h"
|
2023-03-25 10:26:39 +00:00
|
|
|
#include "eTriggerEventType.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
BouncerComponent::BouncerComponent(Entity* parent) : Component(parent) {
|
|
|
|
m_PetEnabled = false;
|
|
|
|
m_PetBouncerEnabled = false;
|
|
|
|
m_PetSwitchLoaded = false;
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (parent->GetLOT() == 7625) {
|
2021-12-05 17:54:36 +00:00
|
|
|
LookupPetSwitch();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BouncerComponent::~BouncerComponent() {
|
|
|
|
}
|
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
void BouncerComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
|
|
|
|
outBitStream.Write(m_PetEnabled);
|
2021-12-05 17:54:36 +00:00
|
|
|
if (m_PetEnabled) {
|
2024-02-27 07:25:44 +00:00
|
|
|
outBitStream.Write(m_PetBouncerEnabled);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
Entity* BouncerComponent::GetParentEntity() const {
|
2021-12-05 17:54:36 +00:00
|
|
|
return m_Parent;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void BouncerComponent::SetPetEnabled(bool value) {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_PetEnabled = value;
|
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->SerializeEntity(m_Parent);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void BouncerComponent::SetPetBouncerEnabled(bool value) {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_PetBouncerEnabled = value;
|
|
|
|
|
|
|
|
GameMessages::SendBouncerActiveStatus(m_Parent->GetObjectID(), value, UNASSIGNED_SYSTEM_ADDRESS);
|
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->SerializeEntity(m_Parent);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (value) {
|
2023-03-25 10:26:39 +00:00
|
|
|
m_Parent->TriggerEvent(eTriggerEventType::PET_ON_SWITCH, m_Parent);
|
2021-12-05 17:54:36 +00:00
|
|
|
GameMessages::SendPlayFXEffect(m_Parent->GetObjectID(), 1513, u"create", "PetOnSwitch", LWOOBJID_EMPTY, 1, 1, true);
|
2022-07-28 13:39:57 +00:00
|
|
|
} else {
|
2023-03-25 10:26:39 +00:00
|
|
|
m_Parent->TriggerEvent(eTriggerEventType::PET_OFF_SWITCH, m_Parent);
|
2021-12-05 17:54:36 +00:00
|
|
|
GameMessages::SendStopFXEffect(m_Parent, true, "PetOnSwitch");
|
|
|
|
}
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
bool BouncerComponent::GetPetEnabled() const {
|
2021-12-05 17:54:36 +00:00
|
|
|
return m_PetEnabled;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
bool BouncerComponent::GetPetBouncerEnabled() const {
|
2021-12-05 17:54:36 +00:00
|
|
|
return m_PetBouncerEnabled;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void BouncerComponent::LookupPetSwitch() {
|
2021-12-05 17:54:36 +00:00
|
|
|
const auto& groups = m_Parent->GetGroups();
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (const auto& group : groups) {
|
2023-07-15 20:56:33 +00:00
|
|
|
const auto& entities = Game::entityManager->GetEntitiesInGroup(group);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (auto* entity : entities) {
|
2021-12-05 17:54:36 +00:00
|
|
|
auto* switchComponent = entity->GetComponent<SwitchComponent>();
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (switchComponent != nullptr) {
|
2021-12-05 17:54:36 +00:00
|
|
|
switchComponent->SetPetBouncer(this);
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
m_PetSwitchLoaded = true;
|
|
|
|
m_PetEnabled = true;
|
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->SerializeEntity(m_Parent);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("Loaded pet bouncer");
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (!m_PetSwitchLoaded) {
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("Failed to load pet bouncer");
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
m_Parent->AddCallbackTimer(0.5f, [this]() {
|
|
|
|
LookupPetSwitch();
|
2022-07-28 13:39:57 +00:00
|
|
|
});
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
}
|