diff --git a/dDatabase/Tables/CDBehaviorParameterTable.cpp b/dDatabase/Tables/CDBehaviorParameterTable.cpp index b29a8267..ef267425 100644 --- a/dDatabase/Tables/CDBehaviorParameterTable.cpp +++ b/dDatabase/Tables/CDBehaviorParameterTable.cpp @@ -40,13 +40,13 @@ std::string CDBehaviorParameterTable::GetName(void) const { return "BehaviorParameter"; } -float CDBehaviorParameterTable::GetEntry(const uint32_t behaviorID, const std::string& name) +float CDBehaviorParameterTable::GetEntry(const uint32_t behaviorID, const std::string& name, const float defaultValue) { size_t hash = 0; GeneralUtils::hash_combine(hash, behaviorID); GeneralUtils::hash_combine(hash, name); - // Search for specific perameter + // Search for specific parameter const auto& it = m_Entries.find(hash); if (it != m_Entries.end()) { return it->second; @@ -55,7 +55,7 @@ float CDBehaviorParameterTable::GetEntry(const uint32_t behaviorID, const std::s // Check if this behavior has already been checked const auto& itChecked = m_Entries.find(behaviorID); if (itChecked != m_Entries.end()) { - return itChecked->second; + return defaultValue; } #ifndef CDCLIENT_CACHE_ALL @@ -86,5 +86,5 @@ float CDBehaviorParameterTable::GetEntry(const uint32_t behaviorID, const std::s } #endif - return 0; + return defaultValue; } diff --git a/dDatabase/Tables/CDBehaviorParameterTable.h b/dDatabase/Tables/CDBehaviorParameterTable.h index 00f08e1d..3d14d66d 100644 --- a/dDatabase/Tables/CDBehaviorParameterTable.h +++ b/dDatabase/Tables/CDBehaviorParameterTable.h @@ -35,5 +35,5 @@ public: */ std::string GetName(void) const override; - float GetEntry(const uint32_t behaviorID, const std::string& name); + float GetEntry(const uint32_t behaviorID, const std::string& name, const float defaultValue = 0); }; diff --git a/dGame/dBehaviors/Behavior.cpp b/dGame/dBehaviors/Behavior.cpp index 4769df7e..74153c11 100644 --- a/dGame/dBehaviors/Behavior.cpp +++ b/dGame/dBehaviors/Behavior.cpp @@ -55,6 +55,7 @@ #include "SkillEventBehavior.h" #include "SpeedBehavior.h" #include "DamageReductionBehavior.h" +#include "JetPackBehavior.h" //CDClient includes #include "CDBehaviorParameterTable.h" @@ -183,7 +184,9 @@ Behavior* Behavior::CreateBehavior(const uint32_t behaviorId) case BehaviorTemplates::BEHAVIOR_BUFF: behavior = new BuffBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_JETPACK: break; + case BehaviorTemplates::BEHAVIOR_JETPACK: + behavior = new JetPackBehavior(behaviorId); + break; case BehaviorTemplates::BEHAVIOR_SKILL_EVENT: behavior = new SkillEventBehavior(behaviorId); break; @@ -455,21 +458,21 @@ Behavior::Behavior(const uint32_t behaviorId) } -float Behavior::GetFloat(const std::string& name) const +float Behavior::GetFloat(const std::string& name, const float defaultValue) const { - return BehaviorParameterTable->GetEntry(this->m_behaviorId, name); + return BehaviorParameterTable->GetEntry(this->m_behaviorId, name, defaultValue); } -bool Behavior::GetBoolean(const std::string& name) const +bool Behavior::GetBoolean(const std::string& name, const bool defaultValue) const { - return GetFloat(name) > 0; + return GetFloat(name, defaultValue) > 0; } -int32_t Behavior::GetInt(const std::string& name) const +int32_t Behavior::GetInt(const std::string& name, const int defaultValue) const { - return static_cast(GetFloat(name)); + return static_cast(GetFloat(name, defaultValue)); } diff --git a/dGame/dBehaviors/Behavior.h b/dGame/dBehaviors/Behavior.h index abdba9e6..e8700f48 100644 --- a/dGame/dBehaviors/Behavior.h +++ b/dGame/dBehaviors/Behavior.h @@ -49,11 +49,11 @@ public: * Behavior parameters */ - float GetFloat(const std::string& name) const; + float GetFloat(const std::string& name, const float defaultValue = 0) const; - bool GetBoolean(const std::string& name) const; + bool GetBoolean(const std::string& name, const bool defaultValue = false) const; - int32_t GetInt(const std::string& name) const; + int32_t GetInt(const std::string& name, const int32_t defaultValue = 0) const; Behavior* GetAction(const std::string& name) const; diff --git a/dGame/dBehaviors/JetPackBehavior.cpp b/dGame/dBehaviors/JetPackBehavior.cpp new file mode 100644 index 00000000..63c0c6a9 --- /dev/null +++ b/dGame/dBehaviors/JetPackBehavior.cpp @@ -0,0 +1,29 @@ +#include "JetPackBehavior.h" + +#include "BehaviorBranchContext.h" +#include "GameMessages.h" + +void JetPackBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bit_stream, const BehaviorBranchContext branch) { + auto* entity = EntityManager::Instance()->GetEntity(branch.target); + + GameMessages::SendSetJetPackMode(entity, true, this->m_BypassChecks, this->m_EnableHover, this->m_effectId, this->m_Airspeed, this->m_MaxAirspeed, this->m_VerticalVelocity, this->m_WarningEffectID); +} + +void JetPackBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch) { + auto* entity = EntityManager::Instance()->GetEntity(branch.target); + + GameMessages::SendSetJetPackMode(entity, false); +} + +void JetPackBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bit_stream, const BehaviorBranchContext branch) { + Handle(context, bit_stream, branch); +} + +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); +} diff --git a/dGame/dBehaviors/JetPackBehavior.h b/dGame/dBehaviors/JetPackBehavior.h new file mode 100644 index 00000000..d891bf54 --- /dev/null +++ b/dGame/dBehaviors/JetPackBehavior.h @@ -0,0 +1,28 @@ +#pragma once +#include "Behavior.h" + +class JetPackBehavior final : public Behavior +{ +public: + int32_t m_WarningEffectID; + float m_Airspeed; + float m_MaxAirspeed; + float m_VerticalVelocity; + bool m_EnableHover; + bool m_BypassChecks = true; // from what I can tell this defaulted true in live + + /* + * Inherited + */ + + explicit JetPackBehavior(const uint32_t behavior_id) : Behavior(behavior_id) { + } + + void Handle(BehaviorContext* context, RakNet::BitStream* bit_stream, BehaviorBranchContext branch) override; + + void UnCast(BehaviorContext* context, BehaviorBranchContext branch) override; + + void Calculate(BehaviorContext* context, RakNet::BitStream* bit_stream, BehaviorBranchContext branch) override; + + void Load() override; +}; diff --git a/dGame/dComponents/InventoryComponent.cpp b/dGame/dComponents/InventoryComponent.cpp index 50ea26b1..922b2de3 100644 --- a/dGame/dComponents/InventoryComponent.cpp +++ b/dGame/dComponents/InventoryComponent.cpp @@ -1000,10 +1000,6 @@ void InventoryComponent::EquipItem(Item* item, const bool skipChecks) { set->OnEquip(lot); } - - if (lot == 1727) GameMessages::SendSetJetpackMode(m_Parent, false, true, false); - if (lot == 7292) GameMessages::SendSetJetpackMode(m_Parent, true, true, false); - if (lot == 14442) GameMessages::SendSetJetpackMode(m_Parent, false, true, true); if (item->GetInfo().isBOE) { @@ -1042,10 +1038,6 @@ void InventoryComponent::UnEquipItem(Item* item) set->OnUnEquip(lot); } - if (lot == 1727) GameMessages::SendSetJetpackMode(m_Parent, false, false, false); - if (lot == 7292) GameMessages::SendSetJetpackMode(m_Parent, true, false, false); - if (lot == 14442) GameMessages::SendSetJetpackMode(m_Parent, false, false, true); - RemoveBuff(item->GetLot()); RemoveItemSkills(item->GetLot()); diff --git a/dGame/dComponents/RacingControlComponent.cpp b/dGame/dComponents/RacingControlComponent.cpp index bba7a892..bbd85672 100644 --- a/dGame/dComponents/RacingControlComponent.cpp +++ b/dGame/dComponents/RacingControlComponent.cpp @@ -257,7 +257,7 @@ void RacingControlComponent::LoadPlayerVehicle(Entity *player, m_Parent->GetObjectID(), playerID, UNASSIGNED_SYSTEM_ADDRESS); }); - GameMessages::SendSetJetpackMode(player, false, false, false); + GameMessages::SendSetJetPackMode(player, false); // Set the vehicle's state. GameMessages::SendNotifyVehicleOfRacingObject(carEntity->GetObjectID(), diff --git a/dGame/dGameMessages/GameMessageHandler.cpp b/dGame/dGameMessages/GameMessageHandler.cpp index bb093d0c..83187e2f 100644 --- a/dGame/dGameMessages/GameMessageHandler.cpp +++ b/dGame/dGameMessages/GameMessageHandler.cpp @@ -105,9 +105,6 @@ void GameMessageHandler::HandleMessage(RakNet::BitStream* inStream, const System auto items = inv->GetEquippedItems(); for (auto pair : items) { const auto item = pair.second; - if (item.lot == 1727) GameMessages::SendSetJetpackMode(entity, false, true, false); - if (item.lot == 7292) GameMessages::SendSetJetpackMode(entity, true, true, false); - if (item.lot == 14442) GameMessages::SendSetJetpackMode(entity, false, true, true); inv->AddItemSkills(item.lot); } diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index 0ade588e..58a3d014 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -872,19 +872,14 @@ void GameMessages::SendSetEmoteLockState(Entity* entity, bool bLock, int emoteID SEND_PACKET } -void GameMessages::SendSetJetpackMode(Entity* entity, bool bDoHover, bool bUse, bool bIsJamessterPhysics) { - int effectID = 167; - int iWarningEffectID = -1; - float fAirspeed = 25; - float fMaxAirspeed = 25; - float fVertVel = 2; - bool bBypassChecks = true; - +void GameMessages::SendSetJetPackMode(Entity* entity, bool use, bool bypassChecks, bool doHover, int effectID, float airspeed, float maxAirspeed, float verticalVelocity, int warningEffectID) { + /* historical jamesster jetpack values if (bIsJamessterPhysics) { fAirspeed = 75; fMaxAirspeed = 75; fVertVel = 15; } + */ CBITSTREAM CMSGHEADER @@ -892,24 +887,24 @@ void GameMessages::SendSetJetpackMode(Entity* entity, bool bDoHover, bool bUse, bitStream.Write(entity->GetObjectID()); bitStream.Write(uint16_t(GAME_MSG_SET_JET_PACK_MODE)); - bitStream.Write(bBypassChecks); - bitStream.Write(bDoHover); - bitStream.Write(bUse); + bitStream.Write(bypassChecks); + bitStream.Write(doHover); + bitStream.Write(use); bitStream.Write(effectID != -1); if (effectID != -1) bitStream.Write(effectID); - bitStream.Write(fAirspeed != 10); - if (fAirspeed != 10) bitStream.Write(fAirspeed); + bitStream.Write(airspeed != 10); + if (airspeed != 10) bitStream.Write(airspeed); - bitStream.Write(fMaxAirspeed != 15); - if (fMaxAirspeed != 15) bitStream.Write(fMaxAirspeed); + bitStream.Write(maxAirspeed != 15); + if (maxAirspeed != 15) bitStream.Write(maxAirspeed); - bitStream.Write(fVertVel != 1); - if (fVertVel != 1) bitStream.Write(fVertVel); + bitStream.Write(verticalVelocity != 1); + if (verticalVelocity != 1) bitStream.Write(verticalVelocity); - bitStream.Write(iWarningEffectID != -1); - if (iWarningEffectID != -1) bitStream.Write(iWarningEffectID); + bitStream.Write(warningEffectID != -1); + if (warningEffectID != -1) bitStream.Write(warningEffectID); SEND_PACKET_BROADCAST } diff --git a/dGame/dGameMessages/GameMessages.h b/dGame/dGameMessages/GameMessages.h index 0bc51c01..579d4ec3 100644 --- a/dGame/dGameMessages/GameMessages.h +++ b/dGame/dGameMessages/GameMessages.h @@ -91,7 +91,7 @@ namespace GameMessages { void SendSetInventorySize(Entity* entity, int invType, int size); void SendSetEmoteLockState(Entity* entity, bool bLock, int emoteID); - void SendSetJetpackMode(Entity* entity, bool bDoHover, bool bUse, bool bIsJamessterPhysics); + void SendSetJetPackMode(Entity* entity, bool use, bool bypassChecks = false, bool doHover = false, int effectID = -1, float airspeed = 10, float maxAirspeed = 15, float verticalVelocity = 1, int warningEffectID = -1); void SendResurrect(Entity* entity); void SendStop2DAmbientSound(Entity* entity, bool force, std::string audioGUID, bool result = false); void SendPlay2DAmbientSound(Entity* entity, std::string audioGUID, bool result = false);