mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-04 09:44:10 +00:00
format codebase
This commit is contained in:
@@ -21,12 +21,10 @@
|
||||
#include "BuffComponent.h"
|
||||
|
||||
|
||||
ProjectileSyncEntry::ProjectileSyncEntry()
|
||||
{
|
||||
ProjectileSyncEntry::ProjectileSyncEntry() {
|
||||
}
|
||||
|
||||
bool SkillComponent::CastPlayerSkill(const uint32_t behaviorId, const uint32_t skillUid, RakNet::BitStream* bitStream, const LWOOBJID target, uint32_t skillID)
|
||||
{
|
||||
bool SkillComponent::CastPlayerSkill(const uint32_t behaviorId, const uint32_t skillUid, RakNet::BitStream* bitStream, const LWOOBJID target, uint32_t skillID) {
|
||||
auto* context = new BehaviorContext(this->m_Parent->GetObjectID());
|
||||
|
||||
context->caster = m_Parent->GetObjectID();
|
||||
@@ -46,12 +44,10 @@ bool SkillComponent::CastPlayerSkill(const uint32_t behaviorId, const uint32_t s
|
||||
return !context->failed;
|
||||
}
|
||||
|
||||
void SkillComponent::SyncPlayerSkill(const uint32_t skillUid, const uint32_t syncId, RakNet::BitStream* bitStream)
|
||||
{
|
||||
void SkillComponent::SyncPlayerSkill(const uint32_t skillUid, const uint32_t syncId, RakNet::BitStream* bitStream) {
|
||||
const auto index = this->m_managedBehaviors.find(skillUid);
|
||||
|
||||
if (index == this->m_managedBehaviors.end())
|
||||
{
|
||||
if (index == this->m_managedBehaviors.end()) {
|
||||
Game::logger->Log("SkillComponent", "Failed to find skill with uid (%i)!", skillUid, syncId);
|
||||
|
||||
return;
|
||||
@@ -63,24 +59,20 @@ void SkillComponent::SyncPlayerSkill(const uint32_t skillUid, const uint32_t syn
|
||||
}
|
||||
|
||||
|
||||
void SkillComponent::SyncPlayerProjectile(const LWOOBJID projectileId, RakNet::BitStream* bitStream, const LWOOBJID target)
|
||||
{
|
||||
void SkillComponent::SyncPlayerProjectile(const LWOOBJID projectileId, RakNet::BitStream* bitStream, const LWOOBJID target) {
|
||||
auto index = -1;
|
||||
|
||||
for (auto i = 0u; i < this->m_managedProjectiles.size(); ++i)
|
||||
{
|
||||
for (auto i = 0u; i < this->m_managedProjectiles.size(); ++i) {
|
||||
const auto& projectile = this->m_managedProjectiles.at(i);
|
||||
|
||||
if (projectile.id == projectileId)
|
||||
{
|
||||
if (projectile.id == projectileId) {
|
||||
index = i;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (index == -1)
|
||||
{
|
||||
if (index == -1) {
|
||||
Game::logger->Log("SkillComponent", "Failed to find projectile id (%llu)!", projectileId);
|
||||
|
||||
return;
|
||||
@@ -90,7 +82,7 @@ void SkillComponent::SyncPlayerProjectile(const LWOOBJID projectileId, RakNet::B
|
||||
|
||||
auto query = CDClientDatabase::CreatePreppedStmt(
|
||||
"SELECT behaviorID FROM SkillBehavior WHERE skillID = (SELECT skillID FROM ObjectSkills WHERE objectTemplate = ?);");
|
||||
query.bind(1, (int) sync_entry.lot);
|
||||
query.bind(1, (int)sync_entry.lot);
|
||||
|
||||
auto result = query.execQuery();
|
||||
|
||||
@@ -110,8 +102,7 @@ void SkillComponent::SyncPlayerProjectile(const LWOOBJID projectileId, RakNet::B
|
||||
|
||||
branch.isProjectile = true;
|
||||
|
||||
if (target != LWOOBJID_EMPTY)
|
||||
{
|
||||
if (target != LWOOBJID_EMPTY) {
|
||||
branch.target = target;
|
||||
}
|
||||
|
||||
@@ -120,8 +111,7 @@ void SkillComponent::SyncPlayerProjectile(const LWOOBJID projectileId, RakNet::B
|
||||
this->m_managedProjectiles.erase(this->m_managedProjectiles.begin() + index);
|
||||
}
|
||||
|
||||
void SkillComponent::RegisterPlayerProjectile(const LWOOBJID projectileId, BehaviorContext* context, const BehaviorBranchContext& branch, const LOT lot)
|
||||
{
|
||||
void SkillComponent::RegisterPlayerProjectile(const LWOOBJID projectileId, BehaviorContext* context, const BehaviorBranchContext& branch, const LOT lot) {
|
||||
ProjectileSyncEntry entry;
|
||||
|
||||
entry.context = context;
|
||||
@@ -132,50 +122,39 @@ void SkillComponent::RegisterPlayerProjectile(const LWOOBJID projectileId, Behav
|
||||
this->m_managedProjectiles.push_back(entry);
|
||||
}
|
||||
|
||||
void SkillComponent::Update(const float deltaTime)
|
||||
{
|
||||
if (!m_Parent->HasComponent(COMPONENT_TYPE_BASE_COMBAT_AI) && m_Parent->GetLOT() != 1)
|
||||
{
|
||||
void SkillComponent::Update(const float deltaTime) {
|
||||
if (!m_Parent->HasComponent(COMPONENT_TYPE_BASE_COMBAT_AI) && m_Parent->GetLOT() != 1) {
|
||||
CalculateUpdate(deltaTime);
|
||||
}
|
||||
|
||||
std::map<uint32_t, BehaviorContext*> keep {};
|
||||
std::map<uint32_t, BehaviorContext*> keep{};
|
||||
|
||||
for (const auto& pair : this->m_managedBehaviors)
|
||||
{
|
||||
for (const auto& pair : this->m_managedBehaviors) {
|
||||
auto* context = pair.second;
|
||||
|
||||
if (context == nullptr)
|
||||
{
|
||||
if (context == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (context->clientInitalized)
|
||||
{
|
||||
if (context->clientInitalized) {
|
||||
context->CalculateUpdate(deltaTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
context->Update(deltaTime);
|
||||
}
|
||||
|
||||
// Cleanup old behaviors
|
||||
if (context->syncEntries.empty() && context->timerEntries.empty())
|
||||
{
|
||||
if (context->syncEntries.empty() && context->timerEntries.empty()) {
|
||||
auto any = false;
|
||||
|
||||
for (const auto& projectile : this->m_managedProjectiles)
|
||||
{
|
||||
if (projectile.context == context)
|
||||
{
|
||||
for (const auto& projectile : this->m_managedProjectiles) {
|
||||
if (projectile.context == context) {
|
||||
any = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!any)
|
||||
{
|
||||
if (!any) {
|
||||
context->Reset();
|
||||
|
||||
delete context;
|
||||
@@ -192,10 +171,8 @@ void SkillComponent::Update(const float deltaTime)
|
||||
this->m_managedBehaviors = keep;
|
||||
}
|
||||
|
||||
void SkillComponent::Reset()
|
||||
{
|
||||
for (const auto& behavior : this->m_managedBehaviors)
|
||||
{
|
||||
void SkillComponent::Reset() {
|
||||
for (const auto& behavior : this->m_managedBehaviors) {
|
||||
delete behavior.second;
|
||||
}
|
||||
|
||||
@@ -203,26 +180,22 @@ void SkillComponent::Reset()
|
||||
this->m_managedBehaviors.clear();
|
||||
}
|
||||
|
||||
void SkillComponent::Interrupt()
|
||||
{
|
||||
void SkillComponent::Interrupt() {
|
||||
if (m_Parent->IsPlayer()) return;
|
||||
|
||||
auto* combat = m_Parent->GetComponent<BaseCombatAIComponent>();
|
||||
|
||||
if (combat != nullptr && combat->GetStunImmune())
|
||||
{
|
||||
if (combat != nullptr && combat->GetStunImmune()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto& behavior : this->m_managedBehaviors)
|
||||
{
|
||||
for (const auto& behavior : this->m_managedBehaviors) {
|
||||
behavior.second->Interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
void SkillComponent::RegisterCalculatedProjectile(const LWOOBJID projectileId, BehaviorContext* context, const BehaviorBranchContext& branch, const LOT lot, const float maxTime,
|
||||
const NiPoint3& startPosition, const NiPoint3& velocity, const bool trackTarget, const float trackRadius)
|
||||
{
|
||||
const NiPoint3& startPosition, const NiPoint3& velocity, const bool trackTarget, const float trackRadius) {
|
||||
ProjectileSyncEntry entry;
|
||||
|
||||
entry.context = context;
|
||||
@@ -242,8 +215,7 @@ void SkillComponent::RegisterCalculatedProjectile(const LWOOBJID projectileId, B
|
||||
}
|
||||
|
||||
|
||||
SkillExecutionResult SkillComponent::CalculateBehavior(const uint32_t skillId, const uint32_t behaviorId, const LWOOBJID target, const bool ignoreTarget, const bool clientInitalized, const LWOOBJID originatorOverride)
|
||||
{
|
||||
SkillExecutionResult SkillComponent::CalculateBehavior(const uint32_t skillId, const uint32_t behaviorId, const LWOOBJID target, const bool ignoreTarget, const bool clientInitalized, const LWOOBJID originatorOverride) {
|
||||
auto* bitStream = new RakNet::BitStream();
|
||||
|
||||
auto* behavior = Behavior::CreateBehavior(behaviorId);
|
||||
@@ -256,14 +228,13 @@ SkillExecutionResult SkillComponent::CalculateBehavior(const uint32_t skillId, c
|
||||
|
||||
context->foundTarget = target != LWOOBJID_EMPTY || ignoreTarget || clientInitalized;
|
||||
|
||||
behavior->Calculate(context, bitStream, { target, 0});
|
||||
behavior->Calculate(context, bitStream, { target, 0 });
|
||||
|
||||
for (auto* script : CppScripts::GetEntityScripts(m_Parent)) {
|
||||
script->OnSkillCast(m_Parent, skillId);
|
||||
script->OnSkillCast(m_Parent, skillId);
|
||||
}
|
||||
|
||||
if (!context->foundTarget)
|
||||
{
|
||||
if (!context->foundTarget) {
|
||||
delete bitStream;
|
||||
delete context;
|
||||
|
||||
@@ -273,8 +244,7 @@ SkillExecutionResult SkillComponent::CalculateBehavior(const uint32_t skillId, c
|
||||
|
||||
this->m_managedBehaviors.insert_or_assign(context->skillUId, context);
|
||||
|
||||
if (!clientInitalized)
|
||||
{
|
||||
if (!clientInitalized) {
|
||||
// Echo start skill
|
||||
GameMessages::EchoStartSkill start;
|
||||
|
||||
@@ -285,8 +255,7 @@ SkillExecutionResult SkillComponent::CalculateBehavior(const uint32_t skillId, c
|
||||
|
||||
auto* originator = EntityManager::Instance()->GetEntity(context->originator);
|
||||
|
||||
if (originator != nullptr)
|
||||
{
|
||||
if (originator != nullptr) {
|
||||
start.originatorRot = originator->GetRotation();
|
||||
}
|
||||
//start.optionalTargetID = target;
|
||||
@@ -311,23 +280,19 @@ SkillExecutionResult SkillComponent::CalculateBehavior(const uint32_t skillId, c
|
||||
return { true, context->skillTime };
|
||||
}
|
||||
|
||||
void SkillComponent::CalculateUpdate(const float deltaTime)
|
||||
{
|
||||
if (this->m_managedBehaviors.empty())
|
||||
return;
|
||||
void SkillComponent::CalculateUpdate(const float deltaTime) {
|
||||
if (this->m_managedBehaviors.empty())
|
||||
return;
|
||||
|
||||
for (const auto& managedBehavior : this->m_managedBehaviors)
|
||||
{
|
||||
if (managedBehavior.second == nullptr)
|
||||
{
|
||||
for (const auto& managedBehavior : this->m_managedBehaviors) {
|
||||
if (managedBehavior.second == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
managedBehavior.second->CalculateUpdate(deltaTime);
|
||||
}
|
||||
|
||||
for (auto& managedProjectile : this->m_managedProjectiles)
|
||||
{
|
||||
for (auto& managedProjectile : this->m_managedProjectiles) {
|
||||
auto entry = managedProjectile;
|
||||
|
||||
if (!entry.calculation) continue;
|
||||
@@ -336,8 +301,7 @@ void SkillComponent::CalculateUpdate(const float deltaTime)
|
||||
|
||||
auto* origin = EntityManager::Instance()->GetEntity(entry.context->originator);
|
||||
|
||||
if (origin == nullptr)
|
||||
{
|
||||
if (origin == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -345,8 +309,7 @@ void SkillComponent::CalculateUpdate(const float deltaTime)
|
||||
|
||||
const auto position = entry.startPosition + (entry.velocity * entry.time);
|
||||
|
||||
for (const auto& targetId : targets)
|
||||
{
|
||||
for (const auto& targetId : targets) {
|
||||
auto* target = EntityManager::Instance()->GetEntity(targetId);
|
||||
|
||||
const auto targetPosition = target->GetPosition();
|
||||
@@ -355,8 +318,7 @@ void SkillComponent::CalculateUpdate(const float deltaTime)
|
||||
|
||||
const auto distance = Vector3::DistanceSquared(targetPosition, closestPoint);
|
||||
|
||||
if (distance > 3 * 3)
|
||||
{
|
||||
if (distance > 3 * 3) {
|
||||
/*
|
||||
if (entry.TrackTarget && distance <= entry.TrackRadius)
|
||||
{
|
||||
@@ -404,12 +366,9 @@ void SkillComponent::CalculateUpdate(const float deltaTime)
|
||||
|
||||
std::vector<ProjectileSyncEntry> valid;
|
||||
|
||||
for (auto& entry : this->m_managedProjectiles)
|
||||
{
|
||||
if (entry.calculation)
|
||||
{
|
||||
if (entry.time >= entry.maxTime)
|
||||
{
|
||||
for (auto& entry : this->m_managedProjectiles) {
|
||||
if (entry.calculation) {
|
||||
if (entry.time >= entry.maxTime) {
|
||||
entry.branchContext.target = LWOOBJID_EMPTY;
|
||||
|
||||
SyncProjectileCalculation(entry);
|
||||
@@ -425,13 +384,11 @@ void SkillComponent::CalculateUpdate(const float deltaTime)
|
||||
}
|
||||
|
||||
|
||||
void SkillComponent::SyncProjectileCalculation(const ProjectileSyncEntry& entry) const
|
||||
{
|
||||
void SkillComponent::SyncProjectileCalculation(const ProjectileSyncEntry& entry) const {
|
||||
auto* other = EntityManager::Instance()->GetEntity(entry.branchContext.target);
|
||||
|
||||
if (other == nullptr) {
|
||||
if (entry.branchContext.target != LWOOBJID_EMPTY)
|
||||
{
|
||||
if (entry.branchContext.target != LWOOBJID_EMPTY) {
|
||||
Game::logger->Log("SkillComponent", "Invalid projectile target (%llu)!", entry.branchContext.target);
|
||||
}
|
||||
|
||||
@@ -440,7 +397,7 @@ void SkillComponent::SyncProjectileCalculation(const ProjectileSyncEntry& entry)
|
||||
|
||||
auto query = CDClientDatabase::CreatePreppedStmt(
|
||||
"SELECT behaviorID FROM SkillBehavior WHERE skillID = (SELECT skillID FROM ObjectSkills WHERE objectTemplate = ?);");
|
||||
query.bind(1, (int) entry.lot);
|
||||
query.bind(1, (int)entry.lot);
|
||||
auto result = query.execQuery();
|
||||
|
||||
if (result.eof()) {
|
||||
@@ -461,7 +418,7 @@ void SkillComponent::SyncProjectileCalculation(const ProjectileSyncEntry& entry)
|
||||
|
||||
GameMessages::DoClientProjectileImpact projectileImpact;
|
||||
|
||||
projectileImpact.sBitStream.assign((char*) bitStream->GetData(), bitStream->GetNumberOfBytesUsed());
|
||||
projectileImpact.sBitStream.assign((char*)bitStream->GetData(), bitStream->GetNumberOfBytesUsed());
|
||||
projectileImpact.i64OwnerID = this->m_Parent->GetObjectID();
|
||||
projectileImpact.i64OrgID = entry.id;
|
||||
projectileImpact.i64TargetID = entry.branchContext.target;
|
||||
@@ -479,8 +436,7 @@ void SkillComponent::SyncProjectileCalculation(const ProjectileSyncEntry& entry)
|
||||
delete bitStream;
|
||||
}
|
||||
|
||||
void SkillComponent::HandleUnmanaged(const uint32_t behaviorId, const LWOOBJID target, LWOOBJID source)
|
||||
{
|
||||
void SkillComponent::HandleUnmanaged(const uint32_t behaviorId, const LWOOBJID target, LWOOBJID source) {
|
||||
auto* context = new BehaviorContext(source);
|
||||
|
||||
context->unmanaged = true;
|
||||
@@ -497,8 +453,7 @@ void SkillComponent::HandleUnmanaged(const uint32_t behaviorId, const LWOOBJID t
|
||||
delete context;
|
||||
}
|
||||
|
||||
void SkillComponent::HandleUnCast(const uint32_t behaviorId, const LWOOBJID target)
|
||||
{
|
||||
void SkillComponent::HandleUnCast(const uint32_t behaviorId, const LWOOBJID target) {
|
||||
auto* context = new BehaviorContext(target);
|
||||
|
||||
context->caster = target;
|
||||
@@ -510,25 +465,22 @@ void SkillComponent::HandleUnCast(const uint32_t behaviorId, const LWOOBJID targ
|
||||
delete context;
|
||||
}
|
||||
|
||||
SkillComponent::SkillComponent(Entity* parent) : Component(parent)
|
||||
{
|
||||
SkillComponent::SkillComponent(Entity* parent) : Component(parent) {
|
||||
this->m_skillUid = 0;
|
||||
}
|
||||
|
||||
SkillComponent::~SkillComponent()
|
||||
{
|
||||
SkillComponent::~SkillComponent() {
|
||||
Reset();
|
||||
}
|
||||
|
||||
void SkillComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
||||
if (bIsInitialUpdate) outBitStream->Write0();
|
||||
if (bIsInitialUpdate) outBitStream->Write0();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a unique skill ID for syncing behaviors to the client
|
||||
/// </summary>
|
||||
/// <returns>Unique skill ID</returns>
|
||||
uint32_t SkillComponent::GetUniqueSkillId()
|
||||
{
|
||||
uint32_t SkillComponent::GetUniqueSkillId() {
|
||||
return ++this->m_skillUid;
|
||||
}
|
||||
|
Reference in New Issue
Block a user