From ce0173d544f0a80683a6e7762a48f31d8690a24f Mon Sep 17 00:00:00 2001 From: Vortrex <3858226+VortrexFTW@users.noreply.github.com> Date: Wed, 22 Dec 2021 23:36:36 -0600 Subject: [PATCH] New job route classes/data --- scripts/server/class.js | 70 ++++++++++++++++++------ scripts/server/job.js | 115 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 170 insertions(+), 15 deletions(-) diff --git a/scripts/server/class.js b/scripts/server/class.js index d7861b71..3f3a80ce 100644 --- a/scripts/server/class.js +++ b/scripts/server/class.js @@ -1351,20 +1351,6 @@ class WhiteListedGameScriptData { } }; -class RemovedWorldObjectData { - constructor(model, position, range) { - this.model = model; - this.position = position; - this.range = range; - } -}; - -class ExcludedGroundSnowModel { - constructor(model) { - this.model = model; - } -}; - class InteriorTemplateData { constructor(exitPosition, exitInterior) { this.exitPosition = exitPosition; @@ -1679,4 +1665,58 @@ class DeckCardHandData { this.cards = []; this.total = 0; } -} \ No newline at end of file +} + +class JobRouteData { + constructor(dbAssoc = false) { + this.databaseId = 0; + this.name = ""; + this.jobId = 0; + this.enabled = false; + this.index = -1; + this.jobIndex = -1; + this.needsSaved = false; + this.pay = 0; + this.vehicleColour1 = toColour(255, 255, 255, 255); + this.vehicleColour2 = toColour(255, 255, 255, 255); + this.detail = 0; + + if(dbAssoc) { + this.databaseId = toInteger(dbAssoc["job_route_id"]); + this.name = toString(dbAssoc["job_route_name"]); + this.jobId = toInteger(dbAssoc["job_route_job"]); + this.enabled = intToBool(toInteger(dbAssoc["job_route_enabled"])); + this.pay = toInteger(dbAssoc["job_route_pay"]); + this.startMessage = toString(dbAssoc["job_route_start_msg"]); + this.finishMessage = toString(dbAssoc["job_route_finish_msg"]); + this.colour1 = toColour(toInteger(dbAssoc["job_route_col1_r"]), toInteger(dbAssoc["job_route_col1_g"]), toInteger(dbAssoc["job_route_col1_b"]), 255); + this.colour2 = toColour(toInteger(dbAssoc["job_route_col2_r"]), toInteger(dbAssoc["job_route_col2_g"]), toInteger(dbAssoc["job_route_col2_b"]), 255); + this.detail = toInteger(dbAssoc["job_route_detail"]); + } + } +}; + +class JobRoutePositionData { + constructor(dbAssoc = false) { + this.databaseId = 0; + this.name = ""; + this.routeId = 0; + this.enabled = false; + this.index = -1; + this.routeIndex = -1; + this.needsSaved = false; + this.position = toVector3(0.0, 0.0, 0.0); + this.stopDelay = 0; + this.pay = 0; + + if(dbAssoc) { + this.databaseId = toInteger(dbAssoc["job_route_pos_id"]); + this.name = toString(dbAssoc["job_route_pos_name"]); + this.routeId = toInteger(dbAssoc["job_route_pos_route"]); + this.enabled = intToBool(toInteger(dbAssoc["job_route_pos_enabled"])); + this.position = toVector3(toFloat(dbAssoc["job_route_pos_x"]), toFloat(dbAssoc["job_route_pos_y"]), toFloat(dbAssoc["job_route_pos_z"])); + this.stopDelay = toInteger(dbAssoc["job_route_pos_delay"]); + this.pay = toInteger(dbAssoc["job_route_pos_pay"]); + } + } +}; \ No newline at end of file diff --git a/scripts/server/job.js b/scripts/server/job.js index 2fe7a7e0..31030e2c 100644 --- a/scripts/server/job.js +++ b/scripts/server/job.js @@ -1416,6 +1416,102 @@ function saveJobToDatabase(jobData) { // =========================================================================== +function saveJobRouteToDatabase(jobId, jobRouteId) { + let tempJobRouteData = getJobRouteData(jobId, jobRouteId); + if(!tempJobRouteData) { + // Invalid job route data + return false; + } + + if(!tempJobRouteData.needsSaved) { + return false; + } + + logToConsole(LOG_DEBUG, `[VRR.Job]: Saving job route ${tempJobRouteData.name} to database ...`); + let dbConnection = connectToDatabase(); + if(dbConnection) { + let data = [ + ["job_route_job", getJobData(jobId).databaseId], + ["job_route_enabled", boolToInt(tempJobRouteData.enabled)], + ["job_route_name", tempJobRouteData.name], + ["job_route_col1_r", tempJobRouteData.vehicleColour1], + ["job_route_col2_r", tempJobRouteData.vehicleColour2], + ["job_route_start_msg", tempJobRouteData.startMessage], + ["job_route_finish_msg", tempJobRouteData.finishMessage], + ["job_route_pay", tempJobRouteData.pay], + ["job_route_detail", tempJobRouteData.detail], + ]; + + let dbQuery = null; + if(tempJobRouteData.databaseId == 0) { + let queryString = createDatabaseInsertQuery("job_route", data); + dbQuery = queryDatabase(dbConnection, queryString); + getServerData().jobs[jobId].routes[jobRouteId].databaseId = getDatabaseInsertId(dbConnection); + } else { + let queryString = createDatabaseUpdateQuery("job_route", data, `job_route_id=${tempJobRouteData.databaseId}`); + dbQuery = queryDatabase(dbConnection, queryString); + } + getServerData().jobs[jobId].routes[jobRouteId].needsSaved = false; + + freeDatabaseQuery(dbQuery); + disconnectFromDatabase(dbConnection); + return true; + } + logToConsole(LOG_DEBUG, `[VRR.Job]: Saved job route ${tempJobRouteData.name} to database!`); + + return false; +} + +// =========================================================================== + +function saveJobRouteToDatabase(jobId, jobRouteId, jobRoutePositionId) { + let tempJobRoutePositionData = getJobRoutePositionData(jobId, jobRouteId, jobRoutePositionId); + if(!tempJobRoutePositionData) { + // Invalid job route data + return false; + } + + if(!tempJobRoutePositionData.needsSaved) { + return false; + } + + logToConsole(LOG_DEBUG, `[VRR.Job]: Saving job route ${temtempJobRoutePositionDatapJobRouteData.name} to database ...`); + let dbConnection = connectToDatabase(); + if(dbConnection) { + let data = [ + ["job_route_pos_job", getJobRouteData(jobId, jobRouteId).databaseId], + ["job_route_pos_enabled", boolToInt(tempJobRoutePositionData.enabled)], + ["job_route_pos_name", tempJobRoutePositionData.name], + ["job_route_pos_x", tempJobRoutePositionData.position.x], + ["job_route_pos_y", tempJobRoutePositionData.position.y], + ["job_route_pos_z", tempJobRoutePositionData.position.z], + ["job_route_finish_msg", tempJobRoutePositionData.finishMessage], + ["job_route_pay", tempJobRoutePositionData.pay], + ["job_route_detail", tempJobRoutePositionData.de], + ]; + + let dbQuery = null; + if(tempJobRouteData.databaseId == 0) { + let queryString = createDatabaseInsertQuery("job_route", data); + dbQuery = queryDatabase(dbConnection, queryString); + getServerData().jobs[jobId].routes[jobRouteId].databaseId = getDatabaseInsertId(dbConnection); + } else { + let queryString = createDatabaseUpdateQuery("job_route", data, `job_route_id=${tempJobRouteData.databaseId}`); + dbQuery = queryDatabase(dbConnection, queryString); + } + getServerData().jobs[jobId].routes[jobRouteId].needsSaved = false; + + freeDatabaseQuery(dbQuery); + disconnectFromDatabase(dbConnection); + return true; + } + logToConsole(LOG_DEBUG, `[VRR.Job]: Saved job route ${tempJobRouteData.name} to database!`); + + return false; +} + +// =========================================================================== + function saveJobLocationToDatabase(jobLocationData) { if(jobLocationData == null) { // Invalid job location data @@ -1779,4 +1875,23 @@ function deleteJobPickups(jobId) { } } +// =========================================================================== + +function createJobRouteCommand(command, params, client) { + let jobId = getPlayerJob(client); + + if(!getJobData(jobId)) { + messagePlayerError(client, `You need to take the job that you want to make a route for.`); + return false; + } + + if(!isPlayerWorking(client)) { + messagePlayerError(client, `You need to be working! Use /startwork at a job site.`); + return false; + } + + //messagePlayerSuccess(client, `{MAINCOLOUR}You now have the {jobYellow}${jobData.name} {MAINCOLOUR}job`); + return true; +} + // =========================================================================== \ No newline at end of file