mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-11 21:01:29 +00:00
Natedog: Fix #gassign to work more appropriately and simplify the function
This commit is contained in:
parent
d63f137a9f
commit
a698eff106
@ -282,6 +282,7 @@ int command_init(void) {
|
||||
command_add("motd", "[new motd] - Set message of the day", 150, command_motd) ||
|
||||
command_add("movechar", "[charname] [zonename] - Move charname to zonename", 50, command_movechar) ||
|
||||
command_add("myskills", "- Show details about your current skill levels", 0, command_myskills) ||
|
||||
command_add("mysqltest", "Akkadius MySQL Bench Test", 250, command_mysqltest) ||
|
||||
command_add("mysql", "Mysql CLI, see 'help' for options.", 250, command_mysql) ||
|
||||
command_add("mystats", "- Show details about you or your pet", 50, command_mystats) ||
|
||||
command_add("name", "[newname] - Rename your player target", 150, command_name) ||
|
||||
@ -1778,10 +1779,12 @@ void command_itemtest(Client *c, const Seperator *sep)
|
||||
|
||||
void command_gassign(Client *c, const Seperator *sep)
|
||||
{
|
||||
if (sep->IsNumber(1) && c->GetTarget() && c->GetTarget()->IsNPC())
|
||||
database.AssignGrid(c, glm::vec2(c->GetTarget()->CastToNPC()->m_SpawnPoint), atoi(sep->arg[1]));
|
||||
if (sep->IsNumber(1) && c->GetTarget() && c->GetTarget()->IsNPC() && c->GetTarget()->CastToNPC()->GetSpawnPointID() > 0) {
|
||||
int spawn2id = c->GetTarget()->CastToNPC()->GetSpawnPointID();
|
||||
database.AssignGrid(c, atoi(sep->arg[1]), spawn2id);
|
||||
}
|
||||
else
|
||||
c->Message(0,"Usage: #gassign [num] - must have an npc target!");
|
||||
c->Message(0, "Usage: #gassign [num] - must have an npc target!");
|
||||
}
|
||||
|
||||
void command_ai(Client *c, const Seperator *sep)
|
||||
@ -10541,3 +10544,17 @@ void command_logs(Client *c, const Seperator *sep){
|
||||
c->Message(0, "--- #logs set [console|file|gmsay] <category_id> <debug_level (1-3)> - Sets log settings during the lifetime of the zone");
|
||||
}
|
||||
}
|
||||
|
||||
void command_mysqltest(Client *c, const Seperator *sep)
|
||||
{
|
||||
clock_t t = std::clock(); /* Function timer start */
|
||||
if (sep->IsNumber(1)){
|
||||
uint32 i = 0;
|
||||
t = std::clock();
|
||||
for (i = 0; i < atoi(sep->arg[1]); i++){
|
||||
std::string query = "SELECT * FROM `zone`";
|
||||
auto results = database.QueryDatabase(query);
|
||||
}
|
||||
}
|
||||
Log.Out(Logs::General, Logs::Debug, "MySQL Test... Took %f seconds", ((float)(std::clock() - t)) / CLOCKS_PER_SEC);
|
||||
}
|
||||
@ -323,6 +323,7 @@ void command_merchantcloseshop(Client *c, const Seperator *sep);
|
||||
void command_shownumhits(Client *c, const Seperator *sep);
|
||||
void command_tune(Client *c, const Seperator *sep);
|
||||
void command_logtest(Client *c, const Seperator *sep);
|
||||
void command_mysqltest(Client *c, const Seperator *sep);
|
||||
void command_logs(Client *c, const Seperator *sep);
|
||||
|
||||
#ifdef EQPROFILE
|
||||
|
||||
@ -1033,76 +1033,21 @@ bool ZoneDatabase::GetWaypoints(uint32 grid, uint16 zoneid, uint32 num, wplist*
|
||||
return true;
|
||||
}
|
||||
|
||||
void ZoneDatabase::AssignGrid(Client *client, const glm::vec2& location, uint32 grid)
|
||||
{
|
||||
int matches = 0, fuzzy = 0, spawn2id = 0;
|
||||
|
||||
// looks like most of the stuff in spawn2 is straight integers
|
||||
// so let's try that first
|
||||
std::string query = StringFormat("SELECT id, x, y FROM spawn2 WHERE zone = '%s' AND x = %i AND y = %i",
|
||||
zone->GetShortName(), (int)location.x, (int)location.y);
|
||||
void ZoneDatabase::AssignGrid(Client *client, int grid, int spawn2id) {
|
||||
std::string query = StringFormat("UPDATE spawn2 SET pathgrid = %d WHERE id = %d", grid, spawn2id);
|
||||
auto results = QueryDatabase(query);
|
||||
if(!results.Success()) {
|
||||
|
||||
if (!results.Success())
|
||||
return;
|
||||
|
||||
if (results.RowsAffected() != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// how much it's allowed to be off by
|
||||
#define _GASSIGN_TOLERANCE 1.0
|
||||
if (results.RowCount() == 0) // try a fuzzy match if that didn't find it
|
||||
{
|
||||
query = StringFormat("SELECT id,x,y FROM spawn2 WHERE zone='%s' AND "
|
||||
"ABS( ABS(x) - ABS(%f) ) < %f AND "
|
||||
"ABS( ABS(y) - ABS(%f) ) < %f",
|
||||
zone->GetShortName(), location.x, _GASSIGN_TOLERANCE, location.y, _GASSIGN_TOLERANCE);
|
||||
results = QueryDatabase(query);
|
||||
if (!results.Success()) {
|
||||
return;
|
||||
}
|
||||
|
||||
fuzzy = 1;
|
||||
matches = results.RowCount();
|
||||
}
|
||||
|
||||
if (matches == 0)
|
||||
{
|
||||
client->Message(0, "ERROR: Unable to assign grid - can't find it in spawn2");
|
||||
return;
|
||||
}
|
||||
|
||||
if(matches > 1)
|
||||
{
|
||||
client->Message(0, "ERROR: Unable to assign grid - multiple spawn2 rows match");
|
||||
return;
|
||||
}
|
||||
|
||||
auto row = results.begin();
|
||||
|
||||
spawn2id = atoi(row[0]);
|
||||
glm::vec2 dbLocation = glm::vec2(atof(row[1]), atof(row[2]));
|
||||
|
||||
query = StringFormat("UPDATE spawn2 SET pathgrid = %d WHERE id = %d", grid, spawn2id);
|
||||
results = QueryDatabase(query);
|
||||
if (!results.Success()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (results.RowsAffected() != 1)
|
||||
{
|
||||
client->Message(0, "ERROR: found spawn2 id %d but the update query failed", spawn2id);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!fuzzy)
|
||||
{
|
||||
client->Message(0, "Grid assign: spawn2 id = %d updated - exact match", spawn2id);
|
||||
return;
|
||||
}
|
||||
|
||||
float difference =
|
||||
sqrtf(pow(std::abs(location.x - dbLocation.x), 2) + pow(std::abs(location.y - dbLocation.y), 2));
|
||||
client->Message(0, "Grid assign: spawn2 id = %d updated - fuzzy match: deviation %f", spawn2id, difference);
|
||||
client->Message(0, "Grid assign: spawn2 id = %d updated", spawn2id);
|
||||
}
|
||||
|
||||
|
||||
/******************
|
||||
* ModifyGrid - Either adds an empty grid, or removes a grid and all its waypoints, for a particular zone.
|
||||
* remove: TRUE if we are deleting the specified grid, FALSE if we are adding it
|
||||
|
||||
@ -379,7 +379,7 @@ public:
|
||||
uint8 GetGridType(uint32 grid, uint32 zoneid);
|
||||
uint8 GetGridType2(uint32 grid, uint16 zoneid);
|
||||
bool GetWaypoints(uint32 grid, uint16 zoneid, uint32 num, wplist* wp);
|
||||
void AssignGrid(Client *client, const glm::vec2& location, uint32 id);
|
||||
void AssignGrid(Client *client, int grid, int spawn2id);
|
||||
int GetHighestGrid(uint32 zoneid);
|
||||
int GetHighestWaypoint(uint32 zoneid, uint32 gridid);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user