2021-12-05 17:54:36 +00:00
|
|
|
#include "InterruptBehavior.h"
|
|
|
|
#include "BehaviorBranchContext.h"
|
|
|
|
#include "BehaviorContext.h"
|
|
|
|
#include "Game.h"
|
|
|
|
#include "dLogger.h"
|
|
|
|
#include "EntityManager.h"
|
|
|
|
#include "SkillComponent.h"
|
|
|
|
|
|
|
|
|
|
|
|
void InterruptBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
|
|
|
if (branch.target != context->originator) {
|
|
|
|
bool unknown = false;
|
|
|
|
|
2022-12-16 21:23:02 +00:00
|
|
|
if (!bitStream->Read(unknown)) {
|
|
|
|
Game::logger->Log("InterruptBehavior", "Unable to read unknown1 from bitStream, aborting Handle! %i", bitStream->GetNumberOfUnreadBits());
|
|
|
|
return;
|
|
|
|
};
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (unknown) return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this->m_interruptBlock) {
|
|
|
|
bool unknown = false;
|
|
|
|
|
2022-12-16 21:23:02 +00:00
|
|
|
if (!bitStream->Read(unknown)) {
|
|
|
|
Game::logger->Log("InterruptBehavior", "Unable to read unknown2 from bitStream, aborting Handle! %i", bitStream->GetNumberOfUnreadBits());
|
|
|
|
return;
|
|
|
|
};
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (unknown) return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this->m_target) // Guess...
|
|
|
|
{
|
|
|
|
bool unknown = false;
|
|
|
|
|
2022-12-16 21:23:02 +00:00
|
|
|
if (!bitStream->Read(unknown)) {
|
|
|
|
Game::logger->Log("InterruptBehavior", "Unable to read unknown3 from bitStream, aborting Handle! %i", bitStream->GetNumberOfUnreadBits());
|
|
|
|
return;
|
|
|
|
};
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (branch.target == context->originator) return;
|
|
|
|
|
|
|
|
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
|
|
|
|
|
|
|
if (target == nullptr) return;
|
|
|
|
|
|
|
|
auto* skillComponent = target->GetComponent<SkillComponent>();
|
|
|
|
|
|
|
|
if (skillComponent == nullptr) return;
|
|
|
|
|
|
|
|
skillComponent->Interrupt();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InterruptBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
|
|
|
if (branch.target != context->originator) {
|
|
|
|
bitStream->Write(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this->m_interruptBlock) {
|
|
|
|
bitStream->Write(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
bitStream->Write(false);
|
|
|
|
|
|
|
|
if (branch.target == context->originator) return;
|
|
|
|
|
|
|
|
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
|
|
|
|
|
|
|
if (target == nullptr) return;
|
|
|
|
|
|
|
|
auto* skillComponent = target->GetComponent<SkillComponent>();
|
|
|
|
|
|
|
|
if (skillComponent == nullptr) return;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
skillComponent->Interrupt();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InterruptBehavior::Load() {
|
|
|
|
this->m_target = GetBoolean("target");
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
this->m_interruptBlock = GetBoolean("interrupt_block");
|
|
|
|
}
|