DarkflameServer/dGame/dBehaviors/ImmunityBehavior.cpp

59 lines
1.5 KiB
C++
Raw Normal View History

2022-08-06 03:01:59 +00:00
#include "ImmunityBehavior.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 ImmunityBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
auto* target = EntityManager::Instance()->GetEntity(branch.target);
2022-07-28 13:39:57 +00:00
if (target == nullptr) {
Game::logger->Log("DamageAbsorptionBehavior", "Failed to find target (%llu)!", branch.target);
return;
}
auto* destroyable = static_cast<DestroyableComponent*>(target->GetComponent(COMPONENT_TYPE_DESTROYABLE));
2022-07-28 13:39:57 +00:00
if (destroyable == nullptr) {
return;
}
2022-07-28 13:39:57 +00:00
if (!this->m_immuneBasicAttack) {
return;
}
destroyable->PushImmunity();
context->RegisterTimerBehavior(this, branch, target->GetObjectID());
}
2022-07-28 13:39:57 +00:00
void ImmunityBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
Handle(context, bitStream, branch);
}
2022-07-28 13:39:57 +00:00
void ImmunityBehavior::Timer(BehaviorContext* context, BehaviorBranchContext branch, const LWOOBJID second) {
auto* target = EntityManager::Instance()->GetEntity(second);
2022-07-28 13:39:57 +00:00
if (target == nullptr) {
Game::logger->Log("DamageAbsorptionBehavior", "Failed to find target (%llu)!", second);
return;
}
auto* destroyable = static_cast<DestroyableComponent*>(target->GetComponent(COMPONENT_TYPE_DESTROYABLE));
2022-07-28 13:39:57 +00:00
if (destroyable == nullptr) {
return;
}
destroyable->PopImmunity();
}
2022-07-28 13:39:57 +00:00
void ImmunityBehavior::Load() {
this->m_immuneBasicAttack = GetBoolean("immune_basic_attack");
}