public AdvancedCommunication.ActorHandler.position getNPCPosition(int npcID) { AdvancedCommunication.ActorHandler.position NPCPosition = new cs_elbot.AdvancedCommunication.ActorHandler.position(); MySqlConnection MyConnection = new MySqlConnection("Server=" + MainClass.SqlServer + ";Port=" + MainClass.SqlPort.ToString() + ";Database=" + MainClass.SqlDatabase + ";Uid=" + MainClass.SqlUsername + ";Pwd=" + MainClass.SqlPassword + ";"); try { MyConnection.Open(); } catch (Exception myException) { Console.WriteLine(myException.Message); Environment.Exit(0); } string sql = "SELECT x,y FROM npc WHERE id = ?npcID;"; MySqlCommand cmd = new MySqlCommand(sql, MyConnection); cmd.Parameters.AddWithValue("?npcID", npcID); MySqlDataReader reader = cmd.ExecuteReader(); try { while (reader.Read()) { NPCPosition.x = reader.GetInt16(0); NPCPosition.y = reader.GetInt16(1); TheLogger.Debug("Complete\n"); } } catch (MySqlException oMySQLException) { myErrorHandler.errorWriter(oMySQLException); } catch (Exception oException) { myErrorHandler.errorWriter(oException); } finally { reader.Close(); } MyConnection.Close(); return NPCPosition; }
public AdvancedCommunication.ActorHandler.position getObjectPosition(string mapName, int objectID, out int useWithObject) { AdvancedCommunication.ActorHandler.position objectPosition = new cs_elbot.AdvancedCommunication.ActorHandler.position(); useWithObject = -1; MySqlConnection MyConnection = new MySqlConnection("Server=" + MainClass.SqlServer + ";Port=" + MainClass.SqlPort.ToString() + ";Database=" + MainClass.SqlDatabase + ";Uid=" + MainClass.SqlUsername + ";Pwd=" + MainClass.SqlPassword + ";"); try { MyConnection.Open(); } catch (Exception myException) { Console.WriteLine(myException.Message); Environment.Exit(0); } string sql = "SELECT x,y,use_with_item FROM mapobjects, maps_area, maps WHERE object_id = ?objectID " + "AND maps_area.id = mapobjects.maps_area_in AND maps.id = maps_area.maps_id AND maps.file_name = ?mapName LIMIT 1"; MySqlCommand cmd = new MySqlCommand(sql, MyConnection); cmd.Parameters.AddWithValue("?objectID", objectID); cmd.Parameters.AddWithValue("?mapName", mapName); MySqlDataReader reader = cmd.ExecuteReader(); try { while (reader.Read()) { objectPosition.x = reader.GetInt16(0); objectPosition.y = reader.GetInt16(1); if (!reader["use_with_item"].Equals(System.DBNull.Value)) { useWithObject = reader.GetInt16(2); } TheLogger.Debug("Complete\n"); } } catch (MySqlException oMySQLException) { myErrorHandler.errorWriter(oMySQLException); } catch (Exception oException) { myErrorHandler.errorWriter(oException); } finally { reader.Close(); } MyConnection.Close(); return objectPosition; }
public AdvancedCommunication.ActorHandler.position getDestination(string mapName, string targetDest, out int objectID, out int useWithObject, ref int lastMoveNumber) { useWithObject = -1; objectID = 0; int npcID = 0; AdvancedCommunication.ActorHandler.position destination = new cs_elbot.AdvancedCommunication.ActorHandler.position(); destination.x = -1; destination.y = -1; MySqlConnection MyConnection = new MySqlConnection("Server=" + MainClass.SqlServer + ";Port=" + MainClass.SqlPort.ToString() + ";Database=" + MainClass.SqlDatabase + ";Uid=" + MainClass.SqlUsername + ";Pwd=" + MainClass.SqlPassword + ";"); try { MyConnection.Open(); } catch (Exception myException) { Console.WriteLine(myException.Message); Environment.Exit(0); } string sql = "SELECT botpath.moveobject,botpath.npcid, botpath.movenumber FROM botpath, maps,botdestination, destination " + "WHERE botpath.mapid = maps.id AND maps.file_name = ?mapName AND botdestination.destid = destination.id " + "AND LOWER(destination.name) = ?targetDest AND botdestination.botid = ?botid AND botdestination.botpathid = botpath.id " + "AND botpath.movenumber > ?lastMoveNumber ORDER BY botpath.movenumber LIMIT 1"; if (mapName == "maps/mapunderworld1.elm" && lastMoveNumber > 0) { lastMoveNumber = 0; } MySqlCommand cmd = new MySqlCommand(sql, MyConnection); cmd.Parameters.AddWithValue("?botid", Settings.botid); cmd.Parameters.AddWithValue("?mapName", mapName); cmd.Parameters.AddWithValue("?targetDest", targetDest.ToLower()); cmd.Parameters.AddWithValue("?lastMoveNumber", lastMoveNumber); MySqlDataReader reader = cmd.ExecuteReader(); try { while (reader.Read()) { if (!reader["moveobject"].Equals(System.DBNull.Value)) { objectID = reader.GetInt16(0); } if (!reader["npcid"].Equals(System.DBNull.Value)) { npcID = reader.GetInt16(1); } if (!reader["movenumber"].Equals(System.DBNull.Value)) { lastMoveNumber = reader.GetInt16(2); } TheLogger.Debug("Complete\n"); } } catch (MySqlException oMySQLException) { myErrorHandler.errorWriter(oMySQLException); } catch (Exception oException) { myErrorHandler.errorWriter(oException); } finally { reader.Close(); } //MyConnection.Close(); //find out if we're going to an npc, or an object //then find the coords for the object/npc if (objectID > 0) { destination = getObjectPosition(mapName, objectID, out useWithObject); } else if (npcID > 0) { destination = getNPCPosition(npcID); } else { //lol, we have real issues if we get here... Console.WriteLine("Cannot find destination for map walking..." + destination.x + "," + destination.y); } MyConnection.Close(); return destination; }