2021-12-05 17:54:36 +00:00
|
|
|
#include "ApplyBuffBehavior.h"
|
|
|
|
#include "EntityManager.h"
|
|
|
|
#include "BehaviorContext.h"
|
|
|
|
#include "BehaviorBranchContext.h"
|
|
|
|
#include "BuffComponent.h"
|
|
|
|
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void ApplyBuffBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
2022-12-24 14:08:51 +00:00
|
|
|
branch.target == LWOOBJID_EMPTY ? context->originator : branch.target;
|
|
|
|
if (m_TargetCaster) branch.target = context->originator;
|
|
|
|
auto* entity = EntityManager::Instance()->GetEntity(branch.target);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (entity == nullptr) return;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
auto* buffComponent = entity->GetComponent<BuffComponent>();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (buffComponent == nullptr) return;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-12-24 15:08:41 +00:00
|
|
|
buffComponent->ApplyBuff(m_BuffId, m_Duration, context->originator,
|
|
|
|
m_AddImmunity, m_ApplyOnTeammates,
|
|
|
|
m_CancelOnDamaged, m_CancelOnDeath, m_CancelOnLogout, m_CancelOnRemoveBuff,
|
|
|
|
m_CancelOnUi, m_CancelOnUnequip, m_CancelOnZone, m_CancelOnDamageAbsDone,
|
|
|
|
m_UseRefCount);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void ApplyBuffBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch) {
|
2022-12-24 14:08:51 +00:00
|
|
|
if (m_IgnoreUncast) return;
|
2022-07-28 13:39:57 +00:00
|
|
|
auto* entity = EntityManager::Instance()->GetEntity(branch.target);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (entity == nullptr) return;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
auto* buffComponent = entity->GetComponent<BuffComponent>();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (buffComponent == nullptr) return;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
buffComponent->RemoveBuff(m_BuffId);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void ApplyBuffBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
|
|
|
Handle(context, bitStream, branch);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void ApplyBuffBehavior::Load() {
|
|
|
|
m_BuffId = GetInt("buff_id");
|
|
|
|
m_Duration = GetFloat("duration_secs");
|
2022-12-24 14:08:51 +00:00
|
|
|
m_IgnoreUncast = GetBoolean("ignore_uncast", false);
|
|
|
|
m_TargetCaster = GetBoolean("target_caster", false);
|
|
|
|
m_AddImmunity = GetBoolean("add_immunity", false);
|
|
|
|
m_ApplyOnTeammates = GetBoolean("apply_on_teammates", false);
|
|
|
|
m_CancelOnDamaged = GetBoolean("cancel_on_damaged", false);
|
|
|
|
m_CancelOnDeath = GetBoolean("cancel_on_death", false);
|
|
|
|
m_CancelOnLogout = GetBoolean("cancel_on_logout", false);
|
|
|
|
m_CancelOnRemoveBuff = GetBoolean("cancel_on_remove_buff", false);
|
|
|
|
m_CancelOnUi = GetBoolean("cancel_on_ui", false);
|
|
|
|
m_CancelOnUnequip = GetBoolean("cancel_on_unequip", false);
|
|
|
|
m_CancelOnZone = GetBoolean("cancel_on_zone", false);
|
|
|
|
m_CancelOnDamageAbsDone = GetBoolean("cancel_on_damage_abs_done", false);
|
|
|
|
m_UseRefCount = GetBoolean("use_ref_count", false);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|