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"
|
2023-01-22 23:38:47 +00:00
|
|
|
#include "eMissionState.h"
|
2023-03-04 07:16:37 +00:00
|
|
|
#include "eReplicaComponentType.h"
|
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
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
// ==============================
|
|
|
|
// Cache Item Rarities
|
|
|
|
// ==============================
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
std::vector<uint32_t> uniqueItems;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (const CDLootTable& loot : lootTableTable->GetEntries()) {
|
|
|
|
uniqueItems.push_back(loot.itemid);
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +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
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (const uint32_t itemID : uniqueItems) {
|
2023-03-04 07:16:37 +00:00
|
|
|
uint32_t itemComponentID = componentsRegistryTable->GetByIDAndType(itemID, eReplicaComponentType::ITEM);
|
2022-07-28 13:39:57 +00:00
|
|
|
const CDItemComponent& item = itemComponentTable->GetItemComponentByID(itemComponentID);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
m_ItemRarities.insert({ itemID, item.rarity });
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
// ==============================
|
|
|
|
// Cache Rarity Tables
|
|
|
|
// ==============================
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
std::vector<uint32_t> uniqueRarityIndices;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (const CDRarityTable& rarity : rarityTableTable->GetEntries()) {
|
|
|
|
uniqueRarityIndices.push_back(rarity.RarityTableIndex);
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +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
|
|
|
|
2022-07-28 13:39:57 +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
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
RarityTable rarityTable;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +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
|
|
|
|
2022-07-28 13:39:57 +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
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
m_RarityTables.insert({ index, rarityTable });
|
|
|
|
}
|
2021-12-20 10:25:45 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
// ==============================
|
|
|
|
// Cache Loot Matrices
|
|
|
|
// ==============================
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
std::vector<uint32_t> uniqueMatrixIndices;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (const CDLootMatrix& matrix : lootMatrixTable->GetEntries()) {
|
|
|
|
uniqueMatrixIndices.push_back(matrix.LootMatrixIndex);
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +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
|
|
|
|
2022-07-28 13:39:57 +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
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
LootMatrix lootMatrix;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +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
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
m_LootMatrices.insert({ index, lootMatrix });
|
|
|
|
}
|
2021-12-20 10:25:45 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
// ==============================
|
|
|
|
// Cache Loot Tables
|
|
|
|
// ==============================
|
2021-12-20 10:25:45 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
std::vector<uint32_t> uniqueTableIndices;
|
2021-12-20 10:25:45 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (const CDLootTable& entry : lootTableTable->GetEntries()) {
|
|
|
|
uniqueTableIndices.push_back(entry.LootTableIndex);
|
|
|
|
}
|
2021-12-20 10:25:45 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
// filter out duplicates
|
|
|
|
std::sort(uniqueTableIndices.begin(), uniqueTableIndices.end());
|
|
|
|
uniqueTableIndices.erase(std::unique(uniqueTableIndices.begin(), uniqueTableIndices.end()), uniqueTableIndices.end());
|
2021-12-20 10:25:45 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (const uint32_t index : uniqueTableIndices) {
|
|
|
|
std::vector<CDLootTable> entries = lootTableTable->Query([index](const CDLootTable& entry) { return entry.LootTableIndex == index; });
|
2021-12-20 10:25:45 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
LootTable lootTable;
|
2021-12-20 10:25:45 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (const CDLootTable& entry : entries) {
|
|
|
|
LootTableEntry tableEntry{ (LOT)entry.itemid, entry.MissionDrop };
|
|
|
|
lootTable.push_back(tableEntry);
|
|
|
|
}
|
2021-12-20 10:25:45 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
// 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];
|
|
|
|
});
|
2021-12-20 10:25:45 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
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) {
|
2022-07-28 13:39:57 +00:00
|
|
|
auto* missionComponent = player->GetComponent<MissionComponent>();
|
|
|
|
|
|
|
|
std::unordered_map<LOT, int32_t> drops;
|
|
|
|
|
|
|
|
if (missionComponent == nullptr) {
|
|
|
|
return drops;
|
|
|
|
}
|
|
|
|
|
|
|
|
const LootMatrix& matrix = m_LootMatrices[matrixIndex];
|
|
|
|
|
|
|
|
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];
|
|
|
|
|
|
|
|
uint32_t dropCount = GeneralUtils::GenerateRandomNumber<uint32_t>(entry.minDrop, entry.maxDrop);
|
|
|
|
for (uint32_t i = 0; i < dropCount; ++i) {
|
|
|
|
uint32_t maxRarity = 1;
|
|
|
|
|
|
|
|
float rarityRoll = GeneralUtils::GenerateRandomNumber<float>(0, 1);
|
|
|
|
|
|
|
|
for (const RarityTableEntry& rarity : rarityTable) {
|
|
|
|
if (rarity.randMax >= rarityRoll) {
|
|
|
|
maxRarity = rarity.rarity;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool rarityFound = false;
|
|
|
|
std::vector<LootTableEntry> possibleDrops;
|
|
|
|
|
|
|
|
for (const LootTableEntry& loot : lootTable) {
|
|
|
|
uint32_t rarity = m_ItemRarities[loot.itemID];
|
|
|
|
|
|
|
|
if (rarity == maxRarity) {
|
|
|
|
possibleDrops.push_back(loot);
|
|
|
|
rarityFound = true;
|
|
|
|
} else if (rarity < maxRarity && !rarityFound) {
|
|
|
|
possibleDrops.push_back(loot);
|
|
|
|
maxRarity = rarity;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (possibleDrops.size() > 0) {
|
|
|
|
LootTableEntry drop = possibleDrops[GeneralUtils::GenerateRandomNumber<uint32_t>(0, possibleDrops.size() - 1)];
|
|
|
|
|
|
|
|
// filter out uneeded mission items
|
|
|
|
if (drop.isMissionDrop && !missionComponent->RequiresItem(drop.itemID))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// convert faction token proxy
|
|
|
|
if (drop.itemID == 13763) {
|
2023-01-22 23:38:47 +00:00
|
|
|
if (missionComponent->GetMissionState(545) == eMissionState::COMPLETE)
|
2022-07-28 13:39:57 +00:00
|
|
|
drop.itemID = 8318; // "Assembly Token"
|
2023-01-22 23:38:47 +00:00
|
|
|
else if (missionComponent->GetMissionState(556) == eMissionState::COMPLETE)
|
2022-07-28 13:39:57 +00:00
|
|
|
drop.itemID = 8321; // "Venture League Token"
|
2023-01-22 23:38:47 +00:00
|
|
|
else if (missionComponent->GetMissionState(567) == eMissionState::COMPLETE)
|
2022-07-28 13:39:57 +00:00
|
|
|
drop.itemID = 8319; // "Sentinels Token"
|
2023-01-22 23:38:47 +00:00
|
|
|
else if (missionComponent->GetMissionState(578) == eMissionState::COMPLETE)
|
2022-07-28 13:39:57 +00:00
|
|
|
drop.itemID = 8320; // "Paradox Token"
|
|
|
|
}
|
|
|
|
|
|
|
|
if (drop.itemID == 13763) {
|
|
|
|
continue;
|
|
|
|
} // check if we aren't in faction
|
|
|
|
|
|
|
|
if (drops.find(drop.itemID) == drops.end()) {
|
|
|
|
drops.insert({ drop.itemID, 1 });
|
|
|
|
} else {
|
|
|
|
++drops[drop.itemID];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2022-07-28 13:39:57 +00:00
|
|
|
std::unordered_map<LOT, int32_t> drops;
|
|
|
|
|
|
|
|
const LootMatrix& matrix = m_LootMatrices[matrixIndex];
|
|
|
|
|
|
|
|
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];
|
|
|
|
|
|
|
|
uint32_t dropCount = GeneralUtils::GenerateRandomNumber<uint32_t>(entry.minDrop, entry.maxDrop);
|
|
|
|
for (uint32_t i = 0; i < dropCount; ++i) {
|
|
|
|
uint32_t maxRarity = 1;
|
|
|
|
|
|
|
|
float rarityRoll = GeneralUtils::GenerateRandomNumber<float>(0, 1);
|
|
|
|
|
|
|
|
for (const RarityTableEntry& rarity : rarityTable) {
|
|
|
|
if (rarity.randMax >= rarityRoll) {
|
|
|
|
maxRarity = rarity.rarity;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool rarityFound = false;
|
|
|
|
std::vector<LootTableEntry> possibleDrops;
|
|
|
|
|
|
|
|
for (const LootTableEntry& loot : lootTable) {
|
|
|
|
uint32_t rarity = m_ItemRarities[loot.itemID];
|
|
|
|
|
|
|
|
if (rarity == maxRarity) {
|
|
|
|
possibleDrops.push_back(loot);
|
|
|
|
rarityFound = true;
|
|
|
|
} else if (rarity < maxRarity && !rarityFound) {
|
|
|
|
possibleDrops.push_back(loot);
|
|
|
|
maxRarity = rarity;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (possibleDrops.size() > 0) {
|
|
|
|
const LootTableEntry& drop = possibleDrops[GeneralUtils::GenerateRandomNumber<uint32_t>(0, possibleDrops.size() - 1)];
|
|
|
|
|
|
|
|
if (drops.find(drop.itemID) == drops.end()) {
|
|
|
|
drops.insert({ drop.itemID, 1 });
|
|
|
|
} else {
|
|
|
|
++drops[drop.itemID];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return drops;
|
2021-12-20 10:25:45 +00:00
|
|
|
}
|
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) {
|
2022-07-28 13:39:57 +00:00
|
|
|
player = player->GetOwner(); // If the owner is overwritten, we collect that here
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
std::unordered_map<LOT, int32_t> result = RollLootMatrix(player, matrixIndex);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +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) {
|
2022-07-28 13:39:57 +00:00
|
|
|
player = player->GetOwner(); // if the owner is overwritten, we collect that here
|
2021-12-20 10:25:45 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
auto* inventoryComponent = player->GetComponent<InventoryComponent>();
|
2021-12-20 10:25:45 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (!inventoryComponent)
|
|
|
|
return;
|
2021-12-20 10:25:45 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (const auto& pair : result) {
|
|
|
|
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>();
|
2022-07-28 13:39:57 +00:00
|
|
|
std::vector<CDActivityRewards> activityRewards = activityRewardsTable->Query([activityID](CDActivityRewards entry) { return (entry.objectTemplate == activityID); });
|
2021-12-20 10:25:45 +00:00
|
|
|
|
2022-07-28 13:39:57 +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-20 10:25:45 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (!selectedReward)
|
|
|
|
return;
|
2021-12-20 10:25:45 +00:00
|
|
|
|
2022-07-28 13:39:57 +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>();
|
2022-07-28 13:39:57 +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
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (currencyTable.size() > 0) {
|
|
|
|
minCoins = currencyTable[0].minvalue;
|
|
|
|
maxCoins = currencyTable[0].maxvalue;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
GiveLoot(player, selectedReward->LootMatrixIndex, eLootSourceType::LOOT_SOURCE_ACTIVITY);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
uint32_t coins = (int)(minCoins + GeneralUtils::GenerateRandomNumber<float>(0, 1) * (maxCoins - minCoins));
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
auto* character = player->GetCharacter();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +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) {
|
2022-07-28 13:39:57 +00:00
|
|
|
player = player->GetOwner(); // if the owner is overwritten, we collect that here
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
auto* inventoryComponent = player->GetComponent<InventoryComponent>();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (!inventoryComponent)
|
|
|
|
return;
|
2021-12-20 10:25:45 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
std::unordered_map<LOT, int32_t> result = RollLootMatrix(player, matrixIndex);
|
2021-12-20 10:25:45 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
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) {
|
2022-07-28 13:39:57 +00:00
|
|
|
player = player->GetOwner(); // if the owner is overwritten, we collect that here
|
2021-12-20 10:25:45 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
auto* inventoryComponent = player->GetComponent<InventoryComponent>();
|
2021-12-20 10:25:45 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (!inventoryComponent)
|
|
|
|
return;
|
2021-12-20 10:25:45 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
const auto spawnPosition = killedObject->GetPosition();
|
2021-12-20 10:25:45 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
const auto source = killedObject->GetObjectID();
|
2021-12-20 10:25:45 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (const auto& pair : result) {
|
|
|
|
for (int i = 0; i < pair.second; ++i) {
|
|
|
|
GameMessages::SendDropClientLoot(player, source, pair.first, 0, spawnPosition, 1);
|
|
|
|
}
|
|
|
|
}
|
2021-12-20 10:25:45 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
uint32_t coins = (int)(minCoins + GeneralUtils::GenerateRandomNumber<float>(0, 1) * (maxCoins - minCoins));
|
2021-12-20 10:25:45 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
GameMessages::SendDropClientLoot(player, source, LOT_NULL, coins, spawnPosition);
|
2021-12-20 10:25:45 +00:00
|
|
|
}
|
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>();
|
2022-07-28 13:39:57 +00:00
|
|
|
std::vector<CDActivityRewards> activityRewards = activityRewardsTable->Query([activityID](CDActivityRewards entry) { return (entry.objectTemplate == activityID); });
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +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
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (selectedReward == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +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>();
|
2022-07-28 13:39:57 +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
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (currencyTable.size() > 0) {
|
|
|
|
minCoins = currencyTable[0].minvalue;
|
|
|
|
maxCoins = currencyTable[0].maxvalue;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
DropLoot(player, source, selectedReward->LootMatrixIndex, minCoins, maxCoins);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|