2022-08-06 03:01:59 +00:00
|
|
|
#define _USE_MATH_DEFINES
|
2021-12-05 17:54:36 +00:00
|
|
|
#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
|
|
|
|
2022-07-28 13:39:57 +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
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void KnockbackBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
2021-12-05 17:54:36 +00:00
|
|
|
bool blocked = false;
|
|
|
|
|
|
|
|
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (target != nullptr) {
|
2021-12-05 17:54:36 +00:00
|
|
|
auto* destroyableComponent = target->GetComponent<DestroyableComponent>();
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (destroyableComponent != nullptr) {
|
2021-12-05 17:54:36 +00:00
|
|
|
blocked = destroyableComponent->IsKnockbackImmune();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bitStream->Write(blocked);
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void KnockbackBehavior::Load() {
|
2021-12-05 17:54:36 +00:00
|
|
|
this->m_strength = GetInt("strength");
|
|
|
|
this->m_angle = GetInt("angle");
|
|
|
|
this->m_relative = GetBoolean("relative");
|
|
|
|
this->m_time = GetInt("time_ms");
|
|
|
|
}
|