mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-19 17:38:26 +00:00
Partial work on loot tables (non-compiling)
This commit is contained in:
@@ -28,234 +28,6 @@ using namespace std;
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
#include "../common/EMuShareMem.h"
|
||||
extern LoadEMuShareMemDLL EMuShareMemDLL;
|
||||
bool SharedDatabase::extDBLoadLoot() {
|
||||
return s_usedb->DBLoadLoot();
|
||||
}
|
||||
|
||||
bool SharedDatabase::LoadLoot() {
|
||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
||||
char *query = 0;
|
||||
MYSQL_RES *result;
|
||||
MYSQL_ROW row;
|
||||
uint32 tmpLootTableCount = 0;
|
||||
uint32 tmpLootTableEntriesCount = 0;
|
||||
uint32 tmpLootDropCount = 0;
|
||||
uint32 tmpLootDropEntriesCount = 0;
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT max(id), count(*) FROM loottable"), errbuf, &result)) {
|
||||
safe_delete_array(query);
|
||||
if (mysql_num_rows(result) == 1) {
|
||||
row = mysql_fetch_row(result);
|
||||
if (row[0])
|
||||
loottable_max = atoi(row[0]);
|
||||
else
|
||||
loottable_max = 0;
|
||||
tmpLootTableCount = atoi(row[1]);
|
||||
}
|
||||
else {
|
||||
mysql_free_result(result);
|
||||
return false;
|
||||
}
|
||||
mysql_free_result(result);
|
||||
}
|
||||
else {
|
||||
cerr << "Error in LoadLoot query, loottable part: '" << query << "' " << errbuf << endl;
|
||||
safe_delete_array(query);
|
||||
return false;
|
||||
}
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT count(*) FROM loottable_entries"), errbuf, &result)) {
|
||||
safe_delete_array(query);
|
||||
if (mysql_num_rows(result) == 1) {
|
||||
row = mysql_fetch_row(result);
|
||||
tmpLootTableEntriesCount = atoi(row[0]);
|
||||
}
|
||||
else {
|
||||
mysql_free_result(result);
|
||||
return false;
|
||||
}
|
||||
mysql_free_result(result);
|
||||
}
|
||||
else {
|
||||
cerr << "Error in LoadLoot query, loottable2 part: '" << query << "' " << errbuf << endl;
|
||||
safe_delete_array(query);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT max(id), count(*) FROM lootdrop"), errbuf, &result)) {
|
||||
safe_delete_array(query);
|
||||
if (mysql_num_rows(result) == 1) {
|
||||
row = mysql_fetch_row(result);
|
||||
if (row[0])
|
||||
lootdrop_max = atoi(row[0]);
|
||||
else
|
||||
lootdrop_max = 0;
|
||||
tmpLootDropCount = atoi(row[1]);
|
||||
}
|
||||
else {
|
||||
mysql_free_result(result);
|
||||
return false;
|
||||
}
|
||||
mysql_free_result(result);
|
||||
}
|
||||
else {
|
||||
cerr << "Error in LoadLoot query, lootdrop1 part: '" << query << "' " << errbuf << endl;
|
||||
safe_delete_array(query);
|
||||
return false;
|
||||
}
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT max(lootdrop_id), count(*) FROM lootdrop_entries"), errbuf, &result)) {
|
||||
safe_delete_array(query);
|
||||
if (mysql_num_rows(result) == 1) {
|
||||
row = mysql_fetch_row(result);
|
||||
tmpLootDropEntriesCount = atoi(row[1]);
|
||||
}
|
||||
else {
|
||||
mysql_free_result(result);
|
||||
return false;
|
||||
}
|
||||
mysql_free_result(result);
|
||||
}
|
||||
else {
|
||||
cerr << "Error in LoadLoot query, lootdrop part: '" << query << "' " << errbuf << endl;
|
||||
safe_delete_array(query);
|
||||
return false;
|
||||
}
|
||||
return EMuShareMemDLL.Loot.DLLLoadLoot(&extDBLoadLoot,
|
||||
sizeof(LootTable_Struct), tmpLootTableCount, loottable_max,
|
||||
sizeof(LootTableEntries_Struct), tmpLootTableEntriesCount,
|
||||
sizeof(LootDrop_Struct), tmpLootDropCount, lootdrop_max,
|
||||
sizeof(LootDropEntries_Struct), tmpLootDropEntriesCount);
|
||||
}
|
||||
|
||||
bool SharedDatabase::DBLoadLoot() {
|
||||
LogFile->write(EQEMuLog::Status, "Loading Loot tables from database...");
|
||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
||||
char *query = 0;
|
||||
MYSQL_RES *result;
|
||||
MYSQL_ROW row;
|
||||
MYSQL_RES *result2;
|
||||
uint32 i, tmpid = 0, tmpmincash = 0, tmpmaxcash = 0, tmpavgcoin = 0;
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT id, mincash, maxcash, avgcoin FROM loottable"), errbuf, &result)) {
|
||||
safe_delete_array(query);
|
||||
LootTable_Struct* tmpLT = 0;
|
||||
while ((row = mysql_fetch_row(result))) {
|
||||
tmpid = atoi(row[0]);
|
||||
tmpmincash = atoi(row[1]);
|
||||
tmpmaxcash = atoi(row[2]);
|
||||
tmpavgcoin = atoi(row[3]);
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT loottable_id, lootdrop_id, droplimit, mindrop, multiplier, probability FROM loottable_entries WHERE loottable_id=%i", tmpid), errbuf, &result2)) {
|
||||
safe_delete_array(query);
|
||||
tmpLT = (LootTable_Struct*) new uchar[sizeof(LootTable_Struct) + (sizeof(LootTableEntries_Struct) * mysql_num_rows(result2))];
|
||||
memset(tmpLT, 0, sizeof(LootTable_Struct) + (sizeof(LootTableEntries_Struct) * mysql_num_rows(result2)));
|
||||
tmpLT->NumEntries = mysql_num_rows(result2);
|
||||
tmpLT->mincash = tmpmincash;
|
||||
tmpLT->maxcash = tmpmaxcash;
|
||||
tmpLT->avgcoin = tmpavgcoin;
|
||||
i=0;
|
||||
while ((row = mysql_fetch_row(result2))) {
|
||||
if (i >= tmpLT->NumEntries) {
|
||||
mysql_free_result(result);
|
||||
mysql_free_result(result2);
|
||||
safe_delete_array(tmpLT);
|
||||
cerr << "Error in ZoneDatabase::DBLoadLoot, i >= NumEntries" << endl;
|
||||
return false;
|
||||
}
|
||||
tmpLT->Entries[i].lootdrop_id = atoi(row[1]);
|
||||
tmpLT->Entries[i].droplimit = atoi(row[2]);
|
||||
tmpLT->Entries[i].mindrop = atoi(row[3]);
|
||||
tmpLT->Entries[i].multiplier = atoi(row[4]);
|
||||
tmpLT->Entries[i].probability = atof(row[5]);
|
||||
i++;
|
||||
}
|
||||
if (!EMuShareMemDLL.Loot.cbAddLootTable(tmpid, tmpLT)) {
|
||||
mysql_free_result(result);
|
||||
mysql_free_result(result2);
|
||||
safe_delete_array(tmpLT);
|
||||
cout << "Error in ZoneDatabase::DBLoadLoot: !cbAddLootTable(" << tmpid << ")" << endl;
|
||||
return false;
|
||||
}
|
||||
safe_delete_array(tmpLT);
|
||||
mysql_free_result(result2);
|
||||
}
|
||||
else {
|
||||
mysql_free_result(result);
|
||||
cerr << "Error in LoadLoot (memshare) #1 query '" << query << "' " << errbuf << endl;
|
||||
safe_delete_array(query);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
mysql_free_result(result);
|
||||
}
|
||||
else {
|
||||
cerr << "Error in LoadLoot (memshare) #2 query '" << query << "' " << errbuf << endl;
|
||||
safe_delete_array(query);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT id FROM lootdrop", tmpid), errbuf, &result)) {
|
||||
safe_delete_array(query);
|
||||
LootDrop_Struct* tmpLD = 0;
|
||||
while ((row = mysql_fetch_row(result))) {
|
||||
tmpid = atoi(row[0]);
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT lootdrop_id, item_id, item_charges, equip_item, chance, minlevel, maxlevel, multiplier FROM lootdrop_entries WHERE lootdrop_id=%i order by chance desc", tmpid), errbuf, &result2)) {
|
||||
safe_delete_array(query);
|
||||
tmpLD = (LootDrop_Struct*) new uchar[sizeof(LootDrop_Struct) + (sizeof(LootDropEntries_Struct) * mysql_num_rows(result2))];
|
||||
memset(tmpLD, 0, sizeof(LootDrop_Struct) + (sizeof(LootDropEntries_Struct) * mysql_num_rows(result2)));
|
||||
tmpLD->NumEntries = mysql_num_rows(result2);
|
||||
i=0;
|
||||
while ((row = mysql_fetch_row(result2))) {
|
||||
if (i >= tmpLD->NumEntries) {
|
||||
mysql_free_result(result);
|
||||
mysql_free_result(result2);
|
||||
safe_delete_array(tmpLD);
|
||||
cerr << "Error in ZoneDatabase::DBLoadLoot, i >= NumEntries" << endl;
|
||||
return false;
|
||||
}
|
||||
tmpLD->Entries[i].item_id = atoi(row[1]);
|
||||
tmpLD->Entries[i].item_charges = atoi(row[2]);
|
||||
tmpLD->Entries[i].equip_item = atoi(row[3]);
|
||||
tmpLD->Entries[i].chance = atof(row[4]);
|
||||
tmpLD->Entries[i].minlevel = atoi(row[5]);
|
||||
tmpLD->Entries[i].maxlevel = atoi(row[6]);
|
||||
tmpLD->Entries[i].multiplier = atoi(row[7]);
|
||||
i++;
|
||||
}
|
||||
if (!EMuShareMemDLL.Loot.cbAddLootDrop(tmpid, tmpLD)) {
|
||||
mysql_free_result(result);
|
||||
mysql_free_result(result2);
|
||||
safe_delete_array(tmpLD);
|
||||
cout << "Error in ZoneDatabase::DBLoadLoot: !cbAddLootDrop(" << tmpid << ")" << endl;
|
||||
return false;
|
||||
}
|
||||
safe_delete_array(tmpLD);
|
||||
mysql_free_result(result2);
|
||||
}
|
||||
else {
|
||||
cerr << "Error in LoadLoot (memshare) #3 query '" << query << "' " << errbuf << endl;
|
||||
mysql_free_result(result);
|
||||
safe_delete_array(query);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
mysql_free_result(result);
|
||||
}
|
||||
else {
|
||||
cerr << "Error in LoadLoot (memshare) #4 query '" << query << "' " << errbuf << endl;
|
||||
safe_delete_array(query);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const LootTable_Struct* SharedDatabase::GetLootTable(uint32 loottable_id) {
|
||||
return EMuShareMemDLL.Loot.GetLootTable(loottable_id);
|
||||
}
|
||||
|
||||
const LootDrop_Struct* SharedDatabase::GetLootDrop(uint32 lootdrop_id) {
|
||||
return EMuShareMemDLL.Loot.GetLootDrop(lootdrop_id);
|
||||
}
|
||||
|
||||
// Queries the loottable: adds item & coin to the npc
|
||||
void ZoneDatabase::AddLootTableToNPC(NPC* npc,uint32 loottable_id, ItemList* itemlist, uint32* copper, uint32* silver, uint32* gold, uint32* plat) {
|
||||
_ZP(Database_AddLootTableToNPC);
|
||||
|
||||
Reference in New Issue
Block a user