2021-12-05 17:54:36 +00:00
|
|
|
|
#include "DamageAbsorptionBehavior.h"
|
|
|
|
|
|
|
|
|
|
#include "BehaviorBranchContext.h"
|
|
|
|
|
#include "BehaviorContext.h"
|
|
|
|
|
#include "EntityManager.h"
|
|
|
|
|
#include "Game.h"
|
|
|
|
|
#include "dLogger.h"
|
|
|
|
|
#include "DestroyableComponent.h"
|
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
|
void DamageAbsorptionBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
|
2021-12-05 17:54:36 +00:00
|
|
|
|
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
|
if (target == nullptr) {
|
2022-07-25 02:26:51 +00:00
|
|
|
|
Game::logger->Log("DamageAbsorptionBehavior", "Failed to find target (%llu)!", branch.target);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto* destroyable = target->GetComponent<DestroyableComponent>();
|
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
|
if (destroyable == nullptr) {
|
2021-12-05 17:54:36 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
destroyable->SetDamageToAbsorb(static_cast<uint32_t>(destroyable->GetDamageToAbsorb()) + this->m_absorbAmount);
|
|
|
|
|
|
|
|
|
|
destroyable->SetIsShielded(true);
|
|
|
|
|
|
|
|
|
|
context->RegisterTimerBehavior(this, branch, target->GetObjectID());
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
|
void DamageAbsorptionBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
2021-12-05 17:54:36 +00:00
|
|
|
|
Handle(context, bitStream, branch);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
|
void DamageAbsorptionBehavior::Timer(BehaviorContext* context, BehaviorBranchContext branch, const LWOOBJID second) {
|
2021-12-05 17:54:36 +00:00
|
|
|
|
auto* target = EntityManager::Instance()->GetEntity(second);
|
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
|
if (target == nullptr) {
|
2022-07-25 02:26:51 +00:00
|
|
|
|
Game::logger->Log("DamageAbsorptionBehavior", "Failed to find target (%llu)!", second);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-07-25 02:26:51 +00:00
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
|
auto* destroyable = target->GetComponent<DestroyableComponent>();
|
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
|
if (destroyable == nullptr) {
|
2021-12-05 17:54:36 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const auto present = static_cast<uint32_t>(destroyable->GetDamageToAbsorb());
|
2022-07-25 02:26:51 +00:00
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
|
const auto toRemove = std::min(present, this->m_absorbAmount);
|
|
|
|
|
|
|
|
|
|
destroyable->SetDamageToAbsorb(present - toRemove);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
|
void DamageAbsorptionBehavior::Load() {
|
2021-12-05 17:54:36 +00:00
|
|
|
|
this->m_absorbAmount = GetInt("absorb_amount");
|
|
|
|
|
}
|