mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-16 01:01:30 +00:00
Filter global_loot [skip ci]
This commit is contained in:
parent
152d985821
commit
f7d4e51da9
@ -26,32 +26,46 @@
|
||||
#include "../../string_util.h"
|
||||
|
||||
namespace ContentFilterCriteria {
|
||||
static std::string apply()
|
||||
static std::string apply(std::string table_prefix = "")
|
||||
{
|
||||
std::string criteria;
|
||||
|
||||
if (!table_prefix.empty()) {
|
||||
table_prefix = table_prefix + ".";
|
||||
}
|
||||
|
||||
criteria += fmt::format(
|
||||
" AND (min_expansion <= {} OR min_expansion = 0)",
|
||||
content_service.GetCurrentExpansion()
|
||||
" AND ({}min_expansion <= {} OR {}min_expansion = 0)",
|
||||
table_prefix,
|
||||
content_service.GetCurrentExpansion(),
|
||||
table_prefix
|
||||
);
|
||||
|
||||
criteria += fmt::format(
|
||||
" AND (max_expansion >= {} OR max_expansion = 0)",
|
||||
content_service.GetCurrentExpansion()
|
||||
" AND ({}max_expansion >= {} OR {}max_expansion = 0)",
|
||||
table_prefix,
|
||||
content_service.GetCurrentExpansion(),
|
||||
table_prefix
|
||||
);
|
||||
|
||||
std::vector<std::string> flags = content_service.GetContentFlags();
|
||||
for (auto &flag: flags) {
|
||||
|
||||
for (auto &flag: flags) {
|
||||
flag = "'" + flag + "'";
|
||||
}
|
||||
|
||||
std::string flags_in_filter;
|
||||
if (!flags.empty()) {
|
||||
flags_in_filter = fmt::format(" OR content_flags IN ({})", implode(", ", flags));
|
||||
flags_in_filter = fmt::format(
|
||||
" OR {}content_flags IN ({})",
|
||||
table_prefix,
|
||||
implode(", ", flags)
|
||||
);
|
||||
}
|
||||
|
||||
criteria += fmt::format(
|
||||
" AND (content_flags IS NULL{})",
|
||||
" AND ({}content_flags IS NULL{})",
|
||||
table_prefix,
|
||||
flags_in_filter
|
||||
);
|
||||
|
||||
|
||||
@ -27,6 +27,7 @@
|
||||
#include "npc.h"
|
||||
#include "zonedb.h"
|
||||
#include "global_loot_manager.h"
|
||||
#include "../common/repositories/criteria/content_filter_criteria.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
@ -463,42 +464,70 @@ void NPC::CheckGlobalLootTables()
|
||||
|
||||
void ZoneDatabase::LoadGlobalLoot()
|
||||
{
|
||||
auto query = StringFormat("SELECT id, loottable_id, description, min_level, max_level, rare, raid, race, "
|
||||
"class, bodytype, zone, hot_zone FROM global_loot WHERE enabled = 1");
|
||||
auto query = fmt::format(
|
||||
SQL
|
||||
(
|
||||
SELECT
|
||||
id,
|
||||
loottable_id,
|
||||
description,
|
||||
min_level,
|
||||
max_level,
|
||||
rare,
|
||||
raid,
|
||||
race,
|
||||
class,
|
||||
bodytype,
|
||||
zone,
|
||||
hot_zone
|
||||
FROM
|
||||
global_loot
|
||||
WHERE
|
||||
enabled = 1
|
||||
{}
|
||||
),
|
||||
ContentFilterCriteria::apply()
|
||||
);
|
||||
|
||||
auto results = QueryDatabase(query);
|
||||
if (!results.Success() || results.RowCount() == 0)
|
||||
if (!results.Success() || results.RowCount() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// we might need this, lets not keep doing it in a loop
|
||||
auto zoneid = std::to_string(zone->GetZoneID());
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
auto zoneid = std::to_string(zone->GetZoneID());
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
// checking zone limits
|
||||
if (row[10]) {
|
||||
auto zones = SplitString(row[10], '|');
|
||||
|
||||
auto it = std::find(zones.begin(), zones.end(), zoneid);
|
||||
if (it == zones.end()) // not in here, skip
|
||||
if (it == zones.end()) { // not in here, skip
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
GlobalLootEntry e(atoi(row[0]), atoi(row[1]), row[2] ? row[2] : "");
|
||||
|
||||
auto min_level = atoi(row[3]);
|
||||
if (min_level)
|
||||
if (min_level) {
|
||||
e.AddRule(GlobalLoot::RuleTypes::LevelMin, min_level);
|
||||
}
|
||||
|
||||
auto max_level = atoi(row[4]);
|
||||
if (max_level)
|
||||
if (max_level) {
|
||||
e.AddRule(GlobalLoot::RuleTypes::LevelMax, max_level);
|
||||
}
|
||||
|
||||
// null is not used
|
||||
if (row[5])
|
||||
if (row[5]) {
|
||||
e.AddRule(GlobalLoot::RuleTypes::Rare, atoi(row[5]));
|
||||
}
|
||||
|
||||
// null is not used
|
||||
if (row[6])
|
||||
if (row[6]) {
|
||||
e.AddRule(GlobalLoot::RuleTypes::Raid, atoi(row[6]));
|
||||
}
|
||||
|
||||
if (row[7]) {
|
||||
auto races = SplitString(row[7], '|');
|
||||
@ -522,8 +551,9 @@ void ZoneDatabase::LoadGlobalLoot()
|
||||
}
|
||||
|
||||
// null is not used
|
||||
if (row[11])
|
||||
if (row[11]) {
|
||||
e.AddRule(GlobalLoot::RuleTypes::HotZone, atoi(row[11]));
|
||||
}
|
||||
|
||||
zone->AddGlobalLootEntry(e);
|
||||
}
|
||||
|
||||
@ -551,32 +551,32 @@ void Zone::GetMerchantDataForZoneLoad() {
|
||||
std::string query = fmt::format(
|
||||
SQL (
|
||||
SELECT
|
||||
DISTINCT ml.merchantid,
|
||||
ml.slot,
|
||||
ml.item,
|
||||
ml.faction_required,
|
||||
ml.level_required,
|
||||
ml.alt_currency_cost,
|
||||
ml.classes_required,
|
||||
ml.probability
|
||||
DISTINCT merchantlist.merchantid,
|
||||
merchantlist.slot,
|
||||
merchantlist.item,
|
||||
merchantlist.faction_required,
|
||||
merchantlist.level_required,
|
||||
merchantlist.alt_currency_cost,
|
||||
merchantlist.classes_required,
|
||||
merchantlist.probability
|
||||
FROM
|
||||
merchantlist AS ml,
|
||||
npc_types AS nt,
|
||||
spawnentry AS se,
|
||||
spawn2 AS s2
|
||||
merchantlist,
|
||||
npc_types,
|
||||
spawnentry,
|
||||
spawn2
|
||||
WHERE
|
||||
nt.merchant_id = ml.merchantid
|
||||
AND nt.id = se.npcid
|
||||
AND se.spawngroupid = s2.spawngroupid
|
||||
AND s2.zone = '{}'
|
||||
AND s2.version = {}
|
||||
npc_types.merchant_id = merchantlist.merchantid
|
||||
AND npc_types.id = spawnentry.npcid
|
||||
AND spawnentry.spawngroupid = spawn2.spawngroupid
|
||||
AND spawn2.zone = '{}'
|
||||
AND spawn2.version = {}
|
||||
{}
|
||||
ORDER BY
|
||||
ml.slot
|
||||
merchantlist.slot
|
||||
),
|
||||
GetShortName(),
|
||||
GetInstanceVersion(),
|
||||
ContentFilterCriteria::apply()
|
||||
ContentFilterCriteria::apply("merchantlist")
|
||||
);
|
||||
|
||||
auto results = content_db.QueryDatabase(query);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user