Merge branch 'feature/peq-expansions' of https://github.com/EQEmu/Server into feature/generated-repositories

This commit is contained in:
Akkadius
2020-04-05 23:21:21 -05:00
21 changed files with 639 additions and 325 deletions
+5 -3
View File
@@ -28,7 +28,7 @@ namespace Expansion {
enum ExpansionNumber {
Classic = 0,
TheRuinsOfKunark,
TheShardsOfVelious,
TheScarsOfVelious,
TheShadowsOfLuclin,
ThePlanesOfPower,
TheLegacyOfYkesha,
@@ -62,8 +62,10 @@ namespace Expansion {
static const char *ExpansionName[ExpansionNumber::MaxId] = {
"Classic",
"The Ruins of Kunark",
"The Scars of Velious",
"The Shadows of Luclin",
"The Planes of Power",
"The Legacy of Ykesha",
"Lost Dungeons of Norrath",
"Gates of Discord",
"Omens of War",
@@ -96,7 +98,7 @@ public:
bool IsClassicEnabled() { return GetCurrentExpansion() >= Expansion::ExpansionNumber::Classic; }
bool IsTheRuinsOfKunarkEnabled() { return GetCurrentExpansion() >= Expansion::ExpansionNumber::TheRuinsOfKunark; }
bool IsTheShardsOfVeliousEnabled() { return GetCurrentExpansion() >= Expansion::ExpansionNumber::TheShardsOfVelious; }
bool IsTheScarsOfVeliousEnabled() { return GetCurrentExpansion() >= Expansion::ExpansionNumber::TheScarsOfVelious; }
bool IsTheShadowsOfLuclinEnabled() { return GetCurrentExpansion() >= Expansion::ExpansionNumber::TheShadowsOfLuclin; }
bool IsThePlanesOfPowerEnabled() { return GetCurrentExpansion() >= Expansion::ExpansionNumber::ThePlanesOfPower; }
bool IsTheLegacyOfYkeshaEnabled() { return GetCurrentExpansion() >= Expansion::ExpansionNumber::TheLegacyOfYkesha; }
@@ -124,7 +126,7 @@ public:
bool IsCurrentExpansionClassic() { return current_expansion == Expansion::ExpansionNumber::Classic; }
bool IsCurrentExpansionTheRuinsOfKunark() { return current_expansion == Expansion::ExpansionNumber::TheRuinsOfKunark; }
bool IsCurrentExpansionTheShardsOfVelious() { return current_expansion == Expansion::ExpansionNumber::TheShardsOfVelious; }
bool IsCurrentExpansionTheScarsOfVelious() { return current_expansion == Expansion::ExpansionNumber::TheScarsOfVelious; }
bool IsCurrentExpansionTheShadowsOfLuclin() { return current_expansion == Expansion::ExpansionNumber::TheShadowsOfLuclin; }
bool IsCurrentExpansionThePlanesOfPower() { return current_expansion == Expansion::ExpansionNumber::ThePlanesOfPower; }
bool IsCurrentExpansionTheLegacyOfYkesha() { return current_expansion == Expansion::ExpansionNumber::TheLegacyOfYkesha; }
@@ -26,28 +26,47 @@
#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) {
flag = "'" + flag + "'";
}
std::string flags_in_filter;
if (!flags.empty()) {
flags_in_filter = fmt::format(
" OR {}content_flags IN ({})",
table_prefix,
implode(", ", flags)
);
}
criteria += fmt::format(
" AND (content_flags IS NULL OR content_flags IN ({}))",
implode(", ", flags)
" AND ({}content_flags IS NULL{})",
table_prefix,
flags_in_filter
);
return std::string(criteria);
+116 -51
View File
@@ -38,6 +38,7 @@
#include "shareddb.h"
#include "string_util.h"
#include "eqemu_config.h"
#include "repositories/criteria/content_filter_criteria.h"
namespace ItemField
{
@@ -431,16 +432,25 @@ bool SharedDatabase::SetSharedPlatinum(uint32 account_id, int32 amount_to_add) {
bool SharedDatabase::SetStartingItems(PlayerProfile_Struct* pp, EQEmu::InventoryProfile* inv, uint32 si_race, uint32 si_class, uint32 si_deity, uint32 si_current_zone, char* si_name, int admin_level) {
const EQEmu::ItemData* myitem;
const EQEmu::ItemData *myitem;
std::string query = StringFormat("SELECT itemid, item_charges, slot FROM starting_items "
"WHERE (race = %i or race = 0) AND (class = %i or class = 0) AND "
"(deityid = %i or deityid = 0) AND (zoneid = %i or zoneid = 0) AND "
"gm <= %i ORDER BY id",
si_race, si_class, si_deity, si_current_zone, admin_level);
auto results = QueryDatabase(query);
if (!results.Success())
return false;
std::string query = StringFormat(
"SELECT itemid, item_charges, slot FROM starting_items "
"WHERE (race = %i or race = 0) AND (class = %i or class = 0) AND "
"(deityid = %i or deityid = 0) AND (zoneid = %i or zoneid = 0) AND "
"gm <= %i %s ORDER BY id",
si_race,
si_class,
si_deity,
si_current_zone,
admin_level,
ContentFilterCriteria::apply().c_str()
);
auto results = QueryDatabase(query);
if (!results.Success()) {
return false;
}
for (auto row = results.begin(); row != results.end(); ++row) {
@@ -567,7 +577,7 @@ bool SharedDatabase::GetInventory(uint32 char_id, EQEmu::InventoryProfile *inv)
{
if (!char_id || !inv)
return false;
// Retrieve character inventory
std::string query =
StringFormat("SELECT slotid, itemid, charges, color, augslot1, augslot2, augslot3, augslot4, augslot5, "
@@ -728,7 +738,7 @@ bool SharedDatabase::GetInventory(uint32 char_id, EQEmu::InventoryProfile *inv)
char_id, item_id, slot_id);
}
}
if (cv_conflict) {
char char_name[64] = "";
GetCharName(char_id, char_name);
@@ -1462,7 +1472,7 @@ bool SharedDatabase::GetCommandSettings(std::map<std::string, std::pair<uint8, s
auto results = QueryDatabase(query);
if (!results.Success())
return false;
for (auto row = results.begin(); row != results.end(); ++row) {
command_settings[row[0]].first = atoi(row[1]);
if (row[2][0] == 0)
@@ -1696,7 +1706,7 @@ bool SharedDatabase::LoadSpells(const std::string &prefix, int32 *records, const
auto Config = EQEmuConfig::get();
EQEmu::IPCMutex mutex("spells");
mutex.Lock();
std::string file_name = Config->SharedMemDir + prefix + std::string("spells");
spells_mmf = std::unique_ptr<EQEmu::MemoryMappedFile>(new EQEmu::MemoryMappedFile(file_name));
*records = *reinterpret_cast<uint32*>(spells_mmf->Get());
@@ -1996,7 +2006,11 @@ void SharedDatabase::GetLootTableInfo(uint32 &loot_table_count, uint32 &max_loot
loot_table_count = 0;
max_loot_table = 0;
loot_table_entries = 0;
const std::string query = "SELECT COUNT(*), MAX(id), (SELECT COUNT(*) FROM loottable_entries) FROM loottable";
const std::string query =
fmt::format(
"SELECT COUNT(*), MAX(id), (SELECT COUNT(*) FROM loottable_entries) FROM loottable WHERE TRUE {}",
ContentFilterCriteria::apply()
);
auto results = QueryDatabase(query);
if (!results.Success()) {
return;
@@ -2017,7 +2031,11 @@ void SharedDatabase::GetLootDropInfo(uint32 &loot_drop_count, uint32 &max_loot_d
max_loot_drop = 0;
loot_drop_entries = 0;
const std::string query = "SELECT COUNT(*), MAX(id), (SELECT COUNT(*) FROM lootdrop_entries) FROM lootdrop";
const std::string query = fmt::format(
"SELECT COUNT(*), MAX(id), (SELECT COUNT(*) FROM lootdrop_entries) FROM lootdrop WHERE TRUE {}",
ContentFilterCriteria::apply()
);
auto results = QueryDatabase(query);
if (!results.Success()) {
return;
@@ -2039,50 +2057,79 @@ void SharedDatabase::LoadLootTables(void *data, uint32 size) {
uint8 loot_table[sizeof(LootTable_Struct) + (sizeof(LootTableEntries_Struct) * 128)];
LootTable_Struct *lt = reinterpret_cast<LootTable_Struct*>(loot_table);
const std::string query = "SELECT loottable.id, loottable.mincash, loottable.maxcash, loottable.avgcoin, "
"loottable_entries.lootdrop_id, loottable_entries.multiplier, loottable_entries.droplimit, "
"loottable_entries.mindrop, loottable_entries.probability FROM loottable LEFT JOIN loottable_entries "
"ON loottable.id = loottable_entries.loottable_id ORDER BY id";
const std::string query = fmt::format(
SQL(
SELECT
loottable.id,
loottable.mincash,
loottable.maxcash,
loottable.avgcoin,
loottable_entries.lootdrop_id,
loottable_entries.multiplier,
loottable_entries.droplimit,
loottable_entries.mindrop,
loottable_entries.probability
FROM
loottable
LEFT JOIN loottable_entries ON loottable.id = loottable_entries.loottable_id
WHERE TRUE {}
ORDER BY
id
),
ContentFilterCriteria::apply()
);
auto results = QueryDatabase(query);
if (!results.Success()) {
return;
}
uint32 current_id = 0;
uint32 current_entry = 0;
uint32 current_id = 0;
uint32 current_entry = 0;
for (auto row = results.begin(); row != results.end(); ++row) {
uint32 id = static_cast<uint32>(atoul(row[0]));
if(id != current_id) {
if(current_id != 0)
hash.insert(current_id, loot_table, (sizeof(LootTable_Struct) + (sizeof(LootTableEntries_Struct) * lt->NumEntries)));
for (auto row = results.begin(); row != results.end(); ++row) {
uint32 id = static_cast<uint32>(atoul(row[0]));
if (id != current_id) {
if (current_id != 0) {
hash.insert(
current_id,
loot_table,
(sizeof(LootTable_Struct) + (sizeof(LootTableEntries_Struct) * lt->NumEntries)));
}
memset(loot_table, 0, sizeof(LootTable_Struct) + (sizeof(LootTableEntries_Struct) * 128));
current_entry = 0;
current_id = id;
lt->mincash = static_cast<uint32>(atoul(row[1]));
lt->maxcash = static_cast<uint32>(atoul(row[2]));
lt->avgcoin = static_cast<uint32>(atoul(row[3]));
}
memset(loot_table, 0, sizeof(LootTable_Struct) + (sizeof(LootTableEntries_Struct) * 128));
current_entry = 0;
current_id = id;
lt->mincash = static_cast<uint32>(atoul(row[1]));
lt->maxcash = static_cast<uint32>(atoul(row[2]));
lt->avgcoin = static_cast<uint32>(atoul(row[3]));
}
if(current_entry > 128)
continue;
if (current_entry > 128) {
continue;
}
if(!row[4])
continue;
if (!row[4]) {
continue;
}
lt->Entries[current_entry].lootdrop_id = static_cast<uint32>(atoul(row[4]));
lt->Entries[current_entry].multiplier = static_cast<uint8>(atoi(row[5]));
lt->Entries[current_entry].droplimit = static_cast<uint8>(atoi(row[6]));
lt->Entries[current_entry].mindrop = static_cast<uint8>(atoi(row[7]));
lt->Entries[current_entry].probability = static_cast<float>(atof(row[8]));
lt->Entries[current_entry].lootdrop_id = static_cast<uint32>(atoul(row[4]));
lt->Entries[current_entry].multiplier = static_cast<uint8>(atoi(row[5]));
lt->Entries[current_entry].droplimit = static_cast<uint8>(atoi(row[6]));
lt->Entries[current_entry].mindrop = static_cast<uint8>(atoi(row[7]));
lt->Entries[current_entry].probability = static_cast<float>(atof(row[8]));
++(lt->NumEntries);
++current_entry;
}
++(lt->NumEntries);
++current_entry;
}
if(current_id != 0)
hash.insert(current_id, loot_table, (sizeof(LootTable_Struct) + (sizeof(LootTableEntries_Struct) * lt->NumEntries)));
if (current_id != 0) {
hash.insert(
current_id,
loot_table,
(sizeof(LootTable_Struct) + (sizeof(LootTableEntries_Struct) * lt->NumEntries))
);
}
}
@@ -2092,10 +2139,28 @@ void SharedDatabase::LoadLootDrops(void *data, uint32 size) {
uint8 loot_drop[sizeof(LootDrop_Struct) + (sizeof(LootDropEntries_Struct) * 1260)];
LootDrop_Struct *ld = reinterpret_cast<LootDrop_Struct*>(loot_drop);
const std::string query = "SELECT lootdrop.id, lootdrop_entries.item_id, lootdrop_entries.item_charges, "
"lootdrop_entries.equip_item, lootdrop_entries.chance, lootdrop_entries.minlevel, "
"lootdrop_entries.maxlevel, lootdrop_entries.multiplier FROM lootdrop JOIN lootdrop_entries "
"ON lootdrop.id = lootdrop_entries.lootdrop_id ORDER BY lootdrop_id";
const std::string query = fmt::format(
SQL(
SELECT
lootdrop.id,
lootdrop_entries.item_id,
lootdrop_entries.item_charges,
lootdrop_entries.equip_item,
lootdrop_entries.chance,
lootdrop_entries.minlevel,
lootdrop_entries.maxlevel,
lootdrop_entries.multiplier
FROM
lootdrop
JOIN lootdrop_entries ON lootdrop.id = lootdrop_entries.lootdrop_id
WHERE
TRUE {}
ORDER BY
lootdrop_id
),
ContentFilterCriteria::apply()
);
auto results = QueryDatabase(query);
if (!results.Success()) {
return;