mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-16 18:52:22 +00:00
Partial work on loot tables (non-compiling)
This commit is contained in:
@@ -111,7 +111,6 @@ SET(zone_headers
|
||||
guild_mgr.h
|
||||
hate_list.h
|
||||
horse.h
|
||||
loottable.h
|
||||
map.h
|
||||
masterentity.h
|
||||
maxskill.h
|
||||
|
||||
@@ -7867,7 +7867,7 @@ void Client::Handle_OP_Trader(const EQApplicationPacket *app)
|
||||
// Verify there are no NODROP or items with a zero price
|
||||
bool TradeItemsValid = true;
|
||||
|
||||
for(int i=0; i<max_items; i++) {
|
||||
for(uint32 i = 0; i < max_items; i++) {
|
||||
|
||||
if(gis->Items[i] == 0) break;
|
||||
|
||||
@@ -7897,11 +7897,11 @@ void Client::Handle_OP_Trader(const EQApplicationPacket *app)
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i=0;i<max_items;i++) {
|
||||
if(gis->Items[i]>0 && gis->Items[i]<database.GetMaxItem() && database.GetItem(gis->Items[i])!=0)
|
||||
for (uint32 i = 0; i < max_items; i++) {
|
||||
if(database.GetItem(gis->Items[i])) {
|
||||
database.SaveTraderItem(this->CharacterID(),gis->Items[i],gis->SerialNumber[i],
|
||||
gis->Charges[i],ints->ItemCost[i],i);
|
||||
else {
|
||||
} else {
|
||||
//return; //sony doesnt memset so assume done on first bad item
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -665,38 +665,6 @@ int32 ZoneDatabase::GetDoorsDBCountPlusOne(const char *zone_name, int16 version)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
extern "C" bool extDBLoadDoors(int32 iDoorCount, uint32 iMaxDoorID) { return database.DBLoadDoors(iDoorCount, iMaxDoorID); }
|
||||
const Door* ZoneDatabase::GetDoor(uint8 door_id, const char* zone_name) {
|
||||
for(uint32 i=0; i!=max_door_type;i++)
|
||||
{
|
||||
const Door* door;
|
||||
door = GetDoorDBID(i);
|
||||
if (!door)
|
||||
continue;
|
||||
if(door->door_id == door_id && strcasecmp(door->zone_name, zone_name) == 0)
|
||||
return door;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const Door* ZoneDatabase::GetDoorDBID(uint32 db_id) {
|
||||
return EMuShareMemDLL.Doors.GetDoor(db_id);
|
||||
}
|
||||
|
||||
bool ZoneDatabase::LoadDoors() {
|
||||
if (!EMuShareMemDLL.Load())
|
||||
return false;
|
||||
int32 tmp = 0;
|
||||
tmp = GetDoorsCount(&max_door_type);
|
||||
if (tmp == -1) {
|
||||
cout << "Error: ZoneDatabase::LoadDoors-ShareMem: GetDoorsCount() returned < 0" << endl;
|
||||
return false;
|
||||
}
|
||||
bool ret = EMuShareMemDLL.Doors.DLLLoadDoors(&extDBLoadDoors, sizeof(Door), &tmp, &max_door_type);
|
||||
return ret;
|
||||
}*/
|
||||
|
||||
bool ZoneDatabase::LoadDoors(int32 iDoorCount, Door *into, const char *zone_name, int16 version) {
|
||||
LogFile->write(EQEMuLog::Status, "Loading Doors from database...");
|
||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
/* EQEMu: Everquest Server Emulator
|
||||
Copyright (C) 2001-2002 EQEMu Development Team (http://eqemu.org)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; version 2 of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY except by those people which sell it, which
|
||||
are required to give you total support for your newly bought product;
|
||||
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
/*
|
||||
alter table npc_types add column loottable_id int(11) unsigned not null;
|
||||
|
||||
create table loottable (id int(11) unsigned auto_increment primary key, name varchar(255) not null unique,
|
||||
mincash int(11) unsigned not null, maxcash int(11) unsigned not null, avgcoin smallint(4) unsigned not null default 0);
|
||||
|
||||
create table loottable_entries (loottable_id int(11) unsigned not null, lootdrop_id int(11) unsigned not null,
|
||||
multiplier tinyint(2) unsigned default 1 not null, probability tinyint(2) unsigned default 100 not null,
|
||||
primary key (loottable_id, lootdrop_id));
|
||||
|
||||
create table lootdrop (id int(11) unsigned auto_increment primary key, name varchar(255) not null unique);
|
||||
|
||||
create table lootdrop_entries (lootdrop_id int(11) unsigned not null, item_id int(11) not null,
|
||||
item_charges tinyint(2) default 1 not null, equip_item tinyint(2) unsigned not null,
|
||||
chance tinyint(2) unsigned default 1 not null, primary key (lootdrop_id, item_id));
|
||||
|
||||
ALTER TABLE `loottable_entries` ADD `probability` FLOAT NOT NULL DEFAULT '100';
|
||||
*/
|
||||
|
||||
|
||||
#ifndef LOOTTABLE_H
|
||||
#define LOOTTABLE_H
|
||||
#include "zonedump.h"
|
||||
#include "../common/linked_list.h"
|
||||
|
||||
#include <list>
|
||||
using namespace std;
|
||||
|
||||
#pragma pack(1)
|
||||
struct LootTableEntries_Struct {
|
||||
uint32 lootdrop_id;
|
||||
uint8 droplimit;
|
||||
uint8 mindrop;
|
||||
uint8 multiplier;
|
||||
float probability;
|
||||
};
|
||||
|
||||
struct LootTable_Struct {
|
||||
uint32 mincash;
|
||||
uint32 maxcash;
|
||||
uint32 avgcoin;
|
||||
uint32 NumEntries;
|
||||
LootTableEntries_Struct Entries[0];
|
||||
};
|
||||
|
||||
struct LootDropEntries_Struct {
|
||||
uint32 item_id;
|
||||
int8 item_charges;
|
||||
uint8 equip_item;
|
||||
float chance;
|
||||
uint8 minlevel;
|
||||
uint8 maxlevel;
|
||||
uint8 multiplier;
|
||||
};
|
||||
|
||||
struct LootDrop_Struct {
|
||||
uint32 NumEntries;
|
||||
LootDropEntries_Struct Entries[0];
|
||||
};
|
||||
#pragma pack()
|
||||
|
||||
typedef list<ServerLootItem_Struct*> ItemList;
|
||||
|
||||
#endif
|
||||
@@ -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);
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ class NPC;
|
||||
using namespace std;
|
||||
|
||||
#include "spawn2.h"
|
||||
#include "loottable.h"
|
||||
#include "../common/loottable.h"
|
||||
#include "zonedump.h"
|
||||
#include "QGlobals.h"
|
||||
#include "../common/rulesys.h"
|
||||
|
||||
@@ -498,10 +498,6 @@ void Parser::Event(QuestEventID event, uint32 npcid, const char * data, NPC* npc
|
||||
|
||||
Parser::Parser() : DEFAULT_QUEST_PREFIX("default") {
|
||||
MainList.clear();
|
||||
pMaxNPCID = database.GetMaxNPCType();
|
||||
/*pNPCqstID = new int32[pMaxNPCID+1];
|
||||
for (uint32 i=0; i<pMaxNPCID+1; i++)
|
||||
pNPCqstID[i] = -1;*/
|
||||
pNPCqstID = new int32[1];
|
||||
npcarrayindex=1;
|
||||
}
|
||||
|
||||
+5
-3
@@ -3,7 +3,8 @@
|
||||
|
||||
#include "../common/shareddb.h"
|
||||
#include "../common/eq_packet_structs.h"
|
||||
#include "loottable.h"
|
||||
#include "../common/loottable.h"
|
||||
#include "zonedump.h"
|
||||
#include "faction.h"
|
||||
//#include "doors.h"
|
||||
|
||||
@@ -169,6 +170,7 @@ struct LootTable_Struct;
|
||||
|
||||
|
||||
class ZoneDatabase : public SharedDatabase {
|
||||
typedef list<ServerLootItem_Struct*> ItemList;
|
||||
public:
|
||||
ZoneDatabase();
|
||||
ZoneDatabase(const char* host, const char* user, const char* passwd, const char* database,uint32 port);
|
||||
@@ -482,8 +484,8 @@ protected:
|
||||
|
||||
uint32 max_faction;
|
||||
Faction** faction_array;
|
||||
|
||||
uint32 npc_spells_maxid;
|
||||
uint32 max_door_type;
|
||||
uint32 npc_spells_maxid;
|
||||
DBnpcspells_Struct** npc_spells_cache;
|
||||
bool* npc_spells_loadtried;
|
||||
uint8 item_minstatus[MAX_ITEM_ID];
|
||||
|
||||
@@ -161,20 +161,6 @@ charname varchar(30) not null, zonename varchar(16)not null, x float not null, y
|
||||
heading float not null, data blob not null, time timestamp(14), index zonename (zonename));
|
||||
*/
|
||||
|
||||
struct ServerLootItem_Struct {
|
||||
uint32 item_id;
|
||||
int16 equipSlot;
|
||||
uint8 charges;
|
||||
uint16 lootslot;
|
||||
uint32 aug1;
|
||||
uint32 aug2;
|
||||
uint32 aug3;
|
||||
uint32 aug4;
|
||||
uint32 aug5;
|
||||
uint8 minlevel;
|
||||
uint8 maxlevel;
|
||||
};
|
||||
|
||||
namespace player_lootitem
|
||||
{
|
||||
struct ServerLootItem_Struct {
|
||||
|
||||
Reference in New Issue
Block a user