2021-12-05 17:54:36 +00:00
|
|
|
#include "StunBehavior.h"
|
|
|
|
|
|
|
|
#include "BaseCombatAIComponent.h"
|
|
|
|
#include "BehaviorBranchContext.h"
|
|
|
|
#include "BehaviorContext.h"
|
|
|
|
#include "EntityManager.h"
|
|
|
|
#include "Game.h"
|
|
|
|
#include "dLogger.h"
|
|
|
|
#include "DestroyableComponent.h"
|
2023-03-04 07:16:37 +00:00
|
|
|
#include "eReplicaComponentType.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
void StunBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
|
|
|
|
if (this->m_stunCaster || branch.target == context->originator) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-16 21:23:02 +00:00
|
|
|
bool blocked{};
|
|
|
|
if (!bitStream->Read(blocked)) {
|
|
|
|
Game::logger->Log("StunBehavior", "Unable to read blocked from bitStream, aborting Handle! %i", bitStream->GetNumberOfUnreadBits());
|
|
|
|
return;
|
|
|
|
};
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
|
|
|
|
|
|
|
if (target == nullptr) {
|
2022-07-25 02:26:51 +00:00
|
|
|
Game::logger->Log("StunBehavior", "Failed to find target (%llu)!", branch.target);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If our target is an enemy we can go ahead and stun it.
|
|
|
|
*/
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2023-06-07 07:23:50 +00:00
|
|
|
auto combatAiComponent = target->GetComponent<BaseCombatAIComponent>();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
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 = EntityManager::Instance()->GetEntity(context->originator);
|
|
|
|
|
|
|
|
if (self == nullptr) {
|
2022-07-25 02:26:51 +00:00
|
|
|
Game::logger->Log("StunBehavior", "Invalid self entity (%llu)!", context->originator);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* See if we can stun ourselves
|
|
|
|
*/
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2023-06-07 07:23:50 +00:00
|
|
|
auto combatAiComponent = self->GetComponent<BaseCombatAIComponent>();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (combatAiComponent == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
combatAiComponent->Stun(branch.duration);
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool blocked = false;
|
|
|
|
|
|
|
|
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
|
|
|
|
|
|
|
if (target != nullptr) {
|
2023-06-07 07:23:50 +00:00
|
|
|
auto destroyableComponent = target->GetComponent<DestroyableComponent>();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (destroyableComponent != nullptr) {
|
|
|
|
blocked = destroyableComponent->IsKnockbackImmune();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bitStream->Write(blocked);
|
|
|
|
|
|
|
|
if (target == nullptr) {
|
2022-07-25 02:26:51 +00:00
|
|
|
Game::logger->Log("StunBehavior", "Failed to find target (%llu)!", branch.target);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If our target is an enemy we can go ahead and stun it.
|
|
|
|
*/
|
|
|
|
|
2023-06-07 07:23:50 +00:00
|
|
|
auto combatAiComponent = target->GetComponent<BaseCombatAIComponent>();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (combatAiComponent == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
combatAiComponent->Stun(branch.duration);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StunBehavior::Load() {
|
|
|
|
this->m_stunCaster = GetBoolean("stun_caster");
|
|
|
|
}
|