DarkflameServer/dGame/dBehaviors/InterruptBehavior.cpp

87 lines
2.0 KiB
C++
Raw Permalink Normal View History

2022-08-06 03:01:59 +00:00
#include "InterruptBehavior.h"
#include "BehaviorBranchContext.h"
#include "BehaviorContext.h"
#include "Game.h"
#include "Logger.h"
#include "EntityManager.h"
#include "SkillComponent.h"
2022-07-28 13:39:57 +00:00
void InterruptBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
if (branch.target != context->originator) {
bool unknown = false;
if (!bitStream->Read(unknown)) {
LOG("Unable to read unknown1 from bitStream, aborting Handle! %i", bitStream->GetNumberOfUnreadBits());
return;
};
if (unknown) return;
}
2022-07-28 13:39:57 +00:00
if (!this->m_interruptBlock) {
bool unknown = false;
if (!bitStream->Read(unknown)) {
LOG("Unable to read unknown2 from bitStream, aborting Handle! %i", bitStream->GetNumberOfUnreadBits());
return;
};
if (unknown) return;
}
if (this->m_target) // Guess...
{
bool unknown = false;
if (!bitStream->Read(unknown)) {
LOG("Unable to read unknown3 from bitStream, aborting Handle! %i", bitStream->GetNumberOfUnreadBits());
return;
};
}
if (branch.target == context->originator) return;
auto* target = Game::entityManager->GetEntity(branch.target);
if (target == nullptr) return;
auto* skillComponent = target->GetComponent<SkillComponent>();
if (skillComponent == nullptr) return;
skillComponent->Interrupt();
}
2022-07-28 13:39:57 +00:00
void InterruptBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
if (branch.target != context->originator) {
bitStream->Write(false);
}
2022-07-28 13:39:57 +00:00
if (!this->m_interruptBlock) {
bitStream->Write(false);
}
bitStream->Write(false);
if (branch.target == context->originator) return;
auto* target = Game::entityManager->GetEntity(branch.target);
if (target == nullptr) return;
auto* skillComponent = target->GetComponent<SkillComponent>();
if (skillComponent == nullptr) return;
2022-07-28 13:39:57 +00:00
skillComponent->Interrupt();
}
2022-07-28 13:39:57 +00:00
void InterruptBehavior::Load() {
this->m_target = GetBoolean("target");
2022-07-28 13:39:57 +00:00
this->m_interruptBlock = GetBoolean("interrupt_block");
}