// printRoomZoneEvents.js
(function () {
/*global adventurejs A*/
"use strict";
var p = adventurejs.Game.prototype;
/**
*
* @method adventurejs.Game#printRoomZoneEvents
* @memberOf adventurejs.Game
*/
p.printRoomZoneEvents = function Game_printRoomZoneEvents(e) {
this.game.log("log", "low", "printRoomZoneEvents", "Game");
if (this.game.getInput().soft_prompt.enabled) return;
if (this.game.getInput().disambiguate.enabled) return;
var currentRoom = this.game.getCurrentRoom();
var room_events;
var msg = "";
var source;
// scenery events disabled
if (false === this.game.settings.enable_events) {
return;
}
// does currentRoom have scenery events?
if ("undefined" !== typeof currentRoom.room_events) {
source = currentRoom.id + ".room_events";
room_events = currentRoom.room_events;
}
// or does it have a zone
else if (
"undefined" !== typeof currentRoom.zone &&
"undefined" !== typeof this.game.world[currentRoom.zone] &&
"undefined" !== typeof this.game.world[currentRoom.zone].zone_events
) {
source = currentRoom.id + ".zone.zone_events";
room_events = this.game.world[currentRoom.zone].zone_events;
}
// we got some events
if ("undefined" !== typeof room_events) {
// ensure that we have randomize setting
if ("undefined" === typeof room_events[0].randomize) {
room_events[0].randomize =
this.game.settings.randomize_arrays_in_getStringOrArrayOrFunction;
}
// ensure that we have index
if ("undefined" === typeof room_events[0].index) {
room_events[0].index = 0;
}
// ensure that we have frequency setting
if ("undefined" === typeof room_events[0].frequency) {
room_events[0].frequency = 1;
}
// if frequency is less than 1, roll for event
// if we roll over frequency, bail out
if (1 > room_events[0].frequency) {
var rand = Math.random(1);
if (rand > room_events[0].frequency) return;
}
source += ", randomize " + room_events[0].randomize;
source += ", index " + room_events[0].index;
source += ", frequency " + room_events[0].frequency;
this.game.debug(
`F1132 | printRoomZoneEvents.js |found zone events in ${source}`
);
msg += A.getSAF.call(this.game, room_events);
if (msg) this.game.print(msg);
return;
}
};
})();