mirror of
https://github.com/EQEmu/Server.git
synced 2026-03-24 03:22:26 +00:00
GetZoneFishing converted to QueryDatabase
This commit is contained in:
parent
9cdf0a7a83
commit
65e865a550
@ -139,12 +139,6 @@ uint32 ZoneDatabase::GetZoneForage(uint32 ZoneID, uint8 skill) {
|
|||||||
|
|
||||||
uint32 ZoneDatabase::GetZoneFishing(uint32 ZoneID, uint8 skill, uint32 &npc_id, uint8 &npc_chance)
|
uint32 ZoneDatabase::GetZoneFishing(uint32 ZoneID, uint8 skill, uint32 &npc_id, uint8 &npc_chance)
|
||||||
{
|
{
|
||||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
|
||||||
char *query = 0;
|
|
||||||
MYSQL_RES *result;
|
|
||||||
MYSQL_ROW row;
|
|
||||||
|
|
||||||
uint8 index = 0;
|
|
||||||
uint32 item[50];
|
uint32 item[50];
|
||||||
uint32 chance[50];
|
uint32 chance[50];
|
||||||
uint32 npc_ids[50];
|
uint32 npc_ids[50];
|
||||||
@ -157,44 +151,44 @@ uint32 ZoneDatabase::GetZoneFishing(uint32 ZoneID, uint8 skill, uint32 &npc_id,
|
|||||||
chance[c]=0;
|
chance[c]=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT itemid,chance,npc_id,npc_chance FROM fishing WHERE (zoneid= '%i' || zoneid = 0) and skill_level <= '%i'",ZoneID, skill ), errbuf, &result))
|
std::string query = StringFormat("SELECT itemid, chance, npc_id, npc_chance "
|
||||||
{
|
"FROM fishing WHERE (zoneid = '%i' || zoneid = 0) AND skill_level <= '%i'",
|
||||||
safe_delete_array(query);
|
ZoneID, skill);
|
||||||
while ((row = mysql_fetch_row(result))&&(index<50)) {
|
auto results = QueryDatabase(query);
|
||||||
item[index] = atoi(row[0]);
|
if (!results.Success()) {
|
||||||
chance[index] = atoi(row[1])+chancepool;
|
std::cerr << "Error in Fishing query '" << query << "' " << results.ErrorMessage() << std::endl;
|
||||||
chancepool = chance[index];
|
|
||||||
|
|
||||||
npc_ids[index] = atoi(row[2]);
|
|
||||||
npc_chances[index] = atoi(row[3]);
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
mysql_free_result(result);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
std::cerr << "Error in Fishing query '" << query << "' " << errbuf << std::endl;
|
|
||||||
safe_delete_array(query);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8 index = 0;
|
||||||
|
for (auto row = results.begin(); row != results.end(); ++row, ++index) {
|
||||||
|
if (index >= 50)
|
||||||
|
break;
|
||||||
|
|
||||||
|
item[index] = atoi(row[0]);
|
||||||
|
chance[index] = atoi(row[1])+chancepool;
|
||||||
|
chancepool = chance[index];
|
||||||
|
|
||||||
|
npc_ids[index] = atoi(row[2]);
|
||||||
|
npc_chances[index] = atoi(row[3]);
|
||||||
|
}
|
||||||
|
|
||||||
npc_id = 0;
|
npc_id = 0;
|
||||||
npc_chance = 0;
|
npc_chance = 0;
|
||||||
if (index>0) {
|
if (index <= 0)
|
||||||
uint32 random = MakeRandomInt(1, chancepool);
|
return 0;
|
||||||
for (int i = 0; i < index; i++)
|
|
||||||
{
|
uint32 random = MakeRandomInt(1, chancepool);
|
||||||
if (random <= chance[i])
|
for (int i = 0; i < index; i++)
|
||||||
{
|
{
|
||||||
ret = item[i];
|
if (random > chance[i])
|
||||||
npc_id = npc_ids[i];
|
continue;
|
||||||
npc_chance = npc_chances[i];
|
|
||||||
break;
|
ret = item[i];
|
||||||
}
|
npc_id = npc_ids[i];
|
||||||
}
|
npc_chance = npc_chances[i];
|
||||||
} else {
|
break;
|
||||||
ret = 0;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user