Files
adarkroom/script/room.js
T

1260 lines
33 KiB
JavaScript
Raw Normal View History

2015-02-11 18:55:27 -05:00
/**
* Module that registers the simple room functionality
*/
var Room = {
// times in (minutes * seconds * milliseconds)
_FIRE_COOL_DELAY: 5 * 60 * 1000, // time after a stoke before the fire cools
_ROOM_WARM_DELAY: 30 * 1000, // time between room temperature updates
_BUILDER_STATE_DELAY: 0.5 * 60 * 1000, // time between builder state updates
_STOKE_COOLDOWN: 10, // cooldown to stoke the fire
_NEED_WOOD_DELAY: 15 * 1000, // from when the stranger shows up, to when you need wood
2020-05-28 19:10:09 -04:00
buttons: {},
2015-02-11 18:55:27 -05:00
Craftables: {
'trap': {
name: _('trap'),
button: null,
maximum: 10,
availableMsg: _('builder says she can make traps to catch any creatures might still be alive out there'),
buildMsg: _('more traps to catch more creatures'),
maxMsg: _("more traps won't help now"),
type: 'building',
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
var n = $SM.get('game.buildings["trap"]', true);
return {
2020-05-28 19:10:09 -04:00
'wood': 10 + (n * 10)
2015-02-11 18:55:27 -05:00
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.BUILD_TRAP
2015-02-11 18:55:27 -05:00
},
'cart': {
name: _('cart'),
button: null,
maximum: 1,
availableMsg: _('builder says she can make a cart for carrying wood'),
buildMsg: _('the rickety cart will carry more wood from the forest'),
type: 'building',
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
return {
'wood': 30
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.BUILD_CART
2015-02-11 18:55:27 -05:00
},
'hut': {
name: _('hut'),
button: null,
maximum: 20,
availableMsg: _("builder says there are more wanderers. says they'll work, too."),
buildMsg: _('builder puts up a hut, out in the forest. says word will get around.'),
maxMsg: _('no more room for huts.'),
type: 'building',
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
var n = $SM.get('game.buildings["hut"]', true);
return {
2020-05-28 19:10:09 -04:00
'wood': 100 + (n * 50)
2015-02-11 18:55:27 -05:00
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.BUILD_HUT
2015-02-11 18:55:27 -05:00
},
'lodge': {
name: _('lodge'),
button: null,
maximum: 1,
availableMsg: _('villagers could help hunt, given the means'),
buildMsg: _('the hunting lodge stands in the forest, a ways out of town'),
type: 'building',
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
return {
wood: 200,
fur: 10,
meat: 5
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.BUILD_LODGE
2015-02-11 18:55:27 -05:00
},
'trading post': {
name: _('trading post'),
button: null,
maximum: 1,
availableMsg: _("a trading post would make commerce easier"),
buildMsg: _("now the nomads have a place to set up shop, they might stick around a while"),
type: 'building',
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
return {
'wood': 400,
'fur': 100
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.BUILD_TRADING_POST
2015-02-11 18:55:27 -05:00
},
'tannery': {
name: _('tannery'),
button: null,
maximum: 1,
availableMsg: _("builder says leather could be useful. says the villagers could make it."),
buildMsg: _('tannery goes up quick, on the edge of the village'),
type: 'building',
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
return {
'wood': 500,
'fur': 50
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.BUILD_TANNERY
2015-02-11 18:55:27 -05:00
},
'smokehouse': {
name: _('smokehouse'),
button: null,
maximum: 1,
availableMsg: _("should cure the meat, or it'll spoil. builder says she can fix something up."),
buildMsg: _('builder finishes the smokehouse. she looks hungry.'),
type: 'building',
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
return {
'wood': 600,
'meat': 50
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.BUILD_SMOKEHOUSE
2015-02-11 18:55:27 -05:00
},
'workshop': {
name: _('workshop'),
button: null,
maximum: 1,
availableMsg: _("builder says she could make finer things, if she had the tools"),
buildMsg: _("workshop's finally ready. builder's excited to get to it"),
type: 'building',
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
return {
'wood': 800,
'leather': 100,
'scales': 10
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.BUILD_WORKSHOP
2015-02-11 18:55:27 -05:00
},
'steelworks': {
name: _('steelworks'),
button: null,
maximum: 1,
availableMsg: _("builder says the villagers could make steel, given the tools"),
buildMsg: _("a haze falls over the village as the steelworks fires up"),
type: 'building',
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
return {
'wood': 1500,
'iron': 100,
'coal': 100
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.BUILD_STEELWORKS
2015-02-11 18:55:27 -05:00
},
'armoury': {
name: _('armoury'),
button: null,
maximum: 1,
availableMsg: _("builder says it'd be useful to have a steady source of bullets"),
buildMsg: _("armoury's done, welcoming back the weapons of the past."),
type: 'building',
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
return {
'wood': 3000,
'steel': 100,
'sulphur': 50
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.BUILD_ARMOURY
2015-02-11 18:55:27 -05:00
},
'torch': {
name: _('torch'),
button: null,
type: 'tool',
buildMsg: _('a torch to keep the dark away'),
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
return {
'wood': 1,
'cloth': 1
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.CRAFT_TORCH
2015-02-11 18:55:27 -05:00
},
'waterskin': {
name: _('waterskin'),
button: null,
type: 'upgrade',
maximum: 1,
buildMsg: _('this waterskin\'ll hold a bit of water, at least'),
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
return {
'leather': 50
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.CRAFT_WATERSKIN
2015-02-11 18:55:27 -05:00
},
'cask': {
name: _('cask'),
button: null,
type: 'upgrade',
maximum: 1,
buildMsg: _('the cask holds enough water for longer expeditions'),
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
return {
'leather': 100,
'iron': 20
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.CRAFT_CASK
2015-02-11 18:55:27 -05:00
},
'water tank': {
name: _('water tank'),
button: null,
type: 'upgrade',
maximum: 1,
buildMsg: _('never go thirsty again'),
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
return {
'iron': 100,
'steel': 50
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.CRAFT_WATER_TANK
2015-02-11 18:55:27 -05:00
},
'bone spear': {
name: _('bone spear'),
button: null,
type: 'weapon',
buildMsg: _("this spear's not elegant, but it's pretty good at stabbing"),
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
return {
'wood': 100,
'teeth': 5
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.CRAFT_BONE_SPEAR
2015-02-11 18:55:27 -05:00
},
'rucksack': {
name: _('rucksack'),
button: null,
type: 'upgrade',
maximum: 1,
buildMsg: _('carrying more means longer expeditions to the wilds'),
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
return {
'leather': 200
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.CRAFT_RUCKSACK
2015-02-11 18:55:27 -05:00
},
'wagon': {
name: _('wagon'),
button: null,
type: 'upgrade',
maximum: 1,
buildMsg: _('the wagon can carry a lot of supplies'),
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
return {
'wood': 500,
'iron': 100
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.CRAFT_WAGON
2015-02-11 18:55:27 -05:00
},
'convoy': {
name: _('convoy'),
button: null,
type: 'upgrade',
maximum: 1,
buildMsg: _('the convoy can haul mostly everything'),
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
return {
'wood': 1000,
'iron': 200,
'steel': 100
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.CRAFT_CONVOY
2015-02-11 18:55:27 -05:00
},
'l armour': {
name: _('l armour'),
type: 'upgrade',
maximum: 1,
buildMsg: _("leather's not strong. better than rags, though."),
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
return {
'leather': 200,
'scales': 20
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.CRAFT_LEATHER_ARMOUR
2015-02-11 18:55:27 -05:00
},
'i armour': {
name: _('i armour'),
type: 'upgrade',
maximum: 1,
buildMsg: _("iron's stronger than leather"),
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
return {
'leather': 200,
'iron': 100
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.CRAFT_IRON_ARMOUR
2015-02-11 18:55:27 -05:00
},
's armour': {
name: _('s armour'),
type: 'upgrade',
maximum: 1,
buildMsg: _("steel's stronger than iron"),
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
return {
'leather': 200,
'steel': 100
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.CRAFT_STEEL_ARMOUR
2015-02-11 18:55:27 -05:00
},
'iron sword': {
name: _('iron sword'),
button: null,
type: 'weapon',
buildMsg: _("sword is sharp. good protection out in the wilds."),
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
return {
'wood': 200,
'leather': 50,
'iron': 20
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.CRAFT_IRON_SWORD
2015-02-11 18:55:27 -05:00
},
'steel sword': {
name: _('steel sword'),
button: null,
type: 'weapon',
buildMsg: _("the steel is strong, and the blade true."),
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
return {
'wood': 500,
'leather': 100,
'steel': 20
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.CRAFT_STEEL_SWORD
2015-02-11 18:55:27 -05:00
},
'rifle': {
name: _('rifle'),
type: 'weapon',
buildMsg: _("black powder and bullets, like the old days."),
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
return {
'wood': 200,
'steel': 50,
'sulphur': 50
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.CRAFT_RIFLE
2015-02-11 18:55:27 -05:00
}
},
2020-05-28 19:10:09 -04:00
2015-02-11 18:55:27 -05:00
TradeGoods: {
'scales': {
type: 'good',
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
return { fur: 150 };
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.BUY_SCALES
2015-02-11 18:55:27 -05:00
},
'teeth': {
type: 'good',
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
return { fur: 300 };
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.BUY_TEETH
2015-02-11 18:55:27 -05:00
},
'iron': {
type: 'good',
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
return {
'fur': 150,
'scales': 50
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.BUY_IRON
2015-02-11 18:55:27 -05:00
},
'coal': {
type: 'good',
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
return {
'fur': 200,
'teeth': 50
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.BUY_COAL
2015-02-11 18:55:27 -05:00
},
'steel': {
type: 'good',
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
return {
'fur': 300,
'scales': 50,
'teeth': 50
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.BUY_STEEL
2015-02-11 18:55:27 -05:00
},
'medicine': {
type: 'good',
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
return {
'scales': 50, 'teeth': 30
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.BUY_MEDICINE
2015-02-11 18:55:27 -05:00
},
'bullets': {
type: 'good',
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
return {
'scales': 10
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.BUY_BULLETS
2015-02-11 18:55:27 -05:00
},
'energy cell': {
type: 'good',
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
return {
'scales': 10,
'teeth': 10
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.BUY_ENERGY_CELL
2015-02-11 18:55:27 -05:00
},
'bolas': {
type: 'weapon',
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
return {
'teeth': 10
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.BUY_BOLAS
2015-02-11 18:55:27 -05:00
},
'grenade': {
type: 'weapon',
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
return {
'scales': 100,
'teeth': 50
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.BUY_GRENADES
2015-02-11 18:55:27 -05:00
},
'bayonet': {
type: 'weapon',
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
return {
'scales': 500,
'teeth': 250
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.BUY_BAYONET
2015-02-11 18:55:27 -05:00
},
'alien alloy': {
type: 'good',
2020-05-28 19:10:09 -04:00
cost: function () {
2015-02-11 18:55:27 -05:00
return {
'fur': 1500,
'scales': 750,
'teeth': 300
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.BUY_ALIEN_ALLOY
2015-02-11 18:55:27 -05:00
},
'compass': {
2015-05-06 20:44:53 +02:00
type: 'special',
2015-02-11 18:55:27 -05:00
maximum: 1,
2020-05-28 19:10:09 -04:00
cost: function () {
return {
fur: 400,
scales: 20,
teeth: 10
2015-02-11 18:55:27 -05:00
};
2020-05-28 19:10:09 -04:00
},
audio: AudioLibrary.BUY_COMPASS
2015-02-11 18:55:27 -05:00
}
},
2020-05-28 19:10:09 -04:00
2015-02-11 18:55:27 -05:00
MiscItems: {
'laser rifle': {
type: 'weapon'
}
},
2020-05-28 19:10:09 -04:00
2015-02-11 18:55:27 -05:00
name: _("Room"),
2020-05-28 19:10:09 -04:00
init: function (options) {
2015-02-11 18:55:27 -05:00
this.options = $.extend(
this.options,
options
);
2020-05-28 19:10:09 -04:00
2015-05-06 20:44:53 +02:00
Room.pathDiscovery = Boolean($SM.get('stores["compass"]'));
2020-05-28 19:10:09 -04:00
if (Engine._debug) {
2015-02-11 18:55:27 -05:00
this._ROOM_WARM_DELAY = 5000;
this._BUILDER_STATE_DELAY = 5000;
this._STOKE_COOLDOWN = 0;
this._NEED_WOOD_DELAY = 5000;
}
2020-05-28 19:10:09 -04:00
if (typeof $SM.get('features.location.room') == 'undefined') {
2015-02-11 18:55:27 -05:00
$SM.set('features.location.room', true);
$SM.set('game.builder.level', -1);
}
2020-05-28 19:10:09 -04:00
2015-02-11 18:55:27 -05:00
// If this is the first time playing, the fire is dead and it's freezing.
// Otherwise grab past save state temp and fire level.
2020-05-28 19:10:09 -04:00
$SM.set('game.temperature', $SM.get('game.temperature.value') === undefined ? this.TempEnum.Freezing : $SM.get('game.temperature'));
$SM.set('game.fire', $SM.get('game.fire.value') === undefined ? this.FireEnum.Dead : $SM.get('game.fire'));
2015-02-11 18:55:27 -05:00
// Create the room tab
this.tab = Header.addLocation(_("A Dark Room"), "room", Room);
2020-05-28 19:10:09 -04:00
2015-02-11 18:55:27 -05:00
// Create the Room panel
this.panel = $('<div>')
.attr('id', "roomPanel")
.addClass('location')
.appendTo('div#locationSlider');
2020-05-28 19:10:09 -04:00
2015-02-11 18:55:27 -05:00
Engine.updateSlider();
2020-05-28 19:10:09 -04:00
2015-02-11 18:55:27 -05:00
// Create the light button
new Button.Button({
id: 'lightButton',
text: _('light fire'),
click: Room.lightFire,
cooldown: Room._STOKE_COOLDOWN,
width: '80px',
2020-05-28 19:10:09 -04:00
cost: { 'wood': 5 }
2015-02-11 18:55:27 -05:00
}).appendTo('div#roomPanel');
2020-05-28 19:10:09 -04:00
2015-02-11 18:55:27 -05:00
// Create the stoke button
new Button.Button({
id: 'stokeButton',
text: _("stoke fire"),
click: Room.stokeFire,
cooldown: Room._STOKE_COOLDOWN,
width: '80px',
2020-05-28 19:10:09 -04:00
cost: { 'wood': 1 }
2015-02-11 18:55:27 -05:00
}).appendTo('div#roomPanel');
2020-05-28 19:10:09 -04:00
2015-02-11 18:55:27 -05:00
// Create the stores container
$('<div>').attr('id', 'storesContainer').prependTo('div#roomPanel');
2020-05-28 19:10:09 -04:00
2015-02-11 18:55:27 -05:00
//subscribe to stateUpdates
$.Dispatch('stateUpdate').subscribe(Room.handleStateUpdates);
2020-05-28 19:10:09 -04:00
2015-02-11 18:55:27 -05:00
Room.updateButton();
Room.updateStoresView();
Room.updateIncomeView();
Room.updateBuildButtons();
2020-05-28 19:10:09 -04:00
2015-02-11 18:55:27 -05:00
Room._fireTimer = Engine.setTimeout(Room.coolFire, Room._FIRE_COOL_DELAY);
Room._tempTimer = Engine.setTimeout(Room.adjustTemp, Room._ROOM_WARM_DELAY);
2020-05-28 19:10:09 -04:00
2015-02-11 18:55:27 -05:00
/*
* Builder states:
* 0 - Approaching
* 1 - Collapsed
* 2 - Shivering
* 3 - Sleeping
* 4 - Helping
*/
2020-05-28 19:10:09 -04:00
if ($SM.get('game.builder.level') >= 0 && $SM.get('game.builder.level') < 3) {
2015-02-11 18:55:27 -05:00
Room._builderTimer = Engine.setTimeout(Room.updateBuilderState, Room._BUILDER_STATE_DELAY);
}
2020-05-28 19:10:09 -04:00
if ($SM.get('game.builder.level') == 1 && $SM.get('stores.wood', true) < 0) {
2015-02-11 18:55:27 -05:00
Engine.setTimeout(Room.unlockForest, Room._NEED_WOOD_DELAY);
}
Engine.setTimeout($SM.collectIncome, 1000);
Notifications.notify(Room, _("the room is {0}", Room.TempEnum.fromInt($SM.get('game.temperature.value')).text));
Notifications.notify(Room, _("the fire is {0}", Room.FireEnum.fromInt($SM.get('game.fire.value')).text));
},
2020-05-28 19:10:09 -04:00
2015-02-11 18:55:27 -05:00
options: {}, // Nothing for now
2020-05-28 19:10:09 -04:00
onArrival: function (transition_diff) {
2015-02-11 18:55:27 -05:00
Room.setTitle();
2020-05-28 19:10:09 -04:00
if (Room.changed) {
2015-02-11 18:55:27 -05:00
Notifications.notify(Room, _("the fire is {0}", Room.FireEnum.fromInt($SM.get('game.fire.value')).text));
Notifications.notify(Room, _("the room is {0}", Room.TempEnum.fromInt($SM.get('game.temperature.value')).text));
Room.changed = false;
}
2020-05-28 19:10:09 -04:00
if ($SM.get('game.builder.level') == 3) {
2015-02-11 18:55:27 -05:00
$SM.add('game.builder.level', 1);
$SM.setIncome('builder', {
delay: 10,
2020-05-28 19:10:09 -04:00
stores: { 'wood': 2 }
2015-02-11 18:55:27 -05:00
});
Room.updateIncomeView();
Notifications.notify(Room, _("the stranger is standing by the fire. she says she can help. says she builds things."));
}
Engine.moveStoresView(null, transition_diff);
2020-05-28 19:10:09 -04:00
Room.setMusic();
2015-02-11 18:55:27 -05:00
},
2020-05-28 19:10:09 -04:00
2015-02-11 18:55:27 -05:00
TempEnum: {
2020-05-28 19:10:09 -04:00
fromInt: function (value) {
for (var k in this) {
if (typeof this[k].value != 'undefined' && this[k].value == value) {
2015-02-11 18:55:27 -05:00
return this[k];
}
}
return null;
},
Freezing: { value: 0, text: _('freezing') },
Cold: { value: 1, text: _('cold') },
Mild: { value: 2, text: _('mild') },
Warm: { value: 3, text: _('warm') },
Hot: { value: 4, text: _('hot') }
},
2020-05-28 19:10:09 -04:00
2015-02-11 18:55:27 -05:00
FireEnum: {
2020-05-28 19:10:09 -04:00
fromInt: function (value) {
for (var k in this) {
if (typeof this[k].value != 'undefined' && this[k].value == value) {
2015-02-11 18:55:27 -05:00
return this[k];
}
}
return null;
},
Dead: { value: 0, text: _('dead') },
Smoldering: { value: 1, text: _('smoldering') },
Flickering: { value: 2, text: _('flickering') },
Burning: { value: 3, text: _('burning') },
Roaring: { value: 4, text: _('roaring') }
},
2020-05-28 19:10:09 -04:00
setTitle: function () {
2015-02-11 18:55:27 -05:00
var title = $SM.get('game.fire.value') < 2 ? _("A Dark Room") : _("A Firelit Room");
2020-05-28 19:10:09 -04:00
if (Engine.activeModule == this) {
2015-02-11 18:55:27 -05:00
document.title = title;
}
$('div#location_room').text(title);
},
2020-05-28 19:10:09 -04:00
updateButton: function () {
2015-02-11 18:55:27 -05:00
var light = $('#lightButton.button');
var stoke = $('#stokeButton.button');
2020-05-28 19:10:09 -04:00
if ($SM.get('game.fire.value') == Room.FireEnum.Dead.value && stoke.css('display') != 'none') {
2015-02-11 18:55:27 -05:00
stoke.hide();
light.show();
2020-05-28 19:10:09 -04:00
if (stoke.hasClass('disabled')) {
2015-02-11 18:55:27 -05:00
Button.cooldown(light);
}
2020-05-28 19:10:09 -04:00
} else if (light.css('display') != 'none') {
2015-02-11 18:55:27 -05:00
stoke.show();
light.hide();
2020-05-28 19:10:09 -04:00
if (light.hasClass('disabled')) {
2015-02-11 18:55:27 -05:00
Button.cooldown(stoke);
}
}
2020-05-28 19:10:09 -04:00
if (!$SM.get('stores.wood')) {
2015-02-11 18:55:27 -05:00
light.addClass('free');
stoke.addClass('free');
} else {
light.removeClass('free');
stoke.removeClass('free');
}
},
2020-05-28 19:10:09 -04:00
2015-02-11 18:55:27 -05:00
_fireTimer: null,
_tempTimer: null,
2020-05-28 19:10:09 -04:00
lightFire: function () {
2015-02-11 18:55:27 -05:00
var wood = $SM.get('stores.wood');
2020-05-28 19:10:09 -04:00
if (wood < 5) {
2015-02-11 18:55:27 -05:00
Notifications.notify(Room, _("not enough wood to get the fire going"));
Button.clearCooldown($('#lightButton.button'));
return;
2020-05-28 19:10:09 -04:00
} else if (wood > 4) {
2015-02-11 18:55:27 -05:00
$SM.set('stores.wood', wood - 5);
}
$SM.set('game.fire', Room.FireEnum.Burning);
2020-05-28 19:10:09 -04:00
AudioEngine.playSound(AudioLibrary.LIGHT_FIRE);
2015-02-11 18:55:27 -05:00
Room.onFireChange();
},
2020-05-28 19:10:09 -04:00
stokeFire: function () {
2015-02-11 18:55:27 -05:00
var wood = $SM.get('stores.wood');
2020-05-28 19:10:09 -04:00
if (wood === 0) {
2015-02-11 18:55:27 -05:00
Notifications.notify(Room, _("the wood has run out"));
Button.clearCooldown($('#stokeButton.button'));
return;
}
2020-05-28 19:10:09 -04:00
if (wood > 0) {
2015-02-11 18:55:27 -05:00
$SM.set('stores.wood', wood - 1);
}
2020-05-28 19:10:09 -04:00
if ($SM.get('game.fire.value') < 4) {
2015-02-11 18:55:27 -05:00
$SM.set('game.fire', Room.FireEnum.fromInt($SM.get('game.fire.value') + 1));
}
2020-05-28 19:10:09 -04:00
AudioEngine.playSound(AudioLibrary.STOKE_FIRE);
2015-02-11 18:55:27 -05:00
Room.onFireChange();
},
2020-05-28 19:10:09 -04:00
onFireChange: function () {
if (Engine.activeModule != Room) {
2015-02-11 18:55:27 -05:00
Room.changed = true;
}
Notifications.notify(Room, _("the fire is {0}", Room.FireEnum.fromInt($SM.get('game.fire.value')).text), true);
2020-05-28 19:10:09 -04:00
if ($SM.get('game.fire.value') > 1 && $SM.get('game.builder.level') < 0) {
2015-02-11 18:55:27 -05:00
$SM.set('game.builder.level', 0);
Notifications.notify(Room, _("the light from the fire spills from the windows, out into the dark"));
Engine.setTimeout(Room.updateBuilderState, Room._BUILDER_STATE_DELAY);
2020-05-28 19:10:09 -04:00
}
2015-02-11 18:55:27 -05:00
window.clearTimeout(Room._fireTimer);
Room._fireTimer = Engine.setTimeout(Room.coolFire, Room._FIRE_COOL_DELAY);
Room.updateButton();
Room.setTitle();
2020-05-28 19:10:09 -04:00
// only update music if in the room
if (Engine.activeModule == Room) {
Room.setMusic();
}
2015-02-11 18:55:27 -05:00
},
2020-05-28 19:10:09 -04:00
coolFire: function () {
2015-02-11 18:55:27 -05:00
var wood = $SM.get('stores.wood');
2020-05-28 19:10:09 -04:00
if ($SM.get('game.fire.value') <= Room.FireEnum.Flickering.value &&
2015-02-11 18:55:27 -05:00
$SM.get('game.builder.level') > 3 && wood > 0) {
Notifications.notify(Room, _("builder stokes the fire"), true);
$SM.set('stores.wood', wood - 1);
2020-05-28 19:10:09 -04:00
$SM.set('game.fire', Room.FireEnum.fromInt($SM.get('game.fire.value') + 1));
2015-02-11 18:55:27 -05:00
}
2020-05-28 19:10:09 -04:00
if ($SM.get('game.fire.value') > 0) {
$SM.set('game.fire', Room.FireEnum.fromInt($SM.get('game.fire.value') - 1));
2015-02-11 18:55:27 -05:00
Room._fireTimer = Engine.setTimeout(Room.coolFire, Room._FIRE_COOL_DELAY);
Room.onFireChange();
}
},
2020-05-28 19:10:09 -04:00
adjustTemp: function () {
2015-02-11 18:55:27 -05:00
var old = $SM.get('game.temperature.value');
2020-05-28 19:10:09 -04:00
if ($SM.get('game.temperature.value') > 0 && $SM.get('game.temperature.value') > $SM.get('game.fire.value')) {
$SM.set('game.temperature', Room.TempEnum.fromInt($SM.get('game.temperature.value') - 1));
Notifications.notify(Room, _("the room is {0}", Room.TempEnum.fromInt($SM.get('game.temperature.value')).text), true);
2015-02-11 18:55:27 -05:00
}
2020-05-28 19:10:09 -04:00
if ($SM.get('game.temperature.value') < 4 && $SM.get('game.temperature.value') < $SM.get('game.fire.value')) {
2015-02-11 18:55:27 -05:00
$SM.set('game.temperature', Room.TempEnum.fromInt($SM.get('game.temperature.value') + 1));
2020-05-28 19:10:09 -04:00
Notifications.notify(Room, _("the room is {0}", Room.TempEnum.fromInt($SM.get('game.temperature.value')).text), true);
2015-02-11 18:55:27 -05:00
}
2020-05-28 19:10:09 -04:00
if ($SM.get('game.temperature.value') != old) {
2015-02-11 18:55:27 -05:00
Room.changed = true;
}
Room._tempTimer = Engine.setTimeout(Room.adjustTemp, Room._ROOM_WARM_DELAY);
},
2020-05-28 19:10:09 -04:00
unlockForest: function () {
2015-02-11 18:55:27 -05:00
$SM.set('stores.wood', 4);
Outside.init();
Notifications.notify(Room, _("the wind howls outside"));
Notifications.notify(Room, _("the wood is running out"));
Engine.event('progress', 'outside');
},
2020-05-28 19:10:09 -04:00
updateBuilderState: function () {
2015-02-11 18:55:27 -05:00
var lBuilder = $SM.get('game.builder.level');
2020-05-28 19:10:09 -04:00
if (lBuilder === 0) {
2015-02-11 18:55:27 -05:00
Notifications.notify(Room, _("a ragged stranger stumbles through the door and collapses in the corner"));
lBuilder = $SM.setget('game.builder.level', 1);
Engine.setTimeout(Room.unlockForest, Room._NEED_WOOD_DELAY);
2020-05-28 19:10:09 -04:00
}
else if (lBuilder < 3 && $SM.get('game.temperature.value') >= Room.TempEnum.Warm.value) {
2015-02-11 18:55:27 -05:00
var msg = "";
2020-05-28 19:10:09 -04:00
switch (lBuilder) {
case 1:
msg = _("the stranger shivers, and mumbles quietly. her words are unintelligible.");
break;
case 2:
msg = _("the stranger in the corner stops shivering. her breathing calms.");
break;
2015-02-11 18:55:27 -05:00
}
Notifications.notify(Room, msg);
2020-05-28 19:10:09 -04:00
if (lBuilder < 3) {
2015-02-11 18:55:27 -05:00
lBuilder = $SM.setget('game.builder.level', lBuilder + 1);
}
}
2020-05-28 19:10:09 -04:00
if (lBuilder < 3) {
2015-02-11 18:55:27 -05:00
Engine.setTimeout(Room.updateBuilderState, Room._BUILDER_STATE_DELAY);
}
Engine.saveGame();
},
2020-05-28 19:10:09 -04:00
updateStoresView: function () {
2015-02-11 18:55:27 -05:00
var stores = $('div#stores');
2016-02-14 21:24:43 +01:00
var resources = $('div#resources');
2015-05-06 20:44:53 +02:00
var special = $('div#special');
2015-02-11 18:55:27 -05:00
var weapons = $('div#weapons');
2015-05-06 20:44:53 +02:00
var needsAppend = false, rNeedsAppend = false, sNeedsAppend = false, wNeedsAppend = false, newRow = false;
2020-05-28 19:10:09 -04:00
if (stores.length === 0) {
2015-02-11 18:55:27 -05:00
stores = $('<div>').attr({
2015-05-18 16:57:17 +02:00
'id': 'stores',
'data-legend': _('stores')
2015-02-11 18:55:27 -05:00
}).css('opacity', 0);
needsAppend = true;
}
2020-05-28 19:10:09 -04:00
if (resources.length === 0) {
2015-05-06 20:44:53 +02:00
resources = $('<div>').attr({
id: 'resources'
}).css('opacity', 0);
rNeedsAppend = true;
}
2020-05-28 19:10:09 -04:00
if (special.length === 0) {
2015-05-06 20:44:53 +02:00
special = $('<div>').attr({
id: 'special'
}).css('opacity', 0);
sNeedsAppend = true;
}
2020-05-28 19:10:09 -04:00
if (weapons.length === 0) {
2015-02-11 18:55:27 -05:00
weapons = $('<div>').attr({
2015-05-18 16:57:17 +02:00
'id': 'weapons',
'data-legend': _('weapons')
2015-02-11 18:55:27 -05:00
}).css('opacity', 0);
wNeedsAppend = true;
}
2020-05-28 19:10:09 -04:00
for (var k in $SM.get('stores')) {
2023-06-09 12:38:16 -04:00
if (k.indexOf('blueprint') > 0) {
// don't show blueprints
continue;
2015-02-11 18:55:27 -05:00
}
2020-05-28 19:10:09 -04:00
2023-06-09 12:38:16 -04:00
const good =
Room.Craftables[k] ||
Room.TradeGoods[k] ||
Room.TradeGoods[k] ||
Room.MiscItems[k] ||
Fabricator.Craftables[k];
const type = good ? good.type : null;
2015-02-11 18:55:27 -05:00
var location;
2020-05-28 19:10:09 -04:00
switch (type) {
case 'upgrade':
// Don't display upgrades on the Room screen
continue;
case 'building':
// Don't display buildings either
continue;
case 'weapon':
location = weapons;
break;
case 'special':
location = special;
break;
default:
location = resources;
break;
2015-02-11 18:55:27 -05:00
}
2020-05-28 19:10:09 -04:00
2023-06-09 12:38:16 -04:00
var id = "row_" + k.replace(/ /g, '-');
2015-02-11 18:55:27 -05:00
var row = $('div#' + id, location);
2020-05-28 19:10:09 -04:00
var num = $SM.get('stores["' + k + '"]');
if (typeof num != 'number' || isNaN(num)) {
2015-02-11 18:55:27 -05:00
// No idea how counts get corrupted, but I have reason to believe that they occassionally do.
// Build a little fence around it!
num = 0;
2020-05-28 19:10:09 -04:00
$SM.set('stores["' + k + '"]', 0);
2015-02-11 18:55:27 -05:00
}
2020-05-28 19:10:09 -04:00
2015-04-30 17:26:56 +02:00
var lk = _(k);
2020-05-28 19:10:09 -04:00
2015-02-11 18:55:27 -05:00
// thieves?
2020-05-28 19:10:09 -04:00
if (typeof $SM.get('game.thieves') == 'undefined' && num > 5000 && $SM.get('features.location.world')) {
2015-02-11 18:55:27 -05:00
$SM.startThieves();
}
2020-05-28 19:10:09 -04:00
if (row.length === 0) {
2015-02-11 18:55:27 -05:00
row = $('<div>').attr('id', id).addClass('storeRow');
2015-04-30 16:57:18 +02:00
$('<div>').addClass('row_key').text(lk).appendTo(row);
2015-02-11 18:55:27 -05:00
$('<div>').addClass('row_val').text(Math.floor(num)).appendTo(row);
$('<div>').addClass('clear').appendTo(row);
var curPrev = null;
2020-05-28 19:10:09 -04:00
location.children().each(function (i) {
2015-02-11 18:55:27 -05:00
var child = $(this);
2015-04-29 23:43:43 +02:00
var cName = child.children('.row_key').text();
2020-05-28 19:10:09 -04:00
if (cName < lk) {
2015-04-29 23:43:43 +02:00
curPrev = child.attr('id');
2015-02-11 18:55:27 -05:00
}
});
2020-05-28 19:10:09 -04:00
if (curPrev == null) {
2015-02-11 18:55:27 -05:00
row.prependTo(location);
} else {
2015-04-29 23:43:43 +02:00
row.insertAfter(location.find('#' + curPrev));
2015-02-11 18:55:27 -05:00
}
newRow = true;
2016-02-14 21:24:43 +01:00
} else {
2015-02-11 18:55:27 -05:00
$('div#' + row.attr('id') + ' > div.row_val', location).text(Math.floor(num));
}
}
2020-05-28 19:10:09 -04:00
if (rNeedsAppend && resources.children().length > 0) {
2015-05-06 20:44:53 +02:00
resources.prependTo(stores);
2020-05-28 19:10:09 -04:00
resources.animate({ opacity: 1 }, 300, 'linear');
2015-05-06 20:44:53 +02:00
}
2020-05-28 19:10:09 -04:00
if (sNeedsAppend && special.children().length > 0) {
2015-05-06 20:44:53 +02:00
special.appendTo(stores);
2020-05-28 19:10:09 -04:00
special.animate({ opacity: 1 }, 300, 'linear');
2015-05-06 20:44:53 +02:00
}
2020-05-28 19:10:09 -04:00
if (needsAppend && stores.find('div.storeRow').length > 0) {
2015-02-11 18:55:27 -05:00
stores.appendTo('div#storesContainer');
2020-05-28 19:10:09 -04:00
stores.animate({ opacity: 1 }, 300, 'linear');
2015-02-11 18:55:27 -05:00
}
2020-05-28 19:10:09 -04:00
if (wNeedsAppend && weapons.children().length > 0) {
2015-02-11 18:55:27 -05:00
weapons.appendTo('div#storesContainer');
2020-05-28 19:10:09 -04:00
weapons.animate({ opacity: 1 }, 300, 'linear');
2015-02-11 18:55:27 -05:00
}
2020-05-28 19:10:09 -04:00
if (newRow) {
2015-02-11 18:55:27 -05:00
Room.updateIncomeView();
}
2020-05-28 19:10:09 -04:00
if ($("div#outsidePanel").length) {
2015-02-11 18:55:27 -05:00
Outside.updateVillage();
}
2015-05-06 20:44:53 +02:00
2020-05-28 19:10:09 -04:00
if ($SM.get('stores.compass') && !Room.pathDiscovery) {
2015-05-06 20:44:53 +02:00
Room.pathDiscovery = true;
Path.openPath();
}
2015-02-11 18:55:27 -05:00
},
2020-05-28 19:10:09 -04:00
updateIncomeView: function () {
2015-05-06 20:44:53 +02:00
var stores = $('div#resources');
2015-07-29 16:57:26 +02:00
var totalIncome = {};
2020-05-28 19:10:09 -04:00
if (stores.length === 0 || typeof $SM.get('income') == 'undefined') return;
$('div.storeRow', stores).each(function (index, el) {
2015-02-11 18:55:27 -05:00
el = $(el);
$('div.tooltip', el).remove();
var ttPos = index > 10 ? 'top right' : 'bottom right';
var tt = $('<div>').addClass('tooltip ' + ttPos);
2015-02-11 18:55:27 -05:00
var storeName = el.attr('id').substring(4).replace('-', ' ');
2020-05-28 19:10:09 -04:00
for (var incomeSource in $SM.get('income')) {
var income = $SM.get('income["' + incomeSource + '"]');
for (var store in income.stores) {
if (store == storeName && income.stores[store] !== 0) {
2015-02-11 18:55:27 -05:00
$('<div>').addClass('row_key').text(_(incomeSource)).appendTo(tt);
$('<div>')
.addClass('row_val')
.text(Engine.getIncomeMsg(income.stores[store], income.delay))
.appendTo(tt);
2015-08-02 11:40:27 -04:00
if (!totalIncome[store] || totalIncome[store].income === undefined) {
totalIncome[store] = { income: 0 };
2015-07-29 20:08:09 +02:00
}
2015-08-02 11:40:27 -04:00
totalIncome[store].income += Number(income.stores[store]);
totalIncome[store].delay = income.delay;
2015-02-11 18:55:27 -05:00
}
}
}
2020-05-28 19:10:09 -04:00
if (tt.children().length > 0) {
2015-08-02 11:40:27 -04:00
var total = totalIncome[storeName].income;
2015-07-29 16:57:26 +02:00
$('<div>').addClass('total row_key').text(_('total')).appendTo(tt);
2015-08-02 11:40:27 -04:00
$('<div>').addClass('total row_val').text(Engine.getIncomeMsg(total, totalIncome[storeName].delay)).appendTo(tt);
2015-02-11 18:55:27 -05:00
tt.appendTo(el);
}
});
},
2020-05-28 19:10:09 -04:00
buy: function (buyBtn) {
2015-02-11 18:55:27 -05:00
var thing = $(buyBtn).attr('buildThing');
var good = Room.TradeGoods[thing];
2020-05-28 19:10:09 -04:00
var numThings = $SM.get('stores["' + thing + '"]', true);
if (numThings < 0) numThings = 0;
if (good.maximum <= numThings) {
2015-02-11 18:55:27 -05:00
return;
}
2020-05-28 19:10:09 -04:00
2015-02-11 18:55:27 -05:00
var storeMod = {};
var cost = good.cost();
2020-05-28 19:10:09 -04:00
for (var k in cost) {
var have = $SM.get('stores["' + k + '"]', true);
if (have < cost[k]) {
2015-02-11 18:55:27 -05:00
Notifications.notify(Room, _("not enough " + k));
return false;
} else {
storeMod[k] = have - cost[k];
}
}
$SM.setM('stores', storeMod);
2020-05-28 19:10:09 -04:00
2015-02-11 18:55:27 -05:00
Notifications.notify(Room, good.buildMsg);
2020-05-28 19:10:09 -04:00
$SM.add('stores["' + thing + '"]', 1);
// audio
AudioEngine.playSound(AudioLibrary.BUY);
2015-02-11 18:55:27 -05:00
},
2020-05-28 19:10:09 -04:00
build: function (buildBtn) {
2015-02-11 18:55:27 -05:00
var thing = $(buildBtn).attr('buildThing');
2020-05-28 19:10:09 -04:00
if ($SM.get('game.temperature.value') <= Room.TempEnum.Cold.value) {
2015-02-11 18:55:27 -05:00
Notifications.notify(Room, _("builder just shivers"));
return false;
}
var craftable = Room.Craftables[thing];
2020-05-28 19:10:09 -04:00
var numThings = 0;
switch (craftable.type) {
case 'good':
case 'weapon':
case 'tool':
case 'upgrade':
numThings = $SM.get('stores["' + thing + '"]', true);
break;
case 'building':
numThings = $SM.get('game.buildings["' + thing + '"]', true);
break;
2015-02-11 18:55:27 -05:00
}
2020-05-28 19:10:09 -04:00
if (numThings < 0) numThings = 0;
if (craftable.maximum <= numThings) {
2015-02-11 18:55:27 -05:00
return;
}
2020-05-28 19:10:09 -04:00
2015-02-11 18:55:27 -05:00
var storeMod = {};
var cost = craftable.cost();
2020-05-28 19:10:09 -04:00
for (var k in cost) {
var have = $SM.get('stores["' + k + '"]', true);
if (have < cost[k]) {
Notifications.notify(Room, _("not enough " + k));
2015-02-11 18:55:27 -05:00
return false;
} else {
storeMod[k] = have - cost[k];
}
}
$SM.setM('stores', storeMod);
2020-05-28 19:10:09 -04:00
2015-02-11 18:55:27 -05:00
Notifications.notify(Room, craftable.buildMsg);
2020-05-28 19:10:09 -04:00
switch (craftable.type) {
case 'good':
case 'weapon':
case 'upgrade':
case 'tool':
$SM.add('stores["' + thing + '"]', 1);
break;
case 'building':
$SM.add('game.buildings["' + thing + '"]', 1);
break;
}
// audio
switch (craftable.type) {
case 'weapon':
case 'upgrade':
case 'tool':
AudioEngine.playSound(AudioLibrary.CRAFT);
break;
case 'building':
AudioEngine.playSound(AudioLibrary.BUILD);
break;
}
2015-02-11 18:55:27 -05:00
},
2020-05-28 19:10:09 -04:00
needsWorkshop: function (type) {
return type == 'weapon' || type == 'upgrade' || type == 'tool';
2015-02-11 18:55:27 -05:00
},
2020-05-28 19:10:09 -04:00
craftUnlocked: function (thing) {
if (Room.buttons[thing]) {
2015-02-11 18:55:27 -05:00
return true;
}
2020-05-28 19:10:09 -04:00
if ($SM.get('game.builder.level') < 4) return false;
2015-02-11 18:55:27 -05:00
var craftable = Room.Craftables[thing];
2020-05-28 19:10:09 -04:00
if (Room.needsWorkshop(craftable.type) && $SM.get('game.buildings["' + 'workshop' + '"]', true) === 0) return false;
2015-02-11 18:55:27 -05:00
var cost = craftable.cost();
2020-05-28 19:10:09 -04:00
2015-02-11 18:55:27 -05:00
//show button if one has already been built
2020-05-28 19:10:09 -04:00
if ($SM.get('game.buildings["' + thing + '"]') > 0) {
2015-02-11 18:55:27 -05:00
Room.buttons[thing] = true;
return true;
}
// Show buttons if we have at least 1/2 the wood, and all other components have been seen.
2020-05-28 19:10:09 -04:00
if ($SM.get('stores.wood', true) < cost['wood'] * 0.5) {
2015-02-11 18:55:27 -05:00
return false;
}
2020-05-28 19:10:09 -04:00
for (var c in cost) {
if (!$SM.get('stores["' + c + '"]')) {
2015-02-11 18:55:27 -05:00
return false;
}
}
2020-05-28 19:10:09 -04:00
2015-02-11 18:55:27 -05:00
Room.buttons[thing] = true;
//don't notify if it has already been built before
2020-05-28 19:10:09 -04:00
if (!$SM.get('game.buildings["' + thing + '"]')) {
2015-02-11 18:55:27 -05:00
Notifications.notify(Room, craftable.availableMsg);
}
return true;
},
2020-05-28 19:10:09 -04:00
buyUnlocked: function (thing) {
if (Room.buttons[thing]) {
2015-02-11 18:55:27 -05:00
return true;
2020-05-28 19:10:09 -04:00
} else if ($SM.get('game.buildings["trading post"]', true) > 0) {
if (thing == 'compass' || typeof $SM.get('stores["' + thing + '"]') != 'undefined') {
2015-02-11 18:55:27 -05:00
// Allow the purchase of stuff once you've seen it
return true;
}
}
return false;
},
2020-05-28 19:10:09 -04:00
updateBuildButtons: function () {
2015-02-11 18:55:27 -05:00
var buildSection = $('#buildBtns');
var needsAppend = false;
2020-05-28 19:10:09 -04:00
if (buildSection.length === 0) {
buildSection = $('<div>').attr({ 'id': 'buildBtns', 'data-legend': _('build:') }).css('opacity', 0);
2015-02-11 18:55:27 -05:00
needsAppend = true;
}
2020-05-28 19:10:09 -04:00
2015-02-11 18:55:27 -05:00
var craftSection = $('#craftBtns');
var cNeedsAppend = false;
2020-05-28 19:10:09 -04:00
if (craftSection.length === 0 && $SM.get('game.buildings["workshop"]', true) > 0) {
craftSection = $('<div>').attr({ 'id': 'craftBtns', 'data-legend': _('craft:') }).css('opacity', 0);
2015-02-11 18:55:27 -05:00
cNeedsAppend = true;
}
2020-05-28 19:10:09 -04:00
2015-02-11 18:55:27 -05:00
var buySection = $('#buyBtns');
var bNeedsAppend = false;
2020-05-28 19:10:09 -04:00
if (buySection.length === 0 && $SM.get('game.buildings["trading post"]', true) > 0) {
buySection = $('<div>').attr({ 'id': 'buyBtns', 'data-legend': _('buy:') }).css('opacity', 0);
2015-02-11 18:55:27 -05:00
bNeedsAppend = true;
}
2020-05-28 19:10:09 -04:00
for (var k in Room.Craftables) {
2015-02-11 18:55:27 -05:00
craftable = Room.Craftables[k];
var max = $SM.num(k, craftable) + 1 > craftable.maximum;
2020-05-28 19:10:09 -04:00
if (craftable.button == null) {
if (Room.craftUnlocked(k)) {
2015-02-11 18:55:27 -05:00
var loc = Room.needsWorkshop(craftable.type) ? craftSection : buildSection;
craftable.button = new Button.Button({
2023-06-09 12:38:16 -04:00
id: 'build_' + k.replace(/ /g, '-'),
2015-02-11 18:55:27 -05:00
cost: craftable.cost(),
text: _(k),
click: Room.build,
width: '80px',
ttPos: loc.children().length > 10 ? 'top right' : 'bottom right'
2020-05-28 19:10:09 -04:00
}).css('opacity', 0).attr('buildThing', k).appendTo(loc).animate({ opacity: 1 }, 300, 'linear');
2015-02-11 18:55:27 -05:00
}
} else {
// refresh the tooltip
var costTooltip = $('.tooltip', craftable.button);
costTooltip.empty();
var cost = craftable.cost();
2020-05-28 19:10:09 -04:00
for (var c in cost) {
2016-10-02 17:52:39 -03:00
$("<div>").addClass('row_key').text(_(c)).appendTo(costTooltip);
$("<div>").addClass('row_val').text(cost[c]).appendTo(costTooltip);
2015-02-11 18:55:27 -05:00
}
2020-05-28 19:10:09 -04:00
if (max && !craftable.button.hasClass('disabled')) {
2015-02-11 18:55:27 -05:00
Notifications.notify(Room, craftable.maxMsg);
}
}
2020-05-28 19:10:09 -04:00
if (max) {
2015-02-11 18:55:27 -05:00
Button.setDisabled(craftable.button, true);
} else {
Button.setDisabled(craftable.button, false);
}
}
2020-05-28 19:10:09 -04:00
for (var g in Room.TradeGoods) {
2016-10-02 17:52:39 -03:00
good = Room.TradeGoods[g];
var goodsMax = $SM.num(g, good) + 1 > good.maximum;
2020-05-28 19:10:09 -04:00
if (good.button == null) {
if (Room.buyUnlocked(g)) {
2015-02-11 18:55:27 -05:00
good.button = new Button.Button({
2016-10-02 17:52:39 -03:00
id: 'build_' + g,
2015-02-11 18:55:27 -05:00
cost: good.cost(),
2016-10-02 17:52:39 -03:00
text: _(g),
2015-02-11 18:55:27 -05:00
click: Room.buy,
width: '80px',
ttPos: buySection.children().length > 10 ? 'top right' : 'bottom right'
2020-05-28 19:10:09 -04:00
}).css('opacity', 0).attr('buildThing', g).appendTo(buySection).animate({ opacity: 1 }, 300, 'linear');
2015-02-11 18:55:27 -05:00
}
} else {
// refresh the tooltip
2016-10-02 17:52:39 -03:00
var goodsCostTooltip = $('.tooltip', good.button);
goodsCostTooltip.empty();
var goodCost = good.cost();
2020-05-28 19:10:09 -04:00
for (var gc in goodCost) {
2016-10-02 17:52:39 -03:00
$("<div>").addClass('row_key').text(_(gc)).appendTo(goodsCostTooltip);
$("<div>").addClass('row_val').text(goodCost[gc]).appendTo(goodsCostTooltip);
2015-02-11 18:55:27 -05:00
}
2020-05-28 19:10:09 -04:00
if (goodsMax && !good.button.hasClass('disabled')) {
2015-02-11 18:55:27 -05:00
Notifications.notify(Room, good.maxMsg);
}
}
2020-05-28 19:10:09 -04:00
if (goodsMax) {
2015-02-11 18:55:27 -05:00
Button.setDisabled(good.button, true);
} else {
Button.setDisabled(good.button, false);
}
}
2020-05-28 19:10:09 -04:00
if (needsAppend && buildSection.children().length > 0) {
buildSection.appendTo('div#roomPanel').animate({ opacity: 1 }, 300, 'linear');
2015-02-11 18:55:27 -05:00
}
2020-05-28 19:10:09 -04:00
if (cNeedsAppend && craftSection.children().length > 0) {
craftSection.appendTo('div#roomPanel').animate({ opacity: 1 }, 300, 'linear');
2015-02-11 18:55:27 -05:00
}
2020-05-28 19:10:09 -04:00
if (bNeedsAppend && buildSection.children().length > 0) {
buySection.appendTo('div#roomPanel').animate({ opacity: 1 }, 300, 'linear');
2015-02-11 18:55:27 -05:00
}
},
2020-05-28 19:10:09 -04:00
compassTooltip: function (direction) {
var ttPos = $('div#resources').children().length > 10 ? 'top right' : 'bottom right';
var tt = $('<div>').addClass('tooltip ' + ttPos);
2020-05-28 19:10:09 -04:00
$('<div>').addClass('row_key').text(_('the compass points ' + direction)).appendTo(tt);
2015-05-06 20:44:53 +02:00
tt.appendTo($('#row_compass'));
},
2020-05-28 19:10:09 -04:00
handleStateUpdates: function (e) {
if (e.category == 'stores') {
2015-02-11 18:55:27 -05:00
Room.updateStoresView();
Room.updateBuildButtons();
2020-05-28 19:10:09 -04:00
} else if (e.category == 'income') {
2015-02-11 18:55:27 -05:00
Room.updateStoresView();
Room.updateIncomeView();
2020-05-28 19:10:09 -04:00
} else if (e.stateName.indexOf('game.buildings') === 0) {
2015-02-11 18:55:27 -05:00
Room.updateBuildButtons();
}
2020-05-28 19:10:09 -04:00
},
setMusic() {
// set music based on fire level
var fireValue = $SM.get('game.fire.value');
switch (fireValue) {
case 0:
AudioEngine.playBackgroundMusic(AudioLibrary.MUSIC_FIRE_DEAD);
break;
case 1:
AudioEngine.playBackgroundMusic(AudioLibrary.MUSIC_FIRE_SMOLDERING);
break;
case 2:
AudioEngine.playBackgroundMusic(AudioLibrary.MUSIC_FIRE_FLICKERING);
break;
case 3:
AudioEngine.playBackgroundMusic(AudioLibrary.MUSIC_FIRE_BURNING);
break;
case 4:
AudioEngine.playBackgroundMusic(AudioLibrary.MUSIC_FIRE_ROARING);
break;
}
2015-02-11 18:55:27 -05:00
}
};