Add trigger stuff

This commit is contained in:
Vortrex
2022-07-07 22:17:02 -05:00
parent eb582a666d
commit 179556b878
2 changed files with 136 additions and 12 deletions

View File

@@ -7,7 +7,7 @@
// TYPE: Server (JavaScript)
// ===========================================================================
let scriptVersion = "1.1";
let scriptVersion = "1.2";
let serverStartTime = 0;
let logLevel = LOG_INFO | LOG_DEBUG | LOG_VERBOSE; // LOG_ERROR|LOG_WARN;
@@ -29,6 +29,7 @@ let playerGUI = new Array(server.maxClients).fill(false);
* @property {Array.<ItemTypeData>} itemTypes
* @property {Array.<ClanData>} clans
* @property {Array} localeStrings
* @property {Array.<TriggerData>} triggers
* @property {Array.<NPCData>} npcs
* @property {Array.<RaceData>} races
* @property {Array.<JobData>} jobs
@@ -52,7 +53,7 @@ let serverData = {
localeStrings: {},
cachedTranslations: [],
cachedTranslationFrom: [],
//triggers: [],
triggers: [],
npcs: [],
races: [],
jobs: [],

View File

@@ -7,6 +7,23 @@
// TYPE: Server (JavaScript)
// ===========================================================================
const AGRP_TRIG_TYPE_NONE = 0;
// ===========================================================================
const AGRP_TRIG_COND_TYPE_NONE = 0;
// ===========================================================================
const AGRP_TRIG_RESP_TYPE_NONE = 0;
// ===========================================================================
const AGRP_TRIG_COND_MATCH_NONE = 0;
// ===========================================================================
/*
const triggerTypes = [
"onBusinessOwnerChange",
"onBusinessNameChange",
@@ -50,6 +67,94 @@ const triggerTypes = [
"onPlayerTalk",
"onPlayerWhisper",
];
*/
// ===========================================================================
/**
* @class Representing a trigger's data. Loaded and saved in the database
* @property {Array.<TriggerConditionData>} conditions
* @property {Array.<TriggerResponseData>} responses
*/
class TriggerData {
constructor(dbAssoc) {
this.databaseId = 0
this.type = AGRP_TRIG_TYPE_NONE;
this.enabled = false;
this.whoAdded = 0;
this.whenAdded = 0;
this.conditions = [];
this.responses = [];
if (dbAssoc != false) {
this.databaseId = toInteger(dbAssoc["trig_id"]);
this.type = toInteger(dbAssoc["trig_type"]);
this.enabled = intToBool(dbAssoc["trig_enabled"]);
this.whoAdded = toInteger(dbAssoc["trig_who_added"]);
this.whenAdded = toInteger(dbAssoc["trig_when_added"]);
}
}
}
// ===========================================================================
/**
* @class Representing a trigger condition's data. Loaded and saved in the database
*/
class TriggerConditionData {
constructor(dbAssoc) {
this.databaseId = 0
this.index = -1;
this.triggerId = 0;
this.triggerIndex = -1;
this.type = AGRP_TRIG_COND_TYPE_NONE;
this.matchType = AGRP_TRIG_COND_MATCH_NONE;
this.enabled = false;
this.whoAdded = 0;
this.whenAdded = 0;
if (dbAssoc != false) {
this.databaseId = toInteger(dbAssoc["trig_cond_id"]);
this.type = toInteger(dbAssoc["trig_cond_type"]);
this.triggerId = toInteger(dbAssoc["trig_cond_trig"]);
this.data = dbAssoc["trig_cond_data"];
this.matchType = toInteger(dbAssoc["trig_cond_match_type"]);
this.enabled = intToBool(dbAssoc["trig_cond_enabled"]);
this.whoAdded = toInteger(dbAssoc["trig_cond_who_added"]);
this.whenAdded = toInteger(dbAssoc["trig_cond_when_added"]);
}
}
}
// ===========================================================================
/**
* @class Representing a trigger response's data. Loaded and saved in the database
*/
class TriggerResponseData {
constructor(dbAssoc) {
this.databaseId = 0
this.index = -1;
this.triggerId = 0;
this.triggerIndex = -1;
this.priority = 0;
this.type = AGRP_TRIG_RESP_TYPE_NONE;
this.enabled = false;
this.whoAdded = 0;
this.whenAdded = 0;
if (dbAssoc != false) {
this.databaseId = toInteger(dbAssoc["trig_resp_id"]);
this.type = toInteger(dbAssoc["trig_resp_type"]);
this.triggerId = toInteger(dbAssoc["trig_resp_trig"]);
this.enabled = intToBool(dbAssoc["trig_resp_enabled"]);
this.whoAdded = toInteger(dbAssoc["trig_resp_who_added"]);
this.whenAdded = toInteger(dbAssoc["trig_resp_when_added"]);
}
}
}
// ===========================================================================
@@ -61,8 +166,26 @@ function initTriggerScript() {
// ===========================================================================
function loadTriggersFromDatabase() {
}
// ===========================================================================
function loadTriggerConditionsFromDatabase(triggerDatabaseId) {
}
// ===========================================================================
function loadTriggerResponsesFromDatabase(triggerDatabaseId) {
}
// ===========================================================================
function createTriggerCommand(command, params, client) {
if(areParamsEmpty(params)) {
if (areParamsEmpty(params)) {
messagePlayerSyntax(client, getCommandSyntaxText(command));
return false;
}
@@ -71,7 +194,7 @@ function createTriggerCommand(command, params, client) {
// ===========================================================================
function deleteTriggerCommand(command, params, client) {
if(areParamsEmpty(params)) {
if (areParamsEmpty(params)) {
messagePlayerSyntax(client, getCommandSyntaxText(command));
return false;
}
@@ -80,7 +203,7 @@ function deleteTriggerCommand(command, params, client) {
// ===========================================================================
function addTriggerConditionCommand(command, params, client) {
if(areParamsEmpty(params)) {
if (areParamsEmpty(params)) {
messagePlayerSyntax(client, getCommandSyntaxText(command));
return false;
}
@@ -89,7 +212,7 @@ function addTriggerConditionCommand(command, params, client) {
// ===========================================================================
function removeTriggerConditionCommand(command, params, client) {
if(areParamsEmpty(params)) {
if (areParamsEmpty(params)) {
messagePlayerSyntax(client, getCommandSyntaxText(command));
return false;
}
@@ -98,7 +221,7 @@ function removeTriggerConditionCommand(command, params, client) {
// ===========================================================================
function addTriggerResponseCommand(command, params, client) {
if(areParamsEmpty(params)) {
if (areParamsEmpty(params)) {
messagePlayerSyntax(client, getCommandSyntaxText(command));
return false;
}
@@ -107,7 +230,7 @@ function addTriggerResponseCommand(command, params, client) {
// ===========================================================================
function removeTriggerResponseCommand(command, params, client) {
if(areParamsEmpty(params)) {
if (areParamsEmpty(params)) {
messagePlayerSyntax(client, getCommandSyntaxText(command));
return false;
}
@@ -116,7 +239,7 @@ function removeTriggerResponseCommand(command, params, client) {
// ===========================================================================
function listTriggersCommand(command, params, client) {
if(areParamsEmpty(params)) {
if (areParamsEmpty(params)) {
messagePlayerSyntax(client, getCommandSyntaxText(command));
return false;
}
@@ -125,7 +248,7 @@ function listTriggersCommand(command, params, client) {
// ===========================================================================
function listTriggerConditionsCommand(command, params, client) {
if(areParamsEmpty(params)) {
if (areParamsEmpty(params)) {
messagePlayerSyntax(client, getCommandSyntaxText(command));
return false;
}
@@ -134,7 +257,7 @@ function listTriggerConditionsCommand(command, params, client) {
// ===========================================================================
function listTriggerResponsesCommand(command, params, client) {
if(areParamsEmpty(params)) {
if (areParamsEmpty(params)) {
messagePlayerSyntax(client, getCommandSyntaxText(command));
return false;
}
@@ -143,7 +266,7 @@ function listTriggerResponsesCommand(command, params, client) {
// ===========================================================================
function toggleTriggerEnabledCommand(command, params, client) {
if(areParamsEmpty(params)) {
if (areParamsEmpty(params)) {
messagePlayerSyntax(client, getCommandSyntaxText(command));
return false;
}