GetBotItems converted to QueryDatabase

This commit is contained in:
Arthur Ice 2014-09-03 16:52:18 -07:00
parent 53572b4d13
commit b8caa5dc31

View File

@ -4200,65 +4200,62 @@ void Bot::RemoveBotItemBySlot(uint32 slotID, std::string *errorMessage) {
// Retrieves all the inventory records from the database for this bot. // Retrieves all the inventory records from the database for this bot.
void Bot::GetBotItems(std::string* errorMessage, Inventory &inv) { void Bot::GetBotItems(std::string* errorMessage, Inventory &inv) {
if(this->GetBotID() > 0) { if(this->GetBotID() == 0)
char errbuf[MYSQL_ERRMSG_SIZE]; return;
char* query = 0;
MYSQL_RES* DatasetResult;
MYSQL_ROW DataRow;
if(database.RunQuery(query, MakeAnyLenString(&query, "SELECT slotid,itemid,charges,color,augslot1,augslot2,augslot3,augslot4,augslot5,instnodrop FROM botinventory WHERE botid=%i order by slotid", this->GetBotID()), errbuf, &DatasetResult)) { std::string query = StringFormat("SELECT slotid, itemid, charges, color, "
while(DataRow = mysql_fetch_row(DatasetResult)) { "augslot1, augslot2, augslot3, augslot4, "
int16 slot_id = atoi(DataRow[0]); "augslot5, instnodrop FROM botinventory "
uint32 item_id = atoi(DataRow[1]); "WHERE botid = %i ORDER BY slotid", this->GetBotID());
uint16 charges = atoi(DataRow[2]); auto results = database.QueryDatabase(query);
uint32 color = atoul(DataRow[3]); if (!results.Success()) {
uint32 aug[EmuConstants::ITEM_COMMON_SIZE]; *errorMessage = std::string(results.ErrorMessage());
aug[0] = (uint32)atoul(DataRow[4]); return;
aug[1] = (uint32)atoul(DataRow[5]); }
aug[2] = (uint32)atoul(DataRow[6]);
aug[3] = (uint32)atoul(DataRow[7]);
aug[4] = (uint32)atoul(DataRow[8]);
bool instnodrop = (DataRow[9] && (uint16)atoi(DataRow[9])) ? true : false;
ItemInst* inst = database.CreateItem(item_id, charges, aug[0], aug[1], aug[2], aug[3], aug[4]); for (auto row = results.begin(); row != results.end(); ++row) {
if(inst) { int16 slot_id = atoi(row[0]);
int16 put_slot_id = INVALID_INDEX; uint32 item_id = atoi(row[1]);
if(instnodrop || ((slot_id >= EmuConstants::EQUIPMENT_BEGIN) && (slot_id <= EmuConstants::EQUIPMENT_END) && inst->GetItem()->Attuneable)) uint16 charges = atoi(row[2]);
inst->SetInstNoDrop(true); uint32 color = atoul(row[3]);
if(color > 0) uint32 aug[EmuConstants::ITEM_COMMON_SIZE];
inst->SetColor(color); aug[0] = (uint32)atoul(row[4]);
if(charges==255) aug[1] = (uint32)atoul(row[5]);
inst->SetCharges(-1); aug[2] = (uint32)atoul(row[6]);
else aug[3] = (uint32)atoul(row[7]);
inst->SetCharges(charges); aug[4] = (uint32)atoul(row[8]);
if((slot_id >= 8000) && (slot_id <= 8999)) { bool instnodrop = (row[9] && (uint16)atoi(row[9])) ? true : false;
// do nothing
}
else {
put_slot_id = inv.PutItem(slot_id, *inst);
}
safe_delete(inst);
// Save ptr to item in inventory ItemInst* inst = database.CreateItem(item_id, charges, aug[0], aug[1], aug[2], aug[3], aug[4]);
if (put_slot_id == INVALID_INDEX) { if (!inst) {
LogFile->write(EQEMuLog::Error, LogFile->write(EQEMuLog::Error, "Warning: botid %i has an invalid item_id %i in inventory slot %i", this->GetBotID(), item_id, slot_id);
"Warning: Invalid slot_id for item in inventory: botid=%i, item_id=%i, slot_id=%i", continue;
this->GetBotID(), item_id, slot_id); }
}
} int16 put_slot_id = INVALID_INDEX;
else {
LogFile->write(EQEMuLog::Error, if (instnodrop || ((slot_id >= EmuConstants::EQUIPMENT_BEGIN) && (slot_id <= EmuConstants::EQUIPMENT_END) && inst->GetItem()->Attuneable))
"Warning: botid %i has an invalid item_id %i in inventory slot %i", inst->SetInstNoDrop(true);
this->GetBotID(), item_id, slot_id);
} if (color > 0)
} inst->SetColor(color);
mysql_free_result(DatasetResult);
} if (charges==255)
else inst->SetCharges(-1);
*errorMessage = std::string(errbuf); else
inst->SetCharges(charges);
if (slot_id < 8000 || slot_id > 8999)
put_slot_id = inv.PutItem(slot_id, *inst);
safe_delete(inst);
// Save ptr to item in inventory
if (put_slot_id == INVALID_INDEX)
LogFile->write(EQEMuLog::Error, "Warning: Invalid slot_id for item in inventory: botid=%i, item_id=%i, slot_id=%i",this->GetBotID(), item_id, slot_id);
}
safe_delete_array(query);
}
} }
// Returns the inventory record for this bot from the database for the specified equipment slot. // Returns the inventory record for this bot from the database for the specified equipment slot.