2021-12-05 17:54:36 +00:00
|
|
|
#include "InterruptBehavior.h"
|
|
|
|
#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) {
|
2024-03-30 16:16:06 +00:00
|
|
|
LWOOBJID usedTarget = m_target ? branch.target : context->originator;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-03-30 16:16:06 +00:00
|
|
|
if (usedTarget != context->originator) {
|
|
|
|
bool isTargetImmuneStuns = false;
|
|
|
|
if (!bitStream.Read(isTargetImmuneStuns)) {
|
|
|
|
LOG("Unable to read isTargetImmune from bitStream, aborting Handle! %i", bitStream.GetNumberOfUnreadBits());
|
2022-12-16 21:23:02 +00:00
|
|
|
return;
|
|
|
|
};
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-03-30 16:16:06 +00:00
|
|
|
if (isTargetImmuneStuns) return;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!this->m_interruptBlock) {
|
2024-03-30 16:16:06 +00:00
|
|
|
bool isBlockingInterrupts = false;
|
|
|
|
if (!bitStream.Read(isBlockingInterrupts)) {
|
|
|
|
LOG("Unable to read isBlockingInterrupts from bitStream, aborting Handle! %i", bitStream.GetNumberOfUnreadBits());
|
2022-12-16 21:23:02 +00:00
|
|
|
return;
|
|
|
|
};
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-03-30 16:16:06 +00:00
|
|
|
if (isBlockingInterrupts) return;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2024-03-30 16:16:06 +00:00
|
|
|
bool hasInterruptedStatusEffects = false;
|
|
|
|
if (!bitStream.Read(hasInterruptedStatusEffects)) {
|
|
|
|
LOG("Unable to read hasInterruptedStatusEffects from bitStream, aborting Handle! %i", bitStream.GetNumberOfUnreadBits());
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (hasInterruptedStatusEffects) {
|
|
|
|
bool hasMoreInterruptedStatusEffects = false;
|
|
|
|
int32_t loopLimit = 0;
|
|
|
|
while (bitStream.Read(hasMoreInterruptedStatusEffects) && hasMoreInterruptedStatusEffects) {
|
|
|
|
int32_t statusEffectID = 0;
|
|
|
|
bitStream.Read(statusEffectID);
|
|
|
|
// nothing happens with this data yes. I have no idea why or what it was used for, but the client literally just reads it and does nothing with it.
|
|
|
|
// 0x004faca4 for a reference. it also has a hard loop limit of 100 soo,
|
|
|
|
loopLimit++;
|
|
|
|
if (loopLimit > 100) {
|
|
|
|
// if this is hit you have a problem
|
|
|
|
LOG("Loop limit reached for interrupted status effects, aborting Handle due to bad bitstream! %i", bitStream.GetNumberOfUnreadBits());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
LOG_DEBUG("Interrupted status effect ID: %i", statusEffectID);
|
|
|
|
}
|
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) {
|
2024-03-30 16:16:06 +00:00
|
|
|
LWOOBJID usedTarget = m_target ? branch.target : context->originator;
|
|
|
|
if (usedTarget != context->originator) {
|
2024-02-27 07:25:44 +00:00
|
|
|
bitStream.Write(false);
|
2021-12-05 17:54:36 +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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|