Source: Game_CommonEvent.js

Game_CommonEvent.js

//-----------------------------------------------------------------------------
// Game_CommonEvent
//
// The game object class for a common event. It contains functionality for
// running parallel process events.
/**
 * The game object class for a common event. It contains functionality for running parallel process events.
 *
 * @class
 */
function Game_CommonEvent() {
    this.initialize(...arguments);
}

/**
 * Initialize the common event
 *
 * @param {number} commonEventId - The id of the common event
 */
Game_CommonEvent.prototype.initialize = function(commonEventId) {
    this._commonEventId = commonEventId;
    this.refresh();
};

/**
 * Get the common event data object
 *
 * @return {Object} Common event data object
 */
Game_CommonEvent.prototype.event = function() {
    return $dataCommonEvents[this._commonEventId];
};

/**
 * The list of event commands
 *
 * @return {Array} Array of event command objects
 */
Game_CommonEvent.prototype.list = function() {
    return this.event().list;
};

/**
 * Refreshes the common event
 */
Game_CommonEvent.prototype.refresh = function() {
    if (this.isActive()) {
        if (!this._interpreter) {
            this._interpreter = new Game_Interpreter();
        }
    } else {
        this._interpreter = null;
    }
};

/**
 * Check if the common event is active
 *
 * @return {boolean} True if active
 */
Game_CommonEvent.prototype.isActive = function() {
    const event = this.event();
    return event.trigger === 2 && $gameSwitches.value(event.switchId);
};

/**
 * Update the common event
 */
Game_CommonEvent.prototype.update = function() {
    if (this._interpreter) {
        if (!this._interpreter.isRunning()) {
            this._interpreter.setup(this.list());
        }
        this._interpreter.update();
    }
};