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"
|
2023-10-21 23:31:55 +00:00
|
|
|
#include "Logger.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "DestroyableComponent.h"
|
2023-03-04 07:16:37 +00:00
|
|
|
#include "eReplicaComponentType.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
void StunBehavior::Handle(BehaviorContext* context, RakNet::BitStream& bitStream, const BehaviorBranchContext branch) {
|
2021-12-05 17:54:36 +00:00
|
|
|
if (this->m_stunCaster || branch.target == context->originator) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-16 21:23:02 +00:00
|
|
|
bool blocked{};
|
2024-02-27 07:25:44 +00:00
|
|
|
if (!bitStream.Read(blocked)) {
|
|
|
|
LOG("Unable to read blocked from bitStream, aborting Handle! %i", bitStream.GetNumberOfUnreadBits());
|
2022-12-16 21:23:02 +00:00
|
|
|
return;
|
|
|
|
};
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
auto* target = Game::entityManager->GetEntity(branch.target);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (target == nullptr) {
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("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-03-04 07:16:37 +00:00
|
|
|
auto* combatAiComponent = static_cast<BaseCombatAIComponent*>(target->GetComponent(eReplicaComponentType::BASE_COMBAT_AI));
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (combatAiComponent == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
combatAiComponent->Stun(branch.duration);
|
|
|
|
}
|
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
void StunBehavior::Calculate(BehaviorContext* context, RakNet::BitStream& bitStream, const BehaviorBranchContext branch) {
|
2021-12-05 17:54:36 +00:00
|
|
|
if (this->m_stunCaster || branch.target == context->originator) {
|
2023-07-15 20:56:33 +00:00
|
|
|
auto* self = Game::entityManager->GetEntity(context->originator);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (self == nullptr) {
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("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-03-04 07:16:37 +00:00
|
|
|
auto* combatAiComponent = static_cast<BaseCombatAIComponent*>(self->GetComponent(eReplicaComponentType::BASE_COMBAT_AI));
|
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;
|
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
auto* target = Game::entityManager->GetEntity(branch.target);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (target != nullptr) {
|
|
|
|
auto* destroyableComponent = target->GetComponent<DestroyableComponent>();
|
|
|
|
|
|
|
|
if (destroyableComponent != nullptr) {
|
|
|
|
blocked = destroyableComponent->IsKnockbackImmune();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
bitStream.Write(blocked);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (target == nullptr) {
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("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-03-04 07:16:37 +00:00
|
|
|
auto* combatAiComponent = static_cast<BaseCombatAIComponent*>(target->GetComponent(eReplicaComponentType::BASE_COMBAT_AI));
|
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");
|
|
|
|
}
|