mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-22 21:47:24 +00:00
Bouncer cleanup
- Correct variable names - Make serialization more efficient and make sense - remove unneeded members - more descriptive logs - Move work to Startup
This commit is contained in:
parent
34cfd45d40
commit
a5611e9c7f
@ -6,41 +6,34 @@
|
||||
#include "Game.h"
|
||||
#include "dLogger.h"
|
||||
#include "GameMessages.h"
|
||||
#include <BitStream.h>
|
||||
#include "BitStream.h"
|
||||
#include "eTriggerEventType.h"
|
||||
|
||||
BouncerComponent::BouncerComponent(Entity* parent) : Component(parent) {
|
||||
m_PetEnabled = false;
|
||||
m_PetBouncerEnabled = false;
|
||||
m_PetSwitchLoaded = false;
|
||||
|
||||
if (parent->GetLOT() == 7625) {
|
||||
LookupPetSwitch();
|
||||
}
|
||||
m_BounceOnCollision = false;
|
||||
m_DirtyBounceInfo = false;
|
||||
}
|
||||
|
||||
BouncerComponent::~BouncerComponent() {
|
||||
void BouncerComponent::Startup() {
|
||||
if (m_ParentEntity->GetLOT() == 7625) LookupPetSwitch();
|
||||
}
|
||||
|
||||
void BouncerComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
||||
outBitStream->Write(m_PetEnabled);
|
||||
if (m_PetEnabled) {
|
||||
outBitStream->Write(m_PetBouncerEnabled);
|
||||
outBitStream->Write(bIsInitialUpdate || m_DirtyBounceInfo);
|
||||
if (bIsInitialUpdate || m_DirtyBounceInfo) {
|
||||
outBitStream->Write(m_BounceOnCollision);
|
||||
m_DirtyBounceInfo = false;
|
||||
}
|
||||
}
|
||||
|
||||
Entity* BouncerComponent::GetParentEntity() const {
|
||||
return m_ParentEntity;
|
||||
void BouncerComponent::SetBounceOnCollision(bool value) {
|
||||
if (m_BounceOnCollision == value) return;
|
||||
m_BounceOnCollision = value;
|
||||
m_DirtyBounceInfo = true;
|
||||
}
|
||||
|
||||
void BouncerComponent::SetPetEnabled(bool value) {
|
||||
m_PetEnabled = value;
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_ParentEntity);
|
||||
}
|
||||
|
||||
void BouncerComponent::SetPetBouncerEnabled(bool value) {
|
||||
m_PetBouncerEnabled = value;
|
||||
void BouncerComponent::SetBouncerEnabled(bool value) {
|
||||
m_BounceOnCollision = value;
|
||||
|
||||
GameMessages::SendBouncerActiveStatus(m_ParentEntity->GetObjectID(), value, UNASSIGNED_SYSTEM_ADDRESS);
|
||||
|
||||
@ -48,7 +41,7 @@ void BouncerComponent::SetPetBouncerEnabled(bool value) {
|
||||
|
||||
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);
|
||||
GameMessages::SendPlayFXEffect(m_ParentEntity->GetObjectID(), 1513, u"create", "PetOnSwitch");
|
||||
} else {
|
||||
m_ParentEntity->TriggerEvent(eTriggerEventType::PET_OFF_SWITCH, m_ParentEntity);
|
||||
GameMessages::SendStopFXEffect(m_ParentEntity, true, "PetOnSwitch");
|
||||
@ -56,14 +49,6 @@ void BouncerComponent::SetPetBouncerEnabled(bool value) {
|
||||
|
||||
}
|
||||
|
||||
bool BouncerComponent::GetPetEnabled() const {
|
||||
return m_PetEnabled;
|
||||
}
|
||||
|
||||
bool BouncerComponent::GetPetBouncerEnabled() const {
|
||||
return m_PetBouncerEnabled;
|
||||
}
|
||||
|
||||
void BouncerComponent::LookupPetSwitch() {
|
||||
const auto& groups = m_ParentEntity->GetGroups();
|
||||
|
||||
@ -73,24 +58,22 @@ void BouncerComponent::LookupPetSwitch() {
|
||||
for (auto* entity : entities) {
|
||||
auto* switchComponent = entity->GetComponent<SwitchComponent>();
|
||||
|
||||
if (switchComponent != nullptr) {
|
||||
switchComponent->SetPetBouncer(this);
|
||||
if (!switchComponent) continue;
|
||||
switchComponent->SetPetBouncer(this);
|
||||
|
||||
m_PetSwitchLoaded = true;
|
||||
m_PetEnabled = true;
|
||||
m_DirtyBounceInfo = true;
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_ParentEntity);
|
||||
EntityManager::Instance()->SerializeEntity(m_ParentEntity);
|
||||
|
||||
Game::logger->Log("BouncerComponent", "Loaded pet bouncer");
|
||||
}
|
||||
Game::logger->Log("BouncerComponent", "Loaded bouncer %i:%llu", m_ParentEntity->GetLOT(), m_ParentEntity->GetObjectID());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_PetSwitchLoaded) {
|
||||
Game::logger->Log("BouncerComponent", "Failed to load pet bouncer");
|
||||
float retryTime = 0.5f;
|
||||
Game::logger->Log("BouncerComponent", "Failed to load pet bouncer for %i:%llu, trying again in %f seconds", m_ParentEntity->GetLOT(), m_ParentEntity->GetObjectID(), retryTime);
|
||||
|
||||
m_ParentEntity->AddCallbackTimer(0.5f, [this]() {
|
||||
LookupPetSwitch();
|
||||
});
|
||||
}
|
||||
m_ParentEntity->AddCallbackTimer(retryTime, [this]() {
|
||||
LookupPetSwitch();
|
||||
});
|
||||
}
|
||||
|
@ -15,36 +15,22 @@ public:
|
||||
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::BOUNCER;
|
||||
|
||||
BouncerComponent(Entity* parentEntity);
|
||||
~BouncerComponent() override;
|
||||
|
||||
void Startup() override;
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
|
||||
|
||||
Entity* GetParentEntity() const;
|
||||
|
||||
/**
|
||||
* Sets whether or not this bouncer needs to be activated by a pet
|
||||
* @param value whether or not this bouncer needs to be activated by a pet
|
||||
*/
|
||||
void SetPetEnabled(bool value);
|
||||
void SetBounceOnCollision(bool value);
|
||||
|
||||
/**
|
||||
* Sets whether or not this bouncer is currently being activated by a pet, allowing entities to bounce off of it,
|
||||
* also displays FX accordingly.
|
||||
* @param value whether or not this bouncer is activated by a pet
|
||||
*/
|
||||
void SetPetBouncerEnabled(bool value);
|
||||
|
||||
/**
|
||||
* Gets whether this bouncer should be enabled using pets
|
||||
* @return whether this bouncer should be enabled using pets
|
||||
*/
|
||||
bool GetPetEnabled() const;
|
||||
|
||||
/**
|
||||
* Gets whether this bouncer is currently activated by a pet
|
||||
* @return whether this bouncer is currently activated by a pet
|
||||
*/
|
||||
bool GetPetBouncerEnabled() const;
|
||||
void SetBouncerEnabled(bool value);
|
||||
|
||||
/**
|
||||
* Finds the switch used to activate this bouncer if its pet-enabled and stores this components' state there
|
||||
@ -52,20 +38,12 @@ public:
|
||||
void LookupPetSwitch();
|
||||
|
||||
private:
|
||||
/**
|
||||
* Whether this bouncer needs to be activated by a pet
|
||||
*/
|
||||
bool m_PetEnabled;
|
||||
|
||||
/**
|
||||
* Whether this bouncer is currently being activated by a pet
|
||||
*/
|
||||
bool m_PetBouncerEnabled;
|
||||
bool m_BounceOnCollision;
|
||||
|
||||
/**
|
||||
* Whether the pet switch for this bouncer has been located
|
||||
*/
|
||||
bool m_PetSwitchLoaded;
|
||||
bool m_DirtyBounceInfo;
|
||||
};
|
||||
|
||||
#endif // BOUNCERCOMPONENT_H
|
||||
|
@ -28,9 +28,7 @@ void SwitchComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitial
|
||||
void SwitchComponent::SetActive(bool active) {
|
||||
m_Active = active;
|
||||
|
||||
if (m_PetBouncer != nullptr) {
|
||||
m_PetBouncer->SetPetBouncerEnabled(active);
|
||||
}
|
||||
if (m_PetBouncer) m_PetBouncer->SetBouncerEnabled(active);
|
||||
}
|
||||
|
||||
bool SwitchComponent::GetActive() const {
|
||||
@ -61,7 +59,7 @@ void SwitchComponent::EntityEnter(Entity* entity) {
|
||||
if (m_PetBouncer != nullptr) {
|
||||
GameMessages::SendPlayFXEffect(m_ParentEntity->GetObjectID(), 2602, u"pettriggeractive", "BounceEffect", LWOOBJID_EMPTY, 1, 1, true);
|
||||
RenderComponent::PlayAnimation(m_ParentEntity, u"engaged");
|
||||
m_PetBouncer->SetPetBouncerEnabled(true);
|
||||
m_PetBouncer->SetBouncerEnabled(true);
|
||||
} else {
|
||||
EntityManager::Instance()->SerializeEntity(m_ParentEntity);
|
||||
}
|
||||
@ -92,8 +90,8 @@ void SwitchComponent::Update(float deltaTime) {
|
||||
}
|
||||
}
|
||||
|
||||
if (m_PetBouncer != nullptr) {
|
||||
m_PetBouncer->SetPetBouncerEnabled(false);
|
||||
if (m_PetBouncer) {
|
||||
m_PetBouncer->SetBouncerEnabled(false);
|
||||
} else {
|
||||
EntityManager::Instance()->SerializeEntity(m_ParentEntity);
|
||||
}
|
||||
@ -126,7 +124,8 @@ void SwitchComponent::SetPetBouncer(BouncerComponent* value) {
|
||||
m_PetBouncer = value;
|
||||
|
||||
if (value != nullptr) {
|
||||
m_PetBouncer->SetPetEnabled(true);
|
||||
m_PetBouncer->SetBounceOnCollision(true);
|
||||
EntityManager::Instance()->SerializeEntity(m_PetBouncer->GetParentEntity());
|
||||
petSwitches.push_back(this);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user