mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-06 18:54:13 +00:00
format codebase
This commit is contained in:
@@ -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;
|
||||
|
Reference in New Issue
Block a user