mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-04 17:54:01 +00:00
format codebase
This commit is contained in:
@@ -3,8 +3,7 @@
|
||||
#include "BehaviorContext.h"
|
||||
#include "EntityManager.h"
|
||||
|
||||
void AirMovementBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void AirMovementBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
uint32_t handle;
|
||||
|
||||
bitStream->Read(handle);
|
||||
@@ -12,15 +11,13 @@ void AirMovementBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bi
|
||||
context->RegisterSyncBehavior(handle, this, branch);
|
||||
}
|
||||
|
||||
void AirMovementBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void AirMovementBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
const auto handle = context->GetUniqueSkillId();
|
||||
|
||||
bitStream->Write(handle);
|
||||
}
|
||||
|
||||
void AirMovementBehavior::Sync(BehaviorContext* context, RakNet::BitStream* bit_stream, BehaviorBranchContext branch)
|
||||
{
|
||||
void AirMovementBehavior::Sync(BehaviorContext* context, RakNet::BitStream* bit_stream, BehaviorBranchContext branch) {
|
||||
uint32_t behaviorId;
|
||||
|
||||
bit_stream->Read(behaviorId);
|
||||
@@ -31,14 +28,12 @@ void AirMovementBehavior::Sync(BehaviorContext* context, RakNet::BitStream* bit_
|
||||
|
||||
auto* behavior = CreateBehavior(behaviorId);
|
||||
|
||||
if (EntityManager::Instance()->GetEntity(target) != nullptr)
|
||||
{
|
||||
if (EntityManager::Instance()->GetEntity(target) != nullptr) {
|
||||
branch.target = target;
|
||||
}
|
||||
|
||||
|
||||
behavior->Handle(context, bit_stream, branch);
|
||||
}
|
||||
|
||||
void AirMovementBehavior::Load()
|
||||
{
|
||||
void AirMovementBehavior::Load() {
|
||||
}
|
||||
|
@@ -9,8 +9,7 @@ public:
|
||||
* Inherited
|
||||
*/
|
||||
|
||||
explicit AirMovementBehavior(const uint32_t behavior_id) : Behavior(behavior_id)
|
||||
{
|
||||
explicit AirMovementBehavior(const uint32_t behavior_id) : Behavior(behavior_id) {
|
||||
}
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
@@ -3,18 +3,14 @@
|
||||
#include "Game.h"
|
||||
#include "dLogger.h"
|
||||
|
||||
void AndBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch)
|
||||
{
|
||||
for (auto* behavior : this->m_behaviors)
|
||||
{
|
||||
void AndBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
|
||||
for (auto* behavior : this->m_behaviors) {
|
||||
behavior->Handle(context, bitStream, branch);
|
||||
}
|
||||
}
|
||||
|
||||
void AndBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch)
|
||||
{
|
||||
for (auto* behavior : this->m_behaviors)
|
||||
{
|
||||
void AndBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
|
||||
for (auto* behavior : this->m_behaviors) {
|
||||
behavior->Calculate(context, bitStream, branch);
|
||||
}
|
||||
}
|
||||
@@ -25,14 +21,11 @@ void AndBehavior::UnCast(BehaviorContext* context, const BehaviorBranchContext b
|
||||
}
|
||||
}
|
||||
|
||||
void AndBehavior::Load()
|
||||
{
|
||||
void AndBehavior::Load() {
|
||||
const auto parameters = GetParameterNames();
|
||||
|
||||
for (const auto& parameter : parameters)
|
||||
{
|
||||
if (parameter.first.rfind("behavior", 0) == 0)
|
||||
{
|
||||
for (const auto& parameter : parameters) {
|
||||
if (parameter.first.rfind("behavior", 0) == 0) {
|
||||
auto* action = GetAction(parameter.second);
|
||||
|
||||
this->m_behaviors.push_back(action);
|
||||
|
@@ -8,18 +8,17 @@ class AndBehavior final : public Behavior
|
||||
{
|
||||
public:
|
||||
std::vector<Behavior*> m_behaviors;
|
||||
|
||||
|
||||
/*
|
||||
* Inherited
|
||||
*/
|
||||
explicit AndBehavior(const uint32_t behaviorId) : Behavior(behaviorId)
|
||||
{
|
||||
explicit AndBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {
|
||||
}
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
void Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
|
||||
void UnCast(BehaviorContext* context, BehaviorBranchContext branch) override;
|
||||
|
||||
void Load() override;
|
||||
|
@@ -5,48 +5,44 @@
|
||||
#include "BuffComponent.h"
|
||||
|
||||
|
||||
void ApplyBuffBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
auto* entity = EntityManager::Instance()->GetEntity(branch.target == LWOOBJID_EMPTY ? context->originator : branch.target);
|
||||
void ApplyBuffBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(branch.target == LWOOBJID_EMPTY ? context->originator : branch.target);
|
||||
|
||||
if (entity == nullptr) return;
|
||||
if (entity == nullptr) return;
|
||||
|
||||
auto* buffComponent = entity->GetComponent<BuffComponent>();
|
||||
auto* buffComponent = entity->GetComponent<BuffComponent>();
|
||||
|
||||
if (buffComponent == nullptr) return;
|
||||
if (buffComponent == nullptr) return;
|
||||
|
||||
buffComponent->ApplyBuff(m_BuffId, m_Duration, context->originator, addImmunity, cancelOnDamaged, cancelOnDeath,
|
||||
cancelOnLogout, cancelonRemoveBuff, cancelOnUi, cancelOnUnequip, cancelOnZone);
|
||||
buffComponent->ApplyBuff(m_BuffId, m_Duration, context->originator, addImmunity, cancelOnDamaged, cancelOnDeath,
|
||||
cancelOnLogout, cancelonRemoveBuff, cancelOnUi, cancelOnUnequip, cancelOnZone);
|
||||
}
|
||||
|
||||
void ApplyBuffBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch)
|
||||
{
|
||||
auto* entity = EntityManager::Instance()->GetEntity(branch.target);
|
||||
void ApplyBuffBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(branch.target);
|
||||
|
||||
if (entity == nullptr) return;
|
||||
if (entity == nullptr) return;
|
||||
|
||||
auto* buffComponent = entity->GetComponent<BuffComponent>();
|
||||
auto* buffComponent = entity->GetComponent<BuffComponent>();
|
||||
|
||||
if (buffComponent == nullptr) return;
|
||||
if (buffComponent == nullptr) return;
|
||||
|
||||
buffComponent->RemoveBuff(m_BuffId);
|
||||
buffComponent->RemoveBuff(m_BuffId);
|
||||
}
|
||||
|
||||
void ApplyBuffBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
Handle(context, bitStream, branch);
|
||||
void ApplyBuffBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
Handle(context, bitStream, branch);
|
||||
}
|
||||
|
||||
void ApplyBuffBehavior::Load()
|
||||
{
|
||||
m_BuffId = GetInt("buff_id");
|
||||
m_Duration = GetFloat("duration_secs");
|
||||
addImmunity = GetBoolean("add_immunity");
|
||||
cancelOnDamaged = GetBoolean("cancel_on_damaged");
|
||||
cancelOnDeath = GetBoolean("cancel_on_death");
|
||||
cancelOnLogout = GetBoolean("cancel_on_logout");
|
||||
cancelonRemoveBuff = GetBoolean("cancel_on_remove_buff");
|
||||
cancelOnUi = GetBoolean("cancel_on_ui");
|
||||
cancelOnUnequip = GetBoolean("cancel_on_unequip");
|
||||
cancelOnZone = GetBoolean("cancel_on_zone");
|
||||
void ApplyBuffBehavior::Load() {
|
||||
m_BuffId = GetInt("buff_id");
|
||||
m_Duration = GetFloat("duration_secs");
|
||||
addImmunity = GetBoolean("add_immunity");
|
||||
cancelOnDamaged = GetBoolean("cancel_on_damaged");
|
||||
cancelOnDeath = GetBoolean("cancel_on_death");
|
||||
cancelOnLogout = GetBoolean("cancel_on_logout");
|
||||
cancelonRemoveBuff = GetBoolean("cancel_on_remove_buff");
|
||||
cancelOnUi = GetBoolean("cancel_on_ui");
|
||||
cancelOnUnequip = GetBoolean("cancel_on_unequip");
|
||||
cancelOnZone = GetBoolean("cancel_on_zone");
|
||||
}
|
||||
|
@@ -7,29 +7,28 @@
|
||||
class ApplyBuffBehavior final : public Behavior
|
||||
{
|
||||
public:
|
||||
int32_t m_BuffId;
|
||||
float m_Duration;
|
||||
bool addImmunity;
|
||||
bool cancelOnDamaged;
|
||||
bool cancelOnDeath;
|
||||
bool cancelOnLogout;
|
||||
bool cancelonRemoveBuff;
|
||||
bool cancelOnUi;
|
||||
bool cancelOnUnequip;
|
||||
bool cancelOnZone;
|
||||
int32_t m_BuffId;
|
||||
float m_Duration;
|
||||
bool addImmunity;
|
||||
bool cancelOnDamaged;
|
||||
bool cancelOnDeath;
|
||||
bool cancelOnLogout;
|
||||
bool cancelonRemoveBuff;
|
||||
bool cancelOnUi;
|
||||
bool cancelOnUnequip;
|
||||
bool cancelOnZone;
|
||||
|
||||
/*
|
||||
* Inherited
|
||||
*/
|
||||
explicit ApplyBuffBehavior(const uint32_t behaviorId) : Behavior(behaviorId)
|
||||
{
|
||||
explicit ApplyBuffBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {
|
||||
}
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
void UnCast(BehaviorContext* context, BehaviorBranchContext branch) override;
|
||||
void UnCast(BehaviorContext* context, BehaviorBranchContext branch) override;
|
||||
|
||||
void Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
|
||||
void Load() override;
|
||||
};
|
||||
|
@@ -10,14 +10,12 @@
|
||||
#include "RebuildComponent.h"
|
||||
#include "DestroyableComponent.h"
|
||||
|
||||
void AreaOfEffectBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void AreaOfEffectBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
uint32_t targetCount;
|
||||
|
||||
bitStream->Read(targetCount);
|
||||
|
||||
if (targetCount > this->m_maxTargets)
|
||||
{
|
||||
if (targetCount > this->m_maxTargets) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -25,8 +23,7 @@ void AreaOfEffectBehavior::Handle(BehaviorContext* context, RakNet::BitStream* b
|
||||
|
||||
targets.reserve(targetCount);
|
||||
|
||||
for (auto i = 0u; i < targetCount; ++i)
|
||||
{
|
||||
for (auto i = 0u; i < targetCount; ++i) {
|
||||
LWOOBJID target;
|
||||
|
||||
bitStream->Read(target);
|
||||
@@ -34,20 +31,17 @@ void AreaOfEffectBehavior::Handle(BehaviorContext* context, RakNet::BitStream* b
|
||||
targets.push_back(target);
|
||||
}
|
||||
|
||||
for (auto target : targets)
|
||||
{
|
||||
for (auto target : targets) {
|
||||
branch.target = target;
|
||||
|
||||
this->m_action->Handle(context, bitStream, branch);
|
||||
}
|
||||
}
|
||||
|
||||
void AreaOfEffectBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void AreaOfEffectBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
auto* self = EntityManager::Instance()->GetEntity(context->caster);
|
||||
|
||||
if (self == nullptr)
|
||||
{
|
||||
if (self == nullptr) {
|
||||
Game::logger->Log("TacArcBehavior", "Invalid self for (%llu)!", context->originator);
|
||||
|
||||
return;
|
||||
@@ -59,10 +53,8 @@ void AreaOfEffectBehavior::Calculate(BehaviorContext* context, RakNet::BitStream
|
||||
|
||||
auto* presetTarget = EntityManager::Instance()->GetEntity(branch.target);
|
||||
|
||||
if (presetTarget != nullptr)
|
||||
{
|
||||
if (this->m_radius * this->m_radius >= Vector3::DistanceSquared(reference, presetTarget->GetPosition()))
|
||||
{
|
||||
if (presetTarget != nullptr) {
|
||||
if (this->m_radius * this->m_radius >= Vector3::DistanceSquared(reference, presetTarget->GetPosition())) {
|
||||
targets.push_back(presetTarget);
|
||||
}
|
||||
}
|
||||
@@ -75,78 +67,67 @@ void AreaOfEffectBehavior::Calculate(BehaviorContext* context, RakNet::BitStream
|
||||
}
|
||||
|
||||
// Gets all of the valid targets, passing in if should target enemies and friends
|
||||
for (auto validTarget : context->GetValidTargets(m_ignoreFaction , includeFaction, m_TargetSelf == 1, m_targetEnemy == 1, m_targetFriend == 1))
|
||||
{
|
||||
for (auto validTarget : context->GetValidTargets(m_ignoreFaction, includeFaction, m_TargetSelf == 1, m_targetEnemy == 1, m_targetFriend == 1)) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(validTarget);
|
||||
|
||||
if (entity == nullptr)
|
||||
{
|
||||
if (entity == nullptr) {
|
||||
Game::logger->Log("TacArcBehavior", "Invalid target (%llu) for (%llu)!", validTarget, context->originator);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (std::find(targets.begin(), targets.end(), entity) != targets.end())
|
||||
{
|
||||
if (std::find(targets.begin(), targets.end(), entity) != targets.end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto* destroyableComponent = entity->GetComponent<DestroyableComponent>();
|
||||
|
||||
if (destroyableComponent == nullptr)
|
||||
{
|
||||
if (destroyableComponent == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (destroyableComponent->HasFaction(m_ignoreFaction))
|
||||
{
|
||||
if (destroyableComponent->HasFaction(m_ignoreFaction)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto distance = Vector3::DistanceSquared(reference, entity->GetPosition());
|
||||
|
||||
if (this->m_radius * this->m_radius >= distance && (this->m_maxTargets == 0 || targets.size() < this->m_maxTargets))
|
||||
{
|
||||
if (this->m_radius * this->m_radius >= distance && (this->m_maxTargets == 0 || targets.size() < this->m_maxTargets)) {
|
||||
targets.push_back(entity);
|
||||
}
|
||||
}
|
||||
|
||||
std::sort(targets.begin(), targets.end(), [reference](Entity* a, Entity* b)
|
||||
{
|
||||
std::sort(targets.begin(), targets.end(), [reference](Entity* a, Entity* b) {
|
||||
const auto aDistance = Vector3::DistanceSquared(a->GetPosition(), reference);
|
||||
const auto bDistance = Vector3::DistanceSquared(b->GetPosition(), reference);
|
||||
|
||||
return aDistance > bDistance;
|
||||
});
|
||||
});
|
||||
|
||||
const uint32_t size = targets.size();
|
||||
|
||||
bitStream->Write(size);
|
||||
|
||||
if (size == 0)
|
||||
{
|
||||
if (size == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
context->foundTarget = true;
|
||||
|
||||
for (auto* target : targets)
|
||||
{
|
||||
for (auto* target : targets) {
|
||||
bitStream->Write(target->GetObjectID());
|
||||
|
||||
PlayFx(u"cast", context->originator, target->GetObjectID());
|
||||
}
|
||||
|
||||
for (auto* target : targets)
|
||||
{
|
||||
for (auto* target : targets) {
|
||||
branch.target = target->GetObjectID();
|
||||
|
||||
this->m_action->Calculate(context, bitStream, branch);
|
||||
}
|
||||
}
|
||||
|
||||
void AreaOfEffectBehavior::Load()
|
||||
{
|
||||
void AreaOfEffectBehavior::Load() {
|
||||
this->m_action = GetAction("action");
|
||||
|
||||
this->m_radius = GetFloat("radius");
|
||||
@@ -157,7 +138,7 @@ void AreaOfEffectBehavior::Load()
|
||||
|
||||
this->m_includeFaction = GetInt("include_faction");
|
||||
|
||||
this->m_TargetSelf = GetInt("target_self");
|
||||
this->m_TargetSelf = GetInt("target_self");
|
||||
|
||||
this->m_targetEnemy = GetInt("target_enemy");
|
||||
|
||||
|
@@ -14,21 +14,20 @@ public:
|
||||
|
||||
int32_t m_includeFaction;
|
||||
|
||||
int32_t m_TargetSelf;
|
||||
int32_t m_TargetSelf;
|
||||
|
||||
int32_t m_targetEnemy;
|
||||
|
||||
int32_t m_targetFriend;
|
||||
|
||||
|
||||
/*
|
||||
* Inherited
|
||||
*/
|
||||
explicit AreaOfEffectBehavior(const uint32_t behaviorId) : Behavior(behaviorId)
|
||||
{
|
||||
explicit AreaOfEffectBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {
|
||||
}
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
|
||||
void Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
void Load() override;
|
||||
|
@@ -4,48 +4,41 @@
|
||||
#include "Game.h"
|
||||
#include "dLogger.h"
|
||||
|
||||
void AttackDelayBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch)
|
||||
{
|
||||
void AttackDelayBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
|
||||
uint32_t handle;
|
||||
|
||||
bitStream->Read(handle);
|
||||
|
||||
for (auto i = 0u; i < this->m_numIntervals; ++i)
|
||||
{
|
||||
|
||||
for (auto i = 0u; i < this->m_numIntervals; ++i) {
|
||||
context->RegisterSyncBehavior(handle, this, branch);
|
||||
}
|
||||
}
|
||||
|
||||
void AttackDelayBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch)
|
||||
{
|
||||
void AttackDelayBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
|
||||
const auto handle = context->GetUniqueSkillId();
|
||||
|
||||
bitStream->Write(handle);
|
||||
|
||||
context->foundTarget = true;
|
||||
|
||||
for (auto i = 0u; i < this->m_numIntervals; ++i)
|
||||
{
|
||||
for (auto i = 0u; i < this->m_numIntervals; ++i) {
|
||||
const auto multiple = static_cast<float>(i + 1);
|
||||
|
||||
context->SyncCalculation(handle, this->m_delay * multiple, this, branch, m_ignoreInterrupts);
|
||||
}
|
||||
}
|
||||
|
||||
void AttackDelayBehavior::Sync(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch)
|
||||
{
|
||||
void AttackDelayBehavior::Sync(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
|
||||
this->m_action->Handle(context, bitStream, branch);
|
||||
}
|
||||
|
||||
void AttackDelayBehavior::SyncCalculation(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch)
|
||||
{
|
||||
void AttackDelayBehavior::SyncCalculation(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
|
||||
PlayFx(u"cast", context->originator);
|
||||
|
||||
this->m_action->Calculate(context, bitStream, branch);
|
||||
}
|
||||
|
||||
void AttackDelayBehavior::Load()
|
||||
{
|
||||
void AttackDelayBehavior::Load() {
|
||||
this->m_numIntervals = GetInt("num_intervals");
|
||||
|
||||
this->m_action = GetAction("action");
|
||||
@@ -54,8 +47,7 @@ void AttackDelayBehavior::Load()
|
||||
|
||||
this->m_ignoreInterrupts = GetBoolean("ignore_interrupts");
|
||||
|
||||
if (this->m_numIntervals == 0)
|
||||
{
|
||||
if (this->m_numIntervals == 0) {
|
||||
this->m_numIntervals = 1;
|
||||
}
|
||||
}
|
||||
|
@@ -15,9 +15,8 @@ public:
|
||||
/*
|
||||
* Inherited
|
||||
*/
|
||||
|
||||
explicit AttackDelayBehavior(const uint32_t behaviorId) : Behavior(behaviorId)
|
||||
{
|
||||
|
||||
explicit AttackDelayBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {
|
||||
}
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
@@ -27,6 +26,6 @@ public:
|
||||
void Sync(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
void SyncCalculation(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
|
||||
void Load() override;
|
||||
};
|
||||
|
@@ -43,7 +43,7 @@ void BasicAttackBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bi
|
||||
uint32_t damageDealt;
|
||||
bitStream->Read(damageDealt);
|
||||
|
||||
// A value that's too large may be a cheating attempt, so we set it to MIN too
|
||||
// A value that's too large may be a cheating attempt, so we set it to MIN too
|
||||
if (damageDealt > this->m_maxDamage || damageDealt < this->m_minDamage) {
|
||||
damageDealt = this->m_minDamage;
|
||||
}
|
||||
@@ -53,7 +53,7 @@ void BasicAttackBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bi
|
||||
bitStream->Read(died);
|
||||
|
||||
if (entity != nullptr) {
|
||||
auto* destroyableComponent = entity->GetComponent<DestroyableComponent>();
|
||||
auto* destroyableComponent = entity->GetComponent<DestroyableComponent>();
|
||||
if (destroyableComponent != nullptr) {
|
||||
PlayFx(u"onhit", entity->GetObjectID());
|
||||
destroyableComponent->Damage(damageDealt, context->originator, context->skillID);
|
||||
@@ -113,7 +113,7 @@ void BasicAttackBehavior::Calculate(BehaviorContext* context, RakNet::BitStream*
|
||||
auto* destroyableComponent = entity->GetComponent<DestroyableComponent>();
|
||||
if (damage != 0 && destroyableComponent != nullptr) {
|
||||
PlayFx(u"onhit", entity->GetObjectID(), 1);
|
||||
destroyableComponent->Damage(damage, context->originator, context->skillID, false);
|
||||
destroyableComponent->Damage(damage, context->originator, context->skillID, false);
|
||||
context->ScheduleUpdate(branch.target);
|
||||
}
|
||||
}
|
||||
|
@@ -9,14 +9,13 @@ public:
|
||||
uint32_t m_maxDamage;
|
||||
|
||||
Behavior* m_onSuccess;
|
||||
|
||||
explicit BasicAttackBehavior(const uint32_t behaviorId) : Behavior(behaviorId)
|
||||
{
|
||||
|
||||
explicit BasicAttackBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {
|
||||
}
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
void Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
|
||||
void Load() override;
|
||||
};
|
||||
|
@@ -60,7 +60,7 @@
|
||||
#include "DamageReductionBehavior.h"
|
||||
#include "JetPackBehavior.h"
|
||||
|
||||
//CDClient includes
|
||||
//CDClient includes
|
||||
#include "CDBehaviorParameterTable.h"
|
||||
#include "CDClientDatabase.h"
|
||||
#include "CDClientManager.h"
|
||||
@@ -73,34 +73,28 @@
|
||||
std::unordered_map<uint32_t, Behavior*> Behavior::Cache = {};
|
||||
CDBehaviorParameterTable* Behavior::BehaviorParameterTable = nullptr;
|
||||
|
||||
Behavior* Behavior::GetBehavior(const uint32_t behaviorId)
|
||||
{
|
||||
if (BehaviorParameterTable == nullptr)
|
||||
{
|
||||
Behavior* Behavior::GetBehavior(const uint32_t behaviorId) {
|
||||
if (BehaviorParameterTable == nullptr) {
|
||||
BehaviorParameterTable = CDClientManager::Instance()->GetTable<CDBehaviorParameterTable>("BehaviorParameter");
|
||||
}
|
||||
|
||||
const auto pair = Cache.find(behaviorId);
|
||||
|
||||
if (pair == Cache.end())
|
||||
{
|
||||
if (pair == Cache.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return static_cast<Behavior*>(pair->second);
|
||||
}
|
||||
|
||||
Behavior* Behavior::CreateBehavior(const uint32_t behaviorId)
|
||||
{
|
||||
Behavior* Behavior::CreateBehavior(const uint32_t behaviorId) {
|
||||
auto* cached = GetBehavior(behaviorId);
|
||||
|
||||
if (cached != nullptr)
|
||||
{
|
||||
if (cached != nullptr) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
if (behaviorId == 0)
|
||||
{
|
||||
if (behaviorId == 0) {
|
||||
return new EmptyBehavior(0);
|
||||
}
|
||||
|
||||
@@ -108,8 +102,7 @@ Behavior* Behavior::CreateBehavior(const uint32_t behaviorId)
|
||||
|
||||
Behavior* behavior = nullptr;
|
||||
|
||||
switch (templateId)
|
||||
{
|
||||
switch (templateId) {
|
||||
case BehaviorTemplates::BEHAVIOR_EMPTY: break;
|
||||
case BehaviorTemplates::BEHAVIOR_BASIC_ATTACK:
|
||||
behavior = new BasicAttackBehavior(behaviorId);
|
||||
@@ -273,8 +266,7 @@ Behavior* Behavior::CreateBehavior(const uint32_t behaviorId)
|
||||
break;
|
||||
}
|
||||
|
||||
if (behavior == nullptr)
|
||||
{
|
||||
if (behavior == nullptr) {
|
||||
//Game::logger->Log("Behavior", "Failed to load unimplemented template id (%i)!", templateId);
|
||||
|
||||
behavior = new EmptyBehavior(behaviorId);
|
||||
@@ -305,19 +297,16 @@ BehaviorTemplates Behavior::GetBehaviorTemplate(const uint32_t behaviorId) {
|
||||
}
|
||||
|
||||
// For use with enemies, to display the correct damage animations on the players
|
||||
void Behavior::PlayFx(std::u16string type, const LWOOBJID target, const LWOOBJID secondary)
|
||||
{
|
||||
void Behavior::PlayFx(std::u16string type, const LWOOBJID target, const LWOOBJID secondary) {
|
||||
auto* targetEntity = EntityManager::Instance()->GetEntity(target);
|
||||
|
||||
if (targetEntity == nullptr)
|
||||
{
|
||||
if (targetEntity == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto effectId = this->m_effectId;
|
||||
|
||||
if (effectId == 0)
|
||||
{
|
||||
if (effectId == 0) {
|
||||
GameMessages::SendPlayFXEffect(targetEntity, -1, type, "", secondary, 1, 1, true);
|
||||
|
||||
return;
|
||||
@@ -327,23 +316,17 @@ void Behavior::PlayFx(std::u16string type, const LWOOBJID target, const LWOOBJID
|
||||
|
||||
const auto typeString = GeneralUtils::UTF16ToWTF8(type);
|
||||
|
||||
if (m_effectNames == nullptr)
|
||||
{
|
||||
if (m_effectNames == nullptr) {
|
||||
m_effectNames = new std::unordered_map<std::string, std::string>();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
const auto pair = m_effectNames->find(typeString);
|
||||
|
||||
if (type.empty())
|
||||
{
|
||||
if (type.empty()) {
|
||||
type = GeneralUtils::ASCIIToUTF16(*m_effectType);
|
||||
}
|
||||
|
||||
if (pair != m_effectNames->end())
|
||||
{
|
||||
if (renderComponent == nullptr)
|
||||
{
|
||||
if (pair != m_effectNames->end()) {
|
||||
if (renderComponent == nullptr) {
|
||||
GameMessages::SendPlayFXEffect(targetEntity, effectId, type, pair->second, secondary, 1, 1, true);
|
||||
|
||||
return;
|
||||
@@ -366,24 +349,22 @@ void Behavior::PlayFx(std::u16string type, const LWOOBJID target, const LWOOBJID
|
||||
|
||||
if (!type.empty()) {
|
||||
typeQuery.bind(1, typeString.c_str());
|
||||
typeQuery.bind(2, (int) effectId);
|
||||
typeQuery.bind(2, (int)effectId);
|
||||
|
||||
result = typeQuery.execQuery();
|
||||
} else {
|
||||
idQuery.bind(1, (int) effectId);
|
||||
idQuery.bind(1, (int)effectId);
|
||||
|
||||
result = idQuery.execQuery();
|
||||
}
|
||||
|
||||
if (result.eof() || result.fieldIsNull(0))
|
||||
{
|
||||
if (result.eof() || result.fieldIsNull(0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto name = std::string(result.getStringField(0));
|
||||
|
||||
if (type.empty())
|
||||
{
|
||||
if (type.empty()) {
|
||||
const auto typeResult = result.getStringField(1);
|
||||
|
||||
type = GeneralUtils::ASCIIToUTF16(typeResult);
|
||||
@@ -395,8 +376,7 @@ void Behavior::PlayFx(std::u16string type, const LWOOBJID target, const LWOOBJID
|
||||
|
||||
m_effectNames->insert_or_assign(typeString, name);
|
||||
|
||||
if (renderComponent == nullptr)
|
||||
{
|
||||
if (renderComponent == nullptr) {
|
||||
GameMessages::SendPlayFXEffect(targetEntity, effectId, type, name, secondary, 1, 1, true);
|
||||
|
||||
return;
|
||||
@@ -405,8 +385,7 @@ void Behavior::PlayFx(std::u16string type, const LWOOBJID target, const LWOOBJID
|
||||
renderComponent->PlayEffect(effectId, type, name, secondary);
|
||||
}
|
||||
|
||||
Behavior::Behavior(const uint32_t behaviorId)
|
||||
{
|
||||
Behavior::Behavior(const uint32_t behaviorId) {
|
||||
auto behaviorTemplateTable = CDClientManager::Instance()->GetTable<CDBehaviorTemplateTable>("BehaviorTemplate");
|
||||
|
||||
CDBehaviorTemplate templateInDatabase{};
|
||||
@@ -430,8 +409,7 @@ Behavior::Behavior(const uint32_t behaviorId)
|
||||
}
|
||||
|
||||
// Make sure we do not proceed if we are trying to load an invalid behavior
|
||||
if (templateInDatabase.behaviorID == 0)
|
||||
{
|
||||
if (templateInDatabase.behaviorID == 0) {
|
||||
Game::logger->Log("Behavior", "Failed to load behavior with id (%i)!", behaviorId);
|
||||
|
||||
this->m_effectId = 0;
|
||||
@@ -449,40 +427,34 @@ Behavior::Behavior(const uint32_t behaviorId)
|
||||
}
|
||||
|
||||
|
||||
float Behavior::GetFloat(const std::string& name, const float defaultValue) const
|
||||
{
|
||||
float Behavior::GetFloat(const std::string& name, const float defaultValue) const {
|
||||
// Get the behavior parameter entry and return its value.
|
||||
if (!BehaviorParameterTable) BehaviorParameterTable = CDClientManager::Instance()->GetTable<CDBehaviorParameterTable>("BehaviorParameter");
|
||||
return BehaviorParameterTable->GetEntry(this->m_behaviorId, name, defaultValue).value;
|
||||
}
|
||||
|
||||
|
||||
bool Behavior::GetBoolean(const std::string& name, const bool defaultValue) const
|
||||
{
|
||||
bool Behavior::GetBoolean(const std::string& name, const bool defaultValue) const {
|
||||
return GetFloat(name, defaultValue) > 0;
|
||||
}
|
||||
|
||||
|
||||
int32_t Behavior::GetInt(const std::string& name, const int defaultValue) const
|
||||
{
|
||||
int32_t Behavior::GetInt(const std::string& name, const int defaultValue) const {
|
||||
return static_cast<int32_t>(GetFloat(name, defaultValue));
|
||||
}
|
||||
|
||||
|
||||
Behavior* Behavior::GetAction(const std::string& name) const
|
||||
{
|
||||
Behavior* Behavior::GetAction(const std::string& name) const {
|
||||
const auto id = GetInt(name);
|
||||
|
||||
return CreateBehavior(id);
|
||||
}
|
||||
|
||||
Behavior* Behavior::GetAction(float value) const
|
||||
{
|
||||
Behavior* Behavior::GetAction(float value) const {
|
||||
return CreateBehavior(static_cast<int32_t>(value));
|
||||
}
|
||||
|
||||
std::map<std::string, float> Behavior::GetParameterNames() const
|
||||
{
|
||||
std::map<std::string, float> Behavior::GetParameterNames() const {
|
||||
std::map<std::string, float> templatesInDatabase;
|
||||
// Find behavior template by its behavior id.
|
||||
if (!BehaviorParameterTable) BehaviorParameterTable = CDClientManager::Instance()->GetTable<CDBehaviorParameterTable>("BehaviorParameter");
|
||||
@@ -493,40 +465,31 @@ std::map<std::string, float> Behavior::GetParameterNames() const
|
||||
return templatesInDatabase;
|
||||
}
|
||||
|
||||
void Behavior::Load()
|
||||
{
|
||||
void Behavior::Load() {
|
||||
}
|
||||
|
||||
void Behavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void Behavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
}
|
||||
|
||||
void Behavior::Sync(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void Behavior::Sync(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
}
|
||||
|
||||
void Behavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch)
|
||||
{
|
||||
void Behavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch) {
|
||||
}
|
||||
|
||||
void Behavior::Timer(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second)
|
||||
{
|
||||
void Behavior::Timer(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) {
|
||||
}
|
||||
|
||||
void Behavior::End(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second)
|
||||
{
|
||||
void Behavior::End(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) {
|
||||
}
|
||||
|
||||
void Behavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void Behavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
}
|
||||
|
||||
void Behavior::SyncCalculation(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void Behavior::SyncCalculation(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
}
|
||||
|
||||
Behavior::~Behavior()
|
||||
{
|
||||
Behavior::~Behavior() {
|
||||
delete m_effectNames;
|
||||
delete m_effectType;
|
||||
delete m_effectHandle;
|
||||
|
@@ -31,24 +31,24 @@ public:
|
||||
/*
|
||||
* Utilities
|
||||
*/
|
||||
|
||||
|
||||
void PlayFx(std::u16string type, LWOOBJID target, LWOOBJID secondary = LWOOBJID_EMPTY);
|
||||
|
||||
/*
|
||||
* Members
|
||||
*/
|
||||
|
||||
|
||||
uint32_t m_behaviorId;
|
||||
BehaviorTemplates m_templateId;
|
||||
uint32_t m_effectId;
|
||||
std::string* m_effectHandle = nullptr;
|
||||
std::unordered_map<std::string, std::string>* m_effectNames = nullptr;
|
||||
std::string* m_effectType = nullptr;
|
||||
|
||||
|
||||
/*
|
||||
* Behavior parameters
|
||||
*/
|
||||
|
||||
|
||||
float GetFloat(const std::string& name, const float defaultValue = 0) const;
|
||||
|
||||
bool GetBoolean(const std::string& name, const bool defaultValue = false) const;
|
||||
@@ -60,7 +60,7 @@ public:
|
||||
Behavior* GetAction(float value) const;
|
||||
|
||||
std::map<std::string, float> GetParameterNames() const;
|
||||
|
||||
|
||||
/*
|
||||
* Virtual
|
||||
*/
|
||||
@@ -69,15 +69,15 @@ public:
|
||||
|
||||
// Player side
|
||||
virtual void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch);
|
||||
|
||||
|
||||
virtual void Sync(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch);
|
||||
|
||||
virtual void UnCast(BehaviorContext* context, BehaviorBranchContext branch);
|
||||
|
||||
virtual void Timer(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second);
|
||||
|
||||
|
||||
virtual void End(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second);
|
||||
|
||||
|
||||
// Npc side
|
||||
virtual void Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch);
|
||||
|
||||
@@ -86,7 +86,7 @@ public:
|
||||
/*
|
||||
* Creations/destruction
|
||||
*/
|
||||
|
||||
|
||||
explicit Behavior(uint32_t behaviorId);
|
||||
virtual ~Behavior();
|
||||
};
|
||||
|
@@ -1,13 +1,11 @@
|
||||
#include "BehaviorBranchContext.h"
|
||||
|
||||
|
||||
BehaviorBranchContext::BehaviorBranchContext()
|
||||
{
|
||||
BehaviorBranchContext::BehaviorBranchContext() {
|
||||
this->isProjectile = false;
|
||||
}
|
||||
|
||||
BehaviorBranchContext::BehaviorBranchContext(const LWOOBJID target, const float duration, const NiPoint3& referencePosition)
|
||||
{
|
||||
BehaviorBranchContext::BehaviorBranchContext(const LWOOBJID target, const float duration, const NiPoint3& referencePosition) {
|
||||
this->target = target;
|
||||
this->duration = duration;
|
||||
this->referencePosition = referencePosition;
|
||||
|
@@ -6,9 +6,9 @@
|
||||
struct BehaviorBranchContext
|
||||
{
|
||||
LWOOBJID target = LWOOBJID_EMPTY;
|
||||
|
||||
|
||||
float duration = 0;
|
||||
|
||||
|
||||
NiPoint3 referencePosition = {};
|
||||
|
||||
bool isProjectile = false;
|
||||
@@ -16,6 +16,6 @@ struct BehaviorBranchContext
|
||||
uint32_t start = 0;
|
||||
|
||||
BehaviorBranchContext();
|
||||
|
||||
|
||||
BehaviorBranchContext(LWOOBJID target, float duration = 0, const NiPoint3& referencePosition = NiPoint3(0, 0, 0));
|
||||
};
|
||||
|
@@ -15,24 +15,19 @@
|
||||
#include "PhantomPhysicsComponent.h"
|
||||
#include "RebuildComponent.h"
|
||||
|
||||
BehaviorSyncEntry::BehaviorSyncEntry()
|
||||
{
|
||||
BehaviorSyncEntry::BehaviorSyncEntry() {
|
||||
}
|
||||
|
||||
BehaviorTimerEntry::BehaviorTimerEntry()
|
||||
{
|
||||
BehaviorTimerEntry::BehaviorTimerEntry() {
|
||||
}
|
||||
|
||||
BehaviorEndEntry::BehaviorEndEntry()
|
||||
{
|
||||
BehaviorEndEntry::BehaviorEndEntry() {
|
||||
}
|
||||
|
||||
uint32_t BehaviorContext::GetUniqueSkillId() const
|
||||
{
|
||||
uint32_t BehaviorContext::GetUniqueSkillId() const {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(this->originator);
|
||||
|
||||
if (entity == nullptr)
|
||||
{
|
||||
if (entity == nullptr) {
|
||||
Game::logger->Log("BehaviorContext", "Invalid entity for (%llu)!", this->originator);
|
||||
|
||||
return 0;
|
||||
@@ -40,8 +35,7 @@ uint32_t BehaviorContext::GetUniqueSkillId() const
|
||||
|
||||
auto* component = entity->GetComponent<SkillComponent>();
|
||||
|
||||
if (component == nullptr)
|
||||
{
|
||||
if (component == nullptr) {
|
||||
Game::logger->Log("BehaviorContext", "No skill component attached to (%llu)!", this->originator);;
|
||||
|
||||
return 0;
|
||||
@@ -51,8 +45,7 @@ uint32_t BehaviorContext::GetUniqueSkillId() const
|
||||
}
|
||||
|
||||
|
||||
void BehaviorContext::RegisterSyncBehavior(const uint32_t syncId, Behavior* behavior, const BehaviorBranchContext& branchContext)
|
||||
{
|
||||
void BehaviorContext::RegisterSyncBehavior(const uint32_t syncId, Behavior* behavior, const BehaviorBranchContext& branchContext) {
|
||||
auto entry = BehaviorSyncEntry();
|
||||
|
||||
entry.handle = syncId;
|
||||
@@ -62,8 +55,7 @@ void BehaviorContext::RegisterSyncBehavior(const uint32_t syncId, Behavior* beha
|
||||
this->syncEntries.push_back(entry);
|
||||
}
|
||||
|
||||
void BehaviorContext::RegisterTimerBehavior(Behavior* behavior, const BehaviorBranchContext& branchContext, const LWOOBJID second)
|
||||
{
|
||||
void BehaviorContext::RegisterTimerBehavior(Behavior* behavior, const BehaviorBranchContext& branchContext, const LWOOBJID second) {
|
||||
BehaviorTimerEntry entry;
|
||||
|
||||
entry.time = branchContext.duration;
|
||||
@@ -74,8 +66,7 @@ void BehaviorContext::RegisterTimerBehavior(Behavior* behavior, const BehaviorBr
|
||||
this->timerEntries.push_back(entry);
|
||||
}
|
||||
|
||||
void BehaviorContext::RegisterEndBehavior(Behavior* behavior, const BehaviorBranchContext& branchContext, const LWOOBJID second)
|
||||
{
|
||||
void BehaviorContext::RegisterEndBehavior(Behavior* behavior, const BehaviorBranchContext& branchContext, const LWOOBJID second) {
|
||||
BehaviorEndEntry entry;
|
||||
|
||||
entry.behavior = behavior;
|
||||
@@ -86,20 +77,16 @@ void BehaviorContext::RegisterEndBehavior(Behavior* behavior, const BehaviorBran
|
||||
this->endEntries.push_back(entry);
|
||||
}
|
||||
|
||||
void BehaviorContext::ScheduleUpdate(const LWOOBJID id)
|
||||
{
|
||||
if (std::find(this->scheduledUpdates.begin(), this->scheduledUpdates.end(), id) != this->scheduledUpdates.end())
|
||||
{
|
||||
void BehaviorContext::ScheduleUpdate(const LWOOBJID id) {
|
||||
if (std::find(this->scheduledUpdates.begin(), this->scheduledUpdates.end(), id) != this->scheduledUpdates.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->scheduledUpdates.push_back(id);
|
||||
}
|
||||
|
||||
void BehaviorContext::ExecuteUpdates()
|
||||
{
|
||||
for (const auto& id : this->scheduledUpdates)
|
||||
{
|
||||
void BehaviorContext::ExecuteUpdates() {
|
||||
for (const auto& id : this->scheduledUpdates) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(id);
|
||||
|
||||
if (entity == nullptr) continue;
|
||||
@@ -110,20 +97,17 @@ void BehaviorContext::ExecuteUpdates()
|
||||
this->scheduledUpdates.clear();
|
||||
}
|
||||
|
||||
void BehaviorContext::SyncBehavior(const uint32_t syncId, RakNet::BitStream* bitStream)
|
||||
{
|
||||
void BehaviorContext::SyncBehavior(const uint32_t syncId, RakNet::BitStream* bitStream) {
|
||||
BehaviorSyncEntry entry;
|
||||
auto found = false;
|
||||
|
||||
/*
|
||||
* There may be more than one of each handle
|
||||
*/
|
||||
for (auto i = 0u; i < this->syncEntries.size(); ++i)
|
||||
{
|
||||
for (auto i = 0u; i < this->syncEntries.size(); ++i) {
|
||||
const auto syncEntry = this->syncEntries.at(i);
|
||||
|
||||
if (syncEntry.handle == syncId)
|
||||
{
|
||||
if (syncEntry.handle == syncId) {
|
||||
found = true;
|
||||
entry = syncEntry;
|
||||
|
||||
@@ -133,8 +117,7 @@ void BehaviorContext::SyncBehavior(const uint32_t syncId, RakNet::BitStream* bit
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
if (!found) {
|
||||
Game::logger->Log("BehaviorContext", "Failed to find behavior sync entry with sync id (%i)!", syncId);
|
||||
|
||||
return;
|
||||
@@ -143,8 +126,7 @@ void BehaviorContext::SyncBehavior(const uint32_t syncId, RakNet::BitStream* bit
|
||||
auto* behavior = entry.behavior;
|
||||
const auto branch = entry.branchContext;
|
||||
|
||||
if (behavior == nullptr)
|
||||
{
|
||||
if (behavior == nullptr) {
|
||||
Game::logger->Log("BehaviorContext", "Invalid behavior for sync id (%i)!", syncId);
|
||||
|
||||
return;
|
||||
@@ -154,21 +136,17 @@ void BehaviorContext::SyncBehavior(const uint32_t syncId, RakNet::BitStream* bit
|
||||
}
|
||||
|
||||
|
||||
void BehaviorContext::Update(const float deltaTime)
|
||||
{
|
||||
for (auto i = 0u; i < this->timerEntries.size(); ++i)
|
||||
{
|
||||
void BehaviorContext::Update(const float deltaTime) {
|
||||
for (auto i = 0u; i < this->timerEntries.size(); ++i) {
|
||||
auto entry = this->timerEntries.at(i);
|
||||
|
||||
if (entry.time > 0)
|
||||
{
|
||||
if (entry.time > 0) {
|
||||
entry.time -= deltaTime;
|
||||
|
||||
this->timerEntries[i] = entry;
|
||||
}
|
||||
|
||||
if (entry.time > 0)
|
||||
{
|
||||
if (entry.time > 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -177,10 +155,8 @@ void BehaviorContext::Update(const float deltaTime)
|
||||
|
||||
std::vector<BehaviorTimerEntry> valid;
|
||||
|
||||
for (const auto& entry : this->timerEntries)
|
||||
{
|
||||
if (entry.time <= 0)
|
||||
{
|
||||
for (const auto& entry : this->timerEntries) {
|
||||
if (entry.time <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -191,8 +167,7 @@ void BehaviorContext::Update(const float deltaTime)
|
||||
}
|
||||
|
||||
|
||||
void BehaviorContext::SyncCalculation(const uint32_t syncId, const float time, Behavior* behavior, const BehaviorBranchContext& branch, const bool ignoreInterrupts)
|
||||
{
|
||||
void BehaviorContext::SyncCalculation(const uint32_t syncId, const float time, Behavior* behavior, const BehaviorBranchContext& branch, const bool ignoreInterrupts) {
|
||||
BehaviorSyncEntry entry;
|
||||
|
||||
entry.behavior = behavior;
|
||||
@@ -204,14 +179,11 @@ void BehaviorContext::SyncCalculation(const uint32_t syncId, const float time, B
|
||||
this->syncEntries.push_back(entry);
|
||||
}
|
||||
|
||||
void BehaviorContext::InvokeEnd(const uint32_t id)
|
||||
{
|
||||
void BehaviorContext::InvokeEnd(const uint32_t id) {
|
||||
std::vector<BehaviorEndEntry> entries;
|
||||
|
||||
for (const auto& entry : this->endEntries)
|
||||
{
|
||||
if (entry.start == id)
|
||||
{
|
||||
for (const auto& entry : this->endEntries) {
|
||||
if (entry.start == id) {
|
||||
entry.behavior->End(this, entry.branchContext, entry.second);
|
||||
|
||||
continue;
|
||||
@@ -223,23 +195,19 @@ void BehaviorContext::InvokeEnd(const uint32_t id)
|
||||
this->endEntries = entries;
|
||||
}
|
||||
|
||||
bool BehaviorContext::CalculateUpdate(const float deltaTime)
|
||||
{
|
||||
bool BehaviorContext::CalculateUpdate(const float deltaTime) {
|
||||
auto any = false;
|
||||
|
||||
for (auto i = 0u; i < this->syncEntries.size(); ++i)
|
||||
{
|
||||
for (auto i = 0u; i < this->syncEntries.size(); ++i) {
|
||||
auto entry = this->syncEntries.at(i);
|
||||
|
||||
if (entry.time > 0)
|
||||
{
|
||||
if (entry.time > 0) {
|
||||
entry.time -= deltaTime;
|
||||
|
||||
this->syncEntries[i] = entry;
|
||||
}
|
||||
|
||||
if (entry.time > 0)
|
||||
{
|
||||
if (entry.time > 0) {
|
||||
any = true;
|
||||
|
||||
continue;
|
||||
@@ -257,9 +225,8 @@ bool BehaviorContext::CalculateUpdate(const float deltaTime)
|
||||
// Calculate sync
|
||||
entry.behavior->SyncCalculation(this, bitStream, entry.branchContext);
|
||||
|
||||
if (!clientInitalized)
|
||||
{
|
||||
echo.sBitStream.assign((char*) bitStream->GetData(), bitStream->GetNumberOfBytesUsed());
|
||||
if (!clientInitalized) {
|
||||
echo.sBitStream.assign((char*)bitStream->GetData(), bitStream->GetNumberOfBytesUsed());
|
||||
|
||||
// Write message
|
||||
RakNet::BitStream message;
|
||||
@@ -278,10 +245,8 @@ bool BehaviorContext::CalculateUpdate(const float deltaTime)
|
||||
|
||||
std::vector<BehaviorSyncEntry> valid;
|
||||
|
||||
for (const auto& entry : this->syncEntries)
|
||||
{
|
||||
if (entry.time <= 0)
|
||||
{
|
||||
for (const auto& entry : this->syncEntries) {
|
||||
if (entry.time <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -293,12 +258,10 @@ bool BehaviorContext::CalculateUpdate(const float deltaTime)
|
||||
return any;
|
||||
}
|
||||
|
||||
void BehaviorContext::Interrupt()
|
||||
{
|
||||
std::vector<BehaviorSyncEntry> keptSync {};
|
||||
void BehaviorContext::Interrupt() {
|
||||
std::vector<BehaviorSyncEntry> keptSync{};
|
||||
|
||||
for (const auto& entry : this->syncEntries)
|
||||
{
|
||||
for (const auto& entry : this->syncEntries) {
|
||||
if (!entry.ignoreInterrupts) continue;
|
||||
|
||||
keptSync.push_back(entry);
|
||||
@@ -307,15 +270,12 @@ void BehaviorContext::Interrupt()
|
||||
this->syncEntries = keptSync;
|
||||
}
|
||||
|
||||
void BehaviorContext::Reset()
|
||||
{
|
||||
for (const auto& entry : this->timerEntries)
|
||||
{
|
||||
void BehaviorContext::Reset() {
|
||||
for (const auto& entry : this->timerEntries) {
|
||||
entry.behavior->Timer(this, entry.branchContext, entry.second);
|
||||
}
|
||||
|
||||
for (const auto& entry : this->endEntries)
|
||||
{
|
||||
for (const auto& entry : this->endEntries) {
|
||||
entry.behavior->End(this, entry.branchContext, entry.second);
|
||||
}
|
||||
|
||||
@@ -325,27 +285,22 @@ void BehaviorContext::Reset()
|
||||
this->scheduledUpdates.clear();
|
||||
}
|
||||
|
||||
std::vector<LWOOBJID> BehaviorContext::GetValidTargets(int32_t ignoreFaction, int32_t includeFaction, bool targetSelf, bool targetEnemy, bool targetFriend) const
|
||||
{
|
||||
std::vector<LWOOBJID> BehaviorContext::GetValidTargets(int32_t ignoreFaction, int32_t includeFaction, bool targetSelf, bool targetEnemy, bool targetFriend) const {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(this->caster);
|
||||
|
||||
std::vector<LWOOBJID> targets;
|
||||
|
||||
if (entity == nullptr)
|
||||
{
|
||||
if (entity == nullptr) {
|
||||
Game::logger->Log("BehaviorContext", "Invalid entity for (%llu)!", this->originator);
|
||||
|
||||
return targets;
|
||||
}
|
||||
|
||||
if (!ignoreFaction && !includeFaction)
|
||||
{
|
||||
for (auto entry : entity->GetTargetsInPhantom())
|
||||
{
|
||||
if (!ignoreFaction && !includeFaction) {
|
||||
for (auto entry : entity->GetTargetsInPhantom()) {
|
||||
auto* instance = EntityManager::Instance()->GetEntity(entry);
|
||||
|
||||
if (instance == nullptr)
|
||||
{
|
||||
if (instance == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -353,21 +308,17 @@ std::vector<LWOOBJID> BehaviorContext::GetValidTargets(int32_t ignoreFaction, in
|
||||
}
|
||||
}
|
||||
|
||||
if (ignoreFaction || includeFaction || (!entity->HasComponent(COMPONENT_TYPE_PHANTOM_PHYSICS) && targets.empty()))
|
||||
{
|
||||
DestroyableComponent* destroyableComponent;
|
||||
if (!entity->TryGetComponent(COMPONENT_TYPE_DESTROYABLE, destroyableComponent))
|
||||
{
|
||||
if (ignoreFaction || includeFaction || (!entity->HasComponent(COMPONENT_TYPE_PHANTOM_PHYSICS) && targets.empty())) {
|
||||
DestroyableComponent* destroyableComponent;
|
||||
if (!entity->TryGetComponent(COMPONENT_TYPE_DESTROYABLE, destroyableComponent)) {
|
||||
return targets;
|
||||
}
|
||||
|
||||
auto entities = EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_CONTROLLABLE_PHYSICS);
|
||||
for (auto* candidate : entities)
|
||||
{
|
||||
for (auto* candidate : entities) {
|
||||
const auto id = candidate->GetObjectID();
|
||||
|
||||
if ((id != entity->GetObjectID() || targetSelf) && destroyableComponent->CheckValidity(id, ignoreFaction || includeFaction, targetEnemy, targetFriend))
|
||||
{
|
||||
if ((id != entity->GetObjectID() || targetSelf) && destroyableComponent->CheckValidity(id, ignoreFaction || includeFaction, targetEnemy, targetFriend)) {
|
||||
targets.push_back(id);
|
||||
}
|
||||
}
|
||||
@@ -377,23 +328,18 @@ std::vector<LWOOBJID> BehaviorContext::GetValidTargets(int32_t ignoreFaction, in
|
||||
}
|
||||
|
||||
|
||||
BehaviorContext::BehaviorContext(const LWOOBJID originator, const bool calculation)
|
||||
{
|
||||
BehaviorContext::BehaviorContext(const LWOOBJID originator, const bool calculation) {
|
||||
this->originator = originator;
|
||||
this->syncEntries = {};
|
||||
this->timerEntries = {};
|
||||
|
||||
if (calculation)
|
||||
{
|
||||
if (calculation) {
|
||||
this->skillUId = GetUniqueSkillId();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
this->skillUId = 0;
|
||||
}
|
||||
}
|
||||
|
||||
BehaviorContext::~BehaviorContext()
|
||||
{
|
||||
BehaviorContext::~BehaviorContext() {
|
||||
Reset();
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@ struct BehaviorSyncEntry
|
||||
float time = 0;
|
||||
|
||||
bool ignoreInterrupts = false;
|
||||
|
||||
|
||||
Behavior* behavior = nullptr;
|
||||
|
||||
BehaviorBranchContext branchContext;
|
||||
@@ -46,7 +46,7 @@ struct BehaviorEndEntry
|
||||
BehaviorBranchContext branchContext;
|
||||
|
||||
LWOOBJID second = LWOOBJID_EMPTY;
|
||||
|
||||
|
||||
BehaviorEndEntry();
|
||||
};
|
||||
|
||||
@@ -65,11 +65,11 @@ struct BehaviorContext
|
||||
bool failed = false;
|
||||
|
||||
bool clientInitalized = false;
|
||||
|
||||
|
||||
std::vector<BehaviorSyncEntry> syncEntries;
|
||||
|
||||
|
||||
std::vector<BehaviorTimerEntry> timerEntries;
|
||||
|
||||
|
||||
std::vector<BehaviorEndEntry> endEntries;
|
||||
|
||||
std::vector<LWOOBJID> scheduledUpdates;
|
||||
@@ -89,15 +89,15 @@ struct BehaviorContext
|
||||
void ScheduleUpdate(LWOOBJID id);
|
||||
|
||||
void ExecuteUpdates();
|
||||
|
||||
|
||||
void SyncBehavior(uint32_t syncId, RakNet::BitStream* bitStream);
|
||||
|
||||
void Update(float deltaTime);
|
||||
|
||||
|
||||
void SyncCalculation(uint32_t syncId, float time, Behavior* behavior, const BehaviorBranchContext& branch, bool ignoreInterrupts = false);
|
||||
|
||||
void InvokeEnd(uint32_t id);
|
||||
|
||||
|
||||
bool CalculateUpdate(float deltaTime);
|
||||
|
||||
void Interrupt();
|
||||
@@ -105,7 +105,7 @@ struct BehaviorContext
|
||||
void Reset();
|
||||
|
||||
std::vector<LWOOBJID> GetValidTargets(int32_t ignoreFaction = 0, int32_t includeFaction = 0, const bool targetSelf = false, const bool targetEnemy = true, const bool targetFriend = false) const;
|
||||
|
||||
|
||||
explicit BehaviorContext(LWOOBJID originator, bool calculation = false);
|
||||
|
||||
~BehaviorContext();
|
||||
|
@@ -67,4 +67,4 @@ enum class BehaviorTemplates : unsigned int {
|
||||
BEHAVIOR_TAKE_PICTURE,
|
||||
BEHAVIOR_MOUNT,
|
||||
BEHAVIOR_SKILL_SET
|
||||
};
|
||||
};
|
||||
|
@@ -7,14 +7,12 @@
|
||||
#include "dLogger.h"
|
||||
#include "DestroyableComponent.h"
|
||||
|
||||
void BlockBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void BlockBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
const auto target = context->originator;
|
||||
|
||||
auto* entity = EntityManager::Instance()->GetEntity(target);
|
||||
|
||||
if (entity == nullptr)
|
||||
{
|
||||
if (entity == nullptr) {
|
||||
Game::logger->Log("DamageAbsorptionBehavior", "Failed to find target (%llu)!", branch.target);
|
||||
|
||||
return;
|
||||
@@ -22,36 +20,29 @@ void BlockBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStrea
|
||||
|
||||
auto* destroyableComponent = entity->GetComponent<DestroyableComponent>();
|
||||
|
||||
if (destroyableComponent == nullptr)
|
||||
{
|
||||
if (destroyableComponent == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
destroyableComponent->SetAttacksToBlock(this->m_numAttacksCanBlock);
|
||||
|
||||
if (branch.start > 0)
|
||||
{
|
||||
if (branch.start > 0) {
|
||||
context->RegisterEndBehavior(this, branch);
|
||||
}
|
||||
else if (branch.duration > 0)
|
||||
{
|
||||
} else if (branch.duration > 0) {
|
||||
context->RegisterTimerBehavior(this, branch);
|
||||
}
|
||||
}
|
||||
|
||||
void BlockBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void BlockBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
Handle(context, bitStream, branch);
|
||||
}
|
||||
|
||||
void BlockBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch)
|
||||
{
|
||||
void BlockBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch) {
|
||||
const auto target = context->originator;
|
||||
|
||||
auto* entity = EntityManager::Instance()->GetEntity(target);
|
||||
|
||||
if (entity == nullptr)
|
||||
{
|
||||
if (entity == nullptr) {
|
||||
Game::logger->Log("DamageAbsorptionBehavior", "Failed to find target (%llu)!", branch.target);
|
||||
|
||||
return;
|
||||
@@ -61,25 +52,21 @@ void BlockBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branc
|
||||
|
||||
destroyableComponent->SetAttacksToBlock(this->m_numAttacksCanBlock);
|
||||
|
||||
if (destroyableComponent == nullptr)
|
||||
{
|
||||
if (destroyableComponent == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
destroyableComponent->SetAttacksToBlock(0);
|
||||
}
|
||||
|
||||
void BlockBehavior::Timer(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second)
|
||||
{
|
||||
void BlockBehavior::Timer(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) {
|
||||
UnCast(context, branch);
|
||||
}
|
||||
|
||||
void BlockBehavior::End(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second)
|
||||
{
|
||||
void BlockBehavior::End(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) {
|
||||
UnCast(context, branch);
|
||||
}
|
||||
|
||||
void BlockBehavior::Load()
|
||||
{
|
||||
void BlockBehavior::Load() {
|
||||
this->m_numAttacksCanBlock = GetInt("num_attacks_can_block");
|
||||
}
|
||||
|
@@ -5,13 +5,12 @@ class BlockBehavior final : public Behavior
|
||||
{
|
||||
public:
|
||||
int32_t m_numAttacksCanBlock;
|
||||
|
||||
|
||||
/*
|
||||
* Inherited
|
||||
*/
|
||||
|
||||
explicit BlockBehavior(const uint32_t behaviorId) : Behavior(behaviorId)
|
||||
{
|
||||
explicit BlockBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {
|
||||
}
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
@@ -19,10 +18,10 @@ public:
|
||||
void Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
void UnCast(BehaviorContext* context, BehaviorBranchContext branch) override;
|
||||
|
||||
|
||||
void Timer(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) override;
|
||||
|
||||
void End(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) override;
|
||||
|
||||
|
||||
void Load() override;
|
||||
};
|
||||
|
@@ -7,14 +7,12 @@
|
||||
#include "dLogger.h"
|
||||
#include "DestroyableComponent.h"
|
||||
|
||||
void BuffBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void BuffBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
const auto target = branch.target != LWOOBJID_EMPTY ? branch.target : context->originator;
|
||||
|
||||
auto* entity = EntityManager::Instance()->GetEntity(target);
|
||||
|
||||
if (entity == nullptr)
|
||||
{
|
||||
if (entity == nullptr) {
|
||||
Game::logger->Log("BuffBehavior", "Invalid target (%llu)!", target);
|
||||
|
||||
return;
|
||||
@@ -22,8 +20,7 @@ void BuffBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream
|
||||
|
||||
auto* component = entity->GetComponent<DestroyableComponent>();
|
||||
|
||||
if (component == nullptr)
|
||||
{
|
||||
if (component == nullptr) {
|
||||
Game::logger->Log("BuffBehavior", "Invalid target, no destroyable component (%llu)!", target);
|
||||
|
||||
return;
|
||||
@@ -35,27 +32,21 @@ void BuffBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(entity);
|
||||
|
||||
if (!context->unmanaged)
|
||||
{
|
||||
if (branch.duration > 0)
|
||||
{
|
||||
if (!context->unmanaged) {
|
||||
if (branch.duration > 0) {
|
||||
context->RegisterTimerBehavior(this, branch);
|
||||
}
|
||||
else if (branch.start > 0)
|
||||
{
|
||||
} else if (branch.start > 0) {
|
||||
context->RegisterEndBehavior(this, branch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BuffBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch)
|
||||
{
|
||||
void BuffBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch) {
|
||||
const auto target = branch.target != LWOOBJID_EMPTY ? branch.target : context->originator;
|
||||
|
||||
auto* entity = EntityManager::Instance()->GetEntity(target);
|
||||
|
||||
if (entity == nullptr)
|
||||
{
|
||||
if (entity == nullptr) {
|
||||
Game::logger->Log("BuffBehavior", "Invalid target (%llu)!", target);
|
||||
|
||||
return;
|
||||
@@ -63,8 +54,7 @@ void BuffBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch
|
||||
|
||||
auto* component = entity->GetComponent<DestroyableComponent>();
|
||||
|
||||
if (component == nullptr)
|
||||
{
|
||||
if (component == nullptr) {
|
||||
Game::logger->Log("BuffBehavior", "Invalid target, no destroyable component (%llu)!", target);
|
||||
|
||||
return;
|
||||
@@ -77,18 +67,15 @@ void BuffBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch
|
||||
EntityManager::Instance()->SerializeEntity(entity);
|
||||
}
|
||||
|
||||
void BuffBehavior::Timer(BehaviorContext* context, const BehaviorBranchContext branch, LWOOBJID second)
|
||||
{
|
||||
void BuffBehavior::Timer(BehaviorContext* context, const BehaviorBranchContext branch, LWOOBJID second) {
|
||||
UnCast(context, branch);
|
||||
}
|
||||
|
||||
void BuffBehavior::End(BehaviorContext* context, const BehaviorBranchContext branch, LWOOBJID second)
|
||||
{
|
||||
void BuffBehavior::End(BehaviorContext* context, const BehaviorBranchContext branch, LWOOBJID second) {
|
||||
UnCast(context, branch);
|
||||
}
|
||||
|
||||
void BuffBehavior::Load()
|
||||
{
|
||||
void BuffBehavior::Load() {
|
||||
this->m_health = GetInt("life");
|
||||
|
||||
this->m_armor = GetInt("armor");
|
||||
|
@@ -9,12 +9,11 @@ public:
|
||||
uint32_t m_armor;
|
||||
|
||||
uint32_t m_imagination;
|
||||
|
||||
|
||||
/*
|
||||
* Inherited
|
||||
*/
|
||||
explicit BuffBehavior(const uint32_t behaviorId) : Behavior(behaviorId)
|
||||
{
|
||||
explicit BuffBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {
|
||||
}
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
@@ -24,6 +23,6 @@ public:
|
||||
void Timer(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) override;
|
||||
|
||||
void End(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) override;
|
||||
|
||||
|
||||
void Load() override;
|
||||
};
|
||||
|
@@ -8,44 +8,41 @@
|
||||
#include "dLogger.h"
|
||||
#include "PossessableComponent.h"
|
||||
|
||||
void CarBoostBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
GameMessages::SendVehicleAddPassiveBoostAction(branch.target, UNASSIGNED_SYSTEM_ADDRESS);
|
||||
void CarBoostBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
GameMessages::SendVehicleAddPassiveBoostAction(branch.target, UNASSIGNED_SYSTEM_ADDRESS);
|
||||
|
||||
auto* entity = EntityManager::Instance()->GetEntity(context->originator);
|
||||
auto* entity = EntityManager::Instance()->GetEntity(context->originator);
|
||||
|
||||
if (entity == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (entity == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
Game::logger->Log("Car boost", "Activating car boost!");
|
||||
Game::logger->Log("Car boost", "Activating car boost!");
|
||||
|
||||
auto* possessableComponent = entity->GetComponent<PossessableComponent>();
|
||||
if (possessableComponent != nullptr) {
|
||||
auto* possessableComponent = entity->GetComponent<PossessableComponent>();
|
||||
if (possessableComponent != nullptr) {
|
||||
|
||||
auto* possessor = EntityManager::Instance()->GetEntity(possessableComponent->GetPossessor());
|
||||
if (possessor != nullptr) {
|
||||
auto* possessor = EntityManager::Instance()->GetEntity(possessableComponent->GetPossessor());
|
||||
if (possessor != nullptr) {
|
||||
|
||||
auto* characterComponent = possessor->GetComponent<CharacterComponent>();
|
||||
if (characterComponent != nullptr) {
|
||||
Game::logger->Log("Car boost", "Tracking car boost!");
|
||||
characterComponent->UpdatePlayerStatistic(RacingCarBoostsActivated);
|
||||
}
|
||||
}
|
||||
}
|
||||
auto* characterComponent = possessor->GetComponent<CharacterComponent>();
|
||||
if (characterComponent != nullptr) {
|
||||
Game::logger->Log("Car boost", "Tracking car boost!");
|
||||
characterComponent->UpdatePlayerStatistic(RacingCarBoostsActivated);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
m_Action->Handle(context, bitStream, branch);
|
||||
m_Action->Handle(context, bitStream, branch);
|
||||
|
||||
entity->AddCallbackTimer(m_Time, [entity] () {
|
||||
GameMessages::SendVehicleRemovePassiveBoostAction(entity->GetObjectID(), UNASSIGNED_SYSTEM_ADDRESS);
|
||||
});
|
||||
entity->AddCallbackTimer(m_Time, [entity]() {
|
||||
GameMessages::SendVehicleRemovePassiveBoostAction(entity->GetObjectID(), UNASSIGNED_SYSTEM_ADDRESS);
|
||||
});
|
||||
}
|
||||
|
||||
void CarBoostBehavior::Load()
|
||||
{
|
||||
m_Action = GetAction("action");
|
||||
void CarBoostBehavior::Load() {
|
||||
m_Action = GetAction("action");
|
||||
|
||||
m_Time = GetFloat("time");
|
||||
m_Time = GetFloat("time");
|
||||
}
|
||||
|
@@ -14,10 +14,9 @@ public:
|
||||
* Inherited
|
||||
*/
|
||||
|
||||
explicit CarBoostBehavior(const uint32_t behaviorId) : Behavior(behaviorId)
|
||||
{
|
||||
explicit CarBoostBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {
|
||||
}
|
||||
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
void Load() override;
|
||||
|
@@ -3,35 +3,29 @@
|
||||
#include "Game.h"
|
||||
#include "dLogger.h"
|
||||
|
||||
void ChainBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch)
|
||||
{
|
||||
void ChainBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
|
||||
uint32_t chain_index;
|
||||
|
||||
bitStream->Read(chain_index);
|
||||
|
||||
chain_index--;
|
||||
|
||||
if (chain_index < this->m_behaviors.size())
|
||||
{
|
||||
if (chain_index < this->m_behaviors.size()) {
|
||||
this->m_behaviors.at(chain_index)->Handle(context, bitStream, branch);
|
||||
}
|
||||
}
|
||||
|
||||
void ChainBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch)
|
||||
{
|
||||
void ChainBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
|
||||
bitStream->Write(1);
|
||||
|
||||
this->m_behaviors.at(0)->Calculate(context, bitStream, branch);
|
||||
}
|
||||
|
||||
void ChainBehavior::Load()
|
||||
{
|
||||
void ChainBehavior::Load() {
|
||||
const auto parameters = GetParameterNames();
|
||||
|
||||
for (const auto& parameter : parameters)
|
||||
{
|
||||
if (parameter.first.rfind("behavior", 0) == 0)
|
||||
{
|
||||
for (const auto& parameter : parameters) {
|
||||
if (parameter.first.rfind("behavior", 0) == 0) {
|
||||
auto* action = GetAction(parameter.second);
|
||||
|
||||
this->m_behaviors.push_back(action);
|
||||
|
@@ -13,10 +13,9 @@ public:
|
||||
* Inherited
|
||||
*/
|
||||
|
||||
explicit ChainBehavior(const uint32_t behaviorId) : Behavior(behaviorId)
|
||||
{
|
||||
explicit ChainBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {
|
||||
}
|
||||
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
void Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
@@ -4,47 +4,41 @@
|
||||
#include "EntityManager.h"
|
||||
#include "BaseCombatAIComponent.h"
|
||||
|
||||
void ChangeOrientationBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void ChangeOrientationBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
}
|
||||
|
||||
void ChangeOrientationBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
if (!m_ToTarget) return; // TODO: Add the other arguments to this behavior
|
||||
void ChangeOrientationBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
if (!m_ToTarget) return; // TODO: Add the other arguments to this behavior
|
||||
|
||||
auto* self = EntityManager::Instance()->GetEntity(context->originator);
|
||||
auto* other = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* self = EntityManager::Instance()->GetEntity(context->originator);
|
||||
auto* other = EntityManager::Instance()->GetEntity(branch.target);
|
||||
|
||||
if (self == nullptr || other == nullptr) return;
|
||||
if (self == nullptr || other == nullptr) return;
|
||||
|
||||
const auto source = self->GetPosition();
|
||||
const auto destination = self->GetPosition();
|
||||
const auto source = self->GetPosition();
|
||||
const auto destination = self->GetPosition();
|
||||
|
||||
if (m_OrientCaster)
|
||||
{
|
||||
auto* baseCombatAIComponent = self->GetComponent<BaseCombatAIComponent>();
|
||||
if (m_OrientCaster) {
|
||||
auto* baseCombatAIComponent = self->GetComponent<BaseCombatAIComponent>();
|
||||
|
||||
/*if (baseCombatAIComponent != nullptr)
|
||||
{
|
||||
baseCombatAIComponent->LookAt(destination);
|
||||
}
|
||||
else*/
|
||||
{
|
||||
self->SetRotation(NiQuaternion::LookAt(source, destination));
|
||||
}
|
||||
/*if (baseCombatAIComponent != nullptr)
|
||||
{
|
||||
baseCombatAIComponent->LookAt(destination);
|
||||
}
|
||||
else*/
|
||||
{
|
||||
self->SetRotation(NiQuaternion::LookAt(source, destination));
|
||||
}
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(self);
|
||||
}
|
||||
else
|
||||
{
|
||||
other->SetRotation(NiQuaternion::LookAt(destination, source));
|
||||
EntityManager::Instance()->SerializeEntity(self);
|
||||
} else {
|
||||
other->SetRotation(NiQuaternion::LookAt(destination, source));
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(other);
|
||||
}
|
||||
EntityManager::Instance()->SerializeEntity(other);
|
||||
}
|
||||
}
|
||||
|
||||
void ChangeOrientationBehavior::Load()
|
||||
{
|
||||
m_OrientCaster = GetBoolean("orient_caster");
|
||||
m_ToTarget = GetBoolean("to_target");
|
||||
void ChangeOrientationBehavior::Load() {
|
||||
m_OrientCaster = GetBoolean("orient_caster");
|
||||
m_ToTarget = GetBoolean("to_target");
|
||||
}
|
||||
|
@@ -7,17 +7,16 @@
|
||||
class ChangeOrientationBehavior final : public Behavior
|
||||
{
|
||||
public:
|
||||
bool m_OrientCaster;
|
||||
bool m_ToTarget;
|
||||
bool m_OrientCaster;
|
||||
bool m_ToTarget;
|
||||
|
||||
/*
|
||||
* Inherited
|
||||
*/
|
||||
|
||||
explicit ChangeOrientationBehavior(const uint32_t behaviorId) : Behavior(behaviorId)
|
||||
{
|
||||
explicit ChangeOrientationBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {
|
||||
}
|
||||
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
void Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
@@ -3,8 +3,7 @@
|
||||
#include "BehaviorContext.h"
|
||||
#include "dLogger.h"
|
||||
|
||||
void ChargeUpBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch)
|
||||
{
|
||||
void ChargeUpBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
|
||||
uint32_t handle;
|
||||
|
||||
bitStream->Read(handle);
|
||||
@@ -12,16 +11,13 @@ void ChargeUpBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitSt
|
||||
context->RegisterSyncBehavior(handle, this, branch);
|
||||
}
|
||||
|
||||
void ChargeUpBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void ChargeUpBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
}
|
||||
|
||||
void ChargeUpBehavior::Sync(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch)
|
||||
{
|
||||
void ChargeUpBehavior::Sync(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
|
||||
this->m_action->Handle(context, bitStream, branch);
|
||||
}
|
||||
|
||||
void ChargeUpBehavior::Load()
|
||||
{
|
||||
void ChargeUpBehavior::Load() {
|
||||
this->m_action = GetAction("action");
|
||||
}
|
||||
|
@@ -5,13 +5,12 @@ class ChargeUpBehavior final : public Behavior
|
||||
{
|
||||
public:
|
||||
Behavior* m_action;
|
||||
|
||||
|
||||
/*
|
||||
* Inherited
|
||||
*/
|
||||
|
||||
explicit ChargeUpBehavior(const uint32_t behaviorId) : Behavior(behaviorId)
|
||||
{
|
||||
explicit ChargeUpBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {
|
||||
}
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
@@ -19,6 +18,6 @@ public:
|
||||
void Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
void Sync(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
|
||||
void Load() override;
|
||||
};
|
||||
|
@@ -3,23 +3,20 @@
|
||||
#include "BehaviorContext.h"
|
||||
|
||||
|
||||
void ClearTargetBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void ClearTargetBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
branch.target = LWOOBJID_EMPTY;
|
||||
|
||||
this->m_action->Handle(context, bitStream, branch);
|
||||
}
|
||||
|
||||
void ClearTargetBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void ClearTargetBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
branch.target = LWOOBJID_EMPTY;
|
||||
|
||||
this->m_action->Calculate(context, bitStream, branch);
|
||||
}
|
||||
|
||||
void ClearTargetBehavior::Load()
|
||||
{
|
||||
void ClearTargetBehavior::Load() {
|
||||
this->m_action = GetAction("action");
|
||||
|
||||
|
||||
this->m_clearIfCaster = GetBoolean("clear_if_caster");
|
||||
}
|
||||
|
@@ -7,12 +7,11 @@ public:
|
||||
Behavior* m_action;
|
||||
|
||||
bool m_clearIfCaster;
|
||||
|
||||
|
||||
/*
|
||||
* Inherited
|
||||
*/
|
||||
explicit ClearTargetBehavior(const uint32_t behaviorId) : Behavior(behaviorId)
|
||||
{
|
||||
explicit ClearTargetBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {
|
||||
}
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
@@ -7,12 +7,10 @@
|
||||
#include "dLogger.h"
|
||||
#include "DestroyableComponent.h"
|
||||
|
||||
void DamageAbsorptionBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch)
|
||||
{
|
||||
void DamageAbsorptionBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
|
||||
if (target == nullptr)
|
||||
{
|
||||
if (target == nullptr) {
|
||||
Game::logger->Log("DamageAbsorptionBehavior", "Failed to find target (%llu)!", branch.target);
|
||||
|
||||
return;
|
||||
@@ -20,8 +18,7 @@ void DamageAbsorptionBehavior::Handle(BehaviorContext* context, RakNet::BitStrea
|
||||
|
||||
auto* destroyable = target->GetComponent<DestroyableComponent>();
|
||||
|
||||
if (destroyable == nullptr)
|
||||
{
|
||||
if (destroyable == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -32,17 +29,14 @@ void DamageAbsorptionBehavior::Handle(BehaviorContext* context, RakNet::BitStrea
|
||||
context->RegisterTimerBehavior(this, branch, target->GetObjectID());
|
||||
}
|
||||
|
||||
void DamageAbsorptionBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void DamageAbsorptionBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
Handle(context, bitStream, branch);
|
||||
}
|
||||
|
||||
void DamageAbsorptionBehavior::Timer(BehaviorContext* context, BehaviorBranchContext branch, const LWOOBJID second)
|
||||
{
|
||||
void DamageAbsorptionBehavior::Timer(BehaviorContext* context, BehaviorBranchContext branch, const LWOOBJID second) {
|
||||
auto* target = EntityManager::Instance()->GetEntity(second);
|
||||
|
||||
if (target == nullptr)
|
||||
{
|
||||
if (target == nullptr) {
|
||||
Game::logger->Log("DamageAbsorptionBehavior", "Failed to find target (%llu)!", second);
|
||||
|
||||
return;
|
||||
@@ -50,8 +44,7 @@ void DamageAbsorptionBehavior::Timer(BehaviorContext* context, BehaviorBranchCon
|
||||
|
||||
auto* destroyable = target->GetComponent<DestroyableComponent>();
|
||||
|
||||
if (destroyable == nullptr)
|
||||
{
|
||||
if (destroyable == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -62,7 +55,6 @@ void DamageAbsorptionBehavior::Timer(BehaviorContext* context, BehaviorBranchCon
|
||||
destroyable->SetDamageToAbsorb(present - toRemove);
|
||||
}
|
||||
|
||||
void DamageAbsorptionBehavior::Load()
|
||||
{
|
||||
void DamageAbsorptionBehavior::Load() {
|
||||
this->m_absorbAmount = GetInt("absorb_amount");
|
||||
}
|
||||
|
@@ -5,13 +5,12 @@ class DamageAbsorptionBehavior final : public Behavior
|
||||
{
|
||||
public:
|
||||
uint32_t m_absorbAmount;
|
||||
|
||||
|
||||
/*
|
||||
* Inherited
|
||||
*/
|
||||
|
||||
explicit DamageAbsorptionBehavior(const uint32_t behaviorId) : Behavior(behaviorId)
|
||||
{
|
||||
explicit DamageAbsorptionBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {
|
||||
}
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
@@ -7,12 +7,10 @@
|
||||
#include "dLogger.h"
|
||||
#include "DestroyableComponent.h"
|
||||
|
||||
void DamageReductionBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch)
|
||||
{
|
||||
void DamageReductionBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
|
||||
if (target == nullptr)
|
||||
{
|
||||
if (target == nullptr) {
|
||||
Game::logger->Log("DamageReductionBehavior", "Failed to find target (%llu)!", branch.target);
|
||||
|
||||
return;
|
||||
@@ -20,8 +18,7 @@ void DamageReductionBehavior::Handle(BehaviorContext* context, RakNet::BitStream
|
||||
|
||||
auto* destroyable = target->GetComponent<DestroyableComponent>();
|
||||
|
||||
if (destroyable == nullptr)
|
||||
{
|
||||
if (destroyable == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -30,17 +27,14 @@ void DamageReductionBehavior::Handle(BehaviorContext* context, RakNet::BitStream
|
||||
context->RegisterTimerBehavior(this, branch, target->GetObjectID());
|
||||
}
|
||||
|
||||
void DamageReductionBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void DamageReductionBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
Handle(context, bitStream, branch);
|
||||
}
|
||||
|
||||
void DamageReductionBehavior::Timer(BehaviorContext* context, BehaviorBranchContext branch, const LWOOBJID second)
|
||||
{
|
||||
void DamageReductionBehavior::Timer(BehaviorContext* context, BehaviorBranchContext branch, const LWOOBJID second) {
|
||||
auto* target = EntityManager::Instance()->GetEntity(second);
|
||||
|
||||
if (target == nullptr)
|
||||
{
|
||||
if (target == nullptr) {
|
||||
Game::logger->Log("DamageReductionBehavior", "Failed to find target (%llu)!", second);
|
||||
|
||||
return;
|
||||
@@ -48,15 +42,13 @@ void DamageReductionBehavior::Timer(BehaviorContext* context, BehaviorBranchCont
|
||||
|
||||
auto* destroyable = target->GetComponent<DestroyableComponent>();
|
||||
|
||||
if (destroyable == nullptr)
|
||||
{
|
||||
if (destroyable == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
destroyable->SetDamageReduction(0);
|
||||
}
|
||||
|
||||
void DamageReductionBehavior::Load()
|
||||
{
|
||||
void DamageReductionBehavior::Load() {
|
||||
this->m_ReductionAmount = GetInt("reduction_amount");
|
||||
}
|
||||
|
@@ -5,13 +5,12 @@ class DamageReductionBehavior final : public Behavior
|
||||
{
|
||||
public:
|
||||
uint32_t m_ReductionAmount;
|
||||
|
||||
|
||||
/*
|
||||
* Inherited
|
||||
*/
|
||||
|
||||
explicit DamageReductionBehavior(const uint32_t behaviorId) : Behavior(behaviorId)
|
||||
{
|
||||
explicit DamageReductionBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {
|
||||
}
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
@@ -2,22 +2,19 @@
|
||||
#include "BehaviorBranchContext.h"
|
||||
#include "BehaviorContext.h"
|
||||
|
||||
void DurationBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void DurationBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
branch.duration = this->m_duration;
|
||||
|
||||
this->m_action->Handle(context, bitStream, branch);
|
||||
}
|
||||
|
||||
void DurationBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void DurationBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
branch.duration = this->m_duration;
|
||||
|
||||
this->m_action->Calculate(context, bitStream, branch);
|
||||
}
|
||||
|
||||
void DurationBehavior::Load()
|
||||
{
|
||||
void DurationBehavior::Load() {
|
||||
this->m_duration = GetFloat("duration");
|
||||
|
||||
this->m_action = GetAction("action");
|
||||
|
@@ -7,11 +7,10 @@ public:
|
||||
float m_duration;
|
||||
|
||||
Behavior* m_action;
|
||||
|
||||
explicit DurationBehavior(const uint32_t behavior_id) : Behavior(behavior_id)
|
||||
{
|
||||
|
||||
explicit DurationBehavior(const uint32_t behavior_id) : Behavior(behavior_id) {
|
||||
}
|
||||
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
void Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
@@ -5,7 +5,6 @@
|
||||
class EmptyBehavior final : public Behavior
|
||||
{
|
||||
public:
|
||||
explicit EmptyBehavior(const uint32_t behavior_id) : Behavior(behavior_id)
|
||||
{
|
||||
explicit EmptyBehavior(const uint32_t behavior_id) : Behavior(behavior_id) {
|
||||
}
|
||||
};
|
||||
|
@@ -3,17 +3,14 @@
|
||||
#include "BehaviorContext.h"
|
||||
#include "BehaviorBranchContext.h"
|
||||
|
||||
void EndBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void EndBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
context->InvokeEnd(this->m_startBehavior);
|
||||
}
|
||||
|
||||
void EndBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void EndBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
context->InvokeEnd(this->m_startBehavior);
|
||||
}
|
||||
|
||||
void EndBehavior::Load()
|
||||
{
|
||||
void EndBehavior::Load() {
|
||||
this->m_startBehavior = GetInt("start_action");
|
||||
}
|
||||
|
@@ -5,17 +5,16 @@ class EndBehavior final : public Behavior
|
||||
{
|
||||
public:
|
||||
uint32_t m_startBehavior;
|
||||
|
||||
|
||||
/*
|
||||
* Inherited
|
||||
*/
|
||||
|
||||
explicit EndBehavior(const uint32_t behaviorId) : Behavior(behaviorId)
|
||||
{
|
||||
explicit EndBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {
|
||||
}
|
||||
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
|
||||
void Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
void Load() override;
|
||||
|
@@ -5,77 +5,75 @@
|
||||
#include "EntityManager.h"
|
||||
|
||||
void ForceMovementBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
|
||||
if (this->m_hitAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_hitEnemyAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_hitFactionAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY) {
|
||||
return;
|
||||
}
|
||||
if (this->m_hitAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_hitEnemyAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_hitFactionAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t handle;
|
||||
bitStream->Read(handle);
|
||||
context->RegisterSyncBehavior(handle, this, branch);
|
||||
uint32_t handle;
|
||||
bitStream->Read(handle);
|
||||
context->RegisterSyncBehavior(handle, this, branch);
|
||||
}
|
||||
|
||||
void ForceMovementBehavior::Sync(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
uint32_t next;
|
||||
bitStream->Read(next);
|
||||
void ForceMovementBehavior::Sync(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
uint32_t next;
|
||||
bitStream->Read(next);
|
||||
|
||||
LWOOBJID target;
|
||||
bitStream->Read(target);
|
||||
LWOOBJID target;
|
||||
bitStream->Read(target);
|
||||
|
||||
branch.target = target;
|
||||
auto* behavior = CreateBehavior(next);
|
||||
behavior->Handle(context, bitStream, branch);
|
||||
branch.target = target;
|
||||
auto* behavior = CreateBehavior(next);
|
||||
behavior->Handle(context, bitStream, branch);
|
||||
}
|
||||
|
||||
void ForceMovementBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
if (this->m_hitAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_hitEnemyAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_hitFactionAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY) {
|
||||
return;
|
||||
}
|
||||
if (this->m_hitAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_hitEnemyAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_hitFactionAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto* casterEntity = EntityManager::Instance()->GetEntity(context->caster);
|
||||
if (casterEntity != nullptr) {
|
||||
auto* controllablePhysicsComponent = casterEntity->GetComponent<ControllablePhysicsComponent>();
|
||||
if (controllablePhysicsComponent != nullptr) {
|
||||
auto* casterEntity = EntityManager::Instance()->GetEntity(context->caster);
|
||||
if (casterEntity != nullptr) {
|
||||
auto* controllablePhysicsComponent = casterEntity->GetComponent<ControllablePhysicsComponent>();
|
||||
if (controllablePhysicsComponent != nullptr) {
|
||||
|
||||
if (m_Forward == 1) {
|
||||
controllablePhysicsComponent->SetVelocity(controllablePhysicsComponent->GetRotation().GetForwardVector() * 25);
|
||||
}
|
||||
if (m_Forward == 1) {
|
||||
controllablePhysicsComponent->SetVelocity(controllablePhysicsComponent->GetRotation().GetForwardVector() * 25);
|
||||
}
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(casterEntity);
|
||||
}
|
||||
}
|
||||
EntityManager::Instance()->SerializeEntity(casterEntity);
|
||||
}
|
||||
}
|
||||
|
||||
const auto skillHandle = context->GetUniqueSkillId();
|
||||
bitStream->Write(skillHandle);
|
||||
const auto skillHandle = context->GetUniqueSkillId();
|
||||
bitStream->Write(skillHandle);
|
||||
|
||||
context->SyncCalculation(skillHandle, this->m_Duration, this, branch);
|
||||
context->SyncCalculation(skillHandle, this->m_Duration, this, branch);
|
||||
}
|
||||
|
||||
void ForceMovementBehavior::Load()
|
||||
{
|
||||
this->m_hitAction = GetAction("hit_action");
|
||||
this->m_hitEnemyAction = GetAction("hit_action_enemy");
|
||||
this->m_hitFactionAction = GetAction("hit_action_faction");
|
||||
this->m_Duration = GetFloat("duration");
|
||||
this->m_Forward = GetFloat("forward");
|
||||
this->m_Left = GetFloat("left");
|
||||
this->m_Yaw = GetFloat("yaw");
|
||||
void ForceMovementBehavior::Load() {
|
||||
this->m_hitAction = GetAction("hit_action");
|
||||
this->m_hitEnemyAction = GetAction("hit_action_enemy");
|
||||
this->m_hitFactionAction = GetAction("hit_action_faction");
|
||||
this->m_Duration = GetFloat("duration");
|
||||
this->m_Forward = GetFloat("forward");
|
||||
this->m_Left = GetFloat("left");
|
||||
this->m_Yaw = GetFloat("yaw");
|
||||
}
|
||||
|
||||
void ForceMovementBehavior::SyncCalculation(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
auto* casterEntity = EntityManager::Instance()->GetEntity(context->caster);
|
||||
if (casterEntity != nullptr) {
|
||||
auto* controllablePhysicsComponent = casterEntity->GetComponent<ControllablePhysicsComponent>();
|
||||
if (controllablePhysicsComponent != nullptr) {
|
||||
auto* casterEntity = EntityManager::Instance()->GetEntity(context->caster);
|
||||
if (casterEntity != nullptr) {
|
||||
auto* controllablePhysicsComponent = casterEntity->GetComponent<ControllablePhysicsComponent>();
|
||||
if (controllablePhysicsComponent != nullptr) {
|
||||
|
||||
controllablePhysicsComponent->SetPosition(controllablePhysicsComponent->GetPosition() + controllablePhysicsComponent->GetVelocity() * m_Duration);
|
||||
controllablePhysicsComponent->SetVelocity({});
|
||||
controllablePhysicsComponent->SetPosition(controllablePhysicsComponent->GetPosition() + controllablePhysicsComponent->GetVelocity() * m_Duration);
|
||||
controllablePhysicsComponent->SetVelocity({});
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(casterEntity);
|
||||
}
|
||||
}
|
||||
EntityManager::Instance()->SerializeEntity(casterEntity);
|
||||
}
|
||||
}
|
||||
|
||||
this->m_hitAction->Calculate(context, bitStream, branch);
|
||||
this->m_hitEnemyAction->Calculate(context, bitStream, branch);
|
||||
this->m_hitEnemyAction->Calculate(context, bitStream, branch);
|
||||
this->m_hitAction->Calculate(context, bitStream, branch);
|
||||
this->m_hitEnemyAction->Calculate(context, bitStream, branch);
|
||||
this->m_hitEnemyAction->Calculate(context, bitStream, branch);
|
||||
}
|
||||
|
@@ -10,27 +10,26 @@ public:
|
||||
|
||||
Behavior* m_hitFactionAction;
|
||||
|
||||
float_t m_Duration;
|
||||
float_t m_Forward;
|
||||
float_t m_Left;
|
||||
float_t m_Yaw;
|
||||
|
||||
float_t m_Duration;
|
||||
float_t m_Forward;
|
||||
float_t m_Left;
|
||||
float_t m_Yaw;
|
||||
|
||||
/*
|
||||
* Inherited
|
||||
*/
|
||||
|
||||
explicit ForceMovementBehavior(const uint32_t behaviorId) : Behavior(behaviorId)
|
||||
{
|
||||
explicit ForceMovementBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {
|
||||
}
|
||||
|
||||
void Calculate(BehaviorContext *context, RakNet::BitStream *bitStream, BehaviorBranchContext branch) override;
|
||||
void Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
void SyncCalculation(BehaviorContext *context, RakNet::BitStream *bitStream, BehaviorBranchContext branch) override;
|
||||
void SyncCalculation(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
void Sync(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
|
||||
void Load() override;
|
||||
|
||||
|
||||
};
|
||||
|
@@ -6,12 +6,10 @@
|
||||
#include "DestroyableComponent.h"
|
||||
|
||||
|
||||
void HealBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bit_stream, const BehaviorBranchContext branch)
|
||||
{
|
||||
void HealBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bit_stream, const BehaviorBranchContext branch) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(branch.target);
|
||||
|
||||
if (entity == nullptr)
|
||||
{
|
||||
if (entity == nullptr) {
|
||||
Game::logger->Log("HealBehavior", "Failed to find entity for (%llu)!", branch.target);
|
||||
|
||||
return;
|
||||
@@ -19,8 +17,7 @@ void HealBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bit_strea
|
||||
|
||||
auto* destroyable = static_cast<DestroyableComponent*>(entity->GetComponent(COMPONENT_TYPE_DESTROYABLE));
|
||||
|
||||
if (destroyable == nullptr)
|
||||
{
|
||||
if (destroyable == nullptr) {
|
||||
Game::logger->Log("HealBehavior", "Failed to find destroyable component for %(llu)!", branch.target);
|
||||
|
||||
return;
|
||||
@@ -30,13 +27,11 @@ void HealBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bit_strea
|
||||
}
|
||||
|
||||
|
||||
void HealBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bit_stream, const BehaviorBranchContext branch)
|
||||
{
|
||||
void HealBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bit_stream, const BehaviorBranchContext branch) {
|
||||
Handle(context, bit_stream, branch);
|
||||
}
|
||||
|
||||
|
||||
void HealBehavior::Load()
|
||||
{
|
||||
void HealBehavior::Load() {
|
||||
this->m_health = GetInt("health");
|
||||
}
|
||||
|
@@ -5,13 +5,12 @@ class HealBehavior final : public Behavior
|
||||
{
|
||||
public:
|
||||
uint32_t m_health;
|
||||
|
||||
|
||||
/*
|
||||
* Inherited
|
||||
*/
|
||||
|
||||
explicit HealBehavior(const uint32_t behavior_id) : Behavior(behavior_id)
|
||||
{
|
||||
explicit HealBehavior(const uint32_t behavior_id) : Behavior(behavior_id) {
|
||||
}
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bit_stream, BehaviorBranchContext branch) override;
|
||||
|
@@ -6,19 +6,16 @@
|
||||
#include "dLogger.h"
|
||||
|
||||
|
||||
void ImaginationBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bit_stream, const BehaviorBranchContext branch)
|
||||
{
|
||||
void ImaginationBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bit_stream, const BehaviorBranchContext branch) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(branch.target);
|
||||
|
||||
if (entity == nullptr)
|
||||
{
|
||||
if (entity == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto* destroyable = entity->GetComponent<DestroyableComponent>();
|
||||
|
||||
if (destroyable == nullptr)
|
||||
{
|
||||
if (destroyable == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -26,12 +23,10 @@ void ImaginationBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bi
|
||||
|
||||
}
|
||||
|
||||
void ImaginationBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bit_stream, const BehaviorBranchContext branch)
|
||||
{
|
||||
void ImaginationBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bit_stream, const BehaviorBranchContext branch) {
|
||||
Handle(context, bit_stream, branch);
|
||||
}
|
||||
|
||||
void ImaginationBehavior::Load()
|
||||
{
|
||||
void ImaginationBehavior::Load() {
|
||||
this->m_imagination = GetInt("imagination");
|
||||
}
|
||||
|
@@ -10,8 +10,7 @@ public:
|
||||
* Inherited
|
||||
*/
|
||||
|
||||
explicit ImaginationBehavior(const uint32_t behavior_id) : Behavior(behavior_id)
|
||||
{
|
||||
explicit ImaginationBehavior(const uint32_t behavior_id) : Behavior(behavior_id) {
|
||||
}
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bit_stream, BehaviorBranchContext branch) override;
|
||||
|
@@ -7,12 +7,10 @@
|
||||
#include "dLogger.h"
|
||||
#include "DestroyableComponent.h"
|
||||
|
||||
void ImmunityBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch)
|
||||
{
|
||||
void ImmunityBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
|
||||
if (target == nullptr)
|
||||
{
|
||||
if (target == nullptr) {
|
||||
Game::logger->Log("DamageAbsorptionBehavior", "Failed to find target (%llu)!", branch.target);
|
||||
|
||||
return;
|
||||
@@ -20,13 +18,11 @@ void ImmunityBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitSt
|
||||
|
||||
auto* destroyable = static_cast<DestroyableComponent*>(target->GetComponent(COMPONENT_TYPE_DESTROYABLE));
|
||||
|
||||
if (destroyable == nullptr)
|
||||
{
|
||||
if (destroyable == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->m_immuneBasicAttack)
|
||||
{
|
||||
if (!this->m_immuneBasicAttack) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -35,17 +31,14 @@ void ImmunityBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitSt
|
||||
context->RegisterTimerBehavior(this, branch, target->GetObjectID());
|
||||
}
|
||||
|
||||
void ImmunityBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void ImmunityBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
Handle(context, bitStream, branch);
|
||||
}
|
||||
|
||||
void ImmunityBehavior::Timer(BehaviorContext* context, BehaviorBranchContext branch, const LWOOBJID second)
|
||||
{
|
||||
void ImmunityBehavior::Timer(BehaviorContext* context, BehaviorBranchContext branch, const LWOOBJID second) {
|
||||
auto* target = EntityManager::Instance()->GetEntity(second);
|
||||
|
||||
if (target == nullptr)
|
||||
{
|
||||
if (target == nullptr) {
|
||||
Game::logger->Log("DamageAbsorptionBehavior", "Failed to find target (%llu)!", second);
|
||||
|
||||
return;
|
||||
@@ -53,15 +46,13 @@ void ImmunityBehavior::Timer(BehaviorContext* context, BehaviorBranchContext bra
|
||||
|
||||
auto* destroyable = static_cast<DestroyableComponent*>(target->GetComponent(COMPONENT_TYPE_DESTROYABLE));
|
||||
|
||||
if (destroyable == nullptr)
|
||||
{
|
||||
if (destroyable == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
destroyable->PopImmunity();
|
||||
}
|
||||
|
||||
void ImmunityBehavior::Load()
|
||||
{
|
||||
void ImmunityBehavior::Load() {
|
||||
this->m_immuneBasicAttack = GetBoolean("immune_basic_attack");
|
||||
}
|
||||
|
@@ -5,13 +5,12 @@ class ImmunityBehavior final : public Behavior
|
||||
{
|
||||
public:
|
||||
uint32_t m_immuneBasicAttack;
|
||||
|
||||
|
||||
/*
|
||||
* Inherited
|
||||
*/
|
||||
|
||||
explicit ImmunityBehavior(const uint32_t behaviorId) : Behavior(behaviorId)
|
||||
{
|
||||
explicit ImmunityBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {
|
||||
}
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
@@ -7,10 +7,8 @@
|
||||
#include "SkillComponent.h"
|
||||
|
||||
|
||||
void InterruptBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
if (branch.target != context->originator)
|
||||
{
|
||||
void InterruptBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
if (branch.target != context->originator) {
|
||||
bool unknown = false;
|
||||
|
||||
bitStream->Read(unknown);
|
||||
@@ -18,8 +16,7 @@ void InterruptBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitS
|
||||
if (unknown) return;
|
||||
}
|
||||
|
||||
if (!this->m_interruptBlock)
|
||||
{
|
||||
if (!this->m_interruptBlock) {
|
||||
bool unknown = false;
|
||||
|
||||
bitStream->Read(unknown);
|
||||
@@ -48,15 +45,12 @@ void InterruptBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitS
|
||||
}
|
||||
|
||||
|
||||
void InterruptBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
if (branch.target != context->originator)
|
||||
{
|
||||
void InterruptBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
if (branch.target != context->originator) {
|
||||
bitStream->Write(false);
|
||||
}
|
||||
|
||||
if (!this->m_interruptBlock)
|
||||
{
|
||||
if (!this->m_interruptBlock) {
|
||||
bitStream->Write(false);
|
||||
}
|
||||
|
||||
@@ -71,14 +65,13 @@ void InterruptBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* b
|
||||
auto* skillComponent = target->GetComponent<SkillComponent>();
|
||||
|
||||
if (skillComponent == nullptr) return;
|
||||
|
||||
|
||||
skillComponent->Interrupt();
|
||||
}
|
||||
|
||||
|
||||
void InterruptBehavior::Load()
|
||||
{
|
||||
void InterruptBehavior::Load() {
|
||||
this->m_target = GetBoolean("target");
|
||||
|
||||
|
||||
this->m_interruptBlock = GetBoolean("interrupt_block");
|
||||
}
|
||||
|
@@ -5,20 +5,19 @@ class InterruptBehavior final : public Behavior
|
||||
{
|
||||
public:
|
||||
bool m_target;
|
||||
|
||||
|
||||
bool m_interruptBlock;
|
||||
|
||||
/*
|
||||
* Inherited
|
||||
*/
|
||||
|
||||
explicit InterruptBehavior(const uint32_t behavior_id) : Behavior(behavior_id)
|
||||
{
|
||||
explicit InterruptBehavior(const uint32_t behavior_id) : Behavior(behavior_id) {
|
||||
}
|
||||
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
|
||||
void Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
|
||||
void Load() override;
|
||||
};
|
||||
|
@@ -4,26 +4,26 @@
|
||||
#include "GameMessages.h"
|
||||
|
||||
void JetPackBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bit_stream, const BehaviorBranchContext branch) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(branch.target);
|
||||
|
||||
auto* entity = EntityManager::Instance()->GetEntity(branch.target);
|
||||
|
||||
GameMessages::SendSetJetPackMode(entity, true, this->m_BypassChecks, this->m_EnableHover, this->m_effectId, this->m_Airspeed, this->m_MaxAirspeed, this->m_VerticalVelocity, this->m_WarningEffectID);
|
||||
}
|
||||
|
||||
void JetPackBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* entity = EntityManager::Instance()->GetEntity(branch.target);
|
||||
|
||||
GameMessages::SendSetJetPackMode(entity, false);
|
||||
}
|
||||
|
||||
void JetPackBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bit_stream, const BehaviorBranchContext branch) {
|
||||
Handle(context, bit_stream, branch);
|
||||
Handle(context, bit_stream, branch);
|
||||
}
|
||||
|
||||
void JetPackBehavior::Load() {
|
||||
this->m_WarningEffectID = GetInt("warning_effect_id");
|
||||
this->m_Airspeed = GetFloat("airspeed");
|
||||
this->m_MaxAirspeed = GetFloat("max_airspeed");
|
||||
this->m_VerticalVelocity = GetFloat("vertical_velocity");
|
||||
this->m_EnableHover = GetBoolean("enable_hover");
|
||||
this->m_BypassChecks = GetBoolean("bypass_checks", true);
|
||||
this->m_WarningEffectID = GetInt("warning_effect_id");
|
||||
this->m_Airspeed = GetFloat("airspeed");
|
||||
this->m_MaxAirspeed = GetFloat("max_airspeed");
|
||||
this->m_VerticalVelocity = GetFloat("vertical_velocity");
|
||||
this->m_EnableHover = GetBoolean("enable_hover");
|
||||
this->m_BypassChecks = GetBoolean("bypass_checks", true);
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include "Behavior.h"
|
||||
|
||||
class JetPackBehavior final : public Behavior
|
||||
class JetPackBehavior final : public Behavior
|
||||
{
|
||||
public:
|
||||
int32_t m_WarningEffectID;
|
||||
|
@@ -7,25 +7,21 @@
|
||||
#include "GameMessages.h"
|
||||
#include "DestroyableComponent.h"
|
||||
|
||||
void KnockbackBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void KnockbackBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
bool unknown;
|
||||
|
||||
bitStream->Read(unknown);
|
||||
}
|
||||
|
||||
void KnockbackBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void KnockbackBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
bool blocked = false;
|
||||
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
|
||||
if (target != nullptr)
|
||||
{
|
||||
if (target != nullptr) {
|
||||
auto* destroyableComponent = target->GetComponent<DestroyableComponent>();
|
||||
|
||||
if (destroyableComponent != nullptr)
|
||||
{
|
||||
if (destroyableComponent != nullptr) {
|
||||
blocked = destroyableComponent->IsKnockbackImmune();
|
||||
}
|
||||
}
|
||||
@@ -33,8 +29,7 @@ void KnockbackBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* b
|
||||
bitStream->Write(blocked);
|
||||
}
|
||||
|
||||
void KnockbackBehavior::Load()
|
||||
{
|
||||
void KnockbackBehavior::Load() {
|
||||
this->m_strength = GetInt("strength");
|
||||
this->m_angle = GetInt("angle");
|
||||
this->m_relative = GetBoolean("relative");
|
||||
|
@@ -12,10 +12,9 @@ public:
|
||||
uint32_t m_angle;
|
||||
bool m_relative;
|
||||
uint32_t m_time;
|
||||
|
||||
|
||||
explicit KnockbackBehavior(const uint32_t behaviorID) : Behavior(behaviorID)
|
||||
{
|
||||
|
||||
explicit KnockbackBehavior(const uint32_t behaviorID) : Behavior(behaviorID) {
|
||||
}
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
@@ -1,38 +1,38 @@
|
||||
#include "LootBuffBehavior.h"
|
||||
|
||||
void LootBuffBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
auto target = EntityManager::Instance()->GetEntity(context->caster);
|
||||
if (!target) return;
|
||||
void LootBuffBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
auto target = EntityManager::Instance()->GetEntity(context->caster);
|
||||
if (!target) return;
|
||||
|
||||
auto controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>();
|
||||
if (!controllablePhysicsComponent) return;
|
||||
auto controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>();
|
||||
if (!controllablePhysicsComponent) return;
|
||||
|
||||
controllablePhysicsComponent->AddPickupRadiusScale(m_Scale);
|
||||
EntityManager::Instance()->SerializeEntity(target);
|
||||
controllablePhysicsComponent->AddPickupRadiusScale(m_Scale);
|
||||
EntityManager::Instance()->SerializeEntity(target);
|
||||
|
||||
if (branch.duration > 0) context->RegisterTimerBehavior(this, branch);
|
||||
if (branch.duration > 0) context->RegisterTimerBehavior(this, branch);
|
||||
|
||||
}
|
||||
|
||||
void LootBuffBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
Handle(context, bitStream, branch);
|
||||
Handle(context, bitStream, branch);
|
||||
}
|
||||
|
||||
void LootBuffBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch) {
|
||||
auto target = EntityManager::Instance()->GetEntity(context->caster);
|
||||
if (!target) return;
|
||||
auto target = EntityManager::Instance()->GetEntity(context->caster);
|
||||
if (!target) return;
|
||||
|
||||
auto controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>();
|
||||
if (!controllablePhysicsComponent) return;
|
||||
auto controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>();
|
||||
if (!controllablePhysicsComponent) return;
|
||||
|
||||
controllablePhysicsComponent->RemovePickupRadiusScale(m_Scale);
|
||||
EntityManager::Instance()->SerializeEntity(target);
|
||||
controllablePhysicsComponent->RemovePickupRadiusScale(m_Scale);
|
||||
EntityManager::Instance()->SerializeEntity(target);
|
||||
}
|
||||
|
||||
void LootBuffBehavior::Timer(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) {
|
||||
UnCast(context, branch);
|
||||
UnCast(context, branch);
|
||||
}
|
||||
|
||||
void LootBuffBehavior::Load() {
|
||||
this->m_Scale = GetFloat("scale");
|
||||
}
|
||||
this->m_Scale = GetFloat("scale");
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@
|
||||
|
||||
/**
|
||||
* @brief This is the behavior class to be used for all Loot Buff behavior nodes in the Behavior tree.
|
||||
*
|
||||
*
|
||||
*/
|
||||
class LootBuffBehavior final : public Behavior
|
||||
{
|
||||
@@ -17,13 +17,13 @@ public:
|
||||
/*
|
||||
* Inherited
|
||||
*/
|
||||
|
||||
|
||||
explicit LootBuffBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {}
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
void Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
|
||||
void UnCast(BehaviorContext* context, BehaviorBranchContext branch) override;
|
||||
|
||||
void Timer(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) override;
|
||||
|
@@ -3,15 +3,13 @@
|
||||
#include "Game.h"
|
||||
#include "dLogger.h"
|
||||
|
||||
void MovementSwitchBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch)
|
||||
{
|
||||
void MovementSwitchBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
|
||||
if (this->m_groundAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY &&
|
||||
this->m_jumpAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY &&
|
||||
this->m_fallingAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY &&
|
||||
this->m_doubleJumpAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY &&
|
||||
this->m_airAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY &&
|
||||
this->m_jetpackAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY)
|
||||
{
|
||||
this->m_jetpackAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -19,8 +17,7 @@ void MovementSwitchBehavior::Handle(BehaviorContext* context, RakNet::BitStream*
|
||||
|
||||
bitStream->Read(movementType);
|
||||
|
||||
switch (movementType)
|
||||
{
|
||||
switch (movementType) {
|
||||
case 1:
|
||||
this->m_groundAction->Handle(context, bitStream, branch);
|
||||
break;
|
||||
@@ -45,8 +42,7 @@ void MovementSwitchBehavior::Handle(BehaviorContext* context, RakNet::BitStream*
|
||||
}
|
||||
}
|
||||
|
||||
void MovementSwitchBehavior::Load()
|
||||
{
|
||||
void MovementSwitchBehavior::Load() {
|
||||
this->m_airAction = GetAction("air_action");
|
||||
|
||||
this->m_doubleJumpAction = GetAction("double_jump_action");
|
||||
|
@@ -8,7 +8,7 @@ public:
|
||||
* Members
|
||||
*/
|
||||
Behavior* m_airAction;
|
||||
|
||||
|
||||
Behavior* m_doubleJumpAction;
|
||||
|
||||
Behavior* m_fallingAction;
|
||||
@@ -18,14 +18,13 @@ public:
|
||||
Behavior* m_jetpackAction;
|
||||
|
||||
Behavior* m_jumpAction;
|
||||
|
||||
|
||||
/*
|
||||
* Inherited
|
||||
*/
|
||||
explicit MovementSwitchBehavior(const uint32_t behavior_id) : Behavior(behavior_id)
|
||||
{
|
||||
explicit MovementSwitchBehavior(const uint32_t behavior_id) : Behavior(behavior_id) {
|
||||
}
|
||||
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
void Load() override;
|
||||
|
@@ -3,26 +3,21 @@
|
||||
#include "BehaviorContext.h"
|
||||
|
||||
|
||||
void NpcCombatSkillBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bit_stream, BehaviorBranchContext branch)
|
||||
{
|
||||
void NpcCombatSkillBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bit_stream, BehaviorBranchContext branch) {
|
||||
context->skillTime = this->m_npcSkillTime;
|
||||
|
||||
for (auto* behavior : this->m_behaviors)
|
||||
{
|
||||
|
||||
for (auto* behavior : this->m_behaviors) {
|
||||
behavior->Calculate(context, bit_stream, branch);
|
||||
}
|
||||
}
|
||||
|
||||
void NpcCombatSkillBehavior::Load()
|
||||
{
|
||||
void NpcCombatSkillBehavior::Load() {
|
||||
this->m_npcSkillTime = GetFloat("npc skill time");
|
||||
|
||||
|
||||
const auto parameters = GetParameterNames();
|
||||
|
||||
for (const auto& parameter : parameters)
|
||||
{
|
||||
if (parameter.first.rfind("behavior", 0) == 0)
|
||||
{
|
||||
for (const auto& parameter : parameters) {
|
||||
if (parameter.first.rfind("behavior", 0) == 0) {
|
||||
auto* action = GetAction(parameter.second);
|
||||
|
||||
this->m_behaviors.push_back(action);
|
||||
|
@@ -12,10 +12,9 @@ public:
|
||||
* Inherited
|
||||
*/
|
||||
|
||||
explicit NpcCombatSkillBehavior(const uint32_t behavior_id) : Behavior(behavior_id)
|
||||
{
|
||||
explicit NpcCombatSkillBehavior(const uint32_t behavior_id) : Behavior(behavior_id) {
|
||||
}
|
||||
|
||||
|
||||
void Calculate(BehaviorContext* context, RakNet::BitStream* bit_stream, BehaviorBranchContext branch) override;
|
||||
|
||||
void Load() override;
|
||||
|
@@ -7,43 +7,39 @@
|
||||
#include "SkillComponent.h"
|
||||
#include "DestroyableComponent.h"
|
||||
|
||||
void OverTimeBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
const auto originator = context->originator;
|
||||
void OverTimeBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
const auto originator = context->originator;
|
||||
|
||||
auto* entity = EntityManager::Instance()->GetEntity(originator);
|
||||
auto* entity = EntityManager::Instance()->GetEntity(originator);
|
||||
|
||||
if (entity == nullptr) return;
|
||||
if (entity == nullptr) return;
|
||||
|
||||
for (size_t i = 0; i < m_NumIntervals; i++)
|
||||
{
|
||||
entity->AddCallbackTimer((i + 1) * m_Delay, [originator, branch, this]() {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(originator);
|
||||
for (size_t i = 0; i < m_NumIntervals; i++) {
|
||||
entity->AddCallbackTimer((i + 1) * m_Delay, [originator, branch, this]() {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(originator);
|
||||
|
||||
if (entity == nullptr) return;
|
||||
if (entity == nullptr) return;
|
||||
|
||||
auto* skillComponent = entity->GetComponent<SkillComponent>();
|
||||
auto* skillComponent = entity->GetComponent<SkillComponent>();
|
||||
|
||||
if (skillComponent == nullptr) return;
|
||||
if (skillComponent == nullptr) return;
|
||||
|
||||
skillComponent->CalculateBehavior(m_Action, m_ActionBehaviorId, branch.target, true, true);
|
||||
});
|
||||
}
|
||||
skillComponent->CalculateBehavior(m_Action, m_ActionBehaviorId, branch.target, true, true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void OverTimeBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
|
||||
void OverTimeBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
|
||||
}
|
||||
|
||||
void OverTimeBehavior::Load()
|
||||
{
|
||||
m_Action = GetInt("action");
|
||||
// Since m_Action is a skillID and not a behavior, get is correlated behaviorID.
|
||||
void OverTimeBehavior::Load() {
|
||||
m_Action = GetInt("action");
|
||||
// Since m_Action is a skillID and not a behavior, get is correlated behaviorID.
|
||||
|
||||
CDSkillBehaviorTable* skillTable = CDClientManager::Instance()->GetTable<CDSkillBehaviorTable>("SkillBehavior");
|
||||
m_ActionBehaviorId = skillTable->GetSkillByID(m_Action).behaviorID;
|
||||
CDSkillBehaviorTable* skillTable = CDClientManager::Instance()->GetTable<CDSkillBehaviorTable>("SkillBehavior");
|
||||
m_ActionBehaviorId = skillTable->GetSkillByID(m_Action).behaviorID;
|
||||
|
||||
m_Delay = GetFloat("delay");
|
||||
m_NumIntervals = GetInt("num_intervals");
|
||||
m_Delay = GetFloat("delay");
|
||||
m_NumIntervals = GetInt("num_intervals");
|
||||
}
|
||||
|
@@ -4,19 +4,18 @@
|
||||
class OverTimeBehavior final : public Behavior
|
||||
{
|
||||
public:
|
||||
uint32_t m_Action;
|
||||
uint32_t m_Action;
|
||||
uint32_t m_ActionBehaviorId;
|
||||
float m_Delay;
|
||||
int32_t m_NumIntervals;
|
||||
float m_Delay;
|
||||
int32_t m_NumIntervals;
|
||||
|
||||
/*
|
||||
* Inherited
|
||||
*/
|
||||
|
||||
explicit OverTimeBehavior(const uint32_t behaviorId) : Behavior(behaviorId)
|
||||
{
|
||||
explicit OverTimeBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {
|
||||
}
|
||||
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
void Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
@@ -3,8 +3,7 @@
|
||||
#include "BehaviorContext.h"
|
||||
#include "BehaviorBranchContext.h"
|
||||
|
||||
void PlayEffectBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void PlayEffectBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
// On managed behaviors this is handled by the client
|
||||
if (!context->unmanaged)
|
||||
return;
|
||||
@@ -14,13 +13,11 @@ void PlayEffectBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bit
|
||||
PlayFx(u"", target);
|
||||
}
|
||||
|
||||
void PlayEffectBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void PlayEffectBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
const auto& target = branch.target == LWOOBJID_EMPTY ? context->originator : branch.target;
|
||||
|
||||
//PlayFx(u"", target);
|
||||
}
|
||||
|
||||
void PlayEffectBehavior::Load()
|
||||
{
|
||||
void PlayEffectBehavior::Load() {
|
||||
}
|
||||
|
@@ -7,13 +7,12 @@ public:
|
||||
/*
|
||||
* Inherited
|
||||
*/
|
||||
explicit PlayEffectBehavior(const uint32_t behaviorId) : Behavior(behaviorId)
|
||||
{
|
||||
explicit PlayEffectBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {
|
||||
}
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
void Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
|
||||
void Load() override;
|
||||
};
|
||||
|
@@ -7,16 +7,14 @@
|
||||
#include "SkillComponent.h"
|
||||
#include "../dWorldServer/ObjectIDManager.h"
|
||||
|
||||
void ProjectileAttackBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void ProjectileAttackBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
LWOOBJID target;
|
||||
|
||||
bitStream->Read(target);
|
||||
|
||||
auto* entity = EntityManager::Instance()->GetEntity(context->originator);
|
||||
|
||||
if (entity == nullptr)
|
||||
{
|
||||
if (entity == nullptr) {
|
||||
Game::logger->Log("ProjectileAttackBehavior", "Failed to find originator (%llu)!", context->originator);
|
||||
|
||||
return;
|
||||
@@ -24,23 +22,20 @@ void ProjectileAttackBehavior::Handle(BehaviorContext* context, RakNet::BitStrea
|
||||
|
||||
auto* skillComponent = entity->GetComponent<SkillComponent>();
|
||||
|
||||
if (skillComponent == nullptr)
|
||||
{
|
||||
if (skillComponent == nullptr) {
|
||||
Game::logger->Log("ProjectileAttackBehavior", "Failed to find skill component for (%llu)!", -context->originator);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_useMouseposit)
|
||||
{
|
||||
if (m_useMouseposit) {
|
||||
NiPoint3 targetPosition = NiPoint3::ZERO;
|
||||
bitStream->Read(targetPosition);
|
||||
}
|
||||
|
||||
auto* targetEntity = EntityManager::Instance()->GetEntity(target);
|
||||
|
||||
for (auto i = 0u; i < this->m_projectileCount; ++i)
|
||||
{
|
||||
for (auto i = 0u; i < this->m_projectileCount; ++i) {
|
||||
LWOOBJID projectileId;
|
||||
|
||||
bitStream->Read(projectileId);
|
||||
@@ -53,14 +48,12 @@ void ProjectileAttackBehavior::Handle(BehaviorContext* context, RakNet::BitStrea
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectileAttackBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void ProjectileAttackBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
bitStream->Write(branch.target);
|
||||
|
||||
auto* entity = EntityManager::Instance()->GetEntity(context->originator);
|
||||
|
||||
if (entity == nullptr)
|
||||
{
|
||||
if (entity == nullptr) {
|
||||
Game::logger->Log("ProjectileAttackBehavior", "Failed to find originator (%llu)!", context->originator);
|
||||
|
||||
return;
|
||||
@@ -68,8 +61,7 @@ void ProjectileAttackBehavior::Calculate(BehaviorContext* context, RakNet::BitSt
|
||||
|
||||
auto* skillComponent = entity->GetComponent<SkillComponent>();
|
||||
|
||||
if (skillComponent == nullptr)
|
||||
{
|
||||
if (skillComponent == nullptr) {
|
||||
Game::logger->Log("ProjectileAttackBehavior", "Failed to find skill component for (%llu)!", context->originator);
|
||||
|
||||
return;
|
||||
@@ -78,8 +70,7 @@ void ProjectileAttackBehavior::Calculate(BehaviorContext* context, RakNet::BitSt
|
||||
|
||||
auto* other = EntityManager::Instance()->GetEntity(branch.target);
|
||||
|
||||
if (other == nullptr)
|
||||
{
|
||||
if (other == nullptr) {
|
||||
Game::logger->Log("ProjectileAttackBehavior", "Invalid projectile target (%llu)!", branch.target);
|
||||
|
||||
return;
|
||||
@@ -104,8 +95,7 @@ void ProjectileAttackBehavior::Calculate(BehaviorContext* context, RakNet::BitSt
|
||||
|
||||
const auto maxTime = this->m_maxDistance / this->m_projectileSpeed;
|
||||
|
||||
for (auto i = 0u; i < this->m_projectileCount; ++i)
|
||||
{
|
||||
for (auto i = 0u; i < this->m_projectileCount; ++i) {
|
||||
auto id = static_cast<LWOOBJID>(ObjectIDManager::Instance()->GenerateObjectID());
|
||||
|
||||
id = GeneralUtils::SetBit(id, OBJECT_BIT_CLIENT);
|
||||
@@ -128,25 +118,20 @@ void ProjectileAttackBehavior::Calculate(BehaviorContext* context, RakNet::BitSt
|
||||
skillComponent->RegisterCalculatedProjectile(id, context, branch, this->m_lot, maxTime, position, direction * this->m_projectileSpeed, this->m_trackTarget, this->m_trackRadius);
|
||||
|
||||
// No idea how to calculate this properly
|
||||
if (this->m_projectileCount == 2)
|
||||
{
|
||||
if (this->m_projectileCount == 2) {
|
||||
angle += angleDelta;
|
||||
}
|
||||
else if (this->m_projectileCount == 3)
|
||||
{
|
||||
} else if (this->m_projectileCount == 3) {
|
||||
angle += angleStep;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectileAttackBehavior::Load()
|
||||
{
|
||||
void ProjectileAttackBehavior::Load() {
|
||||
this->m_lot = GetInt("LOT_ID");
|
||||
|
||||
this->m_projectileCount = GetInt("spread_count");
|
||||
|
||||
if (this->m_projectileCount == 0)
|
||||
{
|
||||
if (this->m_projectileCount == 0) {
|
||||
this->m_projectileCount = 1;
|
||||
}
|
||||
|
||||
|
@@ -27,8 +27,7 @@ public:
|
||||
* Inherited
|
||||
*/
|
||||
|
||||
explicit ProjectileAttackBehavior(const uint32_t behavior_id) : Behavior(behavior_id)
|
||||
{
|
||||
explicit ProjectileAttackBehavior(const uint32_t behavior_id) : Behavior(behavior_id) {
|
||||
}
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
@@ -5,21 +5,18 @@
|
||||
#include "EntityManager.h"
|
||||
#include "MovementAIComponent.h"
|
||||
|
||||
void PullToPointBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void PullToPointBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(context->originator);
|
||||
|
||||
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
|
||||
if (entity == nullptr || target == nullptr)
|
||||
{
|
||||
if (entity == nullptr || target == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
auto* movement = target->GetComponent<MovementAIComponent>();
|
||||
|
||||
if (movement == nullptr)
|
||||
{
|
||||
if (movement == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -28,11 +25,9 @@ void PullToPointBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bi
|
||||
movement->PullToPoint(position);
|
||||
}
|
||||
|
||||
void PullToPointBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void PullToPointBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
Handle(context, bitStream, branch);
|
||||
}
|
||||
|
||||
void PullToPointBehavior::Load()
|
||||
{
|
||||
void PullToPointBehavior::Load() {
|
||||
}
|
||||
|
@@ -9,8 +9,7 @@ public:
|
||||
* Inherited
|
||||
*/
|
||||
|
||||
explicit PullToPointBehavior(const uint32_t behaviorId) : Behavior(behaviorId)
|
||||
{
|
||||
explicit PullToPointBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {
|
||||
}
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
@@ -6,12 +6,10 @@
|
||||
#include "dLogger.h"
|
||||
#include "Game.h"
|
||||
|
||||
void RepairBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bit_stream, const BehaviorBranchContext branch)
|
||||
{
|
||||
void RepairBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bit_stream, const BehaviorBranchContext branch) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(branch.target);
|
||||
|
||||
if (entity == nullptr)
|
||||
{
|
||||
if (entity == nullptr) {
|
||||
Game::logger->Log("RepairBehavior", "Failed to find entity for (%llu)!", branch.target);
|
||||
|
||||
return;
|
||||
@@ -19,8 +17,7 @@ void RepairBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bit_str
|
||||
|
||||
auto* destroyable = static_cast<DestroyableComponent*>(entity->GetComponent(COMPONENT_TYPE_DESTROYABLE));
|
||||
|
||||
if (destroyable == nullptr)
|
||||
{
|
||||
if (destroyable == nullptr) {
|
||||
Game::logger->Log("RepairBehavior", "Failed to find destroyable component for %(llu)!", branch.target);
|
||||
|
||||
return;
|
||||
@@ -29,12 +26,10 @@ void RepairBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bit_str
|
||||
destroyable->Repair(this->m_armor);
|
||||
}
|
||||
|
||||
void RepairBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bit_stream, const BehaviorBranchContext branch)
|
||||
{
|
||||
void RepairBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bit_stream, const BehaviorBranchContext branch) {
|
||||
Handle(context, bit_stream, branch);
|
||||
}
|
||||
|
||||
void RepairBehavior::Load()
|
||||
{
|
||||
void RepairBehavior::Load() {
|
||||
this->m_armor = GetInt("armor");
|
||||
}
|
||||
|
@@ -10,8 +10,7 @@ public:
|
||||
* Inherited
|
||||
*/
|
||||
|
||||
explicit RepairBehavior(const uint32_t behavior_id) : Behavior(behavior_id)
|
||||
{
|
||||
explicit RepairBehavior(const uint32_t behavior_id) : Behavior(behavior_id) {
|
||||
}
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bit_stream, BehaviorBranchContext branch) override;
|
||||
|
@@ -3,16 +3,13 @@
|
||||
#include "BehaviorContext.h"
|
||||
#include "BehaviorBranchContext.h"
|
||||
|
||||
void SkillCastFailedBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void SkillCastFailedBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
context->failed = true;
|
||||
}
|
||||
|
||||
void SkillCastFailedBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void SkillCastFailedBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
context->failed = true;
|
||||
}
|
||||
|
||||
void SkillCastFailedBehavior::Load()
|
||||
{
|
||||
void SkillCastFailedBehavior::Load() {
|
||||
}
|
||||
|
@@ -8,12 +8,11 @@ public:
|
||||
/*
|
||||
* Inherited
|
||||
*/
|
||||
explicit SkillCastFailedBehavior(const uint32_t behaviorId) : Behavior(behaviorId)
|
||||
{
|
||||
explicit SkillCastFailedBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {
|
||||
}
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
|
||||
void Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
void Load() override;
|
||||
|
@@ -4,25 +4,25 @@
|
||||
#include "EntityManager.h"
|
||||
#include "CppScripts.h"
|
||||
|
||||
void SkillEventBehavior::Handle(BehaviorContext *context, RakNet::BitStream *bitStream, BehaviorBranchContext branch) {
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* caster = EntityManager::Instance()->GetEntity(context->originator);
|
||||
void SkillEventBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* caster = EntityManager::Instance()->GetEntity(context->originator);
|
||||
|
||||
if (caster != nullptr && target != nullptr && this->m_effectHandle != nullptr && !this->m_effectHandle->empty()) {
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(target)) {
|
||||
script->OnSkillEventFired(target, caster, *this->m_effectHandle);
|
||||
}
|
||||
}
|
||||
if (caster != nullptr && target != nullptr && this->m_effectHandle != nullptr && !this->m_effectHandle->empty()) {
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(target)) {
|
||||
script->OnSkillEventFired(target, caster, *this->m_effectHandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SkillEventBehavior::Calculate(BehaviorContext *context, RakNet::BitStream *bitStream, BehaviorBranchContext branch) {
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* caster = EntityManager::Instance()->GetEntity(context->originator);
|
||||
SkillEventBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* caster = EntityManager::Instance()->GetEntity(context->originator);
|
||||
|
||||
if (caster != nullptr && target != nullptr && this->m_effectHandle != nullptr && !this->m_effectHandle->empty()) {
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(target)) {
|
||||
script->OnSkillEventFired(target, caster, *this->m_effectHandle);
|
||||
}
|
||||
}
|
||||
if (caster != nullptr && target != nullptr && this->m_effectHandle != nullptr && !this->m_effectHandle->empty()) {
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(target)) {
|
||||
script->OnSkillEventFired(target, caster, *this->m_effectHandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -6,10 +6,10 @@
|
||||
*/
|
||||
class SkillEventBehavior final : public Behavior {
|
||||
public:
|
||||
explicit SkillEventBehavior(const uint32_t behaviorID) : Behavior(behaviorID) {
|
||||
}
|
||||
explicit SkillEventBehavior(const uint32_t behaviorID) : Behavior(behaviorID) {
|
||||
}
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
void Calculate(BehaviorContext *context, RakNet::BitStream *bitStream, BehaviorBranchContext branch) override;
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
void Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
};
|
||||
|
||||
|
@@ -8,23 +8,19 @@
|
||||
#include "DestroyableComponent.h"
|
||||
#include "RebuildComponent.h"
|
||||
|
||||
void SpawnBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void SpawnBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
auto* origin = EntityManager::Instance()->GetEntity(context->originator);
|
||||
|
||||
if (origin == nullptr)
|
||||
{
|
||||
if (origin == nullptr) {
|
||||
Game::logger->Log("SpawnBehavior", "Failed to find self entity (%llu)!", context->originator);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (branch.isProjectile)
|
||||
{
|
||||
if (branch.isProjectile) {
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
|
||||
if (target != nullptr)
|
||||
{
|
||||
if (target != nullptr) {
|
||||
origin = target;
|
||||
}
|
||||
}
|
||||
@@ -42,11 +38,10 @@ void SpawnBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStrea
|
||||
auto* entity = EntityManager::Instance()->CreateEntity(
|
||||
info,
|
||||
nullptr,
|
||||
EntityManager::Instance()->GetEntity(context->originator)
|
||||
EntityManager::Instance()->GetEntity(context->originator)
|
||||
);
|
||||
|
||||
if (entity == nullptr)
|
||||
{
|
||||
if (entity == nullptr) {
|
||||
Game::logger->Log("SpawnBehavior", "Failed to spawn entity (%i)!", this->m_lot);
|
||||
|
||||
return;
|
||||
@@ -57,39 +52,33 @@ void SpawnBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStrea
|
||||
// Unset the flag to reposition the player, this makes it harder to glitch out of the map
|
||||
auto* rebuildComponent = entity->GetComponent<RebuildComponent>();
|
||||
|
||||
if (rebuildComponent != nullptr)
|
||||
{
|
||||
if (rebuildComponent != nullptr) {
|
||||
rebuildComponent->SetRepositionPlayer(false);
|
||||
}
|
||||
|
||||
EntityManager::Instance()->ConstructEntity(entity);
|
||||
|
||||
if (branch.duration > 0)
|
||||
{
|
||||
if (branch.duration > 0) {
|
||||
context->RegisterTimerBehavior(this, branch, entity->GetObjectID());
|
||||
}
|
||||
|
||||
if (branch.start != 0)
|
||||
{
|
||||
if (branch.start != 0) {
|
||||
context->RegisterEndBehavior(this, branch, entity->GetObjectID());
|
||||
}
|
||||
|
||||
entity->AddCallbackTimer(60, [entity] () {
|
||||
entity->AddCallbackTimer(60, [entity]() {
|
||||
entity->Smash();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void SpawnBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void SpawnBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
Handle(context, bitStream, branch);
|
||||
}
|
||||
|
||||
void SpawnBehavior::Timer(BehaviorContext* context, const BehaviorBranchContext branch, const LWOOBJID second)
|
||||
{
|
||||
void SpawnBehavior::Timer(BehaviorContext* context, const BehaviorBranchContext branch, const LWOOBJID second) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(second);
|
||||
|
||||
if (entity == nullptr)
|
||||
{
|
||||
if (entity == nullptr) {
|
||||
Game::logger->Log("SpawnBehavior", "Failed to find spawned entity (%llu)!", second);
|
||||
|
||||
return;
|
||||
@@ -97,8 +86,7 @@ void SpawnBehavior::Timer(BehaviorContext* context, const BehaviorBranchContext
|
||||
|
||||
auto* destroyable = static_cast<DestroyableComponent*>(entity->GetComponent(COMPONENT_TYPE_DESTROYABLE));
|
||||
|
||||
if (destroyable == nullptr)
|
||||
{
|
||||
if (destroyable == nullptr) {
|
||||
entity->Smash(context->originator);
|
||||
|
||||
return;
|
||||
@@ -107,14 +95,12 @@ void SpawnBehavior::Timer(BehaviorContext* context, const BehaviorBranchContext
|
||||
destroyable->Smash(second);
|
||||
}
|
||||
|
||||
void SpawnBehavior::End(BehaviorContext* context, const BehaviorBranchContext branch, const LWOOBJID second)
|
||||
{
|
||||
void SpawnBehavior::End(BehaviorContext* context, const BehaviorBranchContext branch, const LWOOBJID second) {
|
||||
Timer(context, branch, second);
|
||||
}
|
||||
|
||||
|
||||
void SpawnBehavior::Load()
|
||||
{
|
||||
void SpawnBehavior::Load() {
|
||||
this->m_lot = GetInt("LOT_ID");
|
||||
this->m_Distance = GetFloat("distance");
|
||||
}
|
||||
|
@@ -6,21 +6,20 @@ class SpawnBehavior final : public Behavior
|
||||
public:
|
||||
LOT m_lot;
|
||||
float m_Distance;
|
||||
|
||||
|
||||
/*
|
||||
* Inherited
|
||||
*/
|
||||
explicit SpawnBehavior(const uint32_t behaviorId) : Behavior(behaviorId)
|
||||
{
|
||||
explicit SpawnBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {
|
||||
}
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
void Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
|
||||
void Timer(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) override;
|
||||
|
||||
void End(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) override;
|
||||
|
||||
|
||||
void Load() override;
|
||||
};
|
||||
};
|
||||
|
@@ -3,11 +3,8 @@
|
||||
#include "BehaviorBranchContext.h"
|
||||
#include "BehaviorContext.h"
|
||||
|
||||
void SpawnQuickbuildBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void SpawnQuickbuildBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
}
|
||||
|
||||
void SpawnQuickbuildBehavior::Load()
|
||||
{
|
||||
void SpawnQuickbuildBehavior::Load() {
|
||||
}
|
||||
|
@@ -8,8 +8,7 @@ public:
|
||||
/*
|
||||
* Inherited
|
||||
*/
|
||||
explicit SpawnQuickbuildBehavior(const uint32_t behaviorId) : Behavior(behaviorId)
|
||||
{
|
||||
explicit SpawnQuickbuildBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {
|
||||
}
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
@@ -6,101 +6,86 @@
|
||||
#include "dLogger.h"
|
||||
|
||||
|
||||
void SpeedBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
if (m_AffectsCaster)
|
||||
{
|
||||
branch.target = context->caster;
|
||||
}
|
||||
void SpeedBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
if (m_AffectsCaster) {
|
||||
branch.target = context->caster;
|
||||
}
|
||||
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
|
||||
if (target == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (target == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto* controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>();
|
||||
auto* controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>();
|
||||
|
||||
if (controllablePhysicsComponent == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (controllablePhysicsComponent == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto current = controllablePhysicsComponent->GetSpeedMultiplier();
|
||||
const auto current = controllablePhysicsComponent->GetSpeedMultiplier();
|
||||
|
||||
controllablePhysicsComponent->SetSpeedMultiplier(current + ((m_RunSpeed - 500.0f) / 500.0f));
|
||||
controllablePhysicsComponent->SetSpeedMultiplier(current + ((m_RunSpeed - 500.0f) / 500.0f));
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(target);
|
||||
EntityManager::Instance()->SerializeEntity(target);
|
||||
|
||||
if (branch.duration > 0.0f)
|
||||
{
|
||||
context->RegisterTimerBehavior(this, branch);
|
||||
}
|
||||
else if (branch.start > 0)
|
||||
{
|
||||
controllablePhysicsComponent->SetIgnoreMultipliers(true);
|
||||
if (branch.duration > 0.0f) {
|
||||
context->RegisterTimerBehavior(this, branch);
|
||||
} else if (branch.start > 0) {
|
||||
controllablePhysicsComponent->SetIgnoreMultipliers(true);
|
||||
|
||||
context->RegisterEndBehavior(this, branch);
|
||||
}
|
||||
context->RegisterEndBehavior(this, branch);
|
||||
}
|
||||
}
|
||||
|
||||
void SpeedBehavior::Timer(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second)
|
||||
{
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
void SpeedBehavior::Timer(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) {
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
|
||||
if (target == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (target == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto* controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>();
|
||||
auto* controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>();
|
||||
|
||||
if (controllablePhysicsComponent == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (controllablePhysicsComponent == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto current = controllablePhysicsComponent->GetSpeedMultiplier();
|
||||
const auto current = controllablePhysicsComponent->GetSpeedMultiplier();
|
||||
|
||||
controllablePhysicsComponent->SetSpeedMultiplier(current - ((m_RunSpeed - 500.0f) / 500.0f));
|
||||
controllablePhysicsComponent->SetSpeedMultiplier(current - ((m_RunSpeed - 500.0f) / 500.0f));
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(target);
|
||||
EntityManager::Instance()->SerializeEntity(target);
|
||||
}
|
||||
|
||||
void SpeedBehavior::End(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second)
|
||||
{
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
void SpeedBehavior::End(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) {
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
|
||||
if (target == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (target == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto* controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>();
|
||||
auto* controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>();
|
||||
|
||||
if (controllablePhysicsComponent == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (controllablePhysicsComponent == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto current = controllablePhysicsComponent->GetSpeedMultiplier();
|
||||
const auto current = controllablePhysicsComponent->GetSpeedMultiplier();
|
||||
|
||||
controllablePhysicsComponent->SetIgnoreMultipliers(false);
|
||||
controllablePhysicsComponent->SetIgnoreMultipliers(false);
|
||||
|
||||
controllablePhysicsComponent->SetSpeedMultiplier(current - ((m_RunSpeed - 500.0f) / 500.0f));
|
||||
controllablePhysicsComponent->SetSpeedMultiplier(current - ((m_RunSpeed - 500.0f) / 500.0f));
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(target);
|
||||
EntityManager::Instance()->SerializeEntity(target);
|
||||
}
|
||||
|
||||
void SpeedBehavior::Load()
|
||||
{
|
||||
m_RunSpeed = GetFloat("run_speed");
|
||||
void SpeedBehavior::Load() {
|
||||
m_RunSpeed = GetFloat("run_speed");
|
||||
|
||||
if (m_RunSpeed < 500.0f)
|
||||
{
|
||||
m_RunSpeed = 500.0f;
|
||||
}
|
||||
if (m_RunSpeed < 500.0f) {
|
||||
m_RunSpeed = 500.0f;
|
||||
}
|
||||
|
||||
m_AffectsCaster = GetBoolean("affects_caster");
|
||||
m_AffectsCaster = GetBoolean("affects_caster");
|
||||
}
|
||||
|
@@ -8,20 +8,19 @@ public:
|
||||
/*
|
||||
* Inherited
|
||||
*/
|
||||
explicit SpeedBehavior(const uint32_t behaviorId) : Behavior(behaviorId)
|
||||
{
|
||||
explicit SpeedBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {
|
||||
}
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
void Timer(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) override;
|
||||
|
||||
void End(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) override;
|
||||
void Timer(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) override;
|
||||
|
||||
void End(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) override;
|
||||
|
||||
void Load() override;
|
||||
|
||||
private:
|
||||
float m_RunSpeed;
|
||||
float m_RunSpeed;
|
||||
|
||||
bool m_AffectsCaster;
|
||||
bool m_AffectsCaster;
|
||||
};
|
||||
|
@@ -1,21 +1,18 @@
|
||||
#include "StartBehavior.h"
|
||||
#include "BehaviorBranchContext.h"
|
||||
|
||||
void StartBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bit_stream, BehaviorBranchContext branch)
|
||||
{
|
||||
void StartBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bit_stream, BehaviorBranchContext branch) {
|
||||
branch.start = this->m_behaviorId;
|
||||
|
||||
|
||||
this->m_action->Handle(context, bit_stream, branch);
|
||||
}
|
||||
|
||||
void StartBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bit_stream, BehaviorBranchContext branch)
|
||||
{
|
||||
void StartBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bit_stream, BehaviorBranchContext branch) {
|
||||
branch.start = this->m_behaviorId;
|
||||
|
||||
this->m_action->Calculate(context, bit_stream, branch);
|
||||
}
|
||||
|
||||
void StartBehavior::Load()
|
||||
{
|
||||
void StartBehavior::Load() {
|
||||
this->m_action = GetAction("action");
|
||||
}
|
||||
|
@@ -5,13 +5,12 @@ class StartBehavior final : public Behavior
|
||||
{
|
||||
public:
|
||||
Behavior* m_action;
|
||||
|
||||
|
||||
/*
|
||||
* Inherited
|
||||
*/
|
||||
|
||||
explicit StartBehavior(const uint32_t behaviorID) : Behavior(behaviorID)
|
||||
{
|
||||
explicit StartBehavior(const uint32_t behaviorID) : Behavior(behaviorID) {
|
||||
}
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
@@ -9,8 +9,7 @@
|
||||
#include "DestroyableComponent.h"
|
||||
|
||||
|
||||
void StunBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch)
|
||||
{
|
||||
void StunBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
|
||||
if (this->m_stunCaster || branch.target == context->originator) {
|
||||
return;
|
||||
}
|
||||
@@ -20,8 +19,7 @@ void StunBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream
|
||||
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
|
||||
if (target == nullptr)
|
||||
{
|
||||
if (target == nullptr) {
|
||||
Game::logger->Log("StunBehavior", "Failed to find target (%llu)!", branch.target);
|
||||
|
||||
return;
|
||||
@@ -33,22 +31,18 @@ void StunBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream
|
||||
|
||||
auto* combatAiComponent = static_cast<BaseCombatAIComponent*>(target->GetComponent(COMPONENT_TYPE_BASE_COMBAT_AI));
|
||||
|
||||
if (combatAiComponent == nullptr)
|
||||
{
|
||||
if (combatAiComponent == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
combatAiComponent->Stun(branch.duration);
|
||||
}
|
||||
|
||||
void StunBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch)
|
||||
{
|
||||
if (this->m_stunCaster || branch.target == context->originator)
|
||||
{
|
||||
void StunBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
|
||||
if (this->m_stunCaster || branch.target == context->originator) {
|
||||
auto* self = EntityManager::Instance()->GetEntity(context->originator);
|
||||
|
||||
if (self == nullptr)
|
||||
{
|
||||
if (self == nullptr) {
|
||||
Game::logger->Log("StunBehavior", "Invalid self entity (%llu)!", context->originator);
|
||||
|
||||
return;
|
||||
@@ -60,8 +54,7 @@ void StunBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStr
|
||||
|
||||
auto* combatAiComponent = static_cast<BaseCombatAIComponent*>(self->GetComponent(COMPONENT_TYPE_BASE_COMBAT_AI));
|
||||
|
||||
if (combatAiComponent == nullptr)
|
||||
{
|
||||
if (combatAiComponent == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -74,20 +67,17 @@ void StunBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStr
|
||||
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
|
||||
if (target != nullptr)
|
||||
{
|
||||
if (target != nullptr) {
|
||||
auto* destroyableComponent = target->GetComponent<DestroyableComponent>();
|
||||
|
||||
if (destroyableComponent != nullptr)
|
||||
{
|
||||
if (destroyableComponent != nullptr) {
|
||||
blocked = destroyableComponent->IsKnockbackImmune();
|
||||
}
|
||||
}
|
||||
|
||||
bitStream->Write(blocked);
|
||||
|
||||
if (target == nullptr)
|
||||
{
|
||||
if (target == nullptr) {
|
||||
Game::logger->Log("StunBehavior", "Failed to find target (%llu)!", branch.target);
|
||||
|
||||
return;
|
||||
@@ -99,15 +89,13 @@ void StunBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStr
|
||||
|
||||
auto* combatAiComponent = static_cast<BaseCombatAIComponent*>(target->GetComponent(COMPONENT_TYPE_BASE_COMBAT_AI));
|
||||
|
||||
if (combatAiComponent == nullptr)
|
||||
{
|
||||
if (combatAiComponent == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
combatAiComponent->Stun(branch.duration);
|
||||
}
|
||||
|
||||
void StunBehavior::Load()
|
||||
{
|
||||
void StunBehavior::Load() {
|
||||
this->m_stunCaster = GetBoolean("stun_caster");
|
||||
}
|
||||
|
@@ -9,10 +9,9 @@ public:
|
||||
/*
|
||||
* Inherited
|
||||
*/
|
||||
explicit StunBehavior(const uint32_t behavior_id) : Behavior(behavior_id)
|
||||
{
|
||||
explicit StunBehavior(const uint32_t behavior_id) : Behavior(behavior_id) {
|
||||
}
|
||||
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bit_stream, BehaviorBranchContext branch) override;
|
||||
|
||||
void Calculate(BehaviorContext* context, RakNet::BitStream* bit_stream, BehaviorBranchContext branch) override;
|
||||
|
@@ -6,57 +6,46 @@
|
||||
#include "BehaviorContext.h"
|
||||
#include "BuffComponent.h"
|
||||
|
||||
void SwitchBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch)
|
||||
{
|
||||
void SwitchBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
|
||||
auto state = true;
|
||||
|
||||
if (this->m_imagination > 0 || !this->m_isEnemyFaction)
|
||||
{
|
||||
if (this->m_imagination > 0 || !this->m_isEnemyFaction) {
|
||||
bitStream->Read(state);
|
||||
}
|
||||
|
||||
auto* entity = EntityManager::Instance()->GetEntity(context->originator);
|
||||
auto* entity = EntityManager::Instance()->GetEntity(context->originator);
|
||||
|
||||
if (entity == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto* destroyableComponent = entity->GetComponent<DestroyableComponent>();
|
||||
|
||||
if (destroyableComponent == nullptr)
|
||||
{
|
||||
if (entity == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
Game::logger->Log("SwitchBehavior", "[%i] State: (%d), imagination: (%i) / (%f)", entity->GetLOT(), state, destroyableComponent->GetImagination(), destroyableComponent->GetMaxImagination());
|
||||
auto* destroyableComponent = entity->GetComponent<DestroyableComponent>();
|
||||
|
||||
if (state || (entity->GetLOT() == 8092 && destroyableComponent->GetImagination() >= m_imagination))
|
||||
{
|
||||
this->m_actionTrue->Handle(context, bitStream, branch);
|
||||
if (destroyableComponent == nullptr) {
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Game::logger->Log("SwitchBehavior", "[%i] State: (%d), imagination: (%i) / (%f)", entity->GetLOT(), state, destroyableComponent->GetImagination(), destroyableComponent->GetMaxImagination());
|
||||
|
||||
if (state || (entity->GetLOT() == 8092 && destroyableComponent->GetImagination() >= m_imagination)) {
|
||||
this->m_actionTrue->Handle(context, bitStream, branch);
|
||||
} else {
|
||||
this->m_actionFalse->Handle(context, bitStream, branch);
|
||||
}
|
||||
}
|
||||
|
||||
void SwitchBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void SwitchBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
auto state = true;
|
||||
|
||||
if (this->m_imagination > 0 || !this->m_isEnemyFaction)
|
||||
{
|
||||
if (this->m_imagination > 0 || !this->m_isEnemyFaction) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(branch.target);
|
||||
|
||||
state = entity != nullptr;
|
||||
|
||||
if (state && m_targetHasBuff != 0)
|
||||
{
|
||||
auto* buffComponent = entity->GetComponent<BuffComponent>();
|
||||
if (state && m_targetHasBuff != 0) {
|
||||
auto* buffComponent = entity->GetComponent<BuffComponent>();
|
||||
|
||||
if (buffComponent != nullptr && !buffComponent->HasBuff(m_targetHasBuff))
|
||||
{
|
||||
if (buffComponent != nullptr && !buffComponent->HasBuff(m_targetHasBuff)) {
|
||||
state = false;
|
||||
}
|
||||
}
|
||||
@@ -64,18 +53,14 @@ void SwitchBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitS
|
||||
bitStream->Write(state);
|
||||
}
|
||||
|
||||
if (state)
|
||||
{
|
||||
if (state) {
|
||||
this->m_actionTrue->Calculate(context, bitStream, branch);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
this->m_actionFalse->Calculate(context, bitStream, branch);
|
||||
}
|
||||
}
|
||||
|
||||
void SwitchBehavior::Load()
|
||||
{
|
||||
void SwitchBehavior::Load() {
|
||||
this->m_actionTrue = GetAction("action_true");
|
||||
|
||||
this->m_actionFalse = GetAction("action_false");
|
||||
|
@@ -13,13 +13,12 @@ public:
|
||||
bool m_isEnemyFaction;
|
||||
|
||||
int32_t m_targetHasBuff;
|
||||
|
||||
|
||||
/*
|
||||
* Inherited
|
||||
*/
|
||||
|
||||
explicit SwitchBehavior(const uint32_t behaviorId) : Behavior(behaviorId)
|
||||
{
|
||||
explicit SwitchBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {
|
||||
}
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
@@ -9,20 +9,19 @@
|
||||
#include "EntityManager.h"
|
||||
|
||||
|
||||
void SwitchMultipleBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bit_stream, BehaviorBranchContext branch)
|
||||
{
|
||||
void SwitchMultipleBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bit_stream, BehaviorBranchContext branch) {
|
||||
float value;
|
||||
|
||||
bit_stream->Read(value);
|
||||
|
||||
|
||||
uint32_t trigger = 0;
|
||||
|
||||
for (unsigned int i = 0; i < this->m_behaviors.size(); i++) {
|
||||
|
||||
|
||||
const double data = this->m_behaviors.at(i).first;
|
||||
|
||||
|
||||
if (value <= data) {
|
||||
|
||||
|
||||
trigger = i;
|
||||
|
||||
break;
|
||||
@@ -34,8 +33,7 @@ void SwitchMultipleBehavior::Handle(BehaviorContext* context, RakNet::BitStream*
|
||||
behavior->Handle(context, bit_stream, branch);
|
||||
}
|
||||
|
||||
void SwitchMultipleBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bit_stream, BehaviorBranchContext branch)
|
||||
{
|
||||
void SwitchMultipleBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bit_stream, BehaviorBranchContext branch) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@@ -45,7 +43,7 @@ void SwitchMultipleBehavior::Load() {
|
||||
"(select bP2.value FROM BehaviorParameter bP2 WHERE bP2.behaviorID = ?1 AND bP2.parameterID LIKE 'value %' "
|
||||
"AND replace(bP1.parameterID, 'behavior ', '') = replace(bP2.parameterID, 'value ', '')) as value "
|
||||
"FROM BehaviorParameter bP1 WHERE bP1.behaviorID = ?1 AND bP1.parameterID LIKE 'behavior %';");
|
||||
query.bind(1, (int) this->m_behaviorId);
|
||||
query.bind(1, (int)this->m_behaviorId);
|
||||
|
||||
auto result = query.execQuery();
|
||||
|
||||
@@ -57,7 +55,7 @@ void SwitchMultipleBehavior::Load() {
|
||||
auto value = result.getFloatField(2);
|
||||
|
||||
this->m_behaviors.emplace_back(value, behavior);
|
||||
|
||||
|
||||
result.nextRow();
|
||||
}
|
||||
}
|
||||
|
@@ -7,13 +7,12 @@ class SwitchMultipleBehavior final : public Behavior
|
||||
{
|
||||
public:
|
||||
std::vector<std::pair<float, Behavior*>> m_behaviors;
|
||||
|
||||
|
||||
/*
|
||||
* Inherited
|
||||
*/
|
||||
|
||||
explicit SwitchMultipleBehavior(const uint32_t behavior_id) : Behavior(behavior_id)
|
||||
{
|
||||
explicit SwitchMultipleBehavior(const uint32_t behavior_id) : Behavior(behavior_id) {
|
||||
}
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bit_stream, BehaviorBranchContext branch) override;
|
||||
|
@@ -11,10 +11,8 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
void TacArcBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
if (this->m_targetEnemy && this->m_usePickedTarget && branch.target > 0)
|
||||
{
|
||||
void TacArcBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
if (this->m_targetEnemy && this->m_usePickedTarget && branch.target > 0) {
|
||||
this->m_action->Handle(context, bitStream, branch);
|
||||
|
||||
return;
|
||||
@@ -24,35 +22,30 @@ void TacArcBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStre
|
||||
|
||||
bitStream->Read(hit);
|
||||
|
||||
if (this->m_checkEnv)
|
||||
{
|
||||
if (this->m_checkEnv) {
|
||||
bool blocked = false;
|
||||
|
||||
bitStream->Read(blocked);
|
||||
|
||||
if (blocked)
|
||||
{
|
||||
if (blocked) {
|
||||
this->m_blockedAction->Handle(context, bitStream, branch);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (hit)
|
||||
{
|
||||
if (hit) {
|
||||
uint32_t count = 0;
|
||||
|
||||
bitStream->Read(count);
|
||||
|
||||
if (count > m_maxTargets && m_maxTargets > 0)
|
||||
{
|
||||
if (count > m_maxTargets && m_maxTargets > 0) {
|
||||
count = m_maxTargets;
|
||||
}
|
||||
|
||||
std::vector<LWOOBJID> targets;
|
||||
|
||||
for (auto i = 0u; i < count; ++i)
|
||||
{
|
||||
for (auto i = 0u; i < count; ++i) {
|
||||
LWOOBJID id;
|
||||
|
||||
bitStream->Read(id);
|
||||
@@ -60,46 +53,41 @@ void TacArcBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStre
|
||||
targets.push_back(id);
|
||||
}
|
||||
|
||||
for (auto target : targets)
|
||||
{
|
||||
for (auto target : targets) {
|
||||
branch.target = target;
|
||||
|
||||
this->m_action->Handle(context, bitStream, branch);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
this->m_missAction->Handle(context, bitStream, branch);
|
||||
}
|
||||
}
|
||||
|
||||
void TacArcBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
auto* self = EntityManager::Instance()->GetEntity(context->originator);
|
||||
if (self == nullptr) {
|
||||
Game::logger->Log("TacArcBehavior", "Invalid self for (%llu)!", context->originator);
|
||||
return;
|
||||
}
|
||||
void TacArcBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
auto* self = EntityManager::Instance()->GetEntity(context->originator);
|
||||
if (self == nullptr) {
|
||||
Game::logger->Log("TacArcBehavior", "Invalid self for (%llu)!", context->originator);
|
||||
return;
|
||||
}
|
||||
|
||||
const auto* destroyableComponent = self->GetComponent<DestroyableComponent>();
|
||||
const auto* destroyableComponent = self->GetComponent<DestroyableComponent>();
|
||||
|
||||
if ((this->m_usePickedTarget || context->clientInitalized) && branch.target > 0) {
|
||||
const auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
if ((this->m_usePickedTarget || context->clientInitalized) && branch.target > 0) {
|
||||
const auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
|
||||
if (target == nullptr)
|
||||
{
|
||||
if (target == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If the game is specific about who to target, check that
|
||||
if (destroyableComponent == nullptr || ((!m_targetFriend && !m_targetEnemy
|
||||
|| m_targetFriend && destroyableComponent->IsFriend(target)
|
||||
|| m_targetEnemy && destroyableComponent->IsEnemy(target)))) {
|
||||
this->m_action->Calculate(context, bitStream, branch);
|
||||
}
|
||||
// If the game is specific about who to target, check that
|
||||
if (destroyableComponent == nullptr || ((!m_targetFriend && !m_targetEnemy
|
||||
|| m_targetFriend && destroyableComponent->IsFriend(target)
|
||||
|| m_targetEnemy && destroyableComponent->IsEnemy(target)))) {
|
||||
this->m_action->Calculate(context, bitStream, branch);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
auto* combatAi = self->GetComponent<BaseCombatAIComponent>();
|
||||
|
||||
@@ -111,46 +99,40 @@ void TacArcBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitS
|
||||
|
||||
std::vector<LWOOBJID> validTargets;
|
||||
|
||||
if (combatAi != nullptr)
|
||||
{
|
||||
if (combatAi->GetTarget() != LWOOBJID_EMPTY)
|
||||
{
|
||||
if (combatAi != nullptr) {
|
||||
if (combatAi->GetTarget() != LWOOBJID_EMPTY) {
|
||||
validTargets.push_back(combatAi->GetTarget());
|
||||
}
|
||||
}
|
||||
|
||||
// Find all valid targets, based on whether we target enemies or friends
|
||||
for (const auto& contextTarget : context->GetValidTargets()) {
|
||||
if (destroyableComponent != nullptr) {
|
||||
const auto* targetEntity = EntityManager::Instance()->GetEntity(contextTarget);
|
||||
if (destroyableComponent != nullptr) {
|
||||
const auto* targetEntity = EntityManager::Instance()->GetEntity(contextTarget);
|
||||
|
||||
if (m_targetEnemy && destroyableComponent->IsEnemy(targetEntity)
|
||||
|| m_targetFriend && destroyableComponent->IsFriend(targetEntity)) {
|
||||
validTargets.push_back(contextTarget);
|
||||
}
|
||||
} else {
|
||||
validTargets.push_back(contextTarget);
|
||||
}
|
||||
if (m_targetEnemy && destroyableComponent->IsEnemy(targetEntity)
|
||||
|| m_targetFriend && destroyableComponent->IsFriend(targetEntity)) {
|
||||
validTargets.push_back(contextTarget);
|
||||
}
|
||||
} else {
|
||||
validTargets.push_back(contextTarget);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto validTarget : validTargets)
|
||||
{
|
||||
if (targets.size() >= this->m_maxTargets)
|
||||
{
|
||||
for (auto validTarget : validTargets) {
|
||||
if (targets.size() >= this->m_maxTargets) {
|
||||
break;
|
||||
}
|
||||
|
||||
auto* entity = EntityManager::Instance()->GetEntity(validTarget);
|
||||
|
||||
if (entity == nullptr)
|
||||
{
|
||||
if (entity == nullptr) {
|
||||
Game::logger->Log("TacArcBehavior", "Invalid target (%llu) for (%llu)!", validTarget, context->originator);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (std::find(targets.begin(), targets.end(), entity) != targets.end())
|
||||
{
|
||||
if (std::find(targets.begin(), targets.end(), entity) != targets.end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -174,12 +156,10 @@ void TacArcBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitS
|
||||
|
||||
const auto distance = Vector3::Distance(reference, otherPosition);
|
||||
|
||||
if (m_method == 2)
|
||||
{
|
||||
if (m_method == 2) {
|
||||
NiPoint3 rayPoint = casterPosition + forward * distance;
|
||||
|
||||
if (m_farWidth > 0 && Vector3::DistanceSquared(rayPoint, otherPosition) > this->m_farWidth * this->m_farWidth)
|
||||
{
|
||||
if (m_farWidth > 0 && Vector3::DistanceSquared(rayPoint, otherPosition) > this->m_farWidth * this->m_farWidth) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -188,35 +168,30 @@ void TacArcBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitS
|
||||
|
||||
const float degreeAngle = std::abs(Vector3::Angle(forward, normalized) * (180 / 3.14) - 180);
|
||||
|
||||
if (distance >= this->m_minDistance && this->m_maxDistance >= distance && degreeAngle <= 2 * this->m_angle)
|
||||
{
|
||||
if (distance >= this->m_minDistance && this->m_maxDistance >= distance && degreeAngle <= 2 * this->m_angle) {
|
||||
targets.push_back(entity);
|
||||
}
|
||||
}
|
||||
|
||||
std::sort(targets.begin(), targets.end(), [reference](Entity* a, Entity* b)
|
||||
{
|
||||
std::sort(targets.begin(), targets.end(), [reference](Entity* a, Entity* b) {
|
||||
const auto aDistance = Vector3::DistanceSquared(reference, a->GetPosition());
|
||||
const auto bDistance = Vector3::DistanceSquared(reference, b->GetPosition());
|
||||
|
||||
return aDistance > bDistance;
|
||||
});
|
||||
});
|
||||
|
||||
const auto hit = !targets.empty();
|
||||
|
||||
bitStream->Write(hit);
|
||||
|
||||
if (this->m_checkEnv)
|
||||
{
|
||||
if (this->m_checkEnv) {
|
||||
const auto blocked = false; // TODO
|
||||
|
||||
bitStream->Write(blocked);
|
||||
}
|
||||
|
||||
if (hit)
|
||||
{
|
||||
if (combatAi != nullptr)
|
||||
{
|
||||
if (hit) {
|
||||
if (combatAi != nullptr) {
|
||||
combatAi->LookAt(targets[0]->GetPosition());
|
||||
}
|
||||
|
||||
@@ -226,26 +201,21 @@ void TacArcBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitS
|
||||
|
||||
bitStream->Write(count);
|
||||
|
||||
for (auto* target : targets)
|
||||
{
|
||||
for (auto* target : targets) {
|
||||
bitStream->Write(target->GetObjectID());
|
||||
}
|
||||
|
||||
for (auto* target : targets)
|
||||
{
|
||||
for (auto* target : targets) {
|
||||
branch.target = target->GetObjectID();
|
||||
|
||||
this->m_action->Calculate(context, bitStream, branch);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
this->m_missAction->Calculate(context, bitStream, branch);
|
||||
}
|
||||
}
|
||||
|
||||
void TacArcBehavior::Load()
|
||||
{
|
||||
void TacArcBehavior::Load() {
|
||||
this->m_usePickedTarget = GetBoolean("use_picked_target");
|
||||
|
||||
this->m_action = GetAction("action");
|
||||
|
@@ -45,11 +45,10 @@ public:
|
||||
/*
|
||||
* Inherited
|
||||
*/
|
||||
|
||||
explicit TacArcBehavior(const uint32_t behavior_id) : Behavior(behavior_id)
|
||||
{
|
||||
|
||||
explicit TacArcBehavior(const uint32_t behavior_id) : Behavior(behavior_id) {
|
||||
}
|
||||
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
void Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
@@ -3,27 +3,23 @@
|
||||
#include "BehaviorContext.h"
|
||||
|
||||
|
||||
void TargetCasterBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bit_stream, BehaviorBranchContext branch)
|
||||
{
|
||||
void TargetCasterBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bit_stream, BehaviorBranchContext branch) {
|
||||
branch.target = context->caster;
|
||||
|
||||
this->m_action->Handle(context, bit_stream, branch);
|
||||
}
|
||||
|
||||
void TargetCasterBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch)
|
||||
{
|
||||
void TargetCasterBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch) {
|
||||
this->m_action->UnCast(context, branch);
|
||||
}
|
||||
|
||||
void TargetCasterBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bit_stream, BehaviorBranchContext branch)
|
||||
{
|
||||
void TargetCasterBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bit_stream, BehaviorBranchContext branch) {
|
||||
branch.target = context->caster;
|
||||
|
||||
this->m_action->Calculate(context, bit_stream, branch);
|
||||
}
|
||||
|
||||
void TargetCasterBehavior::Load()
|
||||
{
|
||||
void TargetCasterBehavior::Load() {
|
||||
this->m_action = GetAction("action");
|
||||
}
|
||||
|
||||
|
@@ -5,18 +5,17 @@ class TargetCasterBehavior final : public Behavior
|
||||
{
|
||||
public:
|
||||
Behavior* m_action;
|
||||
|
||||
|
||||
/*
|
||||
* Inherited
|
||||
*/
|
||||
|
||||
explicit TargetCasterBehavior(const uint32_t behavior_id) : Behavior(behavior_id)
|
||||
{
|
||||
explicit TargetCasterBehavior(const uint32_t behavior_id) : Behavior(behavior_id) {
|
||||
}
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bit_stream, BehaviorBranchContext branch) override;
|
||||
|
||||
void UnCast(BehaviorContext* context, BehaviorBranchContext branch) override;
|
||||
void UnCast(BehaviorContext* context, BehaviorBranchContext branch) override;
|
||||
|
||||
void Calculate(BehaviorContext* context, RakNet::BitStream* bit_stream, BehaviorBranchContext branch) override;
|
||||
|
||||
|
@@ -6,12 +6,10 @@
|
||||
#include "dLogger.h"
|
||||
|
||||
|
||||
void TauntBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void TauntBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
|
||||
if (target == nullptr)
|
||||
{
|
||||
if (target == nullptr) {
|
||||
Game::logger->Log("TauntBehavior", "Failed to find target (%llu)!", branch.target);
|
||||
|
||||
return;
|
||||
@@ -19,18 +17,15 @@ void TauntBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStrea
|
||||
|
||||
auto* combatComponent = target->GetComponent<BaseCombatAIComponent>();
|
||||
|
||||
if (combatComponent != nullptr)
|
||||
{
|
||||
if (combatComponent != nullptr) {
|
||||
combatComponent->Taunt(context->originator, m_threatToAdd);
|
||||
}
|
||||
}
|
||||
|
||||
void TauntBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void TauntBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
|
||||
if (target == nullptr)
|
||||
{
|
||||
if (target == nullptr) {
|
||||
Game::logger->Log("TauntBehavior", "Failed to find target (%llu)!", branch.target);
|
||||
|
||||
return;
|
||||
@@ -38,14 +33,12 @@ void TauntBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitSt
|
||||
|
||||
auto* combatComponent = target->GetComponent<BaseCombatAIComponent>();
|
||||
|
||||
if (combatComponent != nullptr)
|
||||
{
|
||||
if (combatComponent != nullptr) {
|
||||
combatComponent->Taunt(context->originator, m_threatToAdd);
|
||||
}
|
||||
}
|
||||
|
||||
void TauntBehavior::Load()
|
||||
{
|
||||
void TauntBehavior::Load() {
|
||||
this->m_threatToAdd = GetFloat("threat to add");
|
||||
}
|
||||
|
||||
|
@@ -6,13 +6,12 @@ class TauntBehavior final : public Behavior
|
||||
{
|
||||
public:
|
||||
float m_threatToAdd;
|
||||
|
||||
|
||||
/*
|
||||
* Inherited
|
||||
*/
|
||||
|
||||
explicit TauntBehavior(const uint32_t behaviorId) : Behavior(behaviorId)
|
||||
{
|
||||
explicit TauntBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {
|
||||
}
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
@@ -2,8 +2,8 @@
|
||||
#include "BehaviorBranchContext.h"
|
||||
#include "CharacterComponent.h"
|
||||
#include "BehaviorContext.h"
|
||||
|
||||
void VentureVisionBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch){
|
||||
|
||||
void VentureVisionBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
|
||||
const auto targetEntity = EntityManager::Instance()->GetEntity(branch.target);
|
||||
|
||||
@@ -38,7 +38,7 @@ void VentureVisionBehavior::Timer(BehaviorContext* context, BehaviorBranchContex
|
||||
UnCast(context, branch);
|
||||
}
|
||||
|
||||
void VentureVisionBehavior::Load(){
|
||||
void VentureVisionBehavior::Load() {
|
||||
this->m_show_pet_digs = GetBoolean("show_pet_digs");
|
||||
|
||||
this->m_show_minibosses = GetBoolean("show_minibosses");
|
||||
|
@@ -25,10 +25,9 @@ public:
|
||||
* Inherited
|
||||
*/
|
||||
|
||||
explicit VentureVisionBehavior(const uint32_t behaviorId) : Behavior(behaviorId)
|
||||
{
|
||||
explicit VentureVisionBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {
|
||||
}
|
||||
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
void UnCast(BehaviorContext* context, BehaviorBranchContext branch) override;
|
||||
|
@@ -7,22 +7,17 @@
|
||||
#include "dLogger.h"
|
||||
|
||||
|
||||
void VerifyBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
void VerifyBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(branch.target);
|
||||
|
||||
auto success = true;
|
||||
|
||||
if (entity == nullptr)
|
||||
{
|
||||
if (entity == nullptr) {
|
||||
success = false;
|
||||
}
|
||||
else if (this->m_rangeCheck)
|
||||
{
|
||||
} else if (this->m_rangeCheck) {
|
||||
auto* self = EntityManager::Instance()->GetEntity(context->originator);
|
||||
|
||||
if (self == nullptr)
|
||||
{
|
||||
if (self == nullptr) {
|
||||
Game::logger->Log("VerifyBehavior", "Invalid self for (%llu)", context->originator);
|
||||
|
||||
return;
|
||||
@@ -30,38 +25,31 @@ void VerifyBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitS
|
||||
|
||||
const auto distance = Vector3::DistanceSquared(self->GetPosition(), entity->GetPosition());
|
||||
|
||||
if (distance > this->m_range * this->m_range)
|
||||
{
|
||||
if (distance > this->m_range * this->m_range) {
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
else if (this->m_blockCheck)
|
||||
{
|
||||
} else if (this->m_blockCheck) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
if (branch.target != LWOOBJID_EMPTY && branch.target != context->originator)
|
||||
{
|
||||
if (branch.target != LWOOBJID_EMPTY && branch.target != context->originator) {
|
||||
bitStream->Write(success);
|
||||
|
||||
if (success)
|
||||
{
|
||||
if (success) {
|
||||
bitStream->Write<uint32_t>(1);
|
||||
bitStream->Write0();
|
||||
bitStream->Write0();
|
||||
}
|
||||
}
|
||||
|
||||
if (!success)
|
||||
{
|
||||
if (!success) {
|
||||
branch.target = LWOOBJID_EMPTY;
|
||||
}
|
||||
|
||||
m_action->Calculate(context, bitStream, branch);
|
||||
}
|
||||
|
||||
void VerifyBehavior::Load()
|
||||
{
|
||||
void VerifyBehavior::Load() {
|
||||
this->m_rangeCheck = GetBoolean("check_range");
|
||||
|
||||
this->m_blockCheck = GetBoolean("check blocking");
|
||||
|
@@ -16,10 +16,9 @@ public:
|
||||
* Inherited
|
||||
*/
|
||||
|
||||
explicit VerifyBehavior(const uint32_t behaviorId) : Behavior(behaviorId)
|
||||
{
|
||||
explicit VerifyBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {
|
||||
}
|
||||
|
||||
|
||||
void Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
void Load() override;
|
||||
|
Reference in New Issue
Block a user