2021-12-05 17:54:36 +00:00
|
|
|
#include "BuffBehavior.h"
|
|
|
|
|
|
|
|
#include "BehaviorContext.h"
|
|
|
|
#include "BehaviorBranchContext.h"
|
|
|
|
#include "EntityManager.h"
|
|
|
|
#include "Game.h"
|
|
|
|
#include "dLogger.h"
|
|
|
|
#include "DestroyableComponent.h"
|
|
|
|
|
|
|
|
void BuffBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
|
|
|
const auto target = branch.target != LWOOBJID_EMPTY ? branch.target : context->originator;
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
auto* entity = Game::entityManager->GetEntity(target);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (entity == nullptr) {
|
2022-07-25 02:26:51 +00:00
|
|
|
Game::logger->Log("BuffBehavior", "Invalid target (%llu)!", target);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* component = entity->GetComponent<DestroyableComponent>();
|
|
|
|
|
|
|
|
if (component == nullptr) {
|
2022-07-25 02:26:51 +00:00
|
|
|
Game::logger->Log("BuffBehavior", "Invalid target, no destroyable component (%llu)!", target);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-15 08:54:41 +00:00
|
|
|
component->AddStat(StatProperty(eStatTypes::Health, eStatModifier::Absolute, this->m_health * BASE_MULTIPLIER));
|
|
|
|
component->AddStat(StatProperty(eStatTypes::Armor, eStatModifier::Absolute, this->m_armor * BASE_MULTIPLIER));
|
|
|
|
//component->AddStat(StatProperty(eStatTypes::Imagination, eStatModifier::Absolute, this->m_imagination * BASE_MULTIPLIER));
|
|
|
|
|
|
|
|
/*
|
2021-12-05 17:54:36 +00:00
|
|
|
component->SetMaxHealth(component->GetMaxHealth() + this->m_health);
|
|
|
|
component->SetMaxArmor(component->GetMaxArmor() + this->m_armor);
|
|
|
|
component->SetMaxImagination(component->GetMaxImagination() + this->m_imagination);
|
2023-07-15 08:54:41 +00:00
|
|
|
*/
|
|
|
|
component->SetMaxImagination(component->GetMaxImagination() + this->m_imagination);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->SerializeEntity(entity);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (!context->unmanaged) {
|
|
|
|
if (branch.duration > 0) {
|
|
|
|
context->RegisterTimerBehavior(this, branch);
|
|
|
|
} else if (branch.start > 0) {
|
|
|
|
context->RegisterEndBehavior(this, branch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BuffBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch) {
|
|
|
|
const auto target = branch.target != LWOOBJID_EMPTY ? branch.target : context->originator;
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
auto* entity = Game::entityManager->GetEntity(target);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (entity == nullptr) {
|
2022-07-25 02:26:51 +00:00
|
|
|
Game::logger->Log("BuffBehavior", "Invalid target (%llu)!", target);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* component = entity->GetComponent<DestroyableComponent>();
|
|
|
|
|
|
|
|
if (component == nullptr) {
|
2022-07-25 02:26:51 +00:00
|
|
|
Game::logger->Log("BuffBehavior", "Invalid target, no destroyable component (%llu)!", target);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-15 08:54:41 +00:00
|
|
|
component->RemoveStat(StatProperty(eStatTypes::Health, eStatModifier::Absolute, this->m_health * BASE_MULTIPLIER));
|
|
|
|
component->RemoveStat(StatProperty(eStatTypes::Armor, eStatModifier::Absolute, this->m_armor * BASE_MULTIPLIER));
|
|
|
|
//component->RemoveStat(StatProperty(eStatTypes::Imagination, eStatModifier::Absolute, this->m_imagination * BASE_MULTIPLIER));
|
|
|
|
|
|
|
|
/*
|
2021-12-05 17:54:36 +00:00
|
|
|
component->SetMaxHealth(component->GetMaxHealth() - this->m_health);
|
|
|
|
component->SetMaxArmor(component->GetMaxArmor() - this->m_armor);
|
|
|
|
component->SetMaxImagination(component->GetMaxImagination() - this->m_imagination);
|
2023-07-15 08:54:41 +00:00
|
|
|
*/
|
|
|
|
component->SetMaxImagination(component->GetMaxImagination() - this->m_imagination);
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->SerializeEntity(entity);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BuffBehavior::Timer(BehaviorContext* context, const BehaviorBranchContext branch, LWOOBJID second) {
|
|
|
|
UnCast(context, branch);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BuffBehavior::End(BehaviorContext* context, const BehaviorBranchContext branch, LWOOBJID second) {
|
|
|
|
UnCast(context, branch);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BuffBehavior::Load() {
|
|
|
|
this->m_health = GetInt("life");
|
|
|
|
|
|
|
|
this->m_armor = GetInt("armor");
|
|
|
|
|
|
|
|
this->m_imagination = GetInt("imag");
|
|
|
|
}
|