2021-12-05 17:54:36 +00:00
|
|
|
#include "BlockBehavior.h"
|
|
|
|
|
|
|
|
#include "BehaviorContext.h"
|
|
|
|
#include "BehaviorBranchContext.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"
|
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
void BlockBehavior::Handle(BehaviorContext* context, RakNet::BitStream& bitStream, BehaviorBranchContext branch) {
|
2021-12-05 17:54:36 +00:00
|
|
|
const auto target = context->originator;
|
|
|
|
|
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) {
|
2024-03-13 02:10:01 +00:00
|
|
|
Log::Warn("Failed to find target ({})!", branch.target);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* destroyableComponent = entity->GetComponent<DestroyableComponent>();
|
|
|
|
|
|
|
|
if (destroyableComponent == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
destroyableComponent->SetAttacksToBlock(this->m_numAttacksCanBlock);
|
|
|
|
|
|
|
|
if (branch.start > 0) {
|
|
|
|
context->RegisterEndBehavior(this, branch);
|
|
|
|
} else if (branch.duration > 0) {
|
|
|
|
context->RegisterTimerBehavior(this, branch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
void BlockBehavior::Calculate(BehaviorContext* context, RakNet::BitStream& bitStream, BehaviorBranchContext branch) {
|
2021-12-05 17:54:36 +00:00
|
|
|
Handle(context, bitStream, branch);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BlockBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch) {
|
|
|
|
const auto target = context->originator;
|
|
|
|
|
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) {
|
2024-03-13 02:10:01 +00:00
|
|
|
Log::Warn("Failed to find target ({})!", branch.target);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* destroyableComponent = entity->GetComponent<DestroyableComponent>();
|
|
|
|
|
|
|
|
destroyableComponent->SetAttacksToBlock(this->m_numAttacksCanBlock);
|
|
|
|
|
|
|
|
if (destroyableComponent == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
destroyableComponent->SetAttacksToBlock(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BlockBehavior::Timer(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) {
|
|
|
|
UnCast(context, branch);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BlockBehavior::End(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) {
|
|
|
|
UnCast(context, branch);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BlockBehavior::Load() {
|
|
|
|
this->m_numAttacksCanBlock = GetInt("num_attacks_can_block");
|
|
|
|
}
|