DarkflameServer/dGame/dComponents/BouncerComponent.cpp

97 lines
2.5 KiB
C++
Raw Normal View History

#include "BouncerComponent.h"
#include "EntityManager.h"
#include "dZoneManager.h"
#include "SwitchComponent.h"
#include "Game.h"
#include "dLogger.h"
#include "GameMessages.h"
#include <BitStream.h>
#include "eTriggerEventType.h"
BouncerComponent::BouncerComponent(Entity* parent) : Component(parent) {
m_PetEnabled = false;
m_PetBouncerEnabled = false;
m_PetSwitchLoaded = false;
2022-07-28 13:39:57 +00:00
if (parent->GetLOT() == 7625) {
LookupPetSwitch();
}
}
BouncerComponent::~BouncerComponent() {
}
2022-07-28 13:39:57 +00:00
void BouncerComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
outBitStream->Write(m_PetEnabled);
if (m_PetEnabled) {
outBitStream->Write(m_PetBouncerEnabled);
}
}
2022-07-28 13:39:57 +00:00
Entity* BouncerComponent::GetParentEntity() const {
return m_ParentEntity;
}
2022-07-28 13:39:57 +00:00
void BouncerComponent::SetPetEnabled(bool value) {
m_PetEnabled = value;
EntityManager::Instance()->SerializeEntity(m_ParentEntity);
}
2022-07-28 13:39:57 +00:00
void BouncerComponent::SetPetBouncerEnabled(bool value) {
m_PetBouncerEnabled = value;
GameMessages::SendBouncerActiveStatus(m_ParentEntity->GetObjectID(), value, UNASSIGNED_SYSTEM_ADDRESS);
EntityManager::Instance()->SerializeEntity(m_ParentEntity);
2022-07-28 13:39:57 +00:00
if (value) {
m_ParentEntity->TriggerEvent(eTriggerEventType::PET_ON_SWITCH, m_ParentEntity);
GameMessages::SendPlayFXEffect(m_ParentEntity->GetObjectID(), 1513, u"create", "PetOnSwitch", LWOOBJID_EMPTY, 1, 1, true);
2022-07-28 13:39:57 +00:00
} else {
m_ParentEntity->TriggerEvent(eTriggerEventType::PET_OFF_SWITCH, m_ParentEntity);
GameMessages::SendStopFXEffect(m_ParentEntity, true, "PetOnSwitch");
}
}
2022-07-28 13:39:57 +00:00
bool BouncerComponent::GetPetEnabled() const {
return m_PetEnabled;
}
2022-07-28 13:39:57 +00:00
bool BouncerComponent::GetPetBouncerEnabled() const {
return m_PetBouncerEnabled;
}
2022-07-28 13:39:57 +00:00
void BouncerComponent::LookupPetSwitch() {
const auto& groups = m_ParentEntity->GetGroups();
2022-07-28 13:39:57 +00:00
for (const auto& group : groups) {
const auto& entities = EntityManager::Instance()->GetEntitiesInGroup(group);
2022-07-28 13:39:57 +00:00
for (auto* entity : entities) {
auto* switchComponent = entity->GetComponent<SwitchComponent>();
2022-07-28 13:39:57 +00:00
if (switchComponent != nullptr) {
switchComponent->SetPetBouncer(this);
m_PetSwitchLoaded = true;
m_PetEnabled = true;
EntityManager::Instance()->SerializeEntity(m_ParentEntity);
Game::logger->Log("BouncerComponent", "Loaded pet bouncer");
}
}
}
2022-07-28 13:39:57 +00:00
if (!m_PetSwitchLoaded) {
Game::logger->Log("BouncerComponent", "Failed to load pet bouncer");
m_ParentEntity->AddCallbackTimer(0.5f, [this]() {
LookupPetSwitch();
2022-07-28 13:39:57 +00:00
});
}
}