2021-12-05 17:54:36 +00:00
|
|
|
#define _USE_MATH_DEFINES
|
|
|
|
#include <cmath>
|
|
|
|
#include "KnockbackBehavior.h"
|
|
|
|
#include "BehaviorBranchContext.h"
|
|
|
|
#include "BehaviorContext.h"
|
|
|
|
#include "EntityManager.h"
|
|
|
|
#include "GameMessages.h"
|
|
|
|
#include "DestroyableComponent.h"
|
2022-12-16 21:23:02 +00:00
|
|
|
#include "Game.h"
|
|
|
|
#include "dLogger.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
void KnockbackBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
2022-12-16 21:23:02 +00:00
|
|
|
bool unknown{};
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-12-16 21:23:02 +00:00
|
|
|
if (!bitStream->Read(unknown)) {
|
|
|
|
Game::logger->Log("KnockbackBehavior", "Unable to read unknown from bitStream, aborting Handle! %i", bitStream->GetNumberOfUnreadBits());
|
|
|
|
return;
|
|
|
|
};
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KnockbackBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
|
|
|
bool blocked = false;
|
|
|
|
|
|
|
|
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
|
|
|
|
|
|
|
if (target != nullptr) {
|
2023-06-07 07:23:50 +00:00
|
|
|
auto destroyableComponent = target->GetComponent<DestroyableComponent>();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (destroyableComponent != nullptr) {
|
|
|
|
blocked = destroyableComponent->IsKnockbackImmune();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bitStream->Write(blocked);
|
|
|
|
}
|
|
|
|
|
|
|
|
void KnockbackBehavior::Load() {
|
|
|
|
this->m_strength = GetInt("strength");
|
|
|
|
this->m_angle = GetInt("angle");
|
|
|
|
this->m_relative = GetBoolean("relative");
|
|
|
|
this->m_time = GetInt("time_ms");
|
|
|
|
}
|