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

View File

@@ -7,6 +7,23 @@
// TYPE: Server (JavaScript) // 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 = [ const triggerTypes = [
"onBusinessOwnerChange", "onBusinessOwnerChange",
"onBusinessNameChange", "onBusinessNameChange",
@@ -50,6 +67,94 @@ const triggerTypes = [
"onPlayerTalk", "onPlayerTalk",
"onPlayerWhisper", "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,6 +166,24 @@ function initTriggerScript() {
// =========================================================================== // ===========================================================================
function loadTriggersFromDatabase() {
}
// ===========================================================================
function loadTriggerConditionsFromDatabase(triggerDatabaseId) {
}
// ===========================================================================
function loadTriggerResponsesFromDatabase(triggerDatabaseId) {
}
// ===========================================================================
function createTriggerCommand(command, params, client) { function createTriggerCommand(command, params, client) {
if (areParamsEmpty(params)) { if (areParamsEmpty(params)) {
messagePlayerSyntax(client, getCommandSyntaxText(command)); messagePlayerSyntax(client, getCommandSyntaxText(command));