本文整理汇总了C++中Database::GetItem方法的典型用法代码示例。如果您正苦于以下问题:C++ Database::GetItem方法的具体用法?C++ Database::GetItem怎么用?C++ Database::GetItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Database
的用法示例。
在下文中一共展示了Database::GetItem方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AddLootDropToNPC
// Called by AddLootTableToNPC
// maxdrops = size of the array npcd
void Database::AddLootDropToNPC(int32 lootdrop_id, ItemList* itemlist) {
char errbuf[MYSQL_ERRMSG_SIZE];
char *query = 0;
MYSQL_RES *result;
MYSQL_ROW row;
// This is Wiz's updated Pool Looting functionality. Eventually, the database format should be moved over to use this
// or implemented to support both methods. (A unique identifier in lootable_entries indicates to roll for a pool item
// in another table.
#ifdef POOLLOOTING
int32 chancepool = 0;
int32 items[50];
int32 itemchance[50];
int16 itemcharges[50];
int8 i = 0;
for (int m=0;m < 50;m++)
{
items[m]=0;
itemchance[m]=0;
itemcharges[m]=0;
}
if (RunQuery(query, MakeAnyLenString(&query, "SELECT lootdrop_id, item_id, item_charges, equip_item, chance FROM lootdrop_entries WHERE lootdrop_id=%i order by chance desc", lootdrop_id), errbuf, &result))
{
delete[] query;
while (row = mysql_fetch_row(result))
{
items[i] = atoi(row[1]);
itemchance[i] = atoi(row[4]) + chancepool;
itemcharges[i] = atoi(row[2]);
chancepool += atoi(row[4]);
i++;
}
int32 res;
i = 0;
if (chancepool!=0) //avoid divide by zero if some mobs have 0 for chancepool
{
res = rand()%chancepool;
}
else
{
res = 0;
}
while (items[i] != 0)
{
if (res <= itemchance[i])
break;
else
i++;
}
const Item_Struct* dbitem = database.GetItem(items[i]);
if (dbitem == 0)
{
cerr << "Error in AddLootDropToNPC: dbitem=0, item#=" << items[i] << ", lootdrop_id=" << lootdrop_id << endl;
}
else
{
printf("Adding item2: %i",item->item_nr);
cout << "Adding item to Mob" << endl;
ServerLootItem_Struct* item = new ServerLootItem_Struct;
item->item_nr = dbitem->item_nr;
item->charges = itemcharges[i];
item->equipSlot = 0;
(*itemlist).Append(item);
}
mysql_free_result(result);
}
#else
if (RunQuery(query, MakeAnyLenString(&query, "SELECT lootdrop_id, item_id, item_charges, equip_item, chance FROM lootdrop_entries WHERE lootdrop_id=%i order by chance desc", lootdrop_id), errbuf, &result))
{
delete[] query;
while ((row = mysql_fetch_row(result)))
{
int8 LootDropMod=1; // place holder till I put it in a database variable to make it configurable.
if( (rand()%100) < ((atoi(row[4]) * LootDropMod)) )
{
int32 itemid = atoi(row[1]);
const Item_Struct* dbitem = database.GetItem(itemid);
if (dbitem == 0)
{
cerr << "Error in AddLootDropToNPC: dbitem=0, item#=" << itemid << ", lootdrop_id=" << lootdrop_id << endl;
}
else
{
printf("Adding item: %i",item->item_nr);
ServerLootItem_Struct* item = new ServerLootItem_Struct;
item->item_nr = dbitem->item_nr;
item->charges = atoi(row[2]);
item->equipSlot = 0;
(*itemlist).Append(item);
}
//mysql_free_result(result);
//return;
}
//.........这里部分代码省略.........