mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-12-22 21:43:35 +00:00
Merge pull request #524 from EmosewaMC/lootBuffFix
Added LootBuff behavior and serialization
This commit is contained in:
commit
94c00417ff
@ -19,6 +19,12 @@ void AndBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStre
|
||||
}
|
||||
}
|
||||
|
||||
void AndBehavior::UnCast(BehaviorContext* context, const BehaviorBranchContext branch) {
|
||||
for (auto behavior : this->m_behaviors) {
|
||||
behavior->UnCast(context, branch);
|
||||
}
|
||||
}
|
||||
|
||||
void AndBehavior::Load()
|
||||
{
|
||||
const auto parameters = GetParameterNames();
|
||||
|
@ -20,5 +20,7 @@ public:
|
||||
|
||||
void Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
void UnCast(BehaviorContext* context, BehaviorBranchContext branch) override;
|
||||
|
||||
void Load() override;
|
||||
};
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "AreaOfEffectBehavior.h"
|
||||
#include "DurationBehavior.h"
|
||||
#include "TacArcBehavior.h"
|
||||
#include "LootBuffBehavior.h"
|
||||
#include "AttackDelayBehavior.h"
|
||||
#include "BasicAttackBehavior.h"
|
||||
#include "ChainBehavior.h"
|
||||
@ -172,7 +173,9 @@ Behavior* Behavior::CreateBehavior(const uint32_t behaviorId)
|
||||
behavior = new SpeedBehavior(behaviorId);
|
||||
break;
|
||||
case BehaviorTemplates::BEHAVIOR_DARK_INSPIRATION: break;
|
||||
case BehaviorTemplates::BEHAVIOR_LOOT_BUFF: break;
|
||||
case BehaviorTemplates::BEHAVIOR_LOOT_BUFF:
|
||||
behavior = new LootBuffBehavior(behaviorId);
|
||||
break;
|
||||
case BehaviorTemplates::BEHAVIOR_VENTURE_VISION: break;
|
||||
case BehaviorTemplates::BEHAVIOR_SPAWN_OBJECT:
|
||||
behavior = new SpawnBehavior(behaviorId);
|
||||
|
@ -64,8 +64,8 @@ void BehaviorContext::RegisterSyncBehavior(const uint32_t syncId, Behavior* beha
|
||||
|
||||
void BehaviorContext::RegisterTimerBehavior(Behavior* behavior, const BehaviorBranchContext& branchContext, const LWOOBJID second)
|
||||
{
|
||||
BehaviorTimerEntry entry
|
||||
;
|
||||
BehaviorTimerEntry entry;
|
||||
|
||||
entry.time = branchContext.duration;
|
||||
entry.behavior = behavior;
|
||||
entry.branchContext = branchContext;
|
||||
|
38
dGame/dBehaviors/LootBuffBehavior.cpp
Normal file
38
dGame/dBehaviors/LootBuffBehavior.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include "LootBuffBehavior.h"
|
||||
|
||||
void LootBuffBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
auto target = EntityManager::Instance()->GetEntity(context->caster);
|
||||
if (!target) return;
|
||||
|
||||
auto controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>();
|
||||
if (!controllablePhysicsComponent) return;
|
||||
|
||||
controllablePhysicsComponent->AddPickupRadiusScale(m_Scale);
|
||||
EntityManager::Instance()->SerializeEntity(target);
|
||||
|
||||
if (branch.duration > 0) context->RegisterTimerBehavior(this, branch);
|
||||
|
||||
}
|
||||
|
||||
void LootBuffBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
Handle(context, bitStream, branch);
|
||||
}
|
||||
|
||||
void LootBuffBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch) {
|
||||
auto target = EntityManager::Instance()->GetEntity(context->caster);
|
||||
if (!target) return;
|
||||
|
||||
auto controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>();
|
||||
if (!controllablePhysicsComponent) return;
|
||||
|
||||
controllablePhysicsComponent->RemovePickupRadiusScale(m_Scale);
|
||||
EntityManager::Instance()->SerializeEntity(target);
|
||||
}
|
||||
|
||||
void LootBuffBehavior::Timer(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) {
|
||||
UnCast(context, branch);
|
||||
}
|
||||
|
||||
void LootBuffBehavior::Load() {
|
||||
this->m_Scale = GetFloat("scale");
|
||||
}
|
32
dGame/dBehaviors/LootBuffBehavior.h
Normal file
32
dGame/dBehaviors/LootBuffBehavior.h
Normal file
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include "Behavior.h"
|
||||
#include "BehaviorBranchContext.h"
|
||||
#include "BehaviorContext.h"
|
||||
#include "ControllablePhysicsComponent.h"
|
||||
|
||||
/**
|
||||
* @brief This is the behavior class to be used for all Loot Buff behavior nodes in the Behavior tree.
|
||||
*
|
||||
*/
|
||||
class LootBuffBehavior final : public Behavior
|
||||
{
|
||||
public:
|
||||
|
||||
float m_Scale;
|
||||
|
||||
/*
|
||||
* Inherited
|
||||
*/
|
||||
|
||||
explicit LootBuffBehavior(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 UnCast(BehaviorContext* context, BehaviorBranchContext branch) override;
|
||||
|
||||
void Timer(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) override;
|
||||
|
||||
void Load() override;
|
||||
};
|
@ -29,6 +29,8 @@ ControllablePhysicsComponent::ControllablePhysicsComponent(Entity* entity) : Com
|
||||
m_GravityScale = 1;
|
||||
m_DirtyCheats = false;
|
||||
m_IgnoreMultipliers = false;
|
||||
m_PickupRadius = 0.0f;
|
||||
m_DirtyPickupRadiusScale = true;
|
||||
|
||||
if (entity->GetLOT() != 1) // Other physics entities we care about will be added by BaseCombatAI
|
||||
return;
|
||||
@ -85,7 +87,13 @@ void ControllablePhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bo
|
||||
m_DirtyCheats = false;
|
||||
}
|
||||
|
||||
outBitStream->Write0();
|
||||
outBitStream->Write(m_DirtyPickupRadiusScale);
|
||||
if (m_DirtyPickupRadiusScale) {
|
||||
outBitStream->Write(m_PickupRadius);
|
||||
outBitStream->Write0(); //No clue what this is so im leaving it false.
|
||||
m_DirtyPickupRadiusScale = false;
|
||||
}
|
||||
|
||||
outBitStream->Write0();
|
||||
|
||||
outBitStream->Write(m_DirtyPosition || bIsInitialUpdate);
|
||||
@ -230,4 +238,32 @@ void ControllablePhysicsComponent::SetDirtyVelocity(bool val) {
|
||||
|
||||
void ControllablePhysicsComponent::SetDirtyAngularVelocity(bool val) {
|
||||
m_DirtyAngularVelocity = val;
|
||||
}
|
||||
}
|
||||
|
||||
void ControllablePhysicsComponent::AddPickupRadiusScale(float value) {
|
||||
m_ActivePickupRadiusScales.push_back(value);
|
||||
if (value > m_PickupRadius) {
|
||||
m_PickupRadius = value;
|
||||
m_DirtyPickupRadiusScale = true;
|
||||
}
|
||||
}
|
||||
|
||||
void ControllablePhysicsComponent::RemovePickupRadiusScale(float value) {
|
||||
// Attempt to remove pickup radius from active radii
|
||||
const auto pos = std::find(m_ActivePickupRadiusScales.begin(), m_ActivePickupRadiusScales.end(), value);
|
||||
if (pos != m_ActivePickupRadiusScales.end()) {
|
||||
m_ActivePickupRadiusScales.erase(pos);
|
||||
} else {
|
||||
Game::logger->Log("ControllablePhysicsComponent", "Warning: Could not find pickup radius %f in list of active radii. List has %i active radii.\n", value, m_ActivePickupRadiusScales.size());
|
||||
return;
|
||||
}
|
||||
|
||||
// Recalculate pickup radius since we removed one by now
|
||||
m_PickupRadius = 0.0f;
|
||||
m_DirtyPickupRadiusScale = true;
|
||||
for (uint32_t i = 0; i < m_ActivePickupRadiusScales.size(); i++) {
|
||||
auto candidateRadius = m_ActivePickupRadiusScales[i];
|
||||
if (m_PickupRadius < candidateRadius) m_PickupRadius = candidateRadius;
|
||||
}
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
@ -227,6 +227,24 @@ public:
|
||||
|
||||
dpEntity* GetdpEntity() const { return m_dpEntity; }
|
||||
|
||||
/**
|
||||
* I store this in a vector because if I have 2 separate pickup radii being applied to the player, I dont know which one is correctly active.
|
||||
* This method adds the pickup radius to the vector of active radii and if its larger than the current one, is applied as the new pickup radius.
|
||||
*/
|
||||
void AddPickupRadiusScale(float value) ;
|
||||
|
||||
/**
|
||||
* Removes the provided pickup radius scale from our list of buffs
|
||||
* The recalculates what our pickup radius is.
|
||||
*/
|
||||
void RemovePickupRadiusScale(float value) ;
|
||||
|
||||
/**
|
||||
* The pickup radii of this component.
|
||||
* @return All active radii scales for this component.
|
||||
*/
|
||||
std::vector<float> GetActivePickupRadiusScales() { return m_ActivePickupRadiusScales; };
|
||||
|
||||
private:
|
||||
/**
|
||||
* The entity that owns this component
|
||||
@ -322,6 +340,21 @@ private:
|
||||
* Whether this entity is static, making it unable to move
|
||||
*/
|
||||
bool m_Static;
|
||||
|
||||
/**
|
||||
* Whether the pickup scale is dirty.
|
||||
*/
|
||||
bool m_DirtyPickupRadiusScale;
|
||||
|
||||
/**
|
||||
* The list of pickup radius scales for this entity
|
||||
*/
|
||||
std::vector<float> m_ActivePickupRadiusScales;
|
||||
|
||||
/**
|
||||
* The active pickup radius for this entity
|
||||
*/
|
||||
float m_PickupRadius;
|
||||
};
|
||||
|
||||
#endif // CONTROLLABLEPHYSICSCOMPONENT_H
|
||||
|
Loading…
Reference in New Issue
Block a user