From 0c32be01baab5d2169620865abc0629d675636fb Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Sat, 25 Nov 2023 20:50:20 -0800 Subject: [PATCH 01/12] fix: nexus tower smashable (#1320) --- dGame/Entity.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index 0f8e9351..23bf0577 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -554,6 +554,12 @@ void Entity::Initialize() { Loot::CacheMatrix(activityID); } + const auto timeBeforeSmash = GetVar(u"tmeSmsh"); + + if (timeBeforeSmash > 0) { + rebuildComponent->SetTimeBeforeSmash(timeBeforeSmash); + } + const auto compTime = GetVar(u"compTime"); if (compTime > 0) { From a1f8ab763d5f8bbfdef692c4979067c8b6f942c9 Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Sat, 25 Nov 2023 20:50:28 -0800 Subject: [PATCH 02/12] Entity: Fix death behavior of 0 (#1319) --- dGame/Entity.cpp | 4 ++-- dGame/Entity.h | 2 +- dGame/dComponents/DestroyableComponent.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index 23bf0577..4d4f5c10 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -1509,7 +1509,7 @@ void Entity::Smash(const LWOOBJID source, const eKillType killType, const std::u destroyableComponent->Smash(source, killType, deathType); } -void Entity::Kill(Entity* murderer) { +void Entity::Kill(Entity* murderer, const eKillType killType) { if (!m_PlayerIsReadyForUpdates) return; for (const auto& cb : m_DieCallbacks) { @@ -1533,7 +1533,7 @@ void Entity::Kill(Entity* murderer) { bool waitForDeathAnimation = false; if (destroyableComponent) { - waitForDeathAnimation = destroyableComponent->GetDeathBehavior() == 0; + waitForDeathAnimation = destroyableComponent->GetDeathBehavior() == 0 && killType != eKillType::SILENT; } // Live waited a hard coded 12 seconds for death animations of type 0 before networking destruction! diff --git a/dGame/Entity.h b/dGame/Entity.h index a5588c3e..cdc26838 100644 --- a/dGame/Entity.h +++ b/dGame/Entity.h @@ -210,7 +210,7 @@ public: void RequestActivityExit(Entity* sender, LWOOBJID player, bool canceled); void Smash(const LWOOBJID source = LWOOBJID_EMPTY, const eKillType killType = eKillType::VIOLENT, const std::u16string& deathType = u""); - void Kill(Entity* murderer = nullptr); + void Kill(Entity* murderer = nullptr, const eKillType killType = eKillType::SILENT); void AddRebuildCompleteCallback(const std::function& callback) const; void AddCollisionPhantomCallback(const std::function& callback); void AddDieCallback(const std::function& callback); diff --git a/dGame/dComponents/DestroyableComponent.cpp b/dGame/dComponents/DestroyableComponent.cpp index e98bc33b..ce3743e8 100644 --- a/dGame/dComponents/DestroyableComponent.cpp +++ b/dGame/dComponents/DestroyableComponent.cpp @@ -796,7 +796,7 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType } } - m_Parent->Kill(owner); + m_Parent->Kill(owner, killType); } void DestroyableComponent::SetFaction(int32_t factionID, bool ignoreChecks) { From 3df3552467a0dc1b014e53c5b4f3e07320e9d65d Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sun, 26 Nov 2023 16:30:39 -0600 Subject: [PATCH 03/12] fix: respawn rotation (#1323) * fixed respawn rotation * even though the condensed calls work, splitting em --- dGame/dGameMessages/GameMessages.cpp | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index 34b031d3..b506e3a0 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -944,14 +944,7 @@ void GameMessages::SendResurrect(Entity* entity) { destroyableComponent->SetImagination(imaginationToRestore); } } - }); - - - auto cont = static_cast(entity->GetComponent(eReplicaComponentType::CONTROLLABLE_PHYSICS)); - if (cont && entity->GetLOT() == 1) { - cont->SetPosition(entity->GetRespawnPosition()); - cont->SetRotation(entity->GetRespawnRotation()); - } + }); CBITSTREAM; CMSGHEADER; @@ -1144,18 +1137,16 @@ void GameMessages::SendPlayerReachedRespawnCheckpoint(Entity* entity, const NiPo bitStream.Write(position.y); bitStream.Write(position.z); - auto con = static_cast(entity->GetComponent(eReplicaComponentType::CONTROLLABLE_PHYSICS)); - if (con) { - auto rot = con->GetRotation(); - bitStream.Write(rot.x); - bitStream.Write(rot.y); - bitStream.Write(rot.z); - bitStream.Write(rot.w); + const bool isNotIdentity = rotation != NiQuaternion::IDENTITY; + bitStream.Write(isNotIdentity); + + if (isNotIdentity) { + bitStream.Write(rotation.w); + bitStream.Write(rotation.x); + bitStream.Write(rotation.y); + bitStream.Write(rotation.z); } - //bitStream.Write(position); - //bitStream.Write(rotation); - SystemAddress sysAddr = entity->GetSystemAddress(); SEND_PACKET; } From b3564cb9ea7f336a4b5381a160ceef59ea96dcf0 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Mon, 27 Nov 2023 22:16:31 -0600 Subject: [PATCH 04/12] fix: tacarc not using offset or checking upper/lower bounds --- dGame/dBehaviors/TacArcBehavior.cpp | 47 +++++++++-------------------- 1 file changed, 14 insertions(+), 33 deletions(-) diff --git a/dGame/dBehaviors/TacArcBehavior.cpp b/dGame/dBehaviors/TacArcBehavior.cpp index 29cee327..acce571d 100644 --- a/dGame/dBehaviors/TacArcBehavior.cpp +++ b/dGame/dBehaviors/TacArcBehavior.cpp @@ -104,7 +104,7 @@ void TacArcBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitS const auto casterPosition = self->GetPosition(); - auto reference = self->GetPosition(); //+ m_offset; + auto reference = self->GetPosition() + m_offset; targets.clear(); @@ -114,46 +114,34 @@ void TacArcBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitS context->FilterTargets(validTargets, this->m_ignoreFactionList, this->m_includeFactionList, this->m_targetSelf, this->m_targetEnemy, this->m_targetFriend, this->m_targetTeam); for (auto validTarget : validTargets) { - if (targets.size() >= this->m_maxTargets) { - break; - } - - if (std::find(targets.begin(), targets.end(), validTarget) != targets.end()) { - continue; - } - + if (targets.size() >= this->m_maxTargets) break; + if (std::find(targets.begin(), targets.end(), validTarget) != targets.end()) continue; if (validTarget->GetIsDead()) continue; - const auto otherPosition = validTarget->GetPosition(); + const auto targetPos = validTarget->GetPosition(); - const auto heightDifference = std::abs(otherPosition.y - casterPosition.y); - - /*if (otherPosition.y > reference.y && heightDifference > this->m_upperBound || otherPosition.y < reference.y && heightDifference > this->m_lowerBound) - { + // make sure we aren't too high or low in comparison to the targer + const auto heightDifference = abs(reference.y - targetPos.y); + if (targetPos.y > reference.y && heightDifference > this->m_upperBound || targetPos.y < reference.y && heightDifference > this->m_lowerBound) continue; - }*/ const auto forward = self->GetRotation().GetForwardVector(); // forward is a normalized vector of where the caster is facing. - // otherPosition is the position of the target. + // targetPos is the position of the target. // reference is the position of the caster. // If we cast a ray forward from the caster, does it come within m_farWidth of the target? - const auto distance = Vector3::Distance(reference, otherPosition); + const auto distance = Vector3::Distance(reference, targetPos); 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, targetPos) > this->m_farWidth * this->m_farWidth) continue; - } } - auto normalized = (reference - otherPosition) / distance; - + auto normalized = (reference - targetPos) / distance; const float degreeAngle = std::abs(Vector3::Angle(forward, normalized) * (180 / 3.14) - 180); - if (distance >= this->m_minRange && this->m_maxRange >= distance && degreeAngle <= 2 * this->m_angle) { targets.push_back(validTarget); } @@ -167,33 +155,26 @@ void TacArcBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitS }); const auto hit = !targets.empty(); - bitStream->Write(hit); if (this->m_checkEnv) { const auto blocked = false; // TODO - bitStream->Write(blocked); } if (hit) { - if (combatAi != nullptr) { - combatAi->LookAt(targets[0]->GetPosition()); - } + if (combatAi) combatAi->LookAt(targets[0]->GetPosition()); context->foundTarget = true; // We want to continue with this behavior - const auto count = static_cast(targets.size()); bitStream->Write(count); - for (auto* target : targets) { bitStream->Write(target->GetObjectID()); } for (auto* target : targets) { branch.target = target->GetObjectID(); - this->m_action->Calculate(context, bitStream, branch); } } else { @@ -214,8 +195,8 @@ void TacArcBehavior::Load() { GetFloat("offset_z", 0.0f) ); this->m_method = GetInt("method", 1); - this->m_upperBound = GetFloat("upper_bound", 4.4f); - this->m_lowerBound = GetFloat("lower_bound", 0.4f); + this->m_upperBound = abs(GetFloat("upper_bound", 4.4f)); + this->m_lowerBound = abs(GetFloat("lower_bound", 0.4f)); this->m_usePickedTarget = GetBoolean("use_picked_target", false); this->m_useTargetPostion = GetBoolean("use_target_position", false); this->m_checkEnv = GetBoolean("check_env", false); From e8a0f50ec98ccebcdad3db1cebe466572bce7f24 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Mon, 27 Nov 2023 22:18:27 -0600 Subject: [PATCH 05/12] use std::abs --- dGame/dBehaviors/TacArcBehavior.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dGame/dBehaviors/TacArcBehavior.cpp b/dGame/dBehaviors/TacArcBehavior.cpp index acce571d..c240d5d9 100644 --- a/dGame/dBehaviors/TacArcBehavior.cpp +++ b/dGame/dBehaviors/TacArcBehavior.cpp @@ -121,7 +121,7 @@ void TacArcBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitS const auto targetPos = validTarget->GetPosition(); // make sure we aren't too high or low in comparison to the targer - const auto heightDifference = abs(reference.y - targetPos.y); + const auto heightDifference = std::abs(reference.y - targetPos.y); if (targetPos.y > reference.y && heightDifference > this->m_upperBound || targetPos.y < reference.y && heightDifference > this->m_lowerBound) continue; @@ -195,8 +195,8 @@ void TacArcBehavior::Load() { GetFloat("offset_z", 0.0f) ); this->m_method = GetInt("method", 1); - this->m_upperBound = abs(GetFloat("upper_bound", 4.4f)); - this->m_lowerBound = abs(GetFloat("lower_bound", 0.4f)); + this->m_upperBound = std::abs(GetFloat("upper_bound", 4.4f)); + this->m_lowerBound = std::abs(GetFloat("lower_bound", 0.4f)); this->m_usePickedTarget = GetBoolean("use_picked_target", false); this->m_useTargetPostion = GetBoolean("use_target_position", false); this->m_checkEnv = GetBoolean("check_env", false); From 62a1e135c3795ce461eed599d69a03015fee6996 Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Wed, 29 Nov 2023 00:25:06 -0800 Subject: [PATCH 06/12] Fix backwards name check (#1327) Untested. Fixes not being able to rename a character at character create --- dGame/UserManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dGame/UserManager.cpp b/dGame/UserManager.cpp index 8a58ac69..323bf29a 100644 --- a/dGame/UserManager.cpp +++ b/dGame/UserManager.cpp @@ -405,7 +405,7 @@ void UserManager::RenameCharacter(const SystemAddress& sysAddr, Packet* packet) return; } - if (Database::Get()->GetCharacterInfo(newName)) { + if (!Database::Get()->GetCharacterInfo(newName)) { if (IsNamePreapproved(newName)) { Database::Get()->SetCharacterName(charID, newName); LOG("Character %s now known as %s", character->GetName().c_str(), newName.c_str()); From 7de07a77223c15e9b5b001d0a58f9b2b1f16eef0 Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Thu, 30 Nov 2023 04:21:18 -0600 Subject: [PATCH 07/12] fix: use defaults when getting variables for jetpack behavior (#1328) Tested that the hover jetpack now works and that the normal jetpack still works --- dGame/dBehaviors/JetPackBehavior.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/dGame/dBehaviors/JetPackBehavior.cpp b/dGame/dBehaviors/JetPackBehavior.cpp index 134dd0fb..7fcd78b0 100644 --- a/dGame/dBehaviors/JetPackBehavior.cpp +++ b/dGame/dBehaviors/JetPackBehavior.cpp @@ -38,10 +38,12 @@ void JetPackBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bit } 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", -1); + this->m_Airspeed = GetFloat("airspeed", 10); + this->m_MaxAirspeed = GetFloat("max_airspeed", 15); + this->m_VerticalVelocity = GetFloat("vertical_velocity", 1); + this->m_EnableHover = GetBoolean("enable_hover", false); + + // TODO: Implement proper jetpack checks, so we can set this default to false + this->m_BypassChecks = GetBoolean("bypass_checks", true); } From 0b9dbaedbfe793a8a48ae0272a76ead1a19e6e7a Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Thu, 30 Nov 2023 16:11:45 -0800 Subject: [PATCH 08/12] Add HailStorms guide to README (#1329) --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 310e75eb..f647aaa5 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,9 @@ We do not recommend hosting public servers. Darkflame Universe is intended for s ### Supply of resource files Darkflame Universe is a server emulator and does not distribute any LEGO® Universe files. A separate game client is required to setup this server emulator and play the game, which we cannot supply. Users are strongly suggested to refer to the safe checksums listed [here](#verifying-your-client-files) to see if a client will work. +## Step by step walkthrough for a single-player server +If you would like a setup for a single player server only on a Windows machine, use the [Native Windows Setup Guide by HailStorm](https://gist.github.com/HailStorm32/169df65a47a104199b5cc57d10fa57de) and skip this README. + ## Steps to setup server * [Clone this repository](#clone-the-repository) * [Install dependencies](#install-dependencies) From eca87c7257ce2c0a78ef44161b29c121fd9af191 Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Fri, 1 Dec 2023 08:12:48 -0800 Subject: [PATCH 09/12] fix: Buff FX not playing and general BuffComponent improvements (#1296) * fix: Buff FX not playing Fixes an issue where buff effects would not play at all. Tested that frakjaw and maelstrom dagger now play their respective effects when you are effected by them fix: buffs general improvements add new arguments * Remove duplicated code * fix times and remove buff --- dGame/dBehaviors/ApplyBuffBehavior.cpp | 3 +- dGame/dBehaviors/ApplyBuffBehavior.h | 2 + dGame/dComponents/BuffComponent.cpp | 190 ++++++++++++++++++++----- dGame/dComponents/BuffComponent.h | 22 ++- dGame/dGameMessages/GameMessages.cpp | 20 +-- dGame/dGameMessages/GameMessages.h | 2 +- 6 files changed, 187 insertions(+), 52 deletions(-) diff --git a/dGame/dBehaviors/ApplyBuffBehavior.cpp b/dGame/dBehaviors/ApplyBuffBehavior.cpp index c94762aa..26b3da84 100644 --- a/dGame/dBehaviors/ApplyBuffBehavior.cpp +++ b/dGame/dBehaviors/ApplyBuffBehavior.cpp @@ -15,7 +15,7 @@ void ApplyBuffBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitS if (buffComponent == nullptr) return; buffComponent->ApplyBuff(m_BuffId, m_Duration, context->originator, addImmunity, cancelOnDamaged, cancelOnDeath, - cancelOnLogout, cancelonRemoveBuff, cancelOnUi, cancelOnUnequip, cancelOnZone); + cancelOnLogout, cancelonRemoveBuff, cancelOnUi, cancelOnUnequip, cancelOnZone, m_ApplyOnTeammates); } void ApplyBuffBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch) { @@ -45,4 +45,5 @@ void ApplyBuffBehavior::Load() { cancelOnUi = GetBoolean("cancel_on_ui"); cancelOnUnequip = GetBoolean("cancel_on_unequip"); cancelOnZone = GetBoolean("cancel_on_zone"); + m_ApplyOnTeammates = GetBoolean("apply_on_teammates"); } diff --git a/dGame/dBehaviors/ApplyBuffBehavior.h b/dGame/dBehaviors/ApplyBuffBehavior.h index 139082df..e01a238e 100644 --- a/dGame/dBehaviors/ApplyBuffBehavior.h +++ b/dGame/dBehaviors/ApplyBuffBehavior.h @@ -31,4 +31,6 @@ public: void Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override; void Load() override; +private: + bool m_ApplyOnTeammates; }; diff --git a/dGame/dComponents/BuffComponent.cpp b/dGame/dComponents/BuffComponent.cpp index 24124f6e..be33527f 100644 --- a/dGame/dComponents/BuffComponent.cpp +++ b/dGame/dComponents/BuffComponent.cpp @@ -11,9 +11,21 @@ #include "EntityManager.h" #include "CDClientManager.h" #include "CDSkillBehaviorTable.h" +#include "TeamManager.h" std::unordered_map> BuffComponent::m_Cache{}; +namespace { + std::map BuffFx = { + { "overtime", "OTB_" }, + { "max_health", "HEALTH_" }, + { "max_imagination", "IMAGINATION_" }, + { "max_armor", "ARMOR_" }, + { "speed", "SPEED_" }, + { "loot", "LOOT_" } + }; +} + BuffComponent::BuffComponent(Entity* parent) : Component(parent) { } @@ -22,32 +34,38 @@ BuffComponent::~BuffComponent() { void BuffComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) { if (!bIsInitialUpdate) return; - if (m_Buffs.empty()) { - outBitStream->Write0(); - } else { - outBitStream->Write1(); + outBitStream->Write(!m_Buffs.empty()); + if (!m_Buffs.empty()) { outBitStream->Write(m_Buffs.size()); - for (const auto& buff : m_Buffs) { - outBitStream->Write(buff.first); - outBitStream->Write0(); - outBitStream->Write0(); - outBitStream->Write0(); - outBitStream->Write0(); - outBitStream->Write0(); - outBitStream->Write0(); - outBitStream->Write0(); - outBitStream->Write0(); - outBitStream->Write0(); + for (const auto& [id, buff] : m_Buffs) { + outBitStream->Write(id); + outBitStream->Write(buff.time != 0.0f); + if (buff.time != 0.0f) outBitStream->Write(static_cast(buff.time * 1000.0f)); + outBitStream->Write(buff.cancelOnDeath); + outBitStream->Write(buff.cancelOnZone); + outBitStream->Write(buff.cancelOnDamaged); + outBitStream->Write(buff.cancelOnRemoveBuff); + outBitStream->Write(buff.cancelOnUi); + outBitStream->Write(buff.cancelOnLogout); + outBitStream->Write(buff.cancelOnUnequip); + outBitStream->Write0(); // Cancel on Damage Absorb Ran Out. Generally false from what I can tell - outBitStream->Write0(); - outBitStream->Write0(); + auto* team = TeamManager::Instance()->GetTeam(buff.source); + bool addedByTeammate = false; + if (team) { + addedByTeammate = std::count(team->members.begin(), team->members.end(), m_Parent->GetObjectID()) > 0; + } - outBitStream->Write(0); + outBitStream->Write(addedByTeammate); // Added by teammate. If source is in the same team as the target, this is true. Otherwise, false. + outBitStream->Write(buff.applyOnTeammates); + if (addedByTeammate) outBitStream->Write(buff.source); + + outBitStream->Write(buff.refCount); } } - outBitStream->Write0(); + outBitStream->Write0(); // something to do with immunity buffs? } void BuffComponent::Update(float deltaTime) { @@ -83,17 +101,55 @@ void BuffComponent::Update(float deltaTime) { } } +const std::string& GetFxName(const std::string& buffname) { + const auto& toReturn = BuffFx[buffname]; + if (toReturn.empty()) { + LOG_DEBUG("No fx name for %s", buffname.c_str()); + } + return toReturn; +} + +void BuffComponent::ApplyBuffFx(uint32_t buffId, const BuffParameter& buff) { + std::string fxToPlay; + const auto& buffName = GetFxName(buff.name); + + if (buffName.empty()) return; + + fxToPlay += std::to_string(buffId); + LOG_DEBUG("Playing %s %i", fxToPlay.c_str(), buff.effectId); + GameMessages::SendPlayFXEffect(m_Parent->GetObjectID(), buff.effectId, u"cast", fxToPlay, LWOOBJID_EMPTY, 1.07f, 1.0f, false); +} + +void BuffComponent::RemoveBuffFx(uint32_t buffId, const BuffParameter& buff) { + std::string fxToPlay; + const auto& buffName = GetFxName(buff.name); + + if (buffName.empty()) return; + + fxToPlay += std::to_string(buffId); + LOG_DEBUG("Stopping %s", fxToPlay.c_str()); + GameMessages::SendStopFXEffect(m_Parent, false, fxToPlay); +} + 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 cancelOnUi, bool cancelOnUnequip, bool cancelOnZone, bool applyOnTeammates) { // Prevent buffs from stacking. if (HasBuff(id)) { + m_Buffs[id].refCount++; + m_Buffs[id].time = duration; return; } + auto* team = TeamManager::Instance()->GetTeam(source); + bool addedByTeammate = false; + if (team) { + addedByTeammate = std::count(team->members.begin(), team->members.end(), m_Parent->GetObjectID()) > 0; + } + GameMessages::SendAddBuff(const_cast(m_Parent->GetObjectID()), source, (uint32_t)id, (uint32_t)duration * 1000, addImmunity, cancelOnDamaged, cancelOnDeath, - cancelOnLogout, cancelOnRemoveBuff, cancelOnUi, cancelOnUnequip, cancelOnZone); + cancelOnLogout, cancelOnRemoveBuff, cancelOnUi, cancelOnUnequip, cancelOnZone, addedByTeammate, applyOnTeammates); float tick = 0; float stacks = 0; @@ -121,17 +177,43 @@ void BuffComponent::ApplyBuff(const int32_t id, const float duration, const LWOO buff.stacks = stacks; buff.source = source; buff.behaviorID = behaviorID; + buff.cancelOnDamaged = cancelOnDamaged; + buff.cancelOnDeath = cancelOnDeath; + buff.cancelOnLogout = cancelOnLogout; + buff.cancelOnRemoveBuff = cancelOnRemoveBuff; + buff.cancelOnUi = cancelOnUi; + buff.cancelOnUnequip = cancelOnUnequip; + buff.cancelOnZone = cancelOnZone; + buff.refCount = 1; m_Buffs.emplace(id, buff); + + auto* parent = GetParent(); + if (!cancelOnDeath) return; + + m_Parent->AddDieCallback([parent, id]() { + LOG_DEBUG("Removing buff %i because parent died", id); + if (!parent) return; + auto* buffComponent = parent->GetComponent(); + if (buffComponent) buffComponent->RemoveBuff(id, false, false, true); + }); } -void BuffComponent::RemoveBuff(int32_t id, bool fromUnEquip, bool removeImmunity) { +void BuffComponent::RemoveBuff(int32_t id, bool fromUnEquip, bool removeImmunity, bool ignoreRefCount) { const auto& iter = m_Buffs.find(id); if (iter == m_Buffs.end()) { return; } + if (!ignoreRefCount && !iter->second.cancelOnRemoveBuff) { + iter->second.refCount--; + LOG_DEBUG("refCount for buff %i is now %i", id, iter->second.refCount); + if (iter->second.refCount > 0) { + return; + } + } + GameMessages::SendRemoveBuff(m_Parent, fromUnEquip, removeImmunity, id); m_Buffs.erase(iter); @@ -146,6 +228,7 @@ bool BuffComponent::HasBuff(int32_t id) { void BuffComponent::ApplyBuffEffect(int32_t id) { const auto& parameters = GetBuffParameters(id); for (const auto& parameter : parameters) { + ApplyBuffFx(id, parameter); if (parameter.name == "max_health") { const auto maxHealth = parameter.value; @@ -182,6 +265,7 @@ void BuffComponent::ApplyBuffEffect(int32_t id) { void BuffComponent::RemoveBuffEffect(int32_t id) { const auto& parameters = GetBuffParameters(id); for (const auto& parameter : parameters) { + RemoveBuffFx(id, parameter); if (parameter.name == "max_health") { const auto maxHealth = parameter.value; @@ -251,13 +335,25 @@ void BuffComponent::LoadFromXml(tinyxml2::XMLDocument* doc) { auto* buffEntry = buffElement->FirstChildElement("b"); - while (buffEntry != nullptr) { + while (buffEntry) { int32_t id = buffEntry->IntAttribute("id"); float t = buffEntry->FloatAttribute("t"); float tk = buffEntry->FloatAttribute("tk"); + float tt = buffEntry->FloatAttribute("tt"); int32_t s = buffEntry->FloatAttribute("s"); LWOOBJID sr = buffEntry->Int64Attribute("sr"); int32_t b = buffEntry->IntAttribute("b"); + int32_t refCount = buffEntry->IntAttribute("refCount"); + + bool cancelOnDamaged = buffEntry->BoolAttribute("cancelOnDamaged"); + bool cancelOnDeath = buffEntry->BoolAttribute("cancelOnDeath"); + bool cancelOnLogout = buffEntry->BoolAttribute("cancelOnLogout"); + bool cancelOnRemoveBuff = buffEntry->BoolAttribute("cancelOnRemoveBuff"); + bool cancelOnUi = buffEntry->BoolAttribute("cancelOnUi"); + bool cancelOnUnequip = buffEntry->BoolAttribute("cancelOnUnequip"); + bool cancelOnZone = buffEntry->BoolAttribute("cancelOnZone"); + bool applyOnTeammates = buffEntry->BoolAttribute("applyOnTeammates"); + Buff buff; buff.id = id; @@ -266,6 +362,18 @@ void BuffComponent::LoadFromXml(tinyxml2::XMLDocument* doc) { buff.stacks = s; buff.source = sr; buff.behaviorID = b; + buff.refCount = refCount; + buff.tickTime = tt; + + buff.cancelOnDamaged = cancelOnDamaged; + buff.cancelOnDeath = cancelOnDeath; + buff.cancelOnLogout = cancelOnLogout; + buff.cancelOnRemoveBuff = cancelOnRemoveBuff; + buff.cancelOnUi = cancelOnUi; + buff.cancelOnUnequip = cancelOnUnequip; + buff.cancelOnZone = cancelOnZone; + buff.applyOnTeammates = applyOnTeammates; + m_Buffs.emplace(id, buff); @@ -288,15 +396,27 @@ void BuffComponent::UpdateXml(tinyxml2::XMLDocument* doc) { buffElement->DeleteChildren(); } - for (const auto& buff : m_Buffs) { + for (const auto& [id, buff] : m_Buffs) { auto* buffEntry = doc->NewElement("b"); + if (buff.cancelOnZone || buff.cancelOnLogout) continue; - buffEntry->SetAttribute("id", buff.first); - buffEntry->SetAttribute("t", buff.second.time); - buffEntry->SetAttribute("tk", buff.second.tick); - buffEntry->SetAttribute("s", buff.second.stacks); - buffEntry->SetAttribute("sr", buff.second.source); - buffEntry->SetAttribute("b", buff.second.behaviorID); + buffEntry->SetAttribute("id", id); + buffEntry->SetAttribute("t", buff.time); + buffEntry->SetAttribute("tk", buff.tick); + buffEntry->SetAttribute("tt", buff.tickTime); + buffEntry->SetAttribute("s", buff.stacks); + buffEntry->SetAttribute("sr", buff.source); + buffEntry->SetAttribute("b", buff.behaviorID); + buffEntry->SetAttribute("refCount", buff.refCount); + + buffEntry->SetAttribute("cancelOnDamaged", buff.cancelOnDamaged); + buffEntry->SetAttribute("cancelOnDeath", buff.cancelOnDeath); + buffEntry->SetAttribute("cancelOnLogout", buff.cancelOnLogout); + buffEntry->SetAttribute("cancelOnRemoveBuff", buff.cancelOnRemoveBuff); + buffEntry->SetAttribute("cancelOnUi", buff.cancelOnUi); + buffEntry->SetAttribute("cancelOnUnequip", buff.cancelOnUnequip); + buffEntry->SetAttribute("cancelOnZone", buff.cancelOnZone); + buffEntry->SetAttribute("applyOnTeammates", buff.applyOnTeammates); buffElement->LinkEndChild(buffEntry); } @@ -309,8 +429,7 @@ const std::vector& BuffComponent::GetBuffParameters(int32_t buffI return pair->second; } - auto query = CDClientDatabase::CreatePreppedStmt( - "SELECT * FROM BuffParameters WHERE BuffID = ?;"); + auto query = CDClientDatabase::CreatePreppedStmt("SELECT * FROM BuffParameters WHERE BuffID = ?;"); query.bind(1, (int)buffId); auto result = query.execQuery(); @@ -321,11 +440,12 @@ const std::vector& BuffComponent::GetBuffParameters(int32_t buffI BuffParameter param; param.buffId = buffId; - param.name = result.getStringField(1); - param.value = result.getFloatField(2); + param.name = result.getStringField("ParameterName"); + param.value = result.getFloatField("NumberValue"); + param.effectId = result.getIntField("EffectID"); if (!result.fieldIsNull(3)) { - std::istringstream stream(result.getStringField(3)); + std::istringstream stream(result.getStringField("StringValue")); std::string token; while (std::getline(stream, token, ',')) { diff --git a/dGame/dComponents/BuffComponent.h b/dGame/dComponents/BuffComponent.h index 5b6f8fd6..7187f8f7 100644 --- a/dGame/dComponents/BuffComponent.h +++ b/dGame/dComponents/BuffComponent.h @@ -14,8 +14,7 @@ class Entity; /** * Extra information on effects to apply after applying a buff, for example whether to buff armor, imag or health and by how much */ -struct BuffParameter -{ +struct BuffParameter { int32_t buffId; std::string name; float value; @@ -26,8 +25,7 @@ struct BuffParameter /** * Meta information about a buff that can be applied, e.g. how long it's applied, who applied it, etc. */ -struct Buff -{ +struct Buff { int32_t id = 0; float time = 0; float tick = 0; @@ -35,6 +33,15 @@ struct Buff int32_t stacks = 0; LWOOBJID source = 0; int32_t behaviorID = 0; + bool cancelOnDamaged = false; + bool cancelOnDeath = false; + bool cancelOnLogout = false; + bool cancelOnRemoveBuff = false; + bool cancelOnUi = false; + bool cancelOnUnequip = false; + bool cancelOnZone = false; + bool applyOnTeammates = false; + uint32_t refCount = 0; }; /** @@ -74,14 +81,17 @@ public: */ void ApplyBuff(int32_t id, float duration, LWOOBJID source, bool addImmunity = false, bool cancelOnDamaged = false, bool cancelOnDeath = true, bool cancelOnLogout = false, bool cancelOnRemoveBuff = true, - bool cancelOnUi = false, bool cancelOnUnequip = false, bool cancelOnZone = false); + bool cancelOnUi = false, bool cancelOnUnequip = false, bool cancelOnZone = false, bool applyOnTeammates = false); + + void ApplyBuffFx(uint32_t buffId, const BuffParameter& buffName); + void RemoveBuffFx(uint32_t buffId, const BuffParameter& buffName); /** * Removes a buff from the parent entity, reversing its effects * @param id the id of the buff to remove * @param removeImmunity whether or not to remove immunity on removing the buff */ - void RemoveBuff(int32_t id, bool fromUnEquip = false, bool removeImmunity = false); + void RemoveBuff(int32_t id, bool fromUnEquip = false, bool removeImmunity = false, bool ignoreRefCount = false); /** * Returns whether or not the entity has a buff identified by `id` diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index b506e3a0..fe2ad720 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -4477,7 +4477,7 @@ void GameMessages::SendVehicleNotifyFinishedRace(LWOOBJID objectId, const System void GameMessages::SendAddBuff(LWOOBJID& objectID, const LWOOBJID& casterID, uint32_t buffID, uint32_t msDuration, bool addImmunity, bool cancelOnDamaged, bool cancelOnDeath, bool cancelOnLogout, - bool cancelOnRemoveBuff, bool cancelOnUi, bool cancelOnUnequip, bool cancelOnZone, + bool cancelOnRemoveBuff, bool cancelOnUi, bool cancelOnUnequip, bool cancelOnZone, bool addedByTeammate, bool applyOnTeammates, const SystemAddress& sysAddr) { CBITSTREAM; CMSGHEADER; @@ -4485,27 +4485,29 @@ void GameMessages::SendAddBuff(LWOOBJID& objectID, const LWOOBJID& casterID, uin bitStream.Write(objectID); bitStream.Write(eGameMessageType::ADD_BUFF); - bitStream.Write(false); // Added by teammate - bitStream.Write(false); // Apply on teammates - bitStream.Write(false); // Cancel on damage absorb ran out + bitStream.Write(addedByTeammate); // Added by teammate + bitStream.Write(applyOnTeammates); // Apply on teammates bitStream.Write(cancelOnDamaged); bitStream.Write(cancelOnDeath); bitStream.Write(cancelOnLogout); + bitStream.Write(false); // Cancel on move bitStream.Write(cancelOnRemoveBuff); - bitStream.Write(cancelOnUi); bitStream.Write(cancelOnUnequip); bitStream.Write(cancelOnZone); + bitStream.Write(false); // Ignore immunities bitStream.Write(addImmunity); bitStream.Write(false); // Use ref count - bitStream.Write(buffID); - bitStream.Write(msDuration); + bitStream.Write(casterID != LWOOBJID_EMPTY); + if (casterID != LWOOBJID_EMPTY) bitStream.Write(casterID); - bitStream.Write(casterID); - bitStream.Write(casterID); + bitStream.Write(buffID); + + bitStream.Write(msDuration != 0); + if (msDuration != 0) bitStream.Write(msDuration); if (sysAddr == UNASSIGNED_SYSTEM_ADDRESS) SEND_PACKET_BROADCAST; SEND_PACKET; diff --git a/dGame/dGameMessages/GameMessages.h b/dGame/dGameMessages/GameMessages.h index 6a572d97..5199a72a 100644 --- a/dGame/dGameMessages/GameMessages.h +++ b/dGame/dGameMessages/GameMessages.h @@ -206,7 +206,7 @@ namespace GameMessages { void SendAddBuff(LWOOBJID& objectID, const LWOOBJID& casterID, uint32_t buffID, uint32_t msDuration, bool addImmunity = false, bool cancelOnDamaged = false, bool cancelOnDeath = true, bool cancelOnLogout = false, bool cancelOnRemoveBuff = true, bool cancelOnUi = false, - bool cancelOnUnequip = false, bool cancelOnZone = false, const SystemAddress& sysAddr = UNASSIGNED_SYSTEM_ADDRESS); + bool cancelOnUnequip = false, bool cancelOnZone = false, bool addedByTeammate = false, bool applyOnTeammates = false, const SystemAddress& sysAddr = UNASSIGNED_SYSTEM_ADDRESS); void SendToggleGMInvis(LWOOBJID objectId, bool enabled, const SystemAddress& sysAddr); From 731b828c126fb03fb0d52b78ccad07b18462d2c1 Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Fri, 1 Dec 2023 08:13:01 -0800 Subject: [PATCH 10/12] properties: fix visiting multiple owned by same person (#1325) --- dGame/dComponents/PropertyManagementComponent.h | 2 ++ dScripts/BasePropertyServer.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/dGame/dComponents/PropertyManagementComponent.h b/dGame/dComponents/PropertyManagementComponent.h index 2f2deea4..d38437c4 100644 --- a/dGame/dComponents/PropertyManagementComponent.h +++ b/dGame/dComponents/PropertyManagementComponent.h @@ -164,6 +164,8 @@ public: LWOCLONEID GetCloneId() { return clone_Id; }; + LWOOBJID GetId() const noexcept { return propertyId; } + private: /** * This diff --git a/dScripts/BasePropertyServer.cpp b/dScripts/BasePropertyServer.cpp index fe20b09d..9048adeb 100644 --- a/dScripts/BasePropertyServer.cpp +++ b/dScripts/BasePropertyServer.cpp @@ -101,7 +101,7 @@ void BasePropertyServer::BasePlayerLoaded(Entity* self, Entity* player) { missionComponent->Progress( eMissionTaskType::VISIT_PROPERTY, mapID.GetMapID(), - mapID.GetCloneID() + PropertyManagementComponent::Instance()->GetId() ); } } From 3d85f6639e9f93b4f2ea2bac4d45bfc1d6022742 Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Mon, 4 Dec 2023 09:20:41 -0600 Subject: [PATCH 11/12] chore: rename VehiclePhysics to HavokVehiclePhysics (#1331) since that is it's true name and there's another VehiclePhysics component that is simply named that --- dCommon/dEnums/eReplicaComponentType.h | 4 +-- dGame/Entity.cpp | 26 +++++++++---------- dGame/dComponents/CMakeLists.txt | 2 +- dGame/dComponents/CharacterComponent.cpp | 2 +- ...t.cpp => HavokVehiclePhysicsComponent.cpp} | 22 ++++++++-------- ...onent.h => HavokVehiclePhysicsComponent.h} | 6 ++--- dGame/dComponents/InventoryComponent.cpp | 4 +-- dGame/dComponents/RacingControlComponent.cpp | 2 +- dGame/dGameMessages/GameMessages.cpp | 2 +- dGame/dUtilities/SlashCommandHandler.cpp | 8 +++--- dNet/ClientPackets.cpp | 24 ++++++++--------- 11 files changed, 51 insertions(+), 51 deletions(-) rename dGame/dComponents/{VehiclePhysicsComponent.cpp => HavokVehiclePhysicsComponent.cpp} (77%) rename dGame/dComponents/{VehiclePhysicsComponent.h => HavokVehiclePhysicsComponent.h} (94%) diff --git a/dCommon/dEnums/eReplicaComponentType.h b/dCommon/dEnums/eReplicaComponentType.h index a0be9dd4..ca60355f 100644 --- a/dCommon/dEnums/eReplicaComponentType.h +++ b/dCommon/dEnums/eReplicaComponentType.h @@ -34,7 +34,7 @@ enum class eReplicaComponentType : uint32_t { PLATFORM_BOUNDARY, MODULE, ARCADE, - VEHICLE_PHYSICS, // Havok demo based + HAVOK_VEHICLE_PHYSICS, MOVEMENT_AI, EXHIBIT, OVERHEAD_ICON, @@ -50,7 +50,7 @@ enum class eReplicaComponentType : uint32_t { PROPERTY_ENTRANCE, FX, PROPERTY_MANAGEMENT, - VEHICLE_PHYSICS_NEW, // internal physics based on havok + VEHICLE_PHYSICS, PHYSICS_SYSTEM, QUICK_BUILD, SWITCH, diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index 4d4f5c10..f62a0825 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -62,7 +62,7 @@ #include "ModelComponent.h" #include "ZCompression.h" #include "PetComponent.h" -#include "VehiclePhysicsComponent.h" +#include "HavokVehiclePhysicsComponent.h" #include "PossessableComponent.h" #include "PossessorComponent.h" #include "ModuleAssemblyComponent.h" @@ -299,10 +299,10 @@ void Entity::Initialize() { AddComponent()->SetPhysicsEffectActive(false); } - if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::VEHICLE_PHYSICS) > 0) { - auto* vehiclePhysicsComponent = AddComponent(); - vehiclePhysicsComponent->SetPosition(m_DefaultPosition); - vehiclePhysicsComponent->SetRotation(m_DefaultRotation); + if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::HAVOK_VEHICLE_PHYSICS) > 0) { + auto* havokVehiclePhysicsComponent = AddComponent(); + havokVehiclePhysicsComponent->SetPosition(m_DefaultPosition); + havokVehiclePhysicsComponent->SetRotation(m_DefaultRotation); } if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SOUND_TRIGGER, -1) != -1) { @@ -744,7 +744,7 @@ void Entity::Initialize() { !HasComponent(eReplicaComponentType::PHANTOM_PHYSICS) && !HasComponent(eReplicaComponentType::PROPERTY) && !HasComponent(eReplicaComponentType::RACING_CONTROL) && - !HasComponent(eReplicaComponentType::VEHICLE_PHYSICS) + !HasComponent(eReplicaComponentType::HAVOK_VEHICLE_PHYSICS) ) //if (HasComponent(eReplicaComponentType::BASE_COMBAT_AI)) { @@ -1023,9 +1023,9 @@ void Entity::WriteComponents(RakNet::BitStream* outBitStream, eReplicaPacketType rigidbodyPhantomPhysics->Serialize(outBitStream, bIsInitialUpdate); } - VehiclePhysicsComponent* vehiclePhysicsComponent; - if (TryGetComponent(eReplicaComponentType::VEHICLE_PHYSICS, vehiclePhysicsComponent)) { - vehiclePhysicsComponent->Serialize(outBitStream, bIsInitialUpdate); + HavokVehiclePhysicsComponent* havokVehiclePhysicsComponent; + if (TryGetComponent(eReplicaComponentType::HAVOK_VEHICLE_PHYSICS, havokVehiclePhysicsComponent)) { + havokVehiclePhysicsComponent->Serialize(outBitStream, bIsInitialUpdate); } PhantomPhysicsComponent* phantomPhysicsComponent; @@ -1846,7 +1846,7 @@ const NiPoint3& Entity::GetPosition() const { return simple->GetPosition(); } - auto* vehicel = GetComponent(); + auto* vehicel = GetComponent(); if (vehicel != nullptr) { return vehicel->GetPosition(); @@ -1874,7 +1874,7 @@ const NiQuaternion& Entity::GetRotation() const { return simple->GetRotation(); } - auto* vehicel = GetComponent(); + auto* vehicel = GetComponent(); if (vehicel != nullptr) { return vehicel->GetRotation(); @@ -1902,7 +1902,7 @@ void Entity::SetPosition(NiPoint3 position) { simple->SetPosition(position); } - auto* vehicel = GetComponent(); + auto* vehicel = GetComponent(); if (vehicel != nullptr) { vehicel->SetPosition(position); @@ -1930,7 +1930,7 @@ void Entity::SetRotation(NiQuaternion rotation) { simple->SetRotation(rotation); } - auto* vehicel = GetComponent(); + auto* vehicel = GetComponent(); if (vehicel != nullptr) { vehicel->SetRotation(rotation); diff --git a/dGame/dComponents/CMakeLists.txt b/dGame/dComponents/CMakeLists.txt index b1550f37..814a4fb9 100644 --- a/dGame/dComponents/CMakeLists.txt +++ b/dGame/dComponents/CMakeLists.txt @@ -43,7 +43,7 @@ set(DGAME_DCOMPONENTS_SOURCES "BaseCombatAIComponent.cpp" "SoundTriggerComponent.cpp" "SwitchComponent.cpp" "TriggerComponent.cpp" - "VehiclePhysicsComponent.cpp" + "HavokVehiclePhysicsComponent.cpp" "VendorComponent.cpp" "ZoneControlComponent.cpp" PARENT_SCOPE diff --git a/dGame/dComponents/CharacterComponent.cpp b/dGame/dComponents/CharacterComponent.cpp index d1b7ee21..1e441293 100644 --- a/dGame/dComponents/CharacterComponent.cpp +++ b/dGame/dComponents/CharacterComponent.cpp @@ -10,7 +10,7 @@ #include "InventoryComponent.h" #include "ControllablePhysicsComponent.h" #include "EntityManager.h" -#include "VehiclePhysicsComponent.h" +#include "HavokVehiclePhysicsComponent.h" #include "GameMessages.h" #include "Item.h" #include "Amf3.h" diff --git a/dGame/dComponents/VehiclePhysicsComponent.cpp b/dGame/dComponents/HavokVehiclePhysicsComponent.cpp similarity index 77% rename from dGame/dComponents/VehiclePhysicsComponent.cpp rename to dGame/dComponents/HavokVehiclePhysicsComponent.cpp index 0e93782d..62e49a56 100644 --- a/dGame/dComponents/VehiclePhysicsComponent.cpp +++ b/dGame/dComponents/HavokVehiclePhysicsComponent.cpp @@ -1,7 +1,7 @@ -#include "VehiclePhysicsComponent.h" +#include "HavokVehiclePhysicsComponent.h" #include "EntityManager.h" -VehiclePhysicsComponent::VehiclePhysicsComponent(Entity* parent) : PhysicsComponent(parent) { +HavokVehiclePhysicsComponent::HavokVehiclePhysicsComponent(Entity* parent) : PhysicsComponent(parent) { m_Velocity = NiPoint3::ZERO; m_AngularVelocity = NiPoint3::ZERO; m_IsOnGround = true; @@ -12,45 +12,45 @@ VehiclePhysicsComponent::VehiclePhysicsComponent(Entity* parent) : PhysicsCompon m_EndBehavior = GeneralUtils::GenerateRandomNumber(0, 7); } -void VehiclePhysicsComponent::SetVelocity(const NiPoint3& vel) { +void HavokVehiclePhysicsComponent::SetVelocity(const NiPoint3& vel) { if (vel == m_Velocity) return; m_DirtyPosition = true; m_Velocity = vel; } -void VehiclePhysicsComponent::SetAngularVelocity(const NiPoint3& vel) { +void HavokVehiclePhysicsComponent::SetAngularVelocity(const NiPoint3& vel) { if (vel == m_AngularVelocity) return; m_DirtyPosition = true; m_AngularVelocity = vel; } -void VehiclePhysicsComponent::SetIsOnGround(bool val) { +void HavokVehiclePhysicsComponent::SetIsOnGround(bool val) { if (val == m_IsOnGround) return; m_DirtyPosition = true; m_IsOnGround = val; } -void VehiclePhysicsComponent::SetIsOnRail(bool val) { +void HavokVehiclePhysicsComponent::SetIsOnRail(bool val) { if (val == m_IsOnRail) return; m_DirtyPosition = true; m_IsOnRail = val; } -void VehiclePhysicsComponent::SetRemoteInputInfo(const RemoteInputInfo& remoteInputInfo) { +void HavokVehiclePhysicsComponent::SetRemoteInputInfo(const RemoteInputInfo& remoteInputInfo) { if (m_RemoteInputInfo == remoteInputInfo) return; this->m_RemoteInputInfo = remoteInputInfo; m_DirtyRemoteInput = true; } -void VehiclePhysicsComponent::SetDirtyVelocity(bool val) { +void HavokVehiclePhysicsComponent::SetDirtyVelocity(bool val) { m_DirtyVelocity = val; } -void VehiclePhysicsComponent::SetDirtyAngularVelocity(bool val) { +void HavokVehiclePhysicsComponent::SetDirtyAngularVelocity(bool val) { m_DirtyAngularVelocity = val; } -void VehiclePhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) { +void HavokVehiclePhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) { outBitStream->Write(bIsInitialUpdate || m_DirtyPosition); if (bIsInitialUpdate || m_DirtyPosition) { @@ -111,7 +111,7 @@ void VehiclePhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bool bI outBitStream->Write0(); } -void VehiclePhysicsComponent::Update(float deltaTime) { +void HavokVehiclePhysicsComponent::Update(float deltaTime) { if (m_SoftUpdate > 5) { Game::entityManager->SerializeEntity(m_Parent); m_SoftUpdate = 0; diff --git a/dGame/dComponents/VehiclePhysicsComponent.h b/dGame/dComponents/HavokVehiclePhysicsComponent.h similarity index 94% rename from dGame/dComponents/VehiclePhysicsComponent.h rename to dGame/dComponents/HavokVehiclePhysicsComponent.h index 94ba650a..2d04e0ac 100644 --- a/dGame/dComponents/VehiclePhysicsComponent.h +++ b/dGame/dComponents/HavokVehiclePhysicsComponent.h @@ -33,11 +33,11 @@ struct RemoteInputInfo { /** * Physics component for vehicles. */ -class VehiclePhysicsComponent : public PhysicsComponent { +class HavokVehiclePhysicsComponent : public PhysicsComponent { public: - inline static const eReplicaComponentType ComponentType = eReplicaComponentType::VEHICLE_PHYSICS; + inline static const eReplicaComponentType ComponentType = eReplicaComponentType::HAVOK_VEHICLE_PHYSICS; - VehiclePhysicsComponent(Entity* parentEntity); + HavokVehiclePhysicsComponent(Entity* parentEntity); void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override; diff --git a/dGame/dComponents/InventoryComponent.cpp b/dGame/dComponents/InventoryComponent.cpp index 4d737ab7..fc379398 100644 --- a/dGame/dComponents/InventoryComponent.cpp +++ b/dGame/dComponents/InventoryComponent.cpp @@ -19,7 +19,7 @@ #include "PossessorComponent.h" #include "PossessableComponent.h" #include "ModuleAssemblyComponent.h" -#include "VehiclePhysicsComponent.h" +#include "HavokVehiclePhysicsComponent.h" #include "CharacterComponent.h" #include "dZoneManager.h" #include "PropertyManagementComponent.h" @@ -981,7 +981,7 @@ void InventoryComponent::HandlePossession(Item* item) { auto* mount = Game::entityManager->CreateEntity(info, nullptr, m_Parent); // Check to see if the mount is a vehicle, if so, flip it - auto* vehicleComponent = mount->GetComponent(); + auto* vehicleComponent = mount->GetComponent(); if (vehicleComponent) characterComponent->SetIsRacing(true); // Setup the destroyable stats diff --git a/dGame/dComponents/RacingControlComponent.cpp b/dGame/dComponents/RacingControlComponent.cpp index a4737d9e..6c8df280 100644 --- a/dGame/dComponents/RacingControlComponent.cpp +++ b/dGame/dComponents/RacingControlComponent.cpp @@ -17,7 +17,7 @@ #include "PossessorComponent.h" #include "eRacingTaskParam.h" #include "Spawner.h" -#include "VehiclePhysicsComponent.h" +#include "HavokVehiclePhysicsComponent.h" #include "dServer.h" #include "dZoneManager.h" #include "dConfig.h" diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index fe2ad720..fd174a2b 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -71,7 +71,7 @@ #include "MovingPlatformComponent.h" #include "PetComponent.h" #include "ModuleAssemblyComponent.h" -#include "VehiclePhysicsComponent.h" +#include "HavokVehiclePhysicsComponent.h" #include "RenderComponent.h" #include "PossessableComponent.h" #include "PossessorComponent.h" diff --git a/dGame/dUtilities/SlashCommandHandler.cpp b/dGame/dUtilities/SlashCommandHandler.cpp index 13fc3ded..7c18e9a4 100644 --- a/dGame/dUtilities/SlashCommandHandler.cpp +++ b/dGame/dUtilities/SlashCommandHandler.cpp @@ -59,7 +59,7 @@ #include "dpShapeSphere.h" #include "PossessableComponent.h" #include "PossessorComponent.h" -#include "VehiclePhysicsComponent.h" +#include "HavokVehiclePhysicsComponent.h" #include "BuffComponent.h" #include "SkillComponent.h" #include "VanityUtilities.h" @@ -942,9 +942,9 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit auto* possassableEntity = Game::entityManager->GetEntity(possessorComponent->GetPossessable()); if (possassableEntity != nullptr) { - auto* vehiclePhysicsComponent = possassableEntity->GetComponent(); - if (vehiclePhysicsComponent) { - vehiclePhysicsComponent->SetPosition(pos); + auto* havokVehiclePhysicsComponent = possassableEntity->GetComponent(); + if (havokVehiclePhysicsComponent) { + havokVehiclePhysicsComponent->SetPosition(pos); Game::entityManager->SerializeEntity(possassableEntity); } else GameMessages::SendTeleport(possassableEntity->GetObjectID(), pos, NiQuaternion(), sysAddr); } diff --git a/dNet/ClientPackets.cpp b/dNet/ClientPackets.cpp index 18b2f3d1..cf405053 100644 --- a/dNet/ClientPackets.cpp +++ b/dNet/ClientPackets.cpp @@ -27,7 +27,7 @@ #include "Zone.h" #include "PossessorComponent.h" #include "PossessableComponent.h" -#include "VehiclePhysicsComponent.h" +#include "HavokVehiclePhysicsComponent.h" #include "dConfig.h" #include "CharacterComponent.h" #include "Database.h" @@ -187,17 +187,17 @@ void ClientPackets::HandleClientPositionUpdate(const SystemAddress& sysAddr, Pac if (possessableComponent->GetPossessionType() != ePossessionType::ATTACHED_VISIBLE) updateChar = false; } - auto* vehiclePhysicsComponent = possassableEntity->GetComponent(); - if (vehiclePhysicsComponent != nullptr) { - vehiclePhysicsComponent->SetPosition(position); - vehiclePhysicsComponent->SetRotation(rotation); - vehiclePhysicsComponent->SetIsOnGround(onGround); - vehiclePhysicsComponent->SetIsOnRail(onRail); - vehiclePhysicsComponent->SetVelocity(velocity); - vehiclePhysicsComponent->SetDirtyVelocity(velocityFlag); - vehiclePhysicsComponent->SetAngularVelocity(angVelocity); - vehiclePhysicsComponent->SetDirtyAngularVelocity(angVelocityFlag); - vehiclePhysicsComponent->SetRemoteInputInfo(remoteInput); + auto* havokVehiclePhysicsComponent = possassableEntity->GetComponent(); + if (havokVehiclePhysicsComponent != nullptr) { + havokVehiclePhysicsComponent->SetPosition(position); + havokVehiclePhysicsComponent->SetRotation(rotation); + havokVehiclePhysicsComponent->SetIsOnGround(onGround); + havokVehiclePhysicsComponent->SetIsOnRail(onRail); + havokVehiclePhysicsComponent->SetVelocity(velocity); + havokVehiclePhysicsComponent->SetDirtyVelocity(velocityFlag); + havokVehiclePhysicsComponent->SetAngularVelocity(angVelocity); + havokVehiclePhysicsComponent->SetDirtyAngularVelocity(angVelocityFlag); + havokVehiclePhysicsComponent->SetRemoteInputInfo(remoteInput); } else { // Need to get the mount's controllable physics auto* controllablePhysicsComponent = possassableEntity->GetComponent(); From 1f399a72779dd75ca2aaac1a0b9ab7708ddd6178 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Mon, 4 Dec 2023 20:59:08 -0600 Subject: [PATCH 12/12] chore: rename zonecontrolcomp to minigamecontrolcomp --- dCommon/dEnums/eReplicaComponentType.h | 2 +- dGame/Entity.cpp | 12 ++++++------ dGame/dComponents/CMakeLists.txt | 2 +- dGame/dComponents/MiniGameControlComponent.cpp | 5 +++++ dGame/dComponents/MiniGameControlComponent.h | 15 +++++++++++++++ dGame/dComponents/MinigameComponent.cpp | 5 +++++ dGame/dComponents/ZoneControlComponent.cpp | 5 ----- dGame/dComponents/ZoneControlComponent.h | 15 --------------- 8 files changed, 33 insertions(+), 28 deletions(-) create mode 100644 dGame/dComponents/MiniGameControlComponent.cpp create mode 100644 dGame/dComponents/MiniGameControlComponent.h create mode 100644 dGame/dComponents/MinigameComponent.cpp delete mode 100644 dGame/dComponents/ZoneControlComponent.cpp delete mode 100644 dGame/dComponents/ZoneControlComponent.h diff --git a/dCommon/dEnums/eReplicaComponentType.h b/dCommon/dEnums/eReplicaComponentType.h index ca60355f..83acbf89 100644 --- a/dCommon/dEnums/eReplicaComponentType.h +++ b/dCommon/dEnums/eReplicaComponentType.h @@ -54,7 +54,7 @@ enum class eReplicaComponentType : uint32_t { PHYSICS_SYSTEM, QUICK_BUILD, SWITCH, - ZONE_CONTROL, // Minigame + MINI_GAME_CONTROL, CHANGLING, CHOICE_BUILD, PACKAGE, diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index f62a0825..a73e356f 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -76,7 +76,7 @@ #include "eGameMasterLevel.h" #include "eReplicaComponentType.h" #include "eReplicaPacketType.h" -#include "ZoneControlComponent.h" +#include "MiniGameControlComponent.h" #include "RacingStatsComponent.h" #include "CollectibleComponent.h" #include "ItemComponent.h" @@ -217,8 +217,8 @@ void Entity::Initialize() { AddComponent(petComponentId); } - if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::ZONE_CONTROL) > 0) { - AddComponent(); + if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MINI_GAME_CONTROL) > 0) { + AddComponent(); } uint32_t possessableComponentId = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::POSSESSABLE); @@ -1197,9 +1197,9 @@ void Entity::WriteComponents(RakNet::BitStream* outBitStream, eReplicaPacketType } } - ZoneControlComponent* zoneControlComponent; - if (TryGetComponent(eReplicaComponentType::ZONE_CONTROL, zoneControlComponent)) { - zoneControlComponent->Serialize(outBitStream, bIsInitialUpdate); + MiniGameControlComponent* miniGameControlComponent; + if (TryGetComponent(eReplicaComponentType::MINI_GAME_CONTROL, miniGameControlComponent)) { + miniGameControlComponent->Serialize(outBitStream, bIsInitialUpdate); } // BBB Component, unused currently diff --git a/dGame/dComponents/CMakeLists.txt b/dGame/dComponents/CMakeLists.txt index 814a4fb9..fa0aea35 100644 --- a/dGame/dComponents/CMakeLists.txt +++ b/dGame/dComponents/CMakeLists.txt @@ -45,6 +45,6 @@ set(DGAME_DCOMPONENTS_SOURCES "BaseCombatAIComponent.cpp" "TriggerComponent.cpp" "HavokVehiclePhysicsComponent.cpp" "VendorComponent.cpp" - "ZoneControlComponent.cpp" + "MiniGameControlComponent.cpp" PARENT_SCOPE ) diff --git a/dGame/dComponents/MiniGameControlComponent.cpp b/dGame/dComponents/MiniGameControlComponent.cpp new file mode 100644 index 00000000..fdd56a2c --- /dev/null +++ b/dGame/dComponents/MiniGameControlComponent.cpp @@ -0,0 +1,5 @@ +#include "MiniGameControlComponent.h" + +void MiniGameControlComponent::Serialize(RakNet::BitStream* outBitStream, bool isConstruction) { + outBitStream->Write(0x40000000); +} diff --git a/dGame/dComponents/MiniGameControlComponent.h b/dGame/dComponents/MiniGameControlComponent.h new file mode 100644 index 00000000..06a9c24e --- /dev/null +++ b/dGame/dComponents/MiniGameControlComponent.h @@ -0,0 +1,15 @@ +#ifndef __MINIGAMECONTROLCOMPONENT__H__ +#define __MINIGAMECONTROLCOMPONENT__H__ + +#include "Component.h" +#include "eReplicaComponentType.h" + +class MiniGameControlComponent final : public Component { +public: + inline static const eReplicaComponentType ComponentType = eReplicaComponentType::MINI_GAME_CONTROL; + + MiniGameControlComponent(Entity* parent) : Component(parent) {} + void Serialize(RakNet::BitStream* outBitStream, bool isConstruction); +}; + +#endif //!__MINIGAMECONTROLCOMPONENT__H__ diff --git a/dGame/dComponents/MinigameComponent.cpp b/dGame/dComponents/MinigameComponent.cpp new file mode 100644 index 00000000..6bcb985e --- /dev/null +++ b/dGame/dComponents/MinigameComponent.cpp @@ -0,0 +1,5 @@ +#include "MinigameComponent.h" + +void MinigameComponent::Serialize(RakNet::BitStream* outBitStream, bool isConstruction) { + outBitStream->Write(0x40000000); +} diff --git a/dGame/dComponents/ZoneControlComponent.cpp b/dGame/dComponents/ZoneControlComponent.cpp deleted file mode 100644 index ca9c6626..00000000 --- a/dGame/dComponents/ZoneControlComponent.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "ZoneControlComponent.h" - -void ZoneControlComponent::Serialize(RakNet::BitStream* outBitStream, bool isConstruction) { - outBitStream->Write(0x40000000); -} diff --git a/dGame/dComponents/ZoneControlComponent.h b/dGame/dComponents/ZoneControlComponent.h deleted file mode 100644 index ba235a80..00000000 --- a/dGame/dComponents/ZoneControlComponent.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef __ZONECONTROLCOMPONENT__H__ -#define __ZONECONTROLCOMPONENT__H__ - -#include "Component.h" -#include "eReplicaComponentType.h" - -class ZoneControlComponent final : public Component { -public: - inline static const eReplicaComponentType ComponentType = eReplicaComponentType::ZONE_CONTROL; - - ZoneControlComponent(Entity* parent) : Component(parent) {} - void Serialize(RakNet::BitStream* outBitStream, bool isConstruction); -}; - -#endif //!__ZONECONTROLCOMPONENT__H__