mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-14 07:47:13 +00:00
The damage reduction behavior set the reduction to its amount and back to 0 when it ended, so a second reduction replaced the first and ending either removed both. The client's behavior sends AddDamageReduction (DamageReductionBehavior::Cast) and the destroyable adds it to the current reduction; removing takes off that amount, never below 0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
56 lines
1.5 KiB
C++
56 lines
1.5 KiB
C++
#include "DamageReductionBehavior.h"
|
|
|
|
#include "BehaviorBranchContext.h"
|
|
#include "BehaviorContext.h"
|
|
#include "EntityManager.h"
|
|
#include "Game.h"
|
|
#include "Logger.h"
|
|
#include "DestroyableComponent.h"
|
|
|
|
void DamageReductionBehavior::Handle(BehaviorContext* context, RakNet::BitStream& bitStream, const BehaviorBranchContext branch) {
|
|
auto* target = Game::entityManager->GetEntity(branch.target);
|
|
|
|
if (target == nullptr) {
|
|
LOG("Failed to find target (%llu)!", branch.target);
|
|
|
|
return;
|
|
}
|
|
|
|
auto* destroyable = target->GetComponent<DestroyableComponent>();
|
|
|
|
if (destroyable == nullptr) {
|
|
return;
|
|
}
|
|
|
|
// DamageReductionBehavior::Cast (0x004fdbb0) sends AddDamageReduction: it adds to any other reduction
|
|
destroyable->AddDamageReduction(m_ReductionAmount);
|
|
|
|
context->RegisterTimerBehavior(this, branch, target->GetObjectID());
|
|
}
|
|
|
|
void DamageReductionBehavior::Calculate(BehaviorContext* context, RakNet::BitStream& bitStream, BehaviorBranchContext branch) {
|
|
Handle(context, bitStream, branch);
|
|
}
|
|
|
|
void DamageReductionBehavior::Timer(BehaviorContext* context, BehaviorBranchContext branch, const LWOOBJID second) {
|
|
auto* target = Game::entityManager->GetEntity(second);
|
|
|
|
if (target == nullptr) {
|
|
LOG("Failed to find target (%llu)!", second);
|
|
|
|
return;
|
|
}
|
|
|
|
auto* destroyable = target->GetComponent<DestroyableComponent>();
|
|
|
|
if (destroyable == nullptr) {
|
|
return;
|
|
}
|
|
|
|
destroyable->RemoveDamageReduction(m_ReductionAmount);
|
|
}
|
|
|
|
void DamageReductionBehavior::Load() {
|
|
this->m_ReductionAmount = GetInt("reduction_amount");
|
|
}
|