2021-12-20 10:25:45 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "Loot.h"
|
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
#include "CDComponentsRegistryTable.h"
|
|
|
|
#include "CDItemComponentTable.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "CDLootMatrixTable.h"
|
|
|
|
#include "CDLootTableTable.h"
|
2021-12-20 10:25:45 +00:00
|
|
|
#include "CDRarityTableTable.h"
|
2023-03-17 14:36:21 +00:00
|
|
|
#include "CDActivityRewardsTable.h"
|
|
|
|
#include "CDCurrencyTableTable.h"
|
2021-12-20 10:25:45 +00:00
|
|
|
#include "Character.h"
|
|
|
|
#include "Entity.h"
|
|
|
|
#include "GameMessages.h"
|
|
|
|
#include "GeneralUtils.h"
|
|
|
|
#include "InventoryComponent.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "MissionComponent.h"
|
|
|
|
#include "eMissionState.h"
|
2023-03-04 07:16:37 +00:00
|
|
|
#include "eReplicaComponentType.h"
|
2023-03-20 13:10:52 +00:00
|
|
|
#include "Metrics.hpp"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
LootGenerator::LootGenerator() {
|
2023-03-17 14:36:21 +00:00
|
|
|
CDLootTableTable* lootTableTable = CDClientManager::Instance().GetTable<CDLootTableTable>();
|
|
|
|
CDComponentsRegistryTable* componentsRegistryTable = CDClientManager::Instance().GetTable<CDComponentsRegistryTable>();
|
|
|
|
CDItemComponentTable* itemComponentTable = CDClientManager::Instance().GetTable<CDItemComponentTable>();
|
|
|
|
CDLootMatrixTable* lootMatrixTable = CDClientManager::Instance().GetTable<CDLootMatrixTable>();
|
|
|
|
CDRarityTableTable* rarityTableTable = CDClientManager::Instance().GetTable<CDRarityTableTable>();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
// ==============================
|
|
|
|
// Cache Item Rarities
|
|
|
|
// ==============================
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
std::vector<uint32_t> uniqueItems;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
for (const CDLootTable& loot : lootTableTable->GetEntries()) {
|
|
|
|
uniqueItems.push_back(loot.itemid);
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
// filter out duplicates
|
|
|
|
std::sort(uniqueItems.begin(), uniqueItems.end());
|
|
|
|
uniqueItems.erase(std::unique(uniqueItems.begin(), uniqueItems.end()), uniqueItems.end());
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
for (const uint32_t itemID : uniqueItems) {
|
2023-03-04 07:16:37 +00:00
|
|
|
uint32_t itemComponentID = componentsRegistryTable->GetByIDAndType(itemID, eReplicaComponentType::ITEM);
|
2021-12-20 10:25:45 +00:00
|
|
|
const CDItemComponent& item = itemComponentTable->GetItemComponentByID(itemComponentID);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
m_ItemRarities.insert({ itemID, item.rarity });
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
// ==============================
|
|
|
|
// Cache Rarity Tables
|
|
|
|
// ==============================
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
std::vector<uint32_t> uniqueRarityIndices;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
for (const CDRarityTable& rarity : rarityTableTable->GetEntries()) {
|
|
|
|
uniqueRarityIndices.push_back(rarity.RarityTableIndex);
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
// filter out duplicates
|
|
|
|
std::sort(uniqueRarityIndices.begin(), uniqueRarityIndices.end());
|
|
|
|
uniqueRarityIndices.erase(std::unique(uniqueRarityIndices.begin(), uniqueRarityIndices.end()), uniqueRarityIndices.end());
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
for (const uint32_t index : uniqueRarityIndices) {
|
|
|
|
std::vector<CDRarityTable> table = rarityTableTable->Query([index](const CDRarityTable& entry) { return entry.RarityTableIndex == index; });
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
RarityTable rarityTable;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
for (const CDRarityTable& entry : table) {
|
|
|
|
RarityTableEntry rarity{ entry.rarity, entry.randmax };
|
|
|
|
rarityTable.push_back(rarity);
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
// sort in descending order based on randMax
|
|
|
|
std::sort(rarityTable.begin(), rarityTable.end(), [](const RarityTableEntry& x, const RarityTableEntry& y) { return x.randMax > y.randMax; });
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
m_RarityTables.insert({ index, rarityTable });
|
|
|
|
}
|
|
|
|
|
|
|
|
// ==============================
|
|
|
|
// Cache Loot Matrices
|
|
|
|
// ==============================
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
std::vector<uint32_t> uniqueMatrixIndices;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
for (const CDLootMatrix& matrix : lootMatrixTable->GetEntries()) {
|
|
|
|
uniqueMatrixIndices.push_back(matrix.LootMatrixIndex);
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
// filter out duplicates
|
|
|
|
std::sort(uniqueMatrixIndices.begin(), uniqueMatrixIndices.end());
|
|
|
|
uniqueMatrixIndices.erase(std::unique(uniqueMatrixIndices.begin(), uniqueMatrixIndices.end()), uniqueMatrixIndices.end());
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
for (const uint32_t index : uniqueMatrixIndices) {
|
|
|
|
std::vector<CDLootMatrix> matrix = lootMatrixTable->Query([index](const CDLootMatrix& entry) { return entry.LootMatrixIndex == index; });
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
LootMatrix lootMatrix;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
for (const CDLootMatrix& entry : matrix) {
|
|
|
|
LootMatrixEntry matrixEntry{ entry.LootTableIndex, entry.RarityTableIndex, entry.percent, entry.minToDrop, entry.maxToDrop };
|
|
|
|
lootMatrix.push_back(matrixEntry);
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
m_LootMatrices.insert({ index, lootMatrix });
|
|
|
|
}
|
|
|
|
|
|
|
|
// ==============================
|
|
|
|
// Cache Loot Tables
|
|
|
|
// ==============================
|
|
|
|
|
|
|
|
std::vector<uint32_t> uniqueTableIndices;
|
|
|
|
|
|
|
|
for (const CDLootTable& entry : lootTableTable->GetEntries()) {
|
|
|
|
uniqueTableIndices.push_back(entry.LootTableIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
// filter out duplicates
|
|
|
|
std::sort(uniqueTableIndices.begin(), uniqueTableIndices.end());
|
|
|
|
uniqueTableIndices.erase(std::unique(uniqueTableIndices.begin(), uniqueTableIndices.end()), uniqueTableIndices.end());
|
|
|
|
|
|
|
|
for (const uint32_t index : uniqueTableIndices) {
|
|
|
|
std::vector<CDLootTable> entries = lootTableTable->Query([index](const CDLootTable& entry) { return entry.LootTableIndex == index; });
|
|
|
|
|
|
|
|
LootTable lootTable;
|
|
|
|
|
|
|
|
for (const CDLootTable& entry : entries) {
|
|
|
|
LootTableEntry tableEntry{ (LOT)entry.itemid, entry.MissionDrop };
|
|
|
|
lootTable.push_back(tableEntry);
|
|
|
|
}
|
|
|
|
|
|
|
|
// sort by item rarity descending
|
|
|
|
std::sort(lootTable.begin(), lootTable.end(), [&](const LootTableEntry& x, const LootTableEntry& y) {
|
|
|
|
return m_ItemRarities[x.itemID] > m_ItemRarities[y.itemID];
|
|
|
|
});
|
|
|
|
|
|
|
|
m_LootTables.insert({ index, lootTable });
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
std::unordered_map<LOT, int32_t> LootGenerator::RollLootMatrix(Entity* player, uint32_t matrixIndex) {
|
|
|
|
auto* missionComponent = player->GetComponent<MissionComponent>();
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
std::unordered_map<LOT, int32_t> drops;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-22 16:16:31 +00:00
|
|
|
if (missionComponent == nullptr) {
|
|
|
|
return drops;
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
const LootMatrix& matrix = m_LootMatrices[matrixIndex];
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
for (const LootMatrixEntry& entry : matrix) {
|
|
|
|
if (GeneralUtils::GenerateRandomNumber<float>(0, 1) < entry.percent) {
|
|
|
|
const LootTable& lootTable = m_LootTables[entry.lootTableIndex];
|
|
|
|
const RarityTable& rarityTable = m_RarityTables[entry.rarityTableIndex];
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
uint32_t dropCount = GeneralUtils::GenerateRandomNumber<uint32_t>(entry.minDrop, entry.maxDrop);
|
|
|
|
for (uint32_t i = 0; i < dropCount; ++i) {
|
|
|
|
uint32_t maxRarity = 1;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
float rarityRoll = GeneralUtils::GenerateRandomNumber<float>(0, 1);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
for (const RarityTableEntry& rarity : rarityTable) {
|
|
|
|
if (rarity.randMax >= rarityRoll) {
|
|
|
|
maxRarity = rarity.rarity;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
bool rarityFound = false;
|
|
|
|
std::vector<LootTableEntry> possibleDrops;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
for (const LootTableEntry& loot : lootTable) {
|
|
|
|
uint32_t rarity = m_ItemRarities[loot.itemID];
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
if (rarity == maxRarity) {
|
|
|
|
possibleDrops.push_back(loot);
|
|
|
|
rarityFound = true;
|
|
|
|
} else if (rarity < maxRarity && !rarityFound) {
|
|
|
|
possibleDrops.push_back(loot);
|
|
|
|
maxRarity = rarity;
|
|
|
|
}
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
if (possibleDrops.size() > 0) {
|
|
|
|
LootTableEntry drop = possibleDrops[GeneralUtils::GenerateRandomNumber<uint32_t>(0, possibleDrops.size() - 1)];
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
// filter out uneeded mission items
|
|
|
|
if (drop.isMissionDrop && !missionComponent->RequiresItem(drop.itemID))
|
|
|
|
continue;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
// convert faction token proxy
|
|
|
|
if (drop.itemID == 13763) {
|
|
|
|
if (missionComponent->GetMissionState(545) == eMissionState::COMPLETE)
|
|
|
|
drop.itemID = 8318; // "Assembly Token"
|
|
|
|
else if (missionComponent->GetMissionState(556) == eMissionState::COMPLETE)
|
|
|
|
drop.itemID = 8321; // "Venture League Token"
|
|
|
|
else if (missionComponent->GetMissionState(567) == eMissionState::COMPLETE)
|
|
|
|
drop.itemID = 8319; // "Sentinels Token"
|
|
|
|
else if (missionComponent->GetMissionState(578) == eMissionState::COMPLETE)
|
|
|
|
drop.itemID = 8320; // "Paradox Token"
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
if (drop.itemID == 13763) {
|
|
|
|
continue;
|
|
|
|
} // check if we aren't in faction
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
if (drops.find(drop.itemID) == drops.end()) {
|
|
|
|
drops.insert({ drop.itemID, 1 });
|
|
|
|
} else {
|
|
|
|
++drops[drop.itemID];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
return drops;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
std::unordered_map<LOT, int32_t> LootGenerator::RollLootMatrix(uint32_t matrixIndex) {
|
|
|
|
std::unordered_map<LOT, int32_t> drops;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
const LootMatrix& matrix = m_LootMatrices[matrixIndex];
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
for (const LootMatrixEntry& entry : matrix) {
|
|
|
|
if (GeneralUtils::GenerateRandomNumber<float>(0, 1) < entry.percent) {
|
|
|
|
const LootTable& lootTable = m_LootTables[entry.lootTableIndex];
|
|
|
|
const RarityTable& rarityTable = m_RarityTables[entry.rarityTableIndex];
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
uint32_t dropCount = GeneralUtils::GenerateRandomNumber<uint32_t>(entry.minDrop, entry.maxDrop);
|
|
|
|
for (uint32_t i = 0; i < dropCount; ++i) {
|
|
|
|
uint32_t maxRarity = 1;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
float rarityRoll = GeneralUtils::GenerateRandomNumber<float>(0, 1);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
for (const RarityTableEntry& rarity : rarityTable) {
|
|
|
|
if (rarity.randMax >= rarityRoll) {
|
|
|
|
maxRarity = rarity.rarity;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
bool rarityFound = false;
|
|
|
|
std::vector<LootTableEntry> possibleDrops;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
for (const LootTableEntry& loot : lootTable) {
|
|
|
|
uint32_t rarity = m_ItemRarities[loot.itemID];
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
if (rarity == maxRarity) {
|
|
|
|
possibleDrops.push_back(loot);
|
|
|
|
rarityFound = true;
|
|
|
|
} else if (rarity < maxRarity && !rarityFound) {
|
|
|
|
possibleDrops.push_back(loot);
|
|
|
|
maxRarity = rarity;
|
|
|
|
}
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
if (possibleDrops.size() > 0) {
|
|
|
|
const LootTableEntry& drop = possibleDrops[GeneralUtils::GenerateRandomNumber<uint32_t>(0, possibleDrops.size() - 1)];
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
if (drops.find(drop.itemID) == drops.end()) {
|
|
|
|
drops.insert({ drop.itemID, 1 });
|
|
|
|
} else {
|
|
|
|
++drops[drop.itemID];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
return drops;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-04-24 03:35:34 +00:00
|
|
|
void LootGenerator::GiveLoot(Entity* player, uint32_t matrixIndex, eLootSourceType lootSourceType) {
|
2021-12-20 10:25:45 +00:00
|
|
|
player = player->GetOwner(); // If the owner is overwritten, we collect that here
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
std::unordered_map<LOT, int32_t> result = RollLootMatrix(player, matrixIndex);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-04-24 03:35:34 +00:00
|
|
|
GiveLoot(player, result, lootSourceType);
|
2021-12-20 10:25:45 +00:00
|
|
|
}
|
|
|
|
|
2022-04-24 03:35:34 +00:00
|
|
|
void LootGenerator::GiveLoot(Entity* player, std::unordered_map<LOT, int32_t>& result, eLootSourceType lootSourceType) {
|
2021-12-20 10:25:45 +00:00
|
|
|
player = player->GetOwner(); // if the owner is overwritten, we collect that here
|
|
|
|
|
|
|
|
auto* inventoryComponent = player->GetComponent<InventoryComponent>();
|
|
|
|
|
|
|
|
if (!inventoryComponent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (const auto& pair : result) {
|
2022-04-24 03:35:34 +00:00
|
|
|
inventoryComponent->AddItem(pair.first, pair.second, lootSourceType);
|
2021-12-20 10:25:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LootGenerator::GiveActivityLoot(Entity* player, Entity* source, uint32_t activityID, int32_t rating) {
|
2023-03-17 14:36:21 +00:00
|
|
|
CDActivityRewardsTable* activityRewardsTable = CDClientManager::Instance().GetTable<CDActivityRewardsTable>();
|
2021-12-20 10:25:45 +00:00
|
|
|
std::vector<CDActivityRewards> activityRewards = activityRewardsTable->Query([activityID](CDActivityRewards entry) { return (entry.objectTemplate == activityID); });
|
|
|
|
|
|
|
|
const CDActivityRewards* selectedReward = nullptr;
|
|
|
|
for (const auto& activityReward : activityRewards) {
|
|
|
|
if (activityReward.activityRating <= rating && (selectedReward == nullptr || activityReward.activityRating > selectedReward->activityRating)) {
|
|
|
|
selectedReward = &activityReward;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!selectedReward)
|
|
|
|
return;
|
|
|
|
|
|
|
|
uint32_t minCoins = 0;
|
|
|
|
uint32_t maxCoins = 0;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-03-17 14:36:21 +00:00
|
|
|
CDCurrencyTableTable* currencyTableTable = CDClientManager::Instance().GetTable<CDCurrencyTableTable>();
|
2021-12-20 10:25:45 +00:00
|
|
|
std::vector<CDCurrencyTable> currencyTable = currencyTableTable->Query([selectedReward](CDCurrencyTable entry) { return (entry.currencyIndex == selectedReward->CurrencyIndex && entry.npcminlevel == 1); });
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
if (currencyTable.size() > 0) {
|
|
|
|
minCoins = currencyTable[0].minvalue;
|
|
|
|
maxCoins = currencyTable[0].maxvalue;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-04-24 03:35:34 +00:00
|
|
|
GiveLoot(player, selectedReward->LootMatrixIndex, eLootSourceType::LOOT_SOURCE_ACTIVITY);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
uint32_t coins = (int)(minCoins + GeneralUtils::GenerateRandomNumber<float>(0, 1) * (maxCoins - minCoins));
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
auto* character = player->GetCharacter();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-04-24 03:35:34 +00:00
|
|
|
character->SetCoins(character->GetCoins() + coins, eLootSourceType::LOOT_SOURCE_ACTIVITY);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
void LootGenerator::DropLoot(Entity* player, Entity* killedObject, uint32_t matrixIndex, uint32_t minCoins, uint32_t maxCoins) {
|
|
|
|
player = player->GetOwner(); // if the owner is overwritten, we collect that here
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
auto* inventoryComponent = player->GetComponent<InventoryComponent>();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
if (!inventoryComponent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::unordered_map<LOT, int32_t> result = RollLootMatrix(player, matrixIndex);
|
|
|
|
|
|
|
|
DropLoot(player, killedObject, result, minCoins, maxCoins);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
void LootGenerator::DropLoot(Entity* player, Entity* killedObject, std::unordered_map<LOT, int32_t>& result, uint32_t minCoins, uint32_t maxCoins) {
|
|
|
|
player = player->GetOwner(); // if the owner is overwritten, we collect that here
|
|
|
|
|
|
|
|
auto* inventoryComponent = player->GetComponent<InventoryComponent>();
|
|
|
|
|
|
|
|
if (!inventoryComponent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto spawnPosition = killedObject->GetPosition();
|
|
|
|
|
|
|
|
const auto source = killedObject->GetObjectID();
|
|
|
|
|
|
|
|
for (const auto& pair : result) {
|
|
|
|
for (int i = 0; i < pair.second; ++i) {
|
|
|
|
GameMessages::SendDropClientLoot(player, source, pair.first, 0, spawnPosition, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t coins = (int)(minCoins + GeneralUtils::GenerateRandomNumber<float>(0, 1) * (maxCoins - minCoins));
|
|
|
|
|
|
|
|
GameMessages::SendDropClientLoot(player, source, LOT_NULL, coins, spawnPosition);
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
void LootGenerator::DropActivityLoot(Entity* player, Entity* source, uint32_t activityID, int32_t rating) {
|
2023-03-17 14:36:21 +00:00
|
|
|
CDActivityRewardsTable* activityRewardsTable = CDClientManager::Instance().GetTable<CDActivityRewardsTable>();
|
2021-12-20 10:25:45 +00:00
|
|
|
std::vector<CDActivityRewards> activityRewards = activityRewardsTable->Query([activityID](CDActivityRewards entry) { return (entry.objectTemplate == activityID); });
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
const CDActivityRewards* selectedReward = nullptr;
|
|
|
|
for (const auto& activityReward : activityRewards) {
|
|
|
|
if (activityReward.activityRating <= rating && (selectedReward == nullptr || activityReward.activityRating > selectedReward->activityRating)) {
|
|
|
|
selectedReward = &activityReward;
|
|
|
|
}
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
if (selectedReward == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
uint32_t minCoins = 0;
|
|
|
|
uint32_t maxCoins = 0;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-03-17 14:36:21 +00:00
|
|
|
CDCurrencyTableTable* currencyTableTable = CDClientManager::Instance().GetTable<CDCurrencyTableTable>();
|
2021-12-20 10:25:45 +00:00
|
|
|
std::vector<CDCurrencyTable> currencyTable = currencyTableTable->Query([selectedReward](CDCurrencyTable entry) { return (entry.currencyIndex == selectedReward->CurrencyIndex && entry.npcminlevel == 1); });
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
if (currencyTable.size() > 0) {
|
|
|
|
minCoins = currencyTable[0].minvalue;
|
|
|
|
maxCoins = currencyTable[0].maxvalue;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-20 10:25:45 +00:00
|
|
|
DropLoot(player, source, selectedReward->LootMatrixIndex, minCoins, maxCoins);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|