From cc25ec01514210b0743ab2a7d95705601fbd3c46 Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Mon, 4 Jul 2022 21:48:56 -0700 Subject: [PATCH] Add Venture Vision Behavior (#609) Add the Venture Vision behavior and associated functionality. Pet digs still do not show up however. The Kit bonus for factions have been tested and properly grant and take away the buff when it is casted and uncasted. Tested as well using multiple Venture Vision behaviors at once and the vision only went away when there were zero equipped at once. Remove extra includes Convert to Tabs Remove extra forward declaration --- dGame/dBehaviors/Behavior.cpp | 5 ++- dGame/dBehaviors/VentureVisionBehavior.cpp | 47 ++++++++++++++++++++++ dGame/dBehaviors/VentureVisionBehavior.h | 41 +++++++++++++++++++ dGame/dComponents/CharacterComponent.cpp | 29 +++++++++++++ dGame/dComponents/CharacterComponent.h | 20 +++++++++ 5 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 dGame/dBehaviors/VentureVisionBehavior.cpp create mode 100644 dGame/dBehaviors/VentureVisionBehavior.h diff --git a/dGame/dBehaviors/Behavior.cpp b/dGame/dBehaviors/Behavior.cpp index df24af92..7305ed2d 100644 --- a/dGame/dBehaviors/Behavior.cpp +++ b/dGame/dBehaviors/Behavior.cpp @@ -45,6 +45,7 @@ #include "InterruptBehavior.h" #include "PlayEffectBehavior.h" #include "DamageAbsorptionBehavior.h" +#include "VentureVisionBehavior.h" #include "BlockBehavior.h" #include "ClearTargetBehavior.h" #include "PullToPointBehavior.h" @@ -176,7 +177,9 @@ Behavior* Behavior::CreateBehavior(const uint32_t behaviorId) case BehaviorTemplates::BEHAVIOR_LOOT_BUFF: behavior = new LootBuffBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_VENTURE_VISION: break; + case BehaviorTemplates::BEHAVIOR_VENTURE_VISION: + behavior = new VentureVisionBehavior(behaviorId); + break; case BehaviorTemplates::BEHAVIOR_SPAWN_OBJECT: behavior = new SpawnBehavior(behaviorId); break; diff --git a/dGame/dBehaviors/VentureVisionBehavior.cpp b/dGame/dBehaviors/VentureVisionBehavior.cpp new file mode 100644 index 00000000..9061deb7 --- /dev/null +++ b/dGame/dBehaviors/VentureVisionBehavior.cpp @@ -0,0 +1,47 @@ +#include "VentureVisionBehavior.h" +#include "BehaviorBranchContext.h" +#include "CharacterComponent.h" +#include "BehaviorContext.h" + +void VentureVisionBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch){ + + const auto targetEntity = EntityManager::Instance()->GetEntity(branch.target); + + if (targetEntity) { + auto characterComponent = targetEntity->GetComponent(); + + if (characterComponent) { + if (m_show_collectibles) characterComponent->AddVentureVisionEffect(m_ShowCollectibles); + if (m_show_minibosses) characterComponent->AddVentureVisionEffect(m_ShowMiniBosses); + if (m_show_pet_digs) characterComponent->AddVentureVisionEffect(m_ShowPetDigs); + } + + if (branch.duration > 0) context->RegisterTimerBehavior(this, branch); + } +} + +void VentureVisionBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch) { + const auto targetEntity = EntityManager::Instance()->GetEntity(branch.target); + + if (targetEntity) { + auto characterComponent = targetEntity->GetComponent(); + + if (characterComponent) { + if (m_show_collectibles) characterComponent->RemoveVentureVisionEffect(m_ShowCollectibles); + if (m_show_minibosses) characterComponent->RemoveVentureVisionEffect(m_ShowMiniBosses); + if (m_show_pet_digs) characterComponent->RemoveVentureVisionEffect(m_ShowPetDigs); + } + } +} + +void VentureVisionBehavior::Timer(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) { + UnCast(context, branch); +} + +void VentureVisionBehavior::Load(){ + this->m_show_pet_digs = GetBoolean("show_pet_digs"); + + this->m_show_minibosses = GetBoolean("show_minibosses"); + + this->m_show_collectibles = GetBoolean("show_collectibles"); +} diff --git a/dGame/dBehaviors/VentureVisionBehavior.h b/dGame/dBehaviors/VentureVisionBehavior.h new file mode 100644 index 00000000..96b2642b --- /dev/null +++ b/dGame/dBehaviors/VentureVisionBehavior.h @@ -0,0 +1,41 @@ +#pragma once + +#ifndef __VENTUREVISIONBEHAVIOR__H__ +#define __VENTUREVISIONBEHAVIOR__H__ + +#include "Behavior.h" + +class VentureVisionBehavior final : public Behavior +{ +public: + bool m_show_pet_digs; + + bool m_show_minibosses; + + bool m_show_collectibles; + + const std::string m_ShowCollectibles = "bShowCollectibles"; + + const std::string m_ShowMiniBosses = "bShowMiniBosses"; + + const std::string m_ShowPetDigs = "bShowPetDigs"; + + + /* + * Inherited + */ + + explicit VentureVisionBehavior(const uint32_t behaviorId) : Behavior(behaviorId) + { + } + + void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override; + + void UnCast(BehaviorContext* context, BehaviorBranchContext branch) override; + + void Timer(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) override; + + void Load() override; +}; + +#endif //!__VENTUREVISIONBEHAVIOR__H__ diff --git a/dGame/dComponents/CharacterComponent.cpp b/dGame/dComponents/CharacterComponent.cpp index 14354cb5..dd2b69bb 100644 --- a/dGame/dComponents/CharacterComponent.cpp +++ b/dGame/dComponents/CharacterComponent.cpp @@ -785,3 +785,32 @@ ZoneStatistics& CharacterComponent::GetZoneStatisticsForMap(LWOMAPID mapID) { m_ZoneStatistics.insert({ mapID, {0, 0, 0, 0, 0 } }); return m_ZoneStatistics.at(mapID); } + +void CharacterComponent::AddVentureVisionEffect(std::string ventureVisionType) { + const auto ventureVisionTypeIterator = m_ActiveVentureVisionEffects.find(ventureVisionType); + + if (ventureVisionTypeIterator != m_ActiveVentureVisionEffects.end()) { + ventureVisionTypeIterator->second = ++ventureVisionTypeIterator->second; + } else { + // If the effect it not found, insert it into the active effects. + m_ActiveVentureVisionEffects.insert(std::make_pair(ventureVisionType, 1U)); + } + + UpdateClientMinimap(true, ventureVisionType); +} + +void CharacterComponent::RemoveVentureVisionEffect(std::string ventureVisionType) { + const auto ventureVisionTypeIterator = m_ActiveVentureVisionEffects.find(ventureVisionType); + + if (ventureVisionTypeIterator != m_ActiveVentureVisionEffects.end()) { + ventureVisionTypeIterator->second = --ventureVisionTypeIterator->second; + UpdateClientMinimap(ventureVisionTypeIterator->second != 0U, ventureVisionType); + } +} + +void CharacterComponent::UpdateClientMinimap(bool showFaction, std::string ventureVisionType) const { + if (!m_Parent) return; + AMFArrayValue arrayToSend; + arrayToSend.InsertValue(ventureVisionType, showFaction ? static_cast(new AMFTrueValue()) : static_cast(new AMFFalseValue())); + GameMessages::SendUIMessageServerToSingleClient(m_Parent, m_Parent ? m_Parent->GetSystemAddress() : UNASSIGNED_SYSTEM_ADDRESS, "SetFactionVisibility", &arrayToSend); +} diff --git a/dGame/dComponents/CharacterComponent.h b/dGame/dComponents/CharacterComponent.h index 2a0d860b..c7706325 100644 --- a/dGame/dComponents/CharacterComponent.h +++ b/dGame/dComponents/CharacterComponent.h @@ -274,12 +274,32 @@ public: */ void UpdatePlayerStatistic(StatisticID updateID, uint64_t updateValue = 1); + /** + * Add a venture vision effect to the player minimap. + */ + void AddVentureVisionEffect(std::string ventureVisionType); + + /** + * Remove a venture vision effect from the player minimap. + * When an effect hits 0 active effects, it is deactivated. + */ + void RemoveVentureVisionEffect(std::string ventureVisionType); + + /** + * Update the client minimap to reveal the specified factions + */ + void UpdateClientMinimap(bool showFaction, std::string ventureVisionType) const; + /** * Character info regarding this character, including clothing styles, etc. */ Character* m_Character; private: + /** + * The map of active venture vision effects + */ + std::map m_ActiveVentureVisionEffects; /** * Whether this character is racing