DarkflameServer/dGame/dBehaviors/ApplyBuffBehavior.cpp

49 lines
1.7 KiB
C++
Raw Normal View History

#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) {
auto* entity = EntityManager::Instance()->GetEntity(branch.target == LWOOBJID_EMPTY ? context->originator : branch.target);
2022-07-28 13:39:57 +00:00
if (entity == nullptr) return;
2022-07-28 13:39:57 +00:00
auto* buffComponent = entity->GetComponent<BuffComponent>();
2022-07-28 13:39:57 +00:00
if (buffComponent == nullptr) return;
2022-07-28 13:39:57 +00:00
buffComponent->ApplyBuff(m_BuffId, m_Duration, context->originator, addImmunity, cancelOnDamaged, cancelOnDeath,
cancelOnLogout, cancelonRemoveBuff, cancelOnUi, cancelOnUnequip, cancelOnZone);
}
2022-07-28 13:39:57 +00:00
void ApplyBuffBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch) {
auto* entity = EntityManager::Instance()->GetEntity(branch.target);
2022-07-28 13:39:57 +00:00
if (entity == nullptr) return;
2022-07-28 13:39:57 +00:00
auto* buffComponent = entity->GetComponent<BuffComponent>();
2022-07-28 13:39:57 +00:00
if (buffComponent == nullptr) return;
2022-07-28 13:39:57 +00:00
buffComponent->RemoveBuff(m_BuffId);
}
2022-07-28 13:39:57 +00:00
void ApplyBuffBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
Handle(context, bitStream, branch);
}
2022-07-28 13:39:57 +00:00
void ApplyBuffBehavior::Load() {
m_BuffId = GetInt("buff_id");
m_Duration = GetFloat("duration_secs");
addImmunity = GetBoolean("add_immunity");
cancelOnDamaged = GetBoolean("cancel_on_damaged");
cancelOnDeath = GetBoolean("cancel_on_death");
cancelOnLogout = GetBoolean("cancel_on_logout");
cancelonRemoveBuff = GetBoolean("cancel_on_remove_buff");
cancelOnUi = GetBoolean("cancel_on_ui");
cancelOnUnequip = GetBoolean("cancel_on_unequip");
cancelOnZone = GetBoolean("cancel_on_zone");
}