mirror of
https://github.com/EQEmu/Server.git
synced 2026-03-28 19:52:29 +00:00
CreateNewNPCCommand converted to QueryDatabase
This commit is contained in:
parent
970f7e01a9
commit
444174ef57
121
zone/npc.cpp
121
zone/npc.cpp
@ -962,85 +962,108 @@ NPC* NPC::SpawnNPC(const char* spawncommand, float in_x, float in_y, float in_z,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 ZoneDatabase::CreateNewNPCCommand(uint8 command, const char* zone, uint32 zone_version, Client *c, NPC* spawn, uint32 extra) {
|
uint32 ZoneDatabase::CreateNewNPCCommand(uint8 command, const char* zone, uint32 zone_version, Client *client, NPC* spawn, uint32 extra) {
|
||||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
|
||||||
char *query = 0;
|
|
||||||
MYSQL_RES *result;
|
|
||||||
MYSQL_ROW row;
|
|
||||||
uint32 tmp = 0;
|
|
||||||
uint32 tmp2 = 0;
|
|
||||||
uint32 last_insert_id = 0;
|
|
||||||
uint32 npc_type_id = 0;
|
uint32 npc_type_id = 0;
|
||||||
uint32 spawngroupid;
|
|
||||||
if (extra && c && c->GetZoneID())
|
if (extra && client && client->GetZoneID())
|
||||||
{
|
{
|
||||||
// Set an npc_type ID within the standard range for the current zone if possible (zone_id * 1000)
|
// Set an npc_type ID within the standard range for the current zone if possible (zone_id * 1000)
|
||||||
int starting_npc_id = c->GetZoneID() * 1000;
|
int starting_npc_id = client->GetZoneID() * 1000;
|
||||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT MAX(id) FROM npc_types WHERE id >= %i AND id < %i", starting_npc_id, (starting_npc_id + 1000)), errbuf, &result)) {
|
|
||||||
row = mysql_fetch_row(result);
|
std::string query = StringFormat("SELECT MAX(id) FROM npc_types WHERE id >= %i AND id < %i",
|
||||||
if(row)
|
starting_npc_id, starting_npc_id + 1000);
|
||||||
{
|
auto results = QueryDatabase(query);
|
||||||
if (row[0])
|
if (results.Success()) {
|
||||||
|
if (results.RowCount() != 0)
|
||||||
{
|
{
|
||||||
|
auto row = results.begin();
|
||||||
npc_type_id = atoi(row[0]) + 1;
|
npc_type_id = atoi(row[0]) + 1;
|
||||||
// Prevent the npc_type id from exceeding the range for this zone
|
// Prevent the npc_type id from exceeding the range for this zone
|
||||||
if (npc_type_id >= (starting_npc_id + 1000))
|
if (npc_type_id >= (starting_npc_id + 1000))
|
||||||
{
|
|
||||||
npc_type_id = 0;
|
npc_type_id = 0;
|
||||||
}
|
}
|
||||||
}
|
else // No npc_type IDs set in this range yet
|
||||||
else
|
|
||||||
{
|
|
||||||
// row[0] is nullptr - No npc_type IDs set in this range yet
|
|
||||||
npc_type_id = starting_npc_id;
|
npc_type_id = starting_npc_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
safe_delete_array(query);
|
|
||||||
mysql_free_result(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
char tmpstr[64];
|
char tmpstr[64];
|
||||||
EntityList::RemoveNumbers(strn0cpy(tmpstr, spawn->GetName(), sizeof(tmpstr)));
|
EntityList::RemoveNumbers(strn0cpy(tmpstr, spawn->GetName(), sizeof(tmpstr)));
|
||||||
|
std::string query;
|
||||||
if (npc_type_id)
|
if (npc_type_id)
|
||||||
{
|
{
|
||||||
if (!RunQuery(query, MakeAnyLenString(&query, "INSERT INTO npc_types (id, name, level, race, class, hp, gender, texture, helmtexture, size, loottable_id, merchant_id, face, runspeed, prim_melee_type, sec_melee_type) values(%i,\"%s\",%i,%i,%i,%i,%i,%i,%i,%f,%i,%i,%i,%f,%i,%i)", npc_type_id, tmpstr, spawn->GetLevel(), spawn->GetRace(), spawn->GetClass(), spawn->GetMaxHP(), spawn->GetGender(), spawn->GetTexture(), spawn->GetHelmTexture(), spawn->GetSize(), spawn->GetLoottableID(), spawn->MerchantType, 0, spawn->GetRunspeed(), 28, 28), errbuf, 0, 0, &npc_type_id)) {
|
query = StringFormat("INSERT INTO npc_types (id, name, level, race, class, hp, gender, "
|
||||||
LogFile->write(EQEMuLog::Error, "NPCSpawnDB Error: %s %s", query, errbuf);
|
"texture, helmtexture, size, loottable_id, merchant_id, face, "
|
||||||
safe_delete(query);
|
"runspeed, prim_melee_type, sec_melee_type) "
|
||||||
|
"VALUES(%i, \"%s\" , %i, %i, %i, %i, %i, %i, %i, %f, %i, %i, %i, %f, %i, %i)",
|
||||||
|
npc_type_id, tmpstr, spawn->GetLevel(), spawn->GetRace(), spawn->GetClass(),
|
||||||
|
spawn->GetMaxHP(), spawn->GetGender(), spawn->GetTexture(),
|
||||||
|
spawn->GetHelmTexture(), spawn->GetSize(), spawn->GetLoottableID(),
|
||||||
|
spawn->MerchantType, 0, spawn->GetRunspeed(), 28, 28);
|
||||||
|
auto results = QueryDatabase(query);
|
||||||
|
if (!results.Success()) {
|
||||||
|
LogFile->write(EQEMuLog::Error, "NPCSpawnDB Error: %s %s", query.c_str(), results.ErrorMessage().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
npc_type_id = results.LastInsertedID();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!RunQuery(query, MakeAnyLenString(&query, "INSERT INTO npc_types (name, level, race, class, hp, gender, texture, helmtexture, size, loottable_id, merchant_id, face, runspeed, prim_melee_type, sec_melee_type) values(\"%s\",%i,%i,%i,%i,%i,%i,%i,%f,%i,%i,%i,%f,%i,%i)", tmpstr, spawn->GetLevel(), spawn->GetRace(), spawn->GetClass(), spawn->GetMaxHP(), spawn->GetGender(), spawn->GetTexture(), spawn->GetHelmTexture(), spawn->GetSize(), spawn->GetLoottableID(), spawn->MerchantType, 0, spawn->GetRunspeed(), 28, 28), errbuf, 0, 0, &npc_type_id)) {
|
query = StringFormat("INSERT INTO npc_types (name, level, race, class, hp, gender, "
|
||||||
LogFile->write(EQEMuLog::Error, "NPCSpawnDB Error: %s %s", query, errbuf);
|
"texture, helmtexture, size, loottable_id, merchant_id, face, "
|
||||||
safe_delete(query);
|
"runspeed, prim_melee_type, sec_melee_type) "
|
||||||
|
"VALUES(\"%s\", %i, %i, %i, %i, %i, %i, %i, %f, %i, %i, %i, %f, %i, %i)",
|
||||||
|
tmpstr, spawn->GetLevel(), spawn->GetRace(), spawn->GetClass(),
|
||||||
|
spawn->GetMaxHP(), spawn->GetGender(), spawn->GetTexture(),
|
||||||
|
spawn->GetHelmTexture(), spawn->GetSize(), spawn->GetLoottableID(),
|
||||||
|
spawn->MerchantType, 0, spawn->GetRunspeed(), 28, 28);
|
||||||
|
auto results = QueryDatabase(query);
|
||||||
|
if (!results.Success()) {
|
||||||
|
LogFile->write(EQEMuLog::Error, "NPCSpawnDB Error: %s %s", query.c_str(), results.ErrorMessage().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
npc_type_id = results.LastInsertedID();
|
||||||
}
|
}
|
||||||
if(c) c->LogSQL(query);
|
|
||||||
safe_delete_array(query);
|
if(client)
|
||||||
snprintf(tmpstr, sizeof(tmpstr), "%s-%s", zone, spawn->GetName());
|
client->LogSQL(query.c_str());
|
||||||
if (!RunQuery(query, MakeAnyLenString(&query, "INSERT INTO spawngroup (id, name) values(%i, '%s')", tmp, tmpstr), errbuf, 0, 0, &spawngroupid)) {
|
|
||||||
LogFile->write(EQEMuLog::Error, "NPCSpawnDB Error: %s %s", query, errbuf);
|
query = StringFormat("INSERT INTO spawngroup (id, name) VALUES(%i, '%s-%s')", 0, zone, spawn->GetName());
|
||||||
safe_delete(query);
|
auto results = QueryDatabase(query);
|
||||||
|
if (!results.Success()) {
|
||||||
|
LogFile->write(EQEMuLog::Error, "NPCSpawnDB Error: %s %s", query.c_str(), results.ErrorMessage().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(c) c->LogSQL(query);
|
uint32 spawngroupid = results.LastInsertedID();
|
||||||
safe_delete_array(query);
|
|
||||||
if (!RunQuery(query, MakeAnyLenString(&query, "INSERT INTO spawn2 (zone, version, x, y, z, respawntime, heading, spawngroupID) values('%s', %u, %f, %f, %f, %i, %f, %i)", zone, zone_version, spawn->GetX(), spawn->GetY(), spawn->GetZ(), 1200, spawn->GetHeading(), spawngroupid), errbuf, 0, 0, &tmp)) {
|
if(client)
|
||||||
LogFile->write(EQEMuLog::Error, "NPCSpawnDB Error: %s %s", query, errbuf);
|
client->LogSQL(query.c_str());
|
||||||
safe_delete(query);
|
|
||||||
|
query = StringFormat("INSERT INTO spawn2 (zone, version, x, y, z, respawntime, heading, spawngroupID) "
|
||||||
|
"VALUES('%s', %u, %f, %f, %f, %i, %f, %i)",
|
||||||
|
zone, zone_version, spawn->GetX(), spawn->GetY(), spawn->GetZ(), 1200,
|
||||||
|
spawn->GetHeading(), spawngroupid);
|
||||||
|
results = QueryDatabase(query);
|
||||||
|
if (!results.Success()) {
|
||||||
|
LogFile->write(EQEMuLog::Error, "NPCSpawnDB Error: %s %s", query.c_str(), results.ErrorMessage().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(c) c->LogSQL(query);
|
|
||||||
safe_delete_array(query);
|
if(client)
|
||||||
if (!RunQuery(query, MakeAnyLenString(&query, "INSERT INTO spawnentry (spawngroupID, npcID, chance) values(%i, %i, %i)", spawngroupid, npc_type_id, 100), errbuf, 0)) {
|
client->LogSQL(query.c_str());
|
||||||
LogFile->write(EQEMuLog::Error, "NPCSpawnDB Error: %s %s", query, errbuf);
|
|
||||||
safe_delete(query);
|
query = StringFormat("INSERT INTO spawnentry (spawngroupID, npcID, chance) VALUES(%i, %i, %i)",
|
||||||
|
spawngroupid, npc_type_id, 100);
|
||||||
|
results = QueryDatabase(query);
|
||||||
|
if (!results.Success()) {
|
||||||
|
LogFile->write(EQEMuLog::Error, "NPCSpawnDB Error: %s %s", query.c_str(), results.ErrorMessage().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(c) c->LogSQL(query);
|
|
||||||
safe_delete_array(query);
|
if(client)
|
||||||
|
client->LogSQL(query.c_str());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -372,7 +372,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
const NPCType* GetNPCType(uint32 id);
|
const NPCType* GetNPCType(uint32 id);
|
||||||
uint32 NPCSpawnDB(uint8 command, const char* zone, uint32 zone_version, Client *c, NPC* spawn = 0, uint32 extra = 0); // 0 = Create 1 = Add; 2 = Update; 3 = Remove; 4 = Delete
|
uint32 NPCSpawnDB(uint8 command, const char* zone, uint32 zone_version, Client *c, NPC* spawn = 0, uint32 extra = 0); // 0 = Create 1 = Add; 2 = Update; 3 = Remove; 4 = Delete
|
||||||
uint32 CreateNewNPCCommand(uint8 command, const char* zone, uint32 zone_version, Client *c, NPC* spawn, uint32 extra);
|
uint32 CreateNewNPCCommand(uint8 command, const char* zone, uint32 zone_version, Client *client, NPC* spawn, uint32 extra);
|
||||||
bool SetSpecialAttkFlag(uint8 id, const char* flag);
|
bool SetSpecialAttkFlag(uint8 id, const char* flag);
|
||||||
bool GetPetEntry(const char *pet_type, PetRecord *into);
|
bool GetPetEntry(const char *pet_type, PetRecord *into);
|
||||||
bool GetPoweredPetEntry(const char *pet_type, int16 petpower, PetRecord *into);
|
bool GetPoweredPetEntry(const char *pet_type, int16 petpower, PetRecord *into);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user