2021-12-05 17:54:36 +00:00
# include "BouncerComponent.h"
# include "EntityManager.h"
# include "dZoneManager.h"
# include "SwitchComponent.h"
# include "Game.h"
# include "dLogger.h"
# include "GameMessages.h"
2023-06-26 08:19:49 +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 ) {
2023-06-26 08:19:49 +00:00
m_BounceOnCollision = false ;
m_DirtyBounceInfo = false ;
2021-12-05 17:54:36 +00:00
}
2023-06-26 08:19:49 +00:00
void BouncerComponent : : Startup ( ) {
if ( m_ParentEntity - > GetLOT ( ) = = 7625 ) LookupPetSwitch ( ) ;
2021-12-05 17:54:36 +00:00
}
2022-07-28 13:39:57 +00:00
void BouncerComponent : : Serialize ( RakNet : : BitStream * outBitStream , bool bIsInitialUpdate , unsigned int & flags ) {
2023-06-26 08:19:49 +00:00
outBitStream - > Write ( bIsInitialUpdate | | m_DirtyBounceInfo ) ;
if ( bIsInitialUpdate | | m_DirtyBounceInfo ) {
outBitStream - > Write ( m_BounceOnCollision ) ;
m_DirtyBounceInfo = false ;
2021-12-05 17:54:36 +00:00
}
}
2023-06-26 08:19:49 +00:00
void BouncerComponent : : SetBounceOnCollision ( bool value ) {
if ( m_BounceOnCollision = = value ) return ;
m_BounceOnCollision = value ;
m_DirtyBounceInfo = true ;
2021-12-05 17:54:36 +00:00
}
2023-06-26 08:19:49 +00:00
void BouncerComponent : : SetBouncerEnabled ( bool value ) {
m_BounceOnCollision = value ;
2021-12-05 17:54:36 +00:00
2023-06-09 09:46:01 +00:00
GameMessages : : SendBouncerActiveStatus ( m_ParentEntity - > GetObjectID ( ) , value , UNASSIGNED_SYSTEM_ADDRESS ) ;
2021-12-05 17:54:36 +00:00
2023-06-09 09:46:01 +00:00
EntityManager : : Instance ( ) - > SerializeEntity ( m_ParentEntity ) ;
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
if ( value ) {
2023-06-09 09:46:01 +00:00
m_ParentEntity - > TriggerEvent ( eTriggerEventType : : PET_ON_SWITCH , m_ParentEntity ) ;
2023-06-26 08:19:49 +00:00
GameMessages : : SendPlayFXEffect ( m_ParentEntity - > GetObjectID ( ) , 1513 , u " create " , " PetOnSwitch " ) ;
2022-07-28 13:39:57 +00:00
} else {
2023-06-09 09:46:01 +00:00
m_ParentEntity - > TriggerEvent ( eTriggerEventType : : PET_OFF_SWITCH , m_ParentEntity ) ;
GameMessages : : SendStopFXEffect ( m_ParentEntity , true , " PetOnSwitch " ) ;
2021-12-05 17:54:36 +00:00
}
}
2022-07-28 13:39:57 +00:00
void BouncerComponent : : LookupPetSwitch ( ) {
2023-06-09 09:46:01 +00:00
const auto & groups = m_ParentEntity - > GetGroups ( ) ;
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
for ( const auto & group : groups ) {
2021-12-05 17:54:36 +00:00
const auto & entities = EntityManager : : Instance ( ) - > GetEntitiesInGroup ( group ) ;
2022-07-28 13:39:57 +00:00
for ( auto * entity : entities ) {
2023-06-09 08:27:05 +00:00
auto * switchComponent = entity - > GetComponent < SwitchComponent > ( ) ;
2021-12-05 17:54:36 +00:00
2023-06-26 08:19:49 +00:00
if ( ! switchComponent ) continue ;
switchComponent - > SetPetBouncer ( this ) ;
2022-07-25 02:26:51 +00:00
2023-06-26 08:19:49 +00:00
m_DirtyBounceInfo = true ;
2021-12-05 17:54:36 +00:00
2023-06-26 08:19:49 +00:00
EntityManager : : Instance ( ) - > SerializeEntity ( m_ParentEntity ) ;
2021-12-05 17:54:36 +00:00
2023-06-26 08:19:49 +00:00
Game : : logger - > Log ( " BouncerComponent " , " Loaded bouncer %i:%llu " , m_ParentEntity - > GetLOT ( ) , m_ParentEntity - > GetObjectID ( ) ) ;
return ;
2021-12-05 17:54:36 +00:00
}
}
2023-06-26 08:19:49 +00:00
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 ) ;
2022-07-25 02:26:51 +00:00
2023-06-26 08:19:49 +00:00
m_ParentEntity - > AddCallbackTimer ( retryTime , [ this ] ( ) {
LookupPetSwitch ( ) ;
} ) ;
2021-12-05 17:54:36 +00:00
}