2022-08-06 03:01:59 +00:00
|
|
|
#include "InterruptBehavior.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "BehaviorBranchContext.h"
|
|
|
|
#include "BehaviorContext.h"
|
|
|
|
#include "Game.h"
|
2023-10-21 23:31:55 +00:00
|
|
|
#include "Logger.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "EntityManager.h"
|
|
|
|
#include "SkillComponent.h"
|
|
|
|
|
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
void InterruptBehavior::Handle(BehaviorContext* context, RakNet::BitStream& bitStream, BehaviorBranchContext branch) {
|
2022-07-28 13:39:57 +00:00
|
|
|
if (branch.target != context->originator) {
|
2021-12-05 17:54:36 +00:00
|
|
|
bool unknown = false;
|
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
if (!bitStream.Read(unknown)) {
|
2024-03-08 21:44:02 +00:00
|
|
|
Log::Warn("Unable to read unknown1 from bitStream, aborting Handle! {:d}", bitStream.GetNumberOfUnreadBits());
|
2022-12-16 21:23:02 +00:00
|
|
|
return;
|
|
|
|
};
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (unknown) return;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (!this->m_interruptBlock) {
|
2021-12-05 17:54:36 +00:00
|
|
|
bool unknown = false;
|
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
if (!bitStream.Read(unknown)) {
|
2024-03-08 21:44:02 +00:00
|
|
|
Log::Warn("Unable to read unknown2 from bitStream, aborting Handle! {:d}", bitStream.GetNumberOfUnreadBits());
|
2022-12-16 21:23:02 +00:00
|
|
|
return;
|
|
|
|
};
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (unknown) return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this->m_target) // Guess...
|
|
|
|
{
|
|
|
|
bool unknown = false;
|
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
if (!bitStream.Read(unknown)) {
|
2024-03-08 21:44:02 +00:00
|
|
|
Log::Warn("Unable to read unknown3 from bitStream, aborting Handle! {:d}", bitStream.GetNumberOfUnreadBits());
|
2022-12-16 21:23:02 +00:00
|
|
|
return;
|
|
|
|
};
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (branch.target == context->originator) return;
|
|
|
|
|
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) return;
|
|
|
|
|
|
|
|
auto* skillComponent = target->GetComponent<SkillComponent>();
|
|
|
|
|
|
|
|
if (skillComponent == nullptr) return;
|
|
|
|
|
|
|
|
skillComponent->Interrupt();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
void InterruptBehavior::Calculate(BehaviorContext* context, RakNet::BitStream& bitStream, BehaviorBranchContext branch) {
|
2022-07-28 13:39:57 +00:00
|
|
|
if (branch.target != context->originator) {
|
2024-02-27 07:25:44 +00:00
|
|
|
bitStream.Write(false);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (!this->m_interruptBlock) {
|
2024-02-27 07:25:44 +00:00
|
|
|
bitStream.Write(false);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
bitStream.Write(false);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (branch.target == context->originator) return;
|
|
|
|
|
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) 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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void InterruptBehavior::Load() {
|
2021-12-05 17:54:36 +00:00
|
|
|
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");
|
|
|
|
}
|