|
| 1 | +// This is a "class" to represent the FireDepartment object in the game. If you want to render it in the game do so here. |
| 2 | +var Classe = require("classe"); |
| 3 | +var PIXI = require("pixi.js"); |
| 4 | +var Color = require("color"); |
| 5 | +var ease = require("core/utils").ease; |
| 6 | + |
| 7 | +var Building = require("./building"); |
| 8 | + |
| 9 | +//<<-- Creer-Merge: requires -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs. |
| 10 | +// any additional requires you want can be required here safely between Creer runs |
| 11 | +//<<-- /Creer-Merge: requires -->> |
| 12 | + |
| 13 | +/** |
| 14 | + * @typedef {Object} FireDepartmentState - A state representing a FireDepartment |
| 15 | + * @property {boolean} bribed - When true this building has already been bribed this turn and cannot be bribed again this turn. |
| 16 | + * @property {BuildingState} buildingEast - The Building directly to the east of this building, or null if not present. |
| 17 | + * @property {BuildingState} buildingNorth - The Building directly to the north of this building, or null if not present. |
| 18 | + * @property {BuildingState} buildingSouth - The Building directly to the south of this building, or null if not present. |
| 19 | + * @property {BuildingState} buildingWest - The Building directly to the west of this building, or null if not present. |
| 20 | + * @property {number} fire - How much fire is currently burning the building, and thus how much damage it will take at the end of its owner's turn. 0 means no fire. |
| 21 | + * @property {number} fireExtinguished - The amount of fire removed from a building when bribed to extinguish a building. |
| 22 | + * @property {string} gameObjectName - String representing the top level Class that this game object is an instance of. Used for reflection to create new instances on clients, but exposed for convenience should AIs want this data. |
| 23 | + * @property {number} health - How much health this building currently has. When this reaches 0 the Building has been burned down. |
| 24 | + * @property {string} id - A unique id for each instance of a GameObject or a sub class. Used for client and server communication. Should never change value after being set. |
| 25 | + * @property {boolean} isHeadquarters - True if this is the Headquarters of the owning player, false otherwise. Burning this down wins the game for the other Player. |
| 26 | + * @property {Array.<string>} logs - Any strings logged will be stored here. Intended for debugging. |
| 27 | + * @property {PlayerState} owner - The player that owns this building. If it burns down (health reaches 0) that player gets an additional bribe(s). |
| 28 | + * @property {number} x - The location of the Building along the x-axis. |
| 29 | + * @property {number} y - The location of the Building along the y-axis. |
| 30 | + */ |
| 31 | + |
| 32 | +/** |
| 33 | + * @class |
| 34 | + * @classdesc Can put out fires completely. |
| 35 | + * @extends Building |
| 36 | + */ |
| 37 | +var FireDepartment = Classe(Building, { |
| 38 | + /** |
| 39 | + * Initializes a FireDepartment with basic logic as provided by the Creer code generator. This is a good place to initialize sprites |
| 40 | + * |
| 41 | + * @memberof FireDepartment |
| 42 | + * @param {FireDepartmentState} initialState - the initial state of this game object |
| 43 | + * @param {Game} game - the game this FireDepartment is in |
| 44 | + */ |
| 45 | + init: function(initialState, game) { |
| 46 | + Building.init.apply(this, arguments); |
| 47 | + |
| 48 | + //<<-- Creer-Merge: init -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs. |
| 49 | + // initialization logic goes here |
| 50 | + //<<-- /Creer-Merge: init -->> |
| 51 | + }, |
| 52 | + |
| 53 | + /** |
| 54 | + * Static name of the classe. |
| 55 | + * |
| 56 | + * @static |
| 57 | + */ |
| 58 | + name: "FireDepartment", |
| 59 | + |
| 60 | + /** |
| 61 | + * The current state of this FireDepartment. Undefined when there is no current state. |
| 62 | + * |
| 63 | + * @type {FireDepartmentState|null})} |
| 64 | + */ |
| 65 | + current: null, |
| 66 | + |
| 67 | + /** |
| 68 | + * The next state of this FireDepartment. Undefined when there is no next state. |
| 69 | + * |
| 70 | + * @type {FireDepartmentState|null})} |
| 71 | + */ |
| 72 | + next: null, |
| 73 | + |
| 74 | + // The following values should get overridden when delta states are merged, but we set them here as a reference for you to see what variables this class has. |
| 75 | + |
| 76 | + /** |
| 77 | + * Set this to `true` if this GameObject should be rendered. |
| 78 | + * |
| 79 | + * @static |
| 80 | + */ |
| 81 | + //<<-- Creer-Merge: shouldRender -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs. |
| 82 | + shouldRender: false, |
| 83 | + //<<-- /Creer-Merge: shouldRender -->> |
| 84 | + |
| 85 | + /** |
| 86 | + * Called approx 60 times a second to update and render the FireDepartment. Leave empty if it should not be rendered |
| 87 | + * |
| 88 | + * @param {Number} dt - a floating point number [0, 1) which represents how far into the next turn that current turn we are rendering is at |
| 89 | + * @param {FireDepartmentState} current - the current (most) game state, will be this.next if this.current is null |
| 90 | + * @param {FireDepartmentState} next - the next (most) game state, will be this.current if this.next is null |
| 91 | + * @param {DeltaReason} reason - the reason for the current delta |
| 92 | + * @param {DeltaReason} nextReason - the reason for the next delta |
| 93 | + */ |
| 94 | + render: function(dt, current, next, reason, nextReason) { |
| 95 | + Building.render.apply(this, arguments); |
| 96 | + |
| 97 | + //<<-- Creer-Merge: render -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs. |
| 98 | + // render where the FireDepartment is |
| 99 | + //<<-- /Creer-Merge: render -->> |
| 100 | + }, |
| 101 | + |
| 102 | + /** |
| 103 | + * Invoked when the right click menu needs to be shown. |
| 104 | + * |
| 105 | + * @private |
| 106 | + * @returns {Array} array of context menu items, which can be {text, icon, callback} for items, or "---" for a seperator |
| 107 | + */ |
| 108 | + _getContextMenu: function() { |
| 109 | + var self = this; |
| 110 | + var menu = []; |
| 111 | + |
| 112 | + //<<-- Creer-Merge: _getContextMenu -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs. |
| 113 | + // add context items to the menu here |
| 114 | + //<<-- /Creer-Merge: _getContextMenu -->> |
| 115 | + |
| 116 | + return menu; |
| 117 | + }, |
| 118 | + |
| 119 | + |
| 120 | + // Joueur functions - functions invoked for human playable client |
| 121 | + |
| 122 | + /** |
| 123 | + * Bribes this FireDepartment to extinguish the some of the fire in a building. |
| 124 | + * |
| 125 | + * @param {BuildingState} building - The Building you want to extinguish. |
| 126 | + * @param {Function} [callback] - callback that is passed back the return value of boolean once ran on the server |
| 127 | + */ |
| 128 | + extinguish: function(building, callback) { |
| 129 | + this._runOnServer("extinguish", { |
| 130 | + building: building, |
| 131 | + }, callback); |
| 132 | + }, |
| 133 | + |
| 134 | + // /Joueur functions |
| 135 | + |
| 136 | + /** |
| 137 | + * Invoked when the state updates. |
| 138 | + * |
| 139 | + * @private |
| 140 | + * @param {FireDepartmentState} current - the current (most) game state, will be this.next if this.current is null |
| 141 | + * @param {FireDepartmentState} next - the next (most) game state, will be this.current if this.next is null |
| 142 | + * @param {DeltaReason} reason - the reason for the current delta |
| 143 | + * @param {DeltaReason} nextReason - the reason for the next delta |
| 144 | + */ |
| 145 | + _stateUpdated: function(current, next, reason, nextReason) { |
| 146 | + Building._stateUpdated.apply(this, arguments); |
| 147 | + |
| 148 | + //<<-- Creer-Merge: _stateUpdated -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs. |
| 149 | + // update the FireDepartment based on its current and next states |
| 150 | + //<<-- /Creer-Merge: _stateUpdated -->> |
| 151 | + }, |
| 152 | + |
| 153 | + //<<-- Creer-Merge: functions -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs. |
| 154 | + // any additional functions you want to add to this class can be perserved here |
| 155 | + //<<-- /Creer-Merge: functions -->> |
| 156 | + |
| 157 | +}); |
| 158 | + |
| 159 | +module.exports = FireDepartment; |
0 commit comments