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