mirror of
				https://github.com/DarkflameUniverse/DarkflameServer.git
				synced 2025-11-04 14:42:02 +00:00 
			
		
		
		
	RailActivatorComponent pass
This commit is contained in:
		@@ -13,12 +13,21 @@
 | 
			
		||||
 | 
			
		||||
RailActivatorComponent::RailActivatorComponent(Entity* parent, int32_t componentID) : Component(parent) {
 | 
			
		||||
	m_ComponentID = componentID;
 | 
			
		||||
	const auto tableData = CDClientManager::Instance().GetTable<CDRailActivatorComponentTable>()->GetEntryByID(componentID);;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
	m_Path = parent->GetVar<std::u16string>(u"rail_path");
 | 
			
		||||
	m_PathDirection = parent->GetVar<bool>(u"rail_path_direction");
 | 
			
		||||
	m_PathStart = parent->GetVar<uint32_t>(u"rail_path_start");
 | 
			
		||||
void RailActivatorComponent::LoadConfigData() {
 | 
			
		||||
	m_Path = m_ParentEntity->GetVar<std::u16string>(u"rail_path");
 | 
			
		||||
	m_PathDirection = m_ParentEntity->GetVar<bool>(u"rail_path_direction");
 | 
			
		||||
	m_PathStart = m_ParentEntity->GetVar<uint32_t>(u"rail_path_start");
 | 
			
		||||
	m_DamageImmune = m_ParentEntity->GetVar<bool>(u"rail_activator_damage_immune");
 | 
			
		||||
	m_NoAggro = m_ParentEntity->GetVar<bool>(u"rail_no_aggro");
 | 
			
		||||
	m_NotifyArrived = m_ParentEntity->GetVar<bool>(u"rail_notify_activator_arrived");
 | 
			
		||||
	m_ShowNameBillboard = m_ParentEntity->GetVar<bool>(u"rail_show_name_billboard");
 | 
			
		||||
	m_UseDB = m_ParentEntity->GetVar<bool>(u"rail_use_db");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void RailActivatorComponent::LoadTemplateData() {
 | 
			
		||||
	const auto tableData = CDClientManager::Instance().GetTable<CDRailActivatorComponentTable>()->GetEntryByID(m_ComponentID);
 | 
			
		||||
	m_StartSound = tableData.startSound;
 | 
			
		||||
	m_loopSound = tableData.loopSound;
 | 
			
		||||
	m_StopSound = tableData.stopSound;
 | 
			
		||||
@@ -30,25 +39,16 @@ RailActivatorComponent::RailActivatorComponent(Entity* parent, int32_t component
 | 
			
		||||
	m_StartEffect = tableData.startEffectID;
 | 
			
		||||
	m_LoopEffect = tableData.loopEffectID;
 | 
			
		||||
	m_StopEffect = tableData.stopEffectID;
 | 
			
		||||
 | 
			
		||||
	m_DamageImmune = parent->GetVar<bool>(u"rail_activator_damage_immune");
 | 
			
		||||
	m_NoAggro = parent->GetVar<bool>(u"rail_no_aggro");
 | 
			
		||||
	m_NotifyArrived = parent->GetVar<bool>(u"rail_notify_activator_arrived");
 | 
			
		||||
	m_ShowNameBillboard = parent->GetVar<bool>(u"rail_show_name_billboard");
 | 
			
		||||
	m_UseDB = parent->GetVar<bool>(u"rail_use_db");
 | 
			
		||||
	m_CameraLocked = tableData.cameraLocked;
 | 
			
		||||
	m_CollisionEnabled = tableData.playerCollision;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
RailActivatorComponent::~RailActivatorComponent() = default;
 | 
			
		||||
 | 
			
		||||
void RailActivatorComponent::OnUse(Entity* originator) {
 | 
			
		||||
	auto* quickBuildComponent = m_ParentEntity->GetComponent<QuickBuildComponent>();
 | 
			
		||||
	if (quickBuildComponent != nullptr && quickBuildComponent->GetState() != eRebuildState::COMPLETED)
 | 
			
		||||
		return;
 | 
			
		||||
	if (quickBuildComponent && quickBuildComponent->GetState() != eRebuildState::COMPLETED) return;
 | 
			
		||||
 | 
			
		||||
	if (quickBuildComponent != nullptr) {
 | 
			
		||||
		// Don't want it to be destroyed while a player is using it
 | 
			
		||||
	// Don't want it to be destroyed while a player is using it
 | 
			
		||||
	if (quickBuildComponent) {
 | 
			
		||||
		quickBuildComponent->SetResetTime(quickBuildComponent->GetResetTime() + 10.0f);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -56,8 +56,7 @@ void RailActivatorComponent::OnUse(Entity* originator) {
 | 
			
		||||
 | 
			
		||||
	// Start the initial effects
 | 
			
		||||
	if (!m_StartEffect.second.empty()) {
 | 
			
		||||
		GameMessages::SendPlayFXEffect(originator->GetObjectID(), m_StartEffect.first, m_StartEffect.second,
 | 
			
		||||
			std::to_string(m_StartEffect.first));
 | 
			
		||||
		GameMessages::SendPlayFXEffect(originator->GetObjectID(), m_StartEffect.first, m_StartEffect.second, std::to_string(m_StartEffect.first));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	float animationLength = 0.5f;
 | 
			
		||||
@@ -70,9 +69,7 @@ void RailActivatorComponent::OnUse(Entity* originator) {
 | 
			
		||||
	m_ParentEntity->AddCallbackTimer(animationLength, [originatorID, this]() {
 | 
			
		||||
		auto* originator = EntityManager::Instance()->GetEntity(originatorID);
 | 
			
		||||
 | 
			
		||||
		if (originator == nullptr) {
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		if (!originator) return;
 | 
			
		||||
 | 
			
		||||
		GameMessages::SendStartRailMovement(originator->GetObjectID(), m_Path, m_StartSound,
 | 
			
		||||
			m_loopSound, m_StopSound, originator->GetSystemAddress(),
 | 
			
		||||
@@ -88,26 +85,26 @@ void RailActivatorComponent::OnRailMovementReady(Entity* originator) const {
 | 
			
		||||
		true, true, true, true, true, true, true
 | 
			
		||||
	);
 | 
			
		||||
 | 
			
		||||
	if (std::find(m_EntitiesOnRail.begin(), m_EntitiesOnRail.end(), originator->GetObjectID()) != m_EntitiesOnRail.end()) {
 | 
			
		||||
		// Stop the initial effects
 | 
			
		||||
		if (!m_StartEffect.second.empty()) {
 | 
			
		||||
			GameMessages::SendStopFXEffect(originator, false, std::to_string(m_StartEffect.first));
 | 
			
		||||
		}
 | 
			
		||||
	if (std::find(m_EntitiesOnRail.begin(), m_EntitiesOnRail.end(), originator->GetObjectID()) == m_EntitiesOnRail.end()) return;
 | 
			
		||||
 | 
			
		||||
		// Start the looping effects
 | 
			
		||||
		if (!m_LoopEffect.second.empty()) {
 | 
			
		||||
			GameMessages::SendPlayFXEffect(originator->GetObjectID(), m_LoopEffect.first, m_LoopEffect.second,
 | 
			
		||||
				std::to_string(m_LoopEffect.first));
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (!m_LoopAnimation.empty()) {
 | 
			
		||||
			RenderComponent::PlayAnimation(originator, m_LoopAnimation);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		GameMessages::SendSetRailMovement(originator->GetObjectID(), m_PathDirection, m_Path, m_PathStart,
 | 
			
		||||
			originator->GetSystemAddress(), m_ComponentID,
 | 
			
		||||
			m_ParentEntity->GetObjectID());
 | 
			
		||||
	// Stop the initial effects
 | 
			
		||||
	if (!m_StartEffect.second.empty()) {
 | 
			
		||||
		GameMessages::SendStopFXEffect(originator, false, std::to_string(m_StartEffect.first));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Start the looping effects
 | 
			
		||||
	if (!m_LoopEffect.second.empty()) {
 | 
			
		||||
		GameMessages::SendPlayFXEffect(originator->GetObjectID(), m_LoopEffect.first, m_LoopEffect.second,
 | 
			
		||||
			std::to_string(m_LoopEffect.first));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (!m_LoopAnimation.empty()) {
 | 
			
		||||
		RenderComponent::PlayAnimation(originator, m_LoopAnimation);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	GameMessages::SendSetRailMovement(originator->GetObjectID(), m_PathDirection, m_Path, m_PathStart,
 | 
			
		||||
		originator->GetSystemAddress(), m_ComponentID,
 | 
			
		||||
		m_ParentEntity->GetObjectID());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void RailActivatorComponent::OnCancelRailMovement(Entity* originator) {
 | 
			
		||||
@@ -118,29 +115,28 @@ void RailActivatorComponent::OnCancelRailMovement(Entity* originator) {
 | 
			
		||||
 | 
			
		||||
	auto* quickBuildComponent = m_ParentEntity->GetComponent<QuickBuildComponent>();
 | 
			
		||||
 | 
			
		||||
	if (quickBuildComponent != nullptr) {
 | 
			
		||||
		// Set back reset time
 | 
			
		||||
	// Set back reset time
 | 
			
		||||
	if (quickBuildComponent) {
 | 
			
		||||
		quickBuildComponent->SetResetTime(quickBuildComponent->GetResetTime() - 10.0f);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (std::find(m_EntitiesOnRail.begin(), m_EntitiesOnRail.end(), originator->GetObjectID()) != m_EntitiesOnRail.end()) {
 | 
			
		||||
		// Stop the looping effects
 | 
			
		||||
		if (!m_LoopEffect.second.empty()) {
 | 
			
		||||
			GameMessages::SendStopFXEffect(originator, false, std::to_string(m_LoopEffect.first));
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// Start the end effects
 | 
			
		||||
		if (!m_StopEffect.second.empty()) {
 | 
			
		||||
			GameMessages::SendPlayFXEffect(originator->GetObjectID(), m_StopEffect.first, m_StopEffect.second,
 | 
			
		||||
				std::to_string(m_StopEffect.first));
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (!m_StopAnimation.empty()) {
 | 
			
		||||
			RenderComponent::PlayAnimation(originator, m_StopAnimation);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// Remove the player after they've signalled they're done railing
 | 
			
		||||
		m_EntitiesOnRail.erase(std::remove(m_EntitiesOnRail.begin(), m_EntitiesOnRail.end(),
 | 
			
		||||
			originator->GetObjectID()), m_EntitiesOnRail.end());
 | 
			
		||||
	if (std::find(m_EntitiesOnRail.begin(), m_EntitiesOnRail.end(), originator->GetObjectID()) == m_EntitiesOnRail.end()) return;
 | 
			
		||||
	// Stop the looping effects
 | 
			
		||||
	if (!m_LoopEffect.second.empty()) {
 | 
			
		||||
		GameMessages::SendStopFXEffect(originator, false, std::to_string(m_LoopEffect.first));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Start the end effects
 | 
			
		||||
	if (!m_StopEffect.second.empty()) {
 | 
			
		||||
		GameMessages::SendPlayFXEffect(originator->GetObjectID(), m_StopEffect.first, m_StopEffect.second,
 | 
			
		||||
			std::to_string(m_StopEffect.first));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (!m_StopAnimation.empty()) {
 | 
			
		||||
		RenderComponent::PlayAnimation(originator, m_StopAnimation);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Remove the player after they've signalled they're done railing
 | 
			
		||||
	m_EntitiesOnRail.erase(std::remove(m_EntitiesOnRail.begin(), m_EntitiesOnRail.end(),
 | 
			
		||||
		originator->GetObjectID()), m_EntitiesOnRail.end());
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -12,11 +12,13 @@
 | 
			
		||||
 */
 | 
			
		||||
class RailActivatorComponent final : public Component {
 | 
			
		||||
public:
 | 
			
		||||
	explicit RailActivatorComponent(Entity* parent, int32_t componentID);
 | 
			
		||||
	~RailActivatorComponent() override;
 | 
			
		||||
 | 
			
		||||
	inline static const eReplicaComponentType ComponentType = eReplicaComponentType::RAIL_ACTIVATOR;
 | 
			
		||||
 | 
			
		||||
	explicit RailActivatorComponent(Entity* parent, int32_t componentID);
 | 
			
		||||
 | 
			
		||||
	void LoadConfigData() override;
 | 
			
		||||
	void LoadTemplateData() override;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Handles the OnUse event from some entity, initiates the rail movement
 | 
			
		||||
	 * @param originator the entity that triggered the event
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user