mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-13 19:58:21 +00:00
5942182486
* Logger: Rename logger to Logger from dLogger * Logger: Add compile time filename Fix include issues Add writers Add macros Add macro to force compilation * Logger: Replace calls with macros Allows for filename and line number to be logged * Logger: Add comments and remove extra define Logger: Replace with unique_ptr also flush console at exit. regular file writer should be flushed on file close. Logger: Remove constexpr on variable * Logger: Simplify code * Update Logger.cpp
106 lines
2.5 KiB
C++
106 lines
2.5 KiB
C++
#include "StunBehavior.h"
|
|
|
|
#include "BaseCombatAIComponent.h"
|
|
#include "BehaviorBranchContext.h"
|
|
#include "BehaviorContext.h"
|
|
#include "EntityManager.h"
|
|
#include "Game.h"
|
|
#include "Logger.h"
|
|
#include "DestroyableComponent.h"
|
|
#include "eReplicaComponentType.h"
|
|
|
|
|
|
void StunBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
|
|
if (this->m_stunCaster || branch.target == context->originator) {
|
|
return;
|
|
}
|
|
|
|
bool blocked{};
|
|
if (!bitStream->Read(blocked)) {
|
|
LOG("Unable to read blocked from bitStream, aborting Handle! %i", bitStream->GetNumberOfUnreadBits());
|
|
return;
|
|
};
|
|
|
|
auto* target = Game::entityManager->GetEntity(branch.target);
|
|
|
|
if (target == nullptr) {
|
|
LOG("Failed to find target (%llu)!", branch.target);
|
|
|
|
return;
|
|
}
|
|
|
|
/*
|
|
* If our target is an enemy we can go ahead and stun it.
|
|
*/
|
|
|
|
auto* combatAiComponent = static_cast<BaseCombatAIComponent*>(target->GetComponent(eReplicaComponentType::BASE_COMBAT_AI));
|
|
|
|
if (combatAiComponent == nullptr) {
|
|
return;
|
|
}
|
|
|
|
combatAiComponent->Stun(branch.duration);
|
|
}
|
|
|
|
void StunBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
|
|
if (this->m_stunCaster || branch.target == context->originator) {
|
|
auto* self = Game::entityManager->GetEntity(context->originator);
|
|
|
|
if (self == nullptr) {
|
|
LOG("Invalid self entity (%llu)!", context->originator);
|
|
|
|
return;
|
|
}
|
|
|
|
/*
|
|
* See if we can stun ourselves
|
|
*/
|
|
|
|
auto* combatAiComponent = static_cast<BaseCombatAIComponent*>(self->GetComponent(eReplicaComponentType::BASE_COMBAT_AI));
|
|
|
|
if (combatAiComponent == nullptr) {
|
|
return;
|
|
}
|
|
|
|
combatAiComponent->Stun(branch.duration);
|
|
|
|
return;
|
|
}
|
|
|
|
bool blocked = false;
|
|
|
|
auto* target = Game::entityManager->GetEntity(branch.target);
|
|
|
|
if (target != nullptr) {
|
|
auto* destroyableComponent = target->GetComponent<DestroyableComponent>();
|
|
|
|
if (destroyableComponent != nullptr) {
|
|
blocked = destroyableComponent->IsKnockbackImmune();
|
|
}
|
|
}
|
|
|
|
bitStream->Write(blocked);
|
|
|
|
if (target == nullptr) {
|
|
LOG("Failed to find target (%llu)!", branch.target);
|
|
|
|
return;
|
|
}
|
|
|
|
/*
|
|
* If our target is an enemy we can go ahead and stun it.
|
|
*/
|
|
|
|
auto* combatAiComponent = static_cast<BaseCombatAIComponent*>(target->GetComponent(eReplicaComponentType::BASE_COMBAT_AI));
|
|
|
|
if (combatAiComponent == nullptr) {
|
|
return;
|
|
}
|
|
|
|
combatAiComponent->Stun(branch.duration);
|
|
}
|
|
|
|
void StunBehavior::Load() {
|
|
this->m_stunCaster = GetBoolean("stun_caster");
|
|
}
|