New job route classes/data

This commit is contained in:
Vortrex
2021-12-22 23:36:36 -06:00
parent 3808d832c5
commit ce0173d544
2 changed files with 170 additions and 15 deletions

View File

@@ -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;
}
}
}
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"]);
}
}
};

View File

@@ -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;
}
// ===========================================================================