mirror of
https://github.com/DarkflameUniverse/DarkflameServer
synced 2024-08-30 18:43:58 +00:00
455f9470a5
* Move EntityManager to Game namespace * move initialization to later Need to wait for dZoneManager to be initialized. * Fix bugs - Cannot delete from a RandomAccessIterator while in a range based for loop. Touchup zone manager initialize replace magic numbers with better named constants replace magic zonecontrol id with a more readable hex alternative condense stack variables move initializers closer to their use initialize entity manager with zone control change initialize timings If zone is not zero we expect to initialize the entity manager during zone manager initialization Add constexpr for zone control LOT * Add proper error handling * revert vanity changes * Update WorldServer.cpp * Update dZoneManager.cpp
85 lines
2.4 KiB
C++
85 lines
2.4 KiB
C++
#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;
|
|
|
|
auto* entity = Game::entityManager->GetEntity(target);
|
|
|
|
if (entity == nullptr) {
|
|
Game::logger->Log("BuffBehavior", "Invalid target (%llu)!", target);
|
|
|
|
return;
|
|
}
|
|
|
|
auto* component = entity->GetComponent<DestroyableComponent>();
|
|
|
|
if (component == nullptr) {
|
|
Game::logger->Log("BuffBehavior", "Invalid target, no destroyable component (%llu)!", target);
|
|
|
|
return;
|
|
}
|
|
|
|
component->SetMaxHealth(component->GetMaxHealth() + this->m_health);
|
|
component->SetMaxArmor(component->GetMaxArmor() + this->m_armor);
|
|
component->SetMaxImagination(component->GetMaxImagination() + this->m_imagination);
|
|
|
|
Game::entityManager->SerializeEntity(entity);
|
|
|
|
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;
|
|
|
|
auto* entity = Game::entityManager->GetEntity(target);
|
|
|
|
if (entity == nullptr) {
|
|
Game::logger->Log("BuffBehavior", "Invalid target (%llu)!", target);
|
|
|
|
return;
|
|
}
|
|
|
|
auto* component = entity->GetComponent<DestroyableComponent>();
|
|
|
|
if (component == nullptr) {
|
|
Game::logger->Log("BuffBehavior", "Invalid target, no destroyable component (%llu)!", target);
|
|
|
|
return;
|
|
}
|
|
|
|
component->SetMaxHealth(component->GetMaxHealth() - this->m_health);
|
|
component->SetMaxArmor(component->GetMaxArmor() - this->m_armor);
|
|
component->SetMaxImagination(component->GetMaxImagination() - this->m_imagination);
|
|
|
|
Game::entityManager->SerializeEntity(entity);
|
|
}
|
|
|
|
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");
|
|
}
|