format codebase

This commit is contained in:
aronwk-aaron
2022-07-28 08:39:57 -05:00
parent 4f7aa11067
commit 19e77a38d8
881 changed files with 34700 additions and 38689 deletions

View File

@@ -10,28 +10,23 @@
#include "ControllablePhysicsComponent.h"
#include "EntityManager.h"
std::unordered_map<int32_t, std::vector<BuffParameter>> BuffComponent::m_Cache {};
std::unordered_map<int32_t, std::vector<BuffParameter>> BuffComponent::m_Cache{};
BuffComponent::BuffComponent(Entity* parent) : Component(parent)
{
BuffComponent::BuffComponent(Entity* parent) : Component(parent) {
}
BuffComponent::~BuffComponent() {
}
void BuffComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
if (!bIsInitialUpdate) return;
if (m_Buffs.empty())
{
if (!bIsInitialUpdate) return;
if (m_Buffs.empty()) {
outBitStream->Write0();
}
else
{
} else {
outBitStream->Write1();
outBitStream->Write<uint32_t>(m_Buffs.size());
for (const auto& buff : m_Buffs)
{
for (const auto& buff : m_Buffs) {
outBitStream->Write<uint32_t>(buff.first);
outBitStream->Write0();
outBitStream->Write0();
@@ -53,21 +48,17 @@ void BuffComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUp
outBitStream->Write0();
}
void BuffComponent::Update(float deltaTime)
{
void BuffComponent::Update(float deltaTime) {
/**
* Loop through all buffs and apply deltaTime to ther time.
* If they have expired, remove the buff and break.
*/
for (auto& buff : m_Buffs)
{
for (auto& buff : m_Buffs) {
// For damage buffs
if (buff.second.tick != 0.0f && buff.second.stacks > 0)
{
if (buff.second.tick != 0.0f && buff.second.stacks > 0) {
buff.second.tickTime -= deltaTime;
if (buff.second.tickTime <= 0.0f)
{
if (buff.second.tickTime <= 0.0f) {
buff.second.tickTime = buff.second.tick;
buff.second.stacks--;
@@ -76,15 +67,13 @@ void BuffComponent::Update(float deltaTime)
}
// These are indefinate buffs, don't update them.
if (buff.second.time == 0.0f)
{
if (buff.second.time == 0.0f) {
continue;
}
buff.second.time -= deltaTime;
if (buff.second.time <= 0.0f)
{
if (buff.second.time <= 0.0f) {
RemoveBuff(buff.first);
break;
@@ -93,28 +82,24 @@ void BuffComponent::Update(float deltaTime)
}
void BuffComponent::ApplyBuff(const int32_t id, const float duration, const LWOOBJID source, bool addImmunity,
bool cancelOnDamaged, bool cancelOnDeath, bool cancelOnLogout, bool cancelOnRemoveBuff,
bool cancelOnUi, bool cancelOnUnequip, bool cancelOnZone)
{
bool cancelOnDamaged, bool cancelOnDeath, bool cancelOnLogout, bool cancelOnRemoveBuff,
bool cancelOnUi, bool cancelOnUnequip, bool cancelOnZone) {
// Prevent buffs from stacking.
if (HasBuff(id))
{
if (HasBuff(id)) {
return;
}
GameMessages::SendAddBuff(const_cast<LWOOBJID &>(m_Parent->GetObjectID()), source, (uint32_t) id,
(uint32_t) duration * 1000, addImmunity, cancelOnDamaged, cancelOnDeath,
cancelOnLogout, cancelOnRemoveBuff, cancelOnUi, cancelOnUnequip, cancelOnZone);
GameMessages::SendAddBuff(const_cast<LWOOBJID&>(m_Parent->GetObjectID()), source, (uint32_t)id,
(uint32_t)duration * 1000, addImmunity, cancelOnDamaged, cancelOnDeath,
cancelOnLogout, cancelOnRemoveBuff, cancelOnUi, cancelOnUnequip, cancelOnZone);
float tick = 0;
float stacks = 0;
int32_t behaviorID = 0;
const auto& parameters = GetBuffParameters(id);
for (const auto& parameter : parameters)
{
if (parameter.name == "overtime")
{
for (const auto& parameter : parameters) {
if (parameter.name == "overtime") {
auto* behaviorTemplateTable = CDClientManager::Instance()->GetTable<CDSkillBehaviorTable>("SkillBehavior");
behaviorID = behaviorTemplateTable->GetSkillByID(parameter.values[0]).behaviorID;
@@ -138,12 +123,10 @@ void BuffComponent::ApplyBuff(const int32_t id, const float duration, const LWOO
m_Buffs.emplace(id, buff);
}
void BuffComponent::RemoveBuff(int32_t id)
{
void BuffComponent::RemoveBuff(int32_t id) {
const auto& iter = m_Buffs.find(id);
if (iter == m_Buffs.end())
{
if (iter == m_Buffs.end()) {
return;
}
@@ -152,18 +135,14 @@ void BuffComponent::RemoveBuff(int32_t id)
RemoveBuffEffect(id);
}
bool BuffComponent::HasBuff(int32_t id)
{
bool BuffComponent::HasBuff(int32_t id) {
return m_Buffs.find(id) != m_Buffs.end();
}
void BuffComponent::ApplyBuffEffect(int32_t id)
{
void BuffComponent::ApplyBuffEffect(int32_t id) {
const auto& parameters = GetBuffParameters(id);
for (const auto& parameter : parameters)
{
if (parameter.name == "max_health")
{
for (const auto& parameter : parameters) {
if (parameter.name == "max_health") {
const auto maxHealth = parameter.value;
auto* destroyable = this->GetParent()->GetComponent<DestroyableComponent>();
@@ -171,9 +150,7 @@ void BuffComponent::ApplyBuffEffect(int32_t id)
if (destroyable == nullptr) return;
destroyable->SetMaxHealth(destroyable->GetMaxHealth() + maxHealth);
}
else if (parameter.name == "max_armor")
{
} else if (parameter.name == "max_armor") {
const auto maxArmor = parameter.value;
auto* destroyable = this->GetParent()->GetComponent<DestroyableComponent>();
@@ -181,9 +158,7 @@ void BuffComponent::ApplyBuffEffect(int32_t id)
if (destroyable == nullptr) return;
destroyable->SetMaxArmor(destroyable->GetMaxArmor() + maxArmor);
}
else if (parameter.name == "max_imagination")
{
} else if (parameter.name == "max_imagination") {
const auto maxImagination = parameter.value;
auto* destroyable = this->GetParent()->GetComponent<DestroyableComponent>();
@@ -191,9 +166,7 @@ void BuffComponent::ApplyBuffEffect(int32_t id)
if (destroyable == nullptr) return;
destroyable->SetMaxImagination(destroyable->GetMaxImagination() + maxImagination);
}
else if (parameter.name == "speed")
{
} else if (parameter.name == "speed") {
const auto speed = parameter.value;
auto* controllablePhysicsComponent = this->GetParent()->GetComponent<ControllablePhysicsComponent>();
@@ -209,13 +182,10 @@ void BuffComponent::ApplyBuffEffect(int32_t id)
}
}
void BuffComponent::RemoveBuffEffect(int32_t id)
{
void BuffComponent::RemoveBuffEffect(int32_t id) {
const auto& parameters = GetBuffParameters(id);
for (const auto& parameter : parameters)
{
if (parameter.name == "max_health")
{
for (const auto& parameter : parameters) {
if (parameter.name == "max_health") {
const auto maxHealth = parameter.value;
auto* destroyable = this->GetParent()->GetComponent<DestroyableComponent>();
@@ -223,9 +193,7 @@ void BuffComponent::RemoveBuffEffect(int32_t id)
if (destroyable == nullptr) return;
destroyable->SetMaxHealth(destroyable->GetMaxHealth() - maxHealth);
}
else if (parameter.name == "max_armor")
{
} else if (parameter.name == "max_armor") {
const auto maxArmor = parameter.value;
auto* destroyable = this->GetParent()->GetComponent<DestroyableComponent>();
@@ -233,9 +201,7 @@ void BuffComponent::RemoveBuffEffect(int32_t id)
if (destroyable == nullptr) return;
destroyable->SetMaxArmor(destroyable->GetMaxArmor() - maxArmor);
}
else if (parameter.name == "max_imagination")
{
} else if (parameter.name == "max_imagination") {
const auto maxImagination = parameter.value;
auto* destroyable = this->GetParent()->GetComponent<DestroyableComponent>();
@@ -243,9 +209,7 @@ void BuffComponent::RemoveBuffEffect(int32_t id)
if (destroyable == nullptr) return;
destroyable->SetMaxImagination(destroyable->GetMaxImagination() - maxImagination);
}
else if (parameter.name == "speed")
{
} else if (parameter.name == "speed") {
const auto speed = parameter.value;
auto* controllablePhysicsComponent = this->GetParent()->GetComponent<ControllablePhysicsComponent>();
@@ -261,36 +225,29 @@ void BuffComponent::RemoveBuffEffect(int32_t id)
}
}
void BuffComponent::RemoveAllBuffs()
{
for (const auto& buff : m_Buffs)
{
void BuffComponent::RemoveAllBuffs() {
for (const auto& buff : m_Buffs) {
RemoveBuffEffect(buff.first);
}
m_Buffs.clear();
}
void BuffComponent::Reset()
{
void BuffComponent::Reset() {
RemoveAllBuffs();
}
void BuffComponent::ReApplyBuffs()
{
for (const auto& buff : m_Buffs)
{
void BuffComponent::ReApplyBuffs() {
for (const auto& buff : m_Buffs) {
ApplyBuffEffect(buff.first);
}
}
Entity* BuffComponent::GetParent() const
{
Entity* BuffComponent::GetParent() const {
return m_Parent;
}
void BuffComponent::LoadFromXml(tinyxml2::XMLDocument* doc)
{
void BuffComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
// Load buffs
auto* dest = doc->FirstChildElement("obj")->FirstChildElement("dest");
@@ -298,15 +255,13 @@ void BuffComponent::LoadFromXml(tinyxml2::XMLDocument* doc)
auto* buffElement = dest->FirstChildElement("buff");
// Old character, no buffs to load
if (buffElement == nullptr)
{
if (buffElement == nullptr) {
return;
}
auto* buffEntry = buffElement->FirstChildElement("b");
while (buffEntry != nullptr)
{
while (buffEntry != nullptr) {
int32_t id = buffEntry->IntAttribute("id");
float t = buffEntry->FloatAttribute("t");
float tk = buffEntry->FloatAttribute("tk");
@@ -328,27 +283,22 @@ void BuffComponent::LoadFromXml(tinyxml2::XMLDocument* doc)
}
}
void BuffComponent::UpdateXml(tinyxml2::XMLDocument* doc)
{
void BuffComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
// Save buffs
auto* dest = doc->FirstChildElement("obj")->FirstChildElement("dest");
// Make sure we have a clean buff element.
auto* buffElement = dest->FirstChildElement("buff");
if (buffElement == nullptr)
{
if (buffElement == nullptr) {
buffElement = doc->NewElement("buff");
dest->LinkEndChild(buffElement);
}
else
{
} else {
buffElement->DeleteChildren();
}
for (const auto& buff : m_Buffs)
{
for (const auto& buff : m_Buffs) {
auto* buffEntry = doc->NewElement("b");
buffEntry->SetAttribute("id", buff.first);
@@ -362,46 +312,38 @@ void BuffComponent::UpdateXml(tinyxml2::XMLDocument* doc)
}
}
const std::vector<BuffParameter>& BuffComponent::GetBuffParameters(int32_t buffId)
{
const std::vector<BuffParameter>& BuffComponent::GetBuffParameters(int32_t buffId) {
const auto& pair = m_Cache.find(buffId);
if (pair != m_Cache.end())
{
if (pair != m_Cache.end()) {
return pair->second;
}
auto query = CDClientDatabase::CreatePreppedStmt(
"SELECT * FROM BuffParameters WHERE BuffID = ?;");
query.bind(1, (int) buffId);
query.bind(1, (int)buffId);
auto result = query.execQuery();
std::vector<BuffParameter> parameters {};
std::vector<BuffParameter> parameters{};
while (!result.eof())
{
while (!result.eof()) {
BuffParameter param;
param.buffId = buffId;
param.name = result.getStringField(1);
param.value = result.getFloatField(2);
if (!result.fieldIsNull(3))
{
if (!result.fieldIsNull(3)) {
std::istringstream stream(result.getStringField(3));
std::string token;
while (std::getline(stream, token, ','))
{
try
{
while (std::getline(stream, token, ',')) {
try {
const auto value = std::stof(token);
param.values.push_back(value);
}
catch (std::invalid_argument& exception)
{
} catch (std::invalid_argument& exception) {
Game::logger->Log("BuffComponent", "Failed to parse value (%s): (%s)!", token.c_str(), exception.what());
}
}