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 1/3] 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 From 7d40585211438ef91fe88231cedb957d305a5efd Mon Sep 17 00:00:00 2001 From: Jett <55758076+Jettford@users.noreply.github.com> Date: Fri, 24 Dec 2021 01:14:15 +0000 Subject: [PATCH 2/3] Test frakjaw fix --- dScripts/MinigameTreasureChestServer.cpp | 16 +++++++++++++--- dScripts/MinigameTreasureChestServer.h | 3 +++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/dScripts/MinigameTreasureChestServer.cpp b/dScripts/MinigameTreasureChestServer.cpp index 8f89de54..ff32b527 100644 --- a/dScripts/MinigameTreasureChestServer.cpp +++ b/dScripts/MinigameTreasureChestServer.cpp @@ -18,14 +18,24 @@ void MinigameTreasureChestServer::OnUse(Entity *self, Entity *user) { UpdatePlayer(self, user->GetObjectID()); auto* team = TeamManager::Instance()->GetTeam(user->GetObjectID()); + uint32_t activityRating = 0; if (team != nullptr) { for (const auto& teamMemberID : team->members) { auto* teamMember = EntityManager::Instance()->GetEntity(teamMemberID); - if (teamMember != nullptr) - LootGenerator::Instance().DropActivityLoot(teamMember, self, sac->GetActivityID(), CalculateActivityRating(self, teamMemberID)); + if (teamMember != nullptr) { + activityRating = CalculateActivityRating(self, teamMemberID); + + if (self->GetLOT() == frakjawChestId) activityRating = team->members.size(); + + LootGenerator::Instance().DropActivityLoot(teamMember, self, sac->GetActivityID(), activityRating); + } } } else { - LootGenerator::Instance().DropActivityLoot(user, self, sac->GetActivityID(), CalculateActivityRating(self, user->GetObjectID())); + activityRating = CalculateActivityRating(self, user->GetObjectID()); + + if (self->GetLOT() == frakjawChestId) activityRating = 1; + + LootGenerator::Instance().DropActivityLoot(user, self, sac->GetActivityID(), activityRating); } sac->PlayerRemove(user->GetObjectID()); diff --git a/dScripts/MinigameTreasureChestServer.h b/dScripts/MinigameTreasureChestServer.h index f2cd4328..c718f016 100644 --- a/dScripts/MinigameTreasureChestServer.h +++ b/dScripts/MinigameTreasureChestServer.h @@ -2,7 +2,10 @@ #include "ActivityManager.h" class MinigameTreasureChestServer : public ActivityManager { +public: void OnStartup(Entity* self) override; void OnUse(Entity* self, Entity* user) override; uint32_t CalculateActivityRating(Entity *self, LWOOBJID playerID) override; +private: + const uint32_t frakjawChestId = 16486; }; From 76c9d057cfcbd64d8d1ed6738f03ec1a14cb6846 Mon Sep 17 00:00:00 2001 From: Jett <55758076+Jettford@users.noreply.github.com> Date: Fri, 24 Dec 2021 11:57:31 +0000 Subject: [PATCH 3/3] Update ChatPacketHandler.cpp --- dChatServer/ChatPacketHandler.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/dChatServer/ChatPacketHandler.cpp b/dChatServer/ChatPacketHandler.cpp index 594dd3a0..737bbba4 100644 --- a/dChatServer/ChatPacketHandler.cpp +++ b/dChatServer/ChatPacketHandler.cpp @@ -355,6 +355,7 @@ void ChatPacketHandler::HandleTeamInvite(Packet* packet) // no more teams greater than 4 Game::logger->Log("ChatPacketHandler", "Someone tried to invite a 5th player to a team"); + return; } SendTeamInvite(other, player);