mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-09 01:38:20 +00:00
feature: Implement FallSpeedBehavior (#1084)
* Hacky FallSpeedBehavior * Fixup * Make it more robust like speedboost add check for default Fix error in GetActiveSpeedboosts * simplify and address feedback
This commit is contained in:
parent
07803a7ca2
commit
739eae5244
@ -61,6 +61,7 @@
|
||||
#include "SpeedBehavior.h"
|
||||
#include "DamageReductionBehavior.h"
|
||||
#include "JetPackBehavior.h"
|
||||
#include "FallSpeedBehavior.h"
|
||||
#include "ChangeIdleFlagsBehavior.h"
|
||||
#include "DarkInspirationBehavior.h"
|
||||
|
||||
@ -164,7 +165,9 @@ Behavior* Behavior::CreateBehavior(const uint32_t behaviorId) {
|
||||
case BehaviorTemplates::BEHAVIOR_CAR_BOOST:
|
||||
behavior = new CarBoostBehavior(behaviorId);
|
||||
break;
|
||||
case BehaviorTemplates::BEHAVIOR_FALL_SPEED: break;
|
||||
case BehaviorTemplates::BEHAVIOR_FALL_SPEED:
|
||||
behavior = new FallSpeedBehavior(behaviorId);
|
||||
break;
|
||||
case BehaviorTemplates::BEHAVIOR_SHIELD: break;
|
||||
case BehaviorTemplates::BEHAVIOR_REPAIR_ARMOR:
|
||||
behavior = new RepairBehavior(behaviorId);
|
||||
|
@ -22,6 +22,7 @@ set(DGAME_DBEHAVIORS_SOURCES "AirMovementBehavior.cpp"
|
||||
"DurationBehavior.cpp"
|
||||
"EmptyBehavior.cpp"
|
||||
"EndBehavior.cpp"
|
||||
"FallSpeedBehavior.cpp"
|
||||
"ForceMovementBehavior.cpp"
|
||||
"HealBehavior.cpp"
|
||||
"ImaginationBehavior.cpp"
|
||||
|
50
dGame/dBehaviors/FallSpeedBehavior.cpp
Normal file
50
dGame/dBehaviors/FallSpeedBehavior.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
#include "FallSpeedBehavior.h"
|
||||
|
||||
#include "ControllablePhysicsComponent.h"
|
||||
#include "BehaviorContext.h"
|
||||
#include "BehaviorBranchContext.h"
|
||||
|
||||
|
||||
void FallSpeedBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
// make sure required parameter has non-default value
|
||||
if (m_PercentSlowed == 0.0f) return;
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
if (!target) return;
|
||||
|
||||
auto* controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>();
|
||||
if (!controllablePhysicsComponent) return;
|
||||
controllablePhysicsComponent->SetGravityScale(m_PercentSlowed);
|
||||
EntityManager::Instance()->SerializeEntity(target);
|
||||
|
||||
if (branch.duration > 0.0f) {
|
||||
context->RegisterTimerBehavior(this, branch);
|
||||
} else if (branch.start > 0) {
|
||||
context->RegisterEndBehavior(this, branch);
|
||||
}
|
||||
}
|
||||
|
||||
void FallSpeedBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
Handle(context, bitStream, branch);
|
||||
}
|
||||
|
||||
void FallSpeedBehavior::Timer(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) {
|
||||
End(context, branch, second);
|
||||
}
|
||||
|
||||
void FallSpeedBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch) {
|
||||
End(context, branch, LWOOBJID_EMPTY);
|
||||
}
|
||||
|
||||
void FallSpeedBehavior::End(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) {
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
if (!target) return;
|
||||
|
||||
auto* controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>();
|
||||
if (!controllablePhysicsComponent) return;
|
||||
controllablePhysicsComponent->SetGravityScale(1);
|
||||
EntityManager::Instance()->SerializeEntity(target);
|
||||
}
|
||||
|
||||
void FallSpeedBehavior::Load(){
|
||||
m_PercentSlowed = GetFloat("percent_slowed");
|
||||
}
|
18
dGame/dBehaviors/FallSpeedBehavior.h
Normal file
18
dGame/dBehaviors/FallSpeedBehavior.h
Normal file
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include "Behavior.h"
|
||||
|
||||
class FallSpeedBehavior final : public Behavior
|
||||
{
|
||||
public:
|
||||
explicit FallSpeedBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {}
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
void Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
void Timer(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) override;
|
||||
void End(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) override;
|
||||
void UnCast(BehaviorContext* context, BehaviorBranchContext branch) override;
|
||||
void Load() override;
|
||||
|
||||
private:
|
||||
float m_PercentSlowed;
|
||||
};
|
@ -320,7 +320,7 @@ void ControllablePhysicsComponent::RemoveSpeedboost(float value) {
|
||||
|
||||
// Recalculate speedboost since we removed one
|
||||
m_SpeedBoost = 0.0f;
|
||||
if (m_ActiveSpeedBoosts.size() == 0) { // no active speed boosts left, so return to base speed
|
||||
if (m_ActiveSpeedBoosts.empty()) { // no active speed boosts left, so return to base speed
|
||||
auto* levelProgressionComponent = m_Parent->GetComponent<LevelProgressionComponent>();
|
||||
if (levelProgressionComponent) m_SpeedBoost = levelProgressionComponent->GetSpeedBase();
|
||||
} else { // Used the last applied speedboost
|
||||
|
@ -276,7 +276,7 @@ public:
|
||||
* The speed boosts of this component.
|
||||
* @return All active Speed boosts for this component.
|
||||
*/
|
||||
std::vector<float> GetActiveSpeedboosts() { return m_ActivePickupRadiusScales; };
|
||||
std::vector<float> GetActiveSpeedboosts() { return m_ActiveSpeedBoosts; };
|
||||
|
||||
/**
|
||||
* Activates the Bubble Buff
|
||||
|
Loading…
Reference in New Issue
Block a user