mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-04 09:44:10 +00:00
format codebase
This commit is contained in:
@@ -29,21 +29,21 @@
|
||||
#include "dZoneManager.h"
|
||||
|
||||
DestroyableComponent::DestroyableComponent(Entity* parent) : Component(parent) {
|
||||
m_iArmor = 0;
|
||||
m_fMaxArmor = 0.0f;
|
||||
m_iImagination = 0;
|
||||
m_fMaxImagination = 0.0f;
|
||||
m_FactionIDs = std::vector<int32_t>();
|
||||
m_EnemyFactionIDs = std::vector<int32_t>();
|
||||
m_IsSmashable = false;
|
||||
m_IsDead = false;
|
||||
m_IsSmashed = false;
|
||||
m_IsGMImmune = false;
|
||||
m_IsShielded = false;
|
||||
m_DamageToAbsorb = 0;
|
||||
m_HasBricks = false;
|
||||
m_DirtyThreatList = false;
|
||||
m_HasThreats = false;
|
||||
m_iArmor = 0;
|
||||
m_fMaxArmor = 0.0f;
|
||||
m_iImagination = 0;
|
||||
m_fMaxImagination = 0.0f;
|
||||
m_FactionIDs = std::vector<int32_t>();
|
||||
m_EnemyFactionIDs = std::vector<int32_t>();
|
||||
m_IsSmashable = false;
|
||||
m_IsDead = false;
|
||||
m_IsSmashed = false;
|
||||
m_IsGMImmune = false;
|
||||
m_IsShielded = false;
|
||||
m_DamageToAbsorb = 0;
|
||||
m_HasBricks = false;
|
||||
m_DirtyThreatList = false;
|
||||
m_HasThreats = false;
|
||||
m_ExplodeFactor = 1.0f;
|
||||
m_iHealth = 0;
|
||||
m_fMaxHealth = 0;
|
||||
@@ -87,8 +87,7 @@ void DestroyableComponent::Reinitialize(LOT templateID) {
|
||||
|
||||
SetIsSmashable(destCompData[0].isSmashable);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
SetHealth(1);
|
||||
SetImagination(0);
|
||||
SetArmor(0);
|
||||
@@ -102,65 +101,65 @@ void DestroyableComponent::Reinitialize(LOT templateID) {
|
||||
}
|
||||
|
||||
void DestroyableComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, uint32_t& flags) {
|
||||
if (bIsInitialUpdate) {
|
||||
outBitStream->Write0(); //Contains info about immunities this object has, but it's left out for now.
|
||||
}
|
||||
if (bIsInitialUpdate) {
|
||||
outBitStream->Write0(); //Contains info about immunities this object has, but it's left out for now.
|
||||
}
|
||||
|
||||
outBitStream->Write(m_DirtyHealth || bIsInitialUpdate);
|
||||
if (m_DirtyHealth || bIsInitialUpdate) {
|
||||
outBitStream->Write(m_iHealth);
|
||||
outBitStream->Write(m_fMaxHealth);
|
||||
outBitStream->Write(m_iArmor);
|
||||
outBitStream->Write(m_fMaxArmor);
|
||||
outBitStream->Write(m_iImagination);
|
||||
outBitStream->Write(m_fMaxImagination);
|
||||
outBitStream->Write(m_DirtyHealth || bIsInitialUpdate);
|
||||
if (m_DirtyHealth || bIsInitialUpdate) {
|
||||
outBitStream->Write(m_iHealth);
|
||||
outBitStream->Write(m_fMaxHealth);
|
||||
outBitStream->Write(m_iArmor);
|
||||
outBitStream->Write(m_fMaxArmor);
|
||||
outBitStream->Write(m_iImagination);
|
||||
outBitStream->Write(m_fMaxImagination);
|
||||
|
||||
outBitStream->Write(m_DamageToAbsorb);
|
||||
outBitStream->Write(IsImmune());
|
||||
outBitStream->Write(m_IsGMImmune);
|
||||
outBitStream->Write(m_IsShielded);
|
||||
outBitStream->Write(m_DamageToAbsorb);
|
||||
outBitStream->Write(IsImmune());
|
||||
outBitStream->Write(m_IsGMImmune);
|
||||
outBitStream->Write(m_IsShielded);
|
||||
|
||||
outBitStream->Write(m_fMaxHealth);
|
||||
outBitStream->Write(m_fMaxArmor);
|
||||
outBitStream->Write(m_fMaxImagination);
|
||||
outBitStream->Write(m_fMaxHealth);
|
||||
outBitStream->Write(m_fMaxArmor);
|
||||
outBitStream->Write(m_fMaxImagination);
|
||||
|
||||
outBitStream->Write(uint32_t(m_FactionIDs.size()));
|
||||
for (size_t i = 0; i < m_FactionIDs.size(); ++i) {
|
||||
outBitStream->Write(m_FactionIDs[i]);
|
||||
}
|
||||
|
||||
outBitStream->Write(m_IsSmashable);
|
||||
outBitStream->Write(m_IsSmashable);
|
||||
|
||||
if (bIsInitialUpdate) {
|
||||
outBitStream->Write(m_IsDead);
|
||||
outBitStream->Write(m_IsSmashed);
|
||||
if (bIsInitialUpdate) {
|
||||
outBitStream->Write(m_IsDead);
|
||||
outBitStream->Write(m_IsSmashed);
|
||||
|
||||
if (m_IsSmashable) {
|
||||
outBitStream->Write(m_HasBricks);
|
||||
if (m_IsSmashable) {
|
||||
outBitStream->Write(m_HasBricks);
|
||||
|
||||
if (m_ExplodeFactor != 1.0f) {
|
||||
outBitStream->Write1();
|
||||
outBitStream->Write(m_ExplodeFactor);
|
||||
} else {
|
||||
outBitStream->Write0();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m_ExplodeFactor != 1.0f) {
|
||||
outBitStream->Write1();
|
||||
outBitStream->Write(m_ExplodeFactor);
|
||||
} else {
|
||||
outBitStream->Write0();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_DirtyHealth = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_DirtyThreatList || bIsInitialUpdate) {
|
||||
outBitStream->Write1();
|
||||
outBitStream->Write(m_HasThreats);
|
||||
if (m_DirtyThreatList || bIsInitialUpdate) {
|
||||
outBitStream->Write1();
|
||||
outBitStream->Write(m_HasThreats);
|
||||
m_DirtyThreatList = false;
|
||||
} else {
|
||||
outBitStream->Write0();
|
||||
}
|
||||
} else {
|
||||
outBitStream->Write0();
|
||||
}
|
||||
}
|
||||
|
||||
void DestroyableComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
|
||||
tinyxml2::XMLElement* dest = doc->FirstChildElement("obj")->FirstChildElement("dest");
|
||||
tinyxml2::XMLElement* dest = doc->FirstChildElement("obj")->FirstChildElement("dest");
|
||||
if (!dest) {
|
||||
Game::logger->Log("DestroyableComponent", "Failed to find dest tag!");
|
||||
return;
|
||||
@@ -173,16 +172,16 @@ void DestroyableComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
|
||||
}
|
||||
|
||||
dest->QueryAttribute("hc", &m_iHealth);
|
||||
dest->QueryAttribute("hm", &m_fMaxHealth);
|
||||
dest->QueryAttribute("im", &m_fMaxImagination);
|
||||
dest->QueryAttribute("ic", &m_iImagination);
|
||||
dest->QueryAttribute("ac", &m_iArmor);
|
||||
dest->QueryAttribute("am", &m_fMaxArmor);
|
||||
m_DirtyHealth = true;
|
||||
dest->QueryAttribute("hm", &m_fMaxHealth);
|
||||
dest->QueryAttribute("im", &m_fMaxImagination);
|
||||
dest->QueryAttribute("ic", &m_iImagination);
|
||||
dest->QueryAttribute("ac", &m_iArmor);
|
||||
dest->QueryAttribute("am", &m_fMaxArmor);
|
||||
m_DirtyHealth = true;
|
||||
}
|
||||
|
||||
void DestroyableComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
|
||||
tinyxml2::XMLElement* dest = doc->FirstChildElement("obj")->FirstChildElement("dest");
|
||||
tinyxml2::XMLElement* dest = doc->FirstChildElement("obj")->FirstChildElement("dest");
|
||||
if (!dest) {
|
||||
Game::logger->Log("DestroyableComponent", "Failed to find dest tag!");
|
||||
return;
|
||||
@@ -195,11 +194,11 @@ void DestroyableComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
|
||||
}
|
||||
|
||||
dest->SetAttribute("hc", m_iHealth);
|
||||
dest->SetAttribute("hm", m_fMaxHealth);
|
||||
dest->SetAttribute("im", m_fMaxImagination);
|
||||
dest->SetAttribute("ic", m_iImagination);
|
||||
dest->SetAttribute("ac", m_iArmor);
|
||||
dest->SetAttribute("am", m_fMaxArmor);
|
||||
dest->SetAttribute("hm", m_fMaxHealth);
|
||||
dest->SetAttribute("im", m_fMaxImagination);
|
||||
dest->SetAttribute("ic", m_iImagination);
|
||||
dest->SetAttribute("ac", m_iArmor);
|
||||
dest->SetAttribute("am", m_fMaxArmor);
|
||||
}
|
||||
|
||||
void DestroyableComponent::SetHealth(int32_t value) {
|
||||
@@ -207,7 +206,7 @@ void DestroyableComponent::SetHealth(int32_t value) {
|
||||
|
||||
auto* characterComponent = m_Parent->GetComponent<CharacterComponent>();
|
||||
if (characterComponent != nullptr) {
|
||||
characterComponent->TrackHealthDelta(value - m_iHealth);
|
||||
characterComponent->TrackHealthDelta(value - m_iHealth);
|
||||
}
|
||||
|
||||
m_iHealth = value;
|
||||
@@ -242,17 +241,17 @@ void DestroyableComponent::SetMaxHealth(float value, bool playAnim) {
|
||||
}
|
||||
|
||||
void DestroyableComponent::SetArmor(int32_t value) {
|
||||
m_DirtyHealth = true;
|
||||
m_DirtyHealth = true;
|
||||
|
||||
// If Destroyable Component already has zero armor do not trigger the passive ability again.
|
||||
bool hadArmor = m_iArmor > 0;
|
||||
|
||||
auto* characterComponent = m_Parent->GetComponent<CharacterComponent>();
|
||||
if (characterComponent != nullptr) {
|
||||
characterComponent->TrackArmorDelta(value - m_iArmor);
|
||||
}
|
||||
auto* characterComponent = m_Parent->GetComponent<CharacterComponent>();
|
||||
if (characterComponent != nullptr) {
|
||||
characterComponent->TrackArmorDelta(value - m_iArmor);
|
||||
}
|
||||
|
||||
m_iArmor = value;
|
||||
m_iArmor = value;
|
||||
|
||||
auto* inventroyComponent = m_Parent->GetComponent<InventoryComponent>();
|
||||
if (m_iArmor == 0 && inventroyComponent != nullptr && hadArmor) {
|
||||
@@ -261,8 +260,8 @@ void DestroyableComponent::SetArmor(int32_t value) {
|
||||
}
|
||||
|
||||
void DestroyableComponent::SetMaxArmor(float value, bool playAnim) {
|
||||
m_DirtyHealth = true;
|
||||
m_fMaxArmor = value;
|
||||
m_DirtyHealth = true;
|
||||
m_fMaxArmor = value;
|
||||
|
||||
if (m_iArmor > m_fMaxArmor) {
|
||||
m_iArmor = m_fMaxArmor;
|
||||
@@ -287,14 +286,14 @@ void DestroyableComponent::SetMaxArmor(float value, bool playAnim) {
|
||||
}
|
||||
|
||||
void DestroyableComponent::SetImagination(int32_t value) {
|
||||
m_DirtyHealth = true;
|
||||
m_DirtyHealth = true;
|
||||
|
||||
auto* characterComponent = m_Parent->GetComponent<CharacterComponent>();
|
||||
if (characterComponent != nullptr) {
|
||||
characterComponent->TrackImaginationDelta(value - m_iImagination);
|
||||
}
|
||||
auto* characterComponent = m_Parent->GetComponent<CharacterComponent>();
|
||||
if (characterComponent != nullptr) {
|
||||
characterComponent->TrackImaginationDelta(value - m_iImagination);
|
||||
}
|
||||
|
||||
m_iImagination = value;
|
||||
m_iImagination = value;
|
||||
|
||||
auto* inventroyComponent = m_Parent->GetComponent<InventoryComponent>();
|
||||
if (m_iImagination == 0 && inventroyComponent != nullptr) {
|
||||
@@ -303,10 +302,10 @@ void DestroyableComponent::SetImagination(int32_t value) {
|
||||
}
|
||||
|
||||
void DestroyableComponent::SetMaxImagination(float value, bool playAnim) {
|
||||
m_DirtyHealth = true;
|
||||
m_DirtyHealth = true;
|
||||
// Used for playAnim if opted in for.
|
||||
int32_t difference = static_cast<int32_t>(std::abs(m_fMaxImagination - value));
|
||||
m_fMaxImagination = value;
|
||||
m_fMaxImagination = value;
|
||||
|
||||
if (m_iImagination > m_fMaxImagination) {
|
||||
m_iImagination = m_fMaxImagination;
|
||||
@@ -329,32 +328,27 @@ void DestroyableComponent::SetMaxImagination(float value, bool playAnim) {
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
void DestroyableComponent::SetDamageToAbsorb(int32_t value)
|
||||
{
|
||||
void DestroyableComponent::SetDamageToAbsorb(int32_t value) {
|
||||
m_DirtyHealth = true;
|
||||
m_DamageToAbsorb = value;
|
||||
}
|
||||
|
||||
void DestroyableComponent::SetDamageReduction(int32_t value)
|
||||
{
|
||||
void DestroyableComponent::SetDamageReduction(int32_t value) {
|
||||
m_DirtyHealth = true;
|
||||
m_DamageReduction = value;
|
||||
}
|
||||
|
||||
void DestroyableComponent::SetIsImmune(bool value)
|
||||
{
|
||||
void DestroyableComponent::SetIsImmune(bool value) {
|
||||
m_DirtyHealth = true;
|
||||
m_ImmuneStacks = value ? 1 : 0;
|
||||
}
|
||||
|
||||
void DestroyableComponent::SetIsGMImmune(bool value)
|
||||
{
|
||||
void DestroyableComponent::SetIsGMImmune(bool value) {
|
||||
m_DirtyHealth = true;
|
||||
m_IsGMImmune = value;
|
||||
}
|
||||
|
||||
void DestroyableComponent::SetIsShielded(bool value)
|
||||
{
|
||||
void DestroyableComponent::SetIsShielded(bool value) {
|
||||
m_DirtyHealth = true;
|
||||
m_IsShielded = value;
|
||||
}
|
||||
@@ -365,12 +359,12 @@ void DestroyableComponent::AddFaction(const int32_t factionID, const bool ignore
|
||||
return;
|
||||
}
|
||||
|
||||
m_FactionIDs.push_back(factionID);
|
||||
m_DirtyHealth = true;
|
||||
m_FactionIDs.push_back(factionID);
|
||||
m_DirtyHealth = true;
|
||||
|
||||
auto query = CDClientDatabase::CreatePreppedStmt(
|
||||
"SELECT enemyList FROM Factions WHERE faction = ?;");
|
||||
query.bind(1, (int) factionID);
|
||||
query.bind(1, (int)factionID);
|
||||
|
||||
auto result = query.execQuery();
|
||||
|
||||
@@ -390,13 +384,11 @@ void DestroyableComponent::AddFaction(const int32_t factionID, const bool ignore
|
||||
|
||||
auto exclude = std::find(m_FactionIDs.begin(), m_FactionIDs.end(), id) != m_FactionIDs.end();
|
||||
|
||||
if (!exclude)
|
||||
{
|
||||
if (!exclude) {
|
||||
exclude = std::find(m_EnemyFactionIDs.begin(), m_EnemyFactionIDs.end(), id) != m_EnemyFactionIDs.end();
|
||||
}
|
||||
|
||||
if (exclude)
|
||||
{
|
||||
if (exclude) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -406,60 +398,56 @@ void DestroyableComponent::AddFaction(const int32_t factionID, const bool ignore
|
||||
result.finalize();
|
||||
}
|
||||
|
||||
bool DestroyableComponent::IsEnemy (const Entity* other) const {
|
||||
const auto* otherDestroyableComponent = other->GetComponent<DestroyableComponent>();
|
||||
if (otherDestroyableComponent != nullptr) {
|
||||
for (const auto enemyFaction : m_EnemyFactionIDs) {
|
||||
for (const auto otherFaction : otherDestroyableComponent->GetFactionIDs()) {
|
||||
if (enemyFaction == otherFaction)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
bool DestroyableComponent::IsEnemy(const Entity* other) const {
|
||||
const auto* otherDestroyableComponent = other->GetComponent<DestroyableComponent>();
|
||||
if (otherDestroyableComponent != nullptr) {
|
||||
for (const auto enemyFaction : m_EnemyFactionIDs) {
|
||||
for (const auto otherFaction : otherDestroyableComponent->GetFactionIDs()) {
|
||||
if (enemyFaction == otherFaction)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DestroyableComponent::IsFriend (const Entity* other) const {
|
||||
const auto* otherDestroyableComponent = other->GetComponent<DestroyableComponent>();
|
||||
if (otherDestroyableComponent != nullptr) {
|
||||
for (const auto enemyFaction : m_EnemyFactionIDs) {
|
||||
for (const auto otherFaction : otherDestroyableComponent->GetFactionIDs()) {
|
||||
if (enemyFaction == otherFaction)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
bool DestroyableComponent::IsFriend(const Entity* other) const {
|
||||
const auto* otherDestroyableComponent = other->GetComponent<DestroyableComponent>();
|
||||
if (otherDestroyableComponent != nullptr) {
|
||||
for (const auto enemyFaction : m_EnemyFactionIDs) {
|
||||
for (const auto otherFaction : otherDestroyableComponent->GetFactionIDs()) {
|
||||
if (enemyFaction == otherFaction)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
void DestroyableComponent::AddEnemyFaction(int32_t factionID)
|
||||
{
|
||||
void DestroyableComponent::AddEnemyFaction(int32_t factionID) {
|
||||
m_EnemyFactionIDs.push_back(factionID);
|
||||
}
|
||||
|
||||
|
||||
void DestroyableComponent::SetIsSmashable(bool value) {
|
||||
m_DirtyHealth = true;
|
||||
m_IsSmashable = value;
|
||||
//m_HasBricks = value;
|
||||
m_DirtyHealth = true;
|
||||
m_IsSmashable = value;
|
||||
//m_HasBricks = value;
|
||||
}
|
||||
|
||||
void DestroyableComponent::SetAttacksToBlock(const uint32_t value)
|
||||
{
|
||||
void DestroyableComponent::SetAttacksToBlock(const uint32_t value) {
|
||||
m_AttacksToBlock = value;
|
||||
}
|
||||
|
||||
bool DestroyableComponent::IsImmune() const
|
||||
{
|
||||
bool DestroyableComponent::IsImmune() const {
|
||||
return m_ImmuneStacks > 0 || m_IsGMImmune;
|
||||
}
|
||||
|
||||
bool DestroyableComponent::IsKnockbackImmune() const
|
||||
{
|
||||
bool DestroyableComponent::IsKnockbackImmune() const {
|
||||
auto* characterComponent = m_Parent->GetComponent<CharacterComponent>();
|
||||
auto* inventoryComponent = m_Parent->GetComponent<InventoryComponent>();
|
||||
|
||||
@@ -468,7 +456,7 @@ bool DestroyableComponent::IsKnockbackImmune() const
|
||||
ItemSetPassiveAbilityID::EngineerRank2, ItemSetPassiveAbilityID::EngineerRank3,
|
||||
ItemSetPassiveAbilityID::SummonerRank2, ItemSetPassiveAbilityID::SummonerRank3,
|
||||
ItemSetPassiveAbilityID::InventorRank2, ItemSetPassiveAbilityID::InventorRank3,
|
||||
}, 5);
|
||||
}, 5);
|
||||
|
||||
if (hasPassive) {
|
||||
return true;
|
||||
@@ -478,52 +466,43 @@ bool DestroyableComponent::IsKnockbackImmune() const
|
||||
return IsImmune() || m_IsShielded || m_AttacksToBlock > 0;
|
||||
}
|
||||
|
||||
bool DestroyableComponent::HasFaction(int32_t factionID) const
|
||||
{
|
||||
bool DestroyableComponent::HasFaction(int32_t factionID) const {
|
||||
return std::find(m_FactionIDs.begin(), m_FactionIDs.end(), factionID) != m_FactionIDs.end();
|
||||
}
|
||||
|
||||
LWOOBJID DestroyableComponent::GetKillerID() const
|
||||
{
|
||||
LWOOBJID DestroyableComponent::GetKillerID() const {
|
||||
return m_KillerID;
|
||||
}
|
||||
|
||||
Entity* DestroyableComponent::GetKiller() const
|
||||
{
|
||||
Entity* DestroyableComponent::GetKiller() const {
|
||||
return EntityManager::Instance()->GetEntity(m_KillerID);
|
||||
}
|
||||
|
||||
bool DestroyableComponent::CheckValidity(const LWOOBJID target, const bool ignoreFactions, const bool targetEnemy, const bool targetFriend) const
|
||||
{
|
||||
bool DestroyableComponent::CheckValidity(const LWOOBJID target, const bool ignoreFactions, const bool targetEnemy, const bool targetFriend) const {
|
||||
auto* targetEntity = EntityManager::Instance()->GetEntity(target);
|
||||
|
||||
if (targetEntity == nullptr)
|
||||
{
|
||||
if (targetEntity == nullptr) {
|
||||
Game::logger->Log("DestroyableComponent", "Invalid entity for checking validity (%llu)!", target);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto* targetDestroyable = targetEntity->GetComponent<DestroyableComponent>();
|
||||
|
||||
if (targetDestroyable == nullptr)
|
||||
{
|
||||
if (targetDestroyable == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto* targetQuickbuild = targetEntity->GetComponent<RebuildComponent>();
|
||||
|
||||
if (targetQuickbuild != nullptr)
|
||||
{
|
||||
if (targetQuickbuild != nullptr) {
|
||||
const auto state = targetQuickbuild->GetState();
|
||||
|
||||
if (state != REBUILD_COMPLETED)
|
||||
{
|
||||
if (state != REBUILD_COMPLETED) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (ignoreFactions)
|
||||
{
|
||||
if (ignoreFactions) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -536,8 +515,7 @@ bool DestroyableComponent::CheckValidity(const LWOOBJID target, const bool ignor
|
||||
}
|
||||
|
||||
|
||||
void DestroyableComponent::Heal(const uint32_t health)
|
||||
{
|
||||
void DestroyableComponent::Heal(const uint32_t health) {
|
||||
auto current = static_cast<uint32_t>(GetHealth());
|
||||
const auto max = static_cast<uint32_t>(GetMaxHealth());
|
||||
|
||||
@@ -551,8 +529,7 @@ void DestroyableComponent::Heal(const uint32_t health)
|
||||
}
|
||||
|
||||
|
||||
void DestroyableComponent::Imagine(const int32_t deltaImagination)
|
||||
{
|
||||
void DestroyableComponent::Imagine(const int32_t deltaImagination) {
|
||||
auto current = static_cast<int32_t>(GetImagination());
|
||||
const auto max = static_cast<int32_t>(GetMaxImagination());
|
||||
|
||||
@@ -560,8 +537,7 @@ void DestroyableComponent::Imagine(const int32_t deltaImagination)
|
||||
|
||||
current = std::min(current, max);
|
||||
|
||||
if (current < 0)
|
||||
{
|
||||
if (current < 0) {
|
||||
current = 0;
|
||||
}
|
||||
|
||||
@@ -571,8 +547,7 @@ void DestroyableComponent::Imagine(const int32_t deltaImagination)
|
||||
}
|
||||
|
||||
|
||||
void DestroyableComponent::Repair(const uint32_t armor)
|
||||
{
|
||||
void DestroyableComponent::Repair(const uint32_t armor) {
|
||||
auto current = static_cast<uint32_t>(GetArmor());
|
||||
const auto max = static_cast<uint32_t>(GetMaxArmor());
|
||||
|
||||
@@ -586,34 +561,26 @@ void DestroyableComponent::Repair(const uint32_t armor)
|
||||
}
|
||||
|
||||
|
||||
void DestroyableComponent::Damage(uint32_t damage, const LWOOBJID source, uint32_t skillID, bool echo)
|
||||
{
|
||||
if (GetHealth() <= 0)
|
||||
{
|
||||
void DestroyableComponent::Damage(uint32_t damage, const LWOOBJID source, uint32_t skillID, bool echo) {
|
||||
if (GetHealth() <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsImmune())
|
||||
{
|
||||
if (IsImmune()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_AttacksToBlock > 0)
|
||||
{
|
||||
if (m_AttacksToBlock > 0) {
|
||||
m_AttacksToBlock--;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// If this entity has damage reduction, reduce the damage to a minimum of 1
|
||||
if (m_DamageReduction > 0 && damage > 0)
|
||||
{
|
||||
if (damage > m_DamageReduction)
|
||||
{
|
||||
if (m_DamageReduction > 0 && damage > 0) {
|
||||
if (damage > m_DamageReduction) {
|
||||
damage -= m_DamageReduction;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
damage = 1;
|
||||
}
|
||||
}
|
||||
@@ -641,13 +608,11 @@ void DestroyableComponent::Damage(uint32_t damage, const LWOOBJID source, uint32
|
||||
SetHealth(health);
|
||||
SetIsShielded(absorb > 0);
|
||||
|
||||
if (m_Parent->GetLOT() != 1)
|
||||
{
|
||||
if (m_Parent->GetLOT() != 1) {
|
||||
echo = true;
|
||||
}
|
||||
|
||||
if (echo)
|
||||
{
|
||||
if (echo) {
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
@@ -656,15 +621,13 @@ void DestroyableComponent::Damage(uint32_t damage, const LWOOBJID source, uint32
|
||||
m_Parent->OnHitOrHealResult(attacker, sourceDamage);
|
||||
|
||||
for (const auto& cb : m_OnHitCallbacks) {
|
||||
cb(attacker);
|
||||
cb(attacker);
|
||||
}
|
||||
|
||||
if (health != 0)
|
||||
{
|
||||
if (health != 0) {
|
||||
auto* combatComponent = m_Parent->GetComponent<BaseCombatAIComponent>();
|
||||
|
||||
if (combatComponent != nullptr)
|
||||
{
|
||||
if (combatComponent != nullptr) {
|
||||
combatComponent->Taunt(source, sourceDamage * 10); // * 10 is arbatrary
|
||||
}
|
||||
|
||||
@@ -673,10 +636,8 @@ void DestroyableComponent::Damage(uint32_t damage, const LWOOBJID source, uint32
|
||||
Smash(source, eKillType::VIOLENT, u"", skillID);
|
||||
}
|
||||
|
||||
void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType, const std::u16string& deathType, uint32_t skillID)
|
||||
{
|
||||
if (m_iHealth > 0)
|
||||
{
|
||||
void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType, const std::u16string& deathType, uint32_t skillID) {
|
||||
if (m_iHealth > 0) {
|
||||
SetArmor(0);
|
||||
SetHealth(0);
|
||||
|
||||
@@ -687,8 +648,7 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType
|
||||
|
||||
auto* owner = EntityManager::Instance()->GetEntity(source);
|
||||
|
||||
if (owner != nullptr)
|
||||
{
|
||||
if (owner != nullptr) {
|
||||
owner = owner->GetOwner(); // If the owner is overwritten, we collect that here
|
||||
|
||||
auto* team = TeamManager::Instance()->GetTeam(owner->GetObjectID());
|
||||
@@ -697,19 +657,15 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType
|
||||
|
||||
auto* inventoryComponent = owner->GetComponent<InventoryComponent>();
|
||||
|
||||
if (inventoryComponent != nullptr && isEnemy)
|
||||
{
|
||||
if (inventoryComponent != nullptr && isEnemy) {
|
||||
inventoryComponent->TriggerPassiveAbility(PassiveAbilityTrigger::EnemySmashed);
|
||||
}
|
||||
|
||||
auto* missions = owner->GetComponent<MissionComponent>();
|
||||
|
||||
if (missions != nullptr)
|
||||
{
|
||||
if (team != nullptr && isEnemy)
|
||||
{
|
||||
for (const auto memberId : team->members)
|
||||
{
|
||||
if (missions != nullptr) {
|
||||
if (team != nullptr && isEnemy) {
|
||||
for (const auto memberId : team->members) {
|
||||
auto* member = EntityManager::Instance()->GetEntity(memberId);
|
||||
|
||||
if (member == nullptr) continue;
|
||||
@@ -721,9 +677,7 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType
|
||||
memberMissions->Progress(MissionTaskType::MISSION_TASK_TYPE_SMASH, m_Parent->GetLOT());
|
||||
memberMissions->Progress(MissionTaskType::MISSION_TASK_TYPE_SKILL, m_Parent->GetLOT(), skillID);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
missions->Progress(MissionTaskType::MISSION_TASK_TYPE_SMASH, m_Parent->GetLOT());
|
||||
missions->Progress(MissionTaskType::MISSION_TASK_TYPE_SKILL, m_Parent->GetLOT(), skillID);
|
||||
}
|
||||
@@ -735,14 +689,11 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType
|
||||
GameMessages::SendDie(m_Parent, source, source, true, killType, deathType, 0, 0, 0, isPlayer, false, 1);
|
||||
|
||||
//NANI?!
|
||||
if (!isPlayer)
|
||||
{
|
||||
if (owner != nullptr)
|
||||
{
|
||||
if (!isPlayer) {
|
||||
if (owner != nullptr) {
|
||||
auto* team = TeamManager::Instance()->GetTeam(owner->GetObjectID());
|
||||
|
||||
if (team != nullptr && m_Parent->GetComponent<BaseCombatAIComponent>() != nullptr)
|
||||
{
|
||||
if (team != nullptr && m_Parent->GetComponent<BaseCombatAIComponent>() != nullptr) {
|
||||
LWOOBJID specificOwner = LWOOBJID_EMPTY;
|
||||
auto* scriptedActivityComponent = m_Parent->GetComponent<ScriptedActivityComponent>();
|
||||
uint32_t teamSize = team->members.size();
|
||||
@@ -757,9 +708,8 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType
|
||||
|
||||
auto* member = EntityManager::Instance()->GetEntity(specificOwner);
|
||||
|
||||
if (member) LootGenerator::Instance().DropLoot(member, m_Parent, lootMatrixId, GetMinCoins(), GetMaxCoins());
|
||||
}
|
||||
else {
|
||||
if (member) LootGenerator::Instance().DropLoot(member, m_Parent, lootMatrixId, GetMinCoins(), GetMaxCoins());
|
||||
} else {
|
||||
for (const auto memberId : team->members) { // Free for all
|
||||
auto* member = EntityManager::Instance()->GetEntity(memberId);
|
||||
|
||||
@@ -768,32 +718,25 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType
|
||||
LootGenerator::Instance().DropLoot(member, m_Parent, lootMatrixId, GetMinCoins(), GetMaxCoins());
|
||||
}
|
||||
}
|
||||
}
|
||||
else { // drop loot for non team user
|
||||
} else { // drop loot for non team user
|
||||
LootGenerator::Instance().DropLoot(owner, m_Parent, GetLootMatrixID(), GetMinCoins(), GetMaxCoins());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
//Check if this zone allows coin drops
|
||||
if (dZoneManager::Instance()->GetPlayerLoseCoinOnDeath())
|
||||
{
|
||||
if (dZoneManager::Instance()->GetPlayerLoseCoinOnDeath()) {
|
||||
auto* character = m_Parent->GetCharacter();
|
||||
uint64_t coinsTotal = character->GetCoins();
|
||||
|
||||
if (coinsTotal > 0)
|
||||
{
|
||||
if (coinsTotal > 0) {
|
||||
uint64_t coinsToLoose = 1;
|
||||
|
||||
if (coinsTotal >= 200)
|
||||
{
|
||||
if (coinsTotal >= 200) {
|
||||
float hundreth = (coinsTotal / 100.0f);
|
||||
coinsToLoose = static_cast<int>(hundreth);
|
||||
}
|
||||
|
||||
if (coinsToLoose > 10000)
|
||||
{
|
||||
if (coinsToLoose > 10000) {
|
||||
coinsToLoose = 10000;
|
||||
}
|
||||
|
||||
@@ -804,19 +747,19 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType
|
||||
}
|
||||
}
|
||||
|
||||
Entity* zoneControl = EntityManager::Instance()->GetZoneControlEntity();
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(zoneControl)) {
|
||||
script->OnPlayerDied(zoneControl, m_Parent);
|
||||
}
|
||||
Entity* zoneControl = EntityManager::Instance()->GetZoneControlEntity();
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(zoneControl)) {
|
||||
script->OnPlayerDied(zoneControl, m_Parent);
|
||||
}
|
||||
|
||||
std::vector<Entity*> scriptedActs = EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_SCRIPTED_ACTIVITY);
|
||||
for (Entity* scriptEntity : scriptedActs) {
|
||||
if (scriptEntity->GetObjectID() != zoneControl->GetObjectID()) { // Don't want to trigger twice on instance worlds
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(scriptEntity)) {
|
||||
script->OnPlayerDied(scriptEntity, m_Parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
std::vector<Entity*> scriptedActs = EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_SCRIPTED_ACTIVITY);
|
||||
for (Entity* scriptEntity : scriptedActs) {
|
||||
if (scriptEntity->GetObjectID() != zoneControl->GetObjectID()) { // Don't want to trigger twice on instance worlds
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(scriptEntity)) {
|
||||
script->OnPlayerDied(scriptEntity, m_Parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_Parent->Kill(owner);
|
||||
@@ -829,18 +772,15 @@ void DestroyableComponent::SetFaction(int32_t factionID, bool ignoreChecks) {
|
||||
AddFaction(factionID, ignoreChecks);
|
||||
}
|
||||
|
||||
void DestroyableComponent::PushImmunity(int32_t stacks)
|
||||
{
|
||||
void DestroyableComponent::PushImmunity(int32_t stacks) {
|
||||
m_ImmuneStacks += stacks;
|
||||
}
|
||||
|
||||
void DestroyableComponent::PopImmunity(int32_t stacks)
|
||||
{
|
||||
void DestroyableComponent::PopImmunity(int32_t stacks) {
|
||||
m_ImmuneStacks -= stacks;
|
||||
}
|
||||
|
||||
void DestroyableComponent::FixStats()
|
||||
{
|
||||
void DestroyableComponent::FixStats() {
|
||||
auto* entity = GetParent();
|
||||
|
||||
if (entity == nullptr) return;
|
||||
@@ -853,8 +793,7 @@ void DestroyableComponent::FixStats()
|
||||
auto* destroyableComponent = entity->GetComponent<DestroyableComponent>();
|
||||
|
||||
// If any of the components are nullptr, return
|
||||
if (skillComponent == nullptr || buffComponent == nullptr || missionComponent == nullptr || inventoryComponent == nullptr || destroyableComponent == nullptr)
|
||||
{
|
||||
if (skillComponent == nullptr || buffComponent == nullptr || missionComponent == nullptr || inventoryComponent == nullptr || destroyableComponent == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -866,13 +805,11 @@ void DestroyableComponent::FixStats()
|
||||
// Unequip all items
|
||||
auto equipped = inventoryComponent->GetEquippedItems();
|
||||
|
||||
for (auto& equippedItem : equipped)
|
||||
{
|
||||
for (auto& equippedItem : equipped) {
|
||||
// Get the item with the item ID
|
||||
auto* item = inventoryComponent->FindItemById(equippedItem.second.id);
|
||||
|
||||
if (item == nullptr)
|
||||
{
|
||||
if (item == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -886,12 +823,10 @@ void DestroyableComponent::FixStats()
|
||||
int32_t maxImagination = 0;
|
||||
|
||||
// Go through all completed missions and add the reward stats
|
||||
for (auto& pair : missionComponent->GetMissions())
|
||||
{
|
||||
for (auto& pair : missionComponent->GetMissions()) {
|
||||
auto* mission = pair.second;
|
||||
|
||||
if (!mission->IsComplete())
|
||||
{
|
||||
if (!mission->IsComplete()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -911,13 +846,11 @@ void DestroyableComponent::FixStats()
|
||||
buffComponent->ReApplyBuffs();
|
||||
|
||||
// Requip all items
|
||||
for (auto& equippedItem : equipped)
|
||||
{
|
||||
for (auto& equippedItem : equipped) {
|
||||
// Get the item with the item ID
|
||||
auto* item = inventoryComponent->FindItemById(equippedItem.second.id);
|
||||
|
||||
if (item == nullptr)
|
||||
{
|
||||
if (item == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -945,5 +878,5 @@ void DestroyableComponent::FixStats()
|
||||
}
|
||||
|
||||
void DestroyableComponent::AddOnHitCallback(const std::function<void(Entity*)>& callback) {
|
||||
m_OnHitCallbacks.push_back(callback);
|
||||
m_OnHitCallbacks.push_back(callback);
|
||||
}
|
||||
|
Reference in New Issue
Block a user