2022-08-06 03:01:59 +00:00
|
|
|
#include "ImmunityBehavior.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
#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) {
|
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 = static_cast<DestroyableComponent*>(target->GetComponent(COMPONENT_TYPE_DESTROYABLE));
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (destroyable == nullptr) {
|
2021-12-05 17:54:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (!this->m_immuneBasicAttack) {
|
2021-12-05 17:54:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
destroyable->PushImmunity();
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
context->RegisterTimerBehavior(this, branch, target->GetObjectID());
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void ImmunityBehavior::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 ImmunityBehavior::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;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* destroyable = static_cast<DestroyableComponent*>(target->GetComponent(COMPONENT_TYPE_DESTROYABLE));
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (destroyable == nullptr) {
|
2021-12-05 17:54:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
destroyable->PopImmunity();
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void ImmunityBehavior::Load() {
|
2021-12-05 17:54:36 +00:00
|
|
|
this->m_immuneBasicAttack = GetBoolean("immune_basic_attack");
|
|
|
|
}
|