From 9440af0d672c0c848659993122b6aa2aceb63a75 Mon Sep 17 00:00:00 2001 From: Jett <55758076+Jettford@users.noreply.github.com> Date: Fri, 24 Dec 2021 00:25:52 +0000 Subject: [PATCH] Repaired some bugs - Fixed Team loot - LMI dropping for team sizes - No more > 4 player teams --- dChatServer/ChatPacketHandler.cpp | 6 ++++ dGame/dComponents/DestroyableComponent.cpp | 29 ++++++++++++------- .../dComponents/ScriptedActivityComponent.cpp | 26 +++++++++++++++++ dGame/dComponents/ScriptedActivityComponent.h | 12 ++++++++ 4 files changed, 62 insertions(+), 11 deletions(-) diff --git a/dChatServer/ChatPacketHandler.cpp b/dChatServer/ChatPacketHandler.cpp index 057a6568..594dd3a0 100644 --- a/dChatServer/ChatPacketHandler.cpp +++ b/dChatServer/ChatPacketHandler.cpp @@ -351,6 +351,12 @@ void ChatPacketHandler::HandleTeamInvite(Packet* packet) return; } + if (team->memberIDs.size() > 3) { + // no more teams greater than 4 + + Game::logger->Log("ChatPacketHandler", "Someone tried to invite a 5th player to a team"); + } + SendTeamInvite(other, player); Game::logger->Log("ChatPacketHandler", "Got team invite: %llu -> %s\n", playerID, invitedPlayer.c_str()); diff --git a/dGame/dComponents/DestroyableComponent.cpp b/dGame/dComponents/DestroyableComponent.cpp index c84e906a..01beaa5f 100644 --- a/dGame/dComponents/DestroyableComponent.cpp +++ b/dGame/dComponents/DestroyableComponent.cpp @@ -769,25 +769,32 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType if (team != nullptr && m_Parent->GetComponent() != nullptr) { LWOOBJID specificOwner = LWOOBJID_EMPTY; + auto* scriptedActivityComponent = m_Parent->GetComponent(); + uint32_t teamSize = team->members.size(); + uint32_t lootMatrixId = GetLootMatrixID(); - if (team->lootOption == 0) // Round robin - { - specificOwner = TeamManager::Instance()->GetNextLootOwner(team); + if (scriptedActivityComponent) { + lootMatrixId = scriptedActivityComponent->GetLootMatrixForTeamSize(teamSize); } - for (const auto memberId : team->members) - { - if (specificOwner != LWOOBJID_EMPTY && memberId != specificOwner) continue; + if (team->lootOption == 0) { // Round robin + specificOwner = TeamManager::Instance()->GetNextLootOwner(team); - auto* member = EntityManager::Instance()->GetEntity(memberId); + auto* member = EntityManager::Instance()->GetEntity(specificOwner); - if (member == nullptr) continue; + 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); - LootGenerator::Instance().DropLoot(member, m_Parent, GetLootMatrixID(), GetMinCoins(), GetMaxCoins()); + if (member == nullptr) continue; + + LootGenerator::Instance().DropLoot(member, m_Parent, lootMatrixId, GetMinCoins(), GetMaxCoins()); + } } } - else - { + else { // drop loot for non team user LootGenerator::Instance().DropLoot(owner, m_Parent, GetLootMatrixID(), GetMinCoins(), GetMaxCoins()); } } diff --git a/dGame/dComponents/ScriptedActivityComponent.cpp b/dGame/dComponents/ScriptedActivityComponent.cpp index 54aee019..dba5714d 100644 --- a/dGame/dComponents/ScriptedActivityComponent.cpp +++ b/dGame/dComponents/ScriptedActivityComponent.cpp @@ -16,6 +16,7 @@ #include "GeneralUtils.h" #include "dZoneManager.h" #include "dConfig.h" +#include "DestroyableComponent.h" ScriptedActivityComponent::ScriptedActivityComponent(Entity* parent, int activityID) : Component(parent) { @@ -43,6 +44,31 @@ ScriptedActivityComponent::ScriptedActivityComponent(Entity* parent, int activit } } } + + auto* destroyableComponent = m_Parent->GetComponent(); + + if (destroyableComponent) { + // check for LMIs and set the loot LMIs + CDActivityRewardsTable* activityRewardsTable = CDClientManager::Instance()->GetTable("ActivityRewards"); + std::vector activityRewards = activityRewardsTable->Query([=](CDActivityRewards entry) {return (entry.LootMatrixIndex == destroyableComponent->GetLootMatrixID()); }); + + uint32_t startingLMI = 0; + + if (activityRewards.size() > 0) { + startingLMI = activityRewards[0].LootMatrixIndex; + } + + if (startingLMI > 0) { + // now time for bodge :) + + std::vector objectTemplateActivities = activityRewardsTable->Query([=](CDActivityRewards entry) {return (activityRewards[0].objectTemplate == entry.objectTemplate); }); + for (const auto& item : objectTemplateActivities) { + if (item.activityRating > 0 && item.activityRating < 5) { + m_ActivityLootMatrices.insert({ item.activityRating, item.LootMatrixIndex }); + } + } + } + } } ScriptedActivityComponent::~ScriptedActivityComponent() diff --git a/dGame/dComponents/ScriptedActivityComponent.h b/dGame/dComponents/ScriptedActivityComponent.h index bbeca2b4..8d79df8b 100644 --- a/dGame/dComponents/ScriptedActivityComponent.h +++ b/dGame/dComponents/ScriptedActivityComponent.h @@ -328,6 +328,13 @@ public: * @param mapID the map ID to set */ void SetInstanceMapID(uint32_t mapID) { m_ActivityInfo.instanceMapID = mapID; }; + + /** + * Returns the LMI that this activity points to for a team size + * @param teamSize the team size to get the LMI for + * @return the LMI that this activity points to for a team size + */ + uint32_t GetLootMatrixForTeamSize(uint32_t teamSize) { return m_ActivityLootMatrices[teamSize]; } private: /** @@ -349,6 +356,11 @@ private: * All the activity score for the players in this activity */ std::vector m_ActivityPlayers; + + /** + * LMIs for team sizes + */ + std::unordered_map m_ActivityLootMatrices; }; #endif // SCRIPTEDACTIVITYCOMPONENT_H