// Zone.js
(function () {
/* global adventurejs A */
/**
* @ajspath adventurejs.Atom.Asset.Zone
* @augments adventurejs.Asset
* @class adventurejs.Zone
* @ajsconstruct MyGame.createAsset({ "class":"Zone", "name":"foo", [...] })
* @ajsconstructedby adventurejs.Game#createAsset
* @ajsnavheading BaseClasses
* @param {String} game_name Name of top level game instance that is scoped to window.
* @param {String} name Instance name.
* @summary Set UniversalScenery descriptions for groups of Rooms.
* @tutorial Scenery_AreaScenery
* @tutorial Scenery_AreaEvents
* @classdesc
* <p>
* <strong>Zone</strong> is a low-level subclass of
* {@link adventurejs.Asset|Asset} with just a couple
* of properties: area_events and area_scenery. Use
* Zone to define customized sets of global Assets that
* can be shared by any number of
* {@link adventurejs.Room|Rooms}. For instance, you might
* create a desert Zone which describes a starry night sky,
* a blood moon, and exits that are blocked by
* sand dunes in every direction that hasn't got a defined
* Exit, with random gusts of blown sand and shimmering heat haze.
* </p>
* <p>
* There are three types of predefined global Assets:
* {@link adventurejs.Scenery|Scenery},
* {@link adventurejs.Wall|Walls}, and
* {@link adventurejs.Exit|Exits} (aka NoExits).
* Game comes with a number of predefined global Assets:
* {@link global_air|air},
* {@link global_moon|moon},
* {@link global_sky|sky},
* {@link global_sun|sun},
* {@link global_stars|stars},
* {@link global_ceiling|ceiling},
* {@link global_sound|sound},
* {@link global_rain|rain},
* {@link global_trees|trees}, and
* {@link global_wind|wind}; Walls for each of 12 directions; and
* NoExits for each of 18 directions. (NoExits are only called
* if the Room hasn't got an actual Exit in the given direction.)
* Scenery and Walls are disabled by default and must be
* enabled to use. NoExits are enabled by default,
* and can be disabled or customized.
* </p>
* <p>
* In addition to scenery, authors can create sets of
* random (or sequential) events that will print at any
* specified frequency. (<i>Events</i> here means in-game events,
* such as a periodic car alarm or a twinkling light, as opposed
* to JavaScript events.) A few random area events can help to
* spice up frequently visited locations. Look to the bottom
* of the following example to see how events are set up.
* </p>
* <h3 class="examples">Example:</h3>
* <p>
* In this example, we've defined a room with its
* <code class="property">zone</code> property set
* to "Desert Zone", where we've set custom
* descriptions for a couple of Game's predefined global
* Assets, and given it some random events.
* </p>
* <pre class="display"><code class="language-javascript">MyGame.createAsset({
* class: "Room",
* name: "Eastern Sands",
* zone: "Desert Zone",
* description: "It's swelteringly hot here. ",
* exits: {
* west: "Western Sands",
* north: "Nothing but sand dunes that way. ",
* },
* });
*
* MyGame.createAsset({
* class: "Zone",
* name: "Desert Zone",
* area_scenery:
* {
* sky: {
* enabled: true,
* description: "Even the sky is burnt to a pale sandy color. ",
* },
* sun: {
* enabled: true,
* description: "The sun burns is punishingly bright. ",
* },
* },
*
* area_events: [
* {
* frequency: .1,
* randomize: true,
* },
* "You hear the distant shriek of a desert hawk. ",
* "A flurry of sand trickles down a nearby dune. ",
* "A shimmer of heat haze rises up from the sands. "
* ],
* });
* </code></pre>
* <p>
* To learn more about customizing global Assets, see
* <a href="/doc/Scenery_AreaScenery.html">Area Scenery</a>.
* </p>
* <p>
* This longer version below shows all of the available global Assets.
* It's a pretty long list and it might look intimidating, but don't panic!
* It's all optional.
* In this example, we've expanded the
* "Desert Zone" with all of the Game's predefined
* global Assets. Note where the Room has
* <code class="property">exits.west</code> set to
* an actual Exit, which overrides the west NoExit
* set in Desert Zone. Similarly, the Room has a
* custom error message set for
* <code class="property">exits.north</code>, and
* this also overrides the north NoExit set in Desert Zone.
* </p>
* <pre class="display"><code class="language-javascript">MyGame.createAsset({
* class: "Room",
* name: "Eastern Sands",
* zone: "Desert Zone",
* description: "It's swelteringly hot here. ",
* exits: {
* west: "Western Sands",
* north: "Nothing but sand dunes that way. ",
* },
* });
*
* MyGame.createAsset({
* class: "Zone",
* name: "Desert Zone",
* area_scenery:
* {
* air: {
* enabled: true,
* description: "The air is hot and dry. ",
* },
* moon: { enabled: false,
* description: "The sun makes it impossible to see it. ",
* },
* sky: {
* enabled: true,
* description: "Even the sky is burnt to a pale sandy color. ",
* },
* sun: {
* enabled: true,
* description: "The sun burns is punishingly bright. ",
* },
* stars: {
* enabled: false,
* description: "Invisible under this brilliant sun. ",
* },
* floor: {
* enabled: true,
* description: "Endless sand. ",
* },
* ceiling: { enabled: false, description: "", },
* sound: {
* enabled: true,
* description: "You can hear a constant dry breeze. ",
* },
* "east wall": { enabled: false, description: "", },
* "west wall": { enabled: false, description: "", },
* "north wall": { enabled: false, description: "", },
* "northeast wall": { enabled: false, description: "", },
* "northwest wall": { enabled: false, description: "", },
* "south wall": {
* enabled: true,
* description: "A crumbling sandstone wall divides the entire region,
* blocking any passage to the south. ",
* },
* "southeast wall": {
* enabled: true,
* description: "The crumbling sandstone wall stretches away
* to the east, blocking any southeast passage. ",
* },
* "southwest wall": {
* enabled: true,
* descriptions: "The crumbling sandstone wall stretches away
* to the west, blocking any southwest passage. ",
* },
* "aft wall": { enabled: false, description: "", },
* "port wall": { enabled: false, description: "", },
* "starboard wall": { enabled: false, description: "", },
* "fore wall": { enabled: false, description: "", },
* east: {
* enabled: true,
* description: "Nothing but endless sand lies to the east. ",
* },
* west: {
* enabled: true,
* description: "Only trackless wastes lie to the west. ",
* },
* north: {
* enabled: true,
* description: "Tall dunes block passage to the north. ",
* },
* northeast: {
* enabled: true,
* description: "Towering dunes block any passage to the northeast. ",
* },
* northwest: {
* enabled: true,
* description: "Sand dunes prevent passage to the northwest. ",
* },
* south: {
* enabled: true,
* description: "The crumbling southern wall blocks all passage. ",
* },
* southeast: {
* enabled: true,
* description: "The endless sandstone wall lies southeast. ",
* },
* southwest: {
* enabled: true,
* description: "The sandstone wall prevents passage to the southwest. ",
* },
* aft: { enabled: false, description: "", },
* port: { enabled: false, description: "", },
* starboard: { enabled: false, description: "", },
* fore: { enabled: false, description: "", },
* },
*
* area_events: [
* {
* frequency: .1,
* randomize: true,
* },
* "You hear the distant shriek of a desert hawk. ",
* "A flurry of sand trickles down a nearby dune. ",
* "A shimmer of heat haze rises up from the sands. "
* ],
* });
* </code></pre>
**/
class Zone extends adventurejs.Asset {
constructor(name, game_name) {
super(name, game_name);
this.class = "Zone";
this.exclude_from_lookup = true;
/**
* Used to store arbitrary events that may be printed
* randomly to the game display.
* @var {Boolean} adventurejs.Zone#area_events
* @default {}
*/
this.area_events = {};
/**
* Used to define the area scenery that is available
* in this zone.
* @var {Boolean} adventurejs.Zone#area_scenery
* @default {}
*/
this.area_scenery = {
air: { enabled: false, description: "It smells like air. " },
moon: { enabled: false, description: "It's the moon. " },
sky: { enabled: false, description: "The sky. " },
sun: { enabled: false, description: "The sun. " },
stars: { enabled: false, description: "The stars. " },
floor: { enabled: false, description: "The floor. " },
ceiling: { enabled: false, description: "The ceiling. " },
sound: { enabled: false, description: "No particular sound. " },
rain: { enabled: false, description: "A light spring rain. " },
wind: { enabled: false, description: "A mighty wind. " },
trees: {
enabled: false,
description: "Can't see the forest for 'em. ",
},
clouds: { enabled: false, description: "Dark clouds. " },
lightning: {
enabled: false,
description: "Distant lightning. ",
},
mountains: {
enabled: false,
description: "Snow capped mountains. ",
},
mountain: { enabled: false, description: "Mount Doom. " },
"east wall": { enabled: false, description: "The east wall. " },
"west wall": { enabled: false, description: "The west wall. " },
"north wall": { enabled: false, description: "The north wall. " },
"northeast wall": {
enabled: false,
description: "The northeast wall. ",
},
"northwest wall": {
enabled: false,
description: "The northwest wall. ",
},
"south wall": { enabled: false, description: "The south wall. " },
southeast_wall: {
enabled: false,
description: "The southeast wall. ",
},
"southwest wall": {
enabled: false,
description: "The southwest wall. ",
},
"aft wall": { enabled: false, description: "The aft wall. " },
"port wall": { enabled: false, description: "The port wall. " },
"starboard wall": {
enabled: false,
description: "The starboard wall. ",
},
"fore wall": { enabled: false, description: "The fore wall. " },
east: {
enabled: true,
description: "There's no exit to the east. ",
},
west: {
enabled: true,
description: "There's no exit to the west. ",
},
north: {
enabled: true,
description: "There's no exit to the north. ",
},
northeast: {
enabled: true,
description: "There's no exit to the northeast. ",
},
northwest: {
enabled: true,
description: "There's no exit to the northwest. ",
},
south: {
enabled: true,
description: "There's no exit to the south. ",
},
southeast: {
enabled: true,
description: "There's no exit to the southeast. ",
},
southwest: {
enabled: true,
description: "There's no exit to the southwest. ",
},
aft: {
enabled: true,
description: "There's no exit to the aft. ",
},
port: {
enabled: true,
description: "There's no exit to the port. ",
},
starboard: {
enabled: true,
description: "There's no exit to the starboard. ",
},
fore: {
enabled: true,
description: "There's no exit to the fore. ",
},
};
}
initialize(game) {
super.initialize(game);
// add to list of rooms, which we use for "go to room"
this.game.room_lookup.push(this.id);
if (this.area_events && this.area_events.array) {
// ensure that we have use_saf setting
if ("undefined" === typeof this.area_events.use_saf) {
this.area_events.use_saf = true;
}
// ensure that we have randomize setting
if ("undefined" === typeof this.area_events.randomize) {
this.area_events.randomize =
this.game.settings.randomize_arrays_in_getStringArrayFunction;
}
// ensure that we have index
if ("undefined" === typeof this.area_events.index) {
this.area_events.index = 0;
}
// ensure that we have frequency setting
if ("undefined" === typeof this.area_events.frequency) {
this.area_events.frequency = 0;
}
}
return true;
}
}
adventurejs.Zone = Zone;
})();