mirror of
https://github.com/doublespeakgames/adarkroom.git
synced 2026-05-28 08:11:54 +08:00
Hyper-proof cooldown state
Kept the distinction between "argument" time and script time. I called the latter "time" instead of "milliseconds" because, well, it's just tenth of seconds. Residual timeout is always stored in "nominal" time, not adjusted by hyper. I.e. if a button has a nominal timeout of 60 seconds and half cooldown had expired on reload, residual is stored as 300. In cooldown, Engine.setInterval makes the time flow with double speed
This commit is contained in:
committed by
Blake Grotewold
parent
a923c1c0bd
commit
65d7cfd784
+46
-13
@@ -24,6 +24,9 @@ var Button = {
|
|||||||
|
|
||||||
el.append($("<div>").addClass('cooldown'));
|
el.append($("<div>").addClass('cooldown'));
|
||||||
|
|
||||||
|
// waiting for expiry of residual cooldown detected in state
|
||||||
|
Button.cooldown(el, 'state');
|
||||||
|
|
||||||
if(options.cost) {
|
if(options.cost) {
|
||||||
var ttPos = options.ttPos ? options.ttPos : "bottom right";
|
var ttPos = options.ttPos ? options.ttPos : "bottom right";
|
||||||
var costTooltip = $('<div>').addClass('tooltip ' + ttPos);
|
var costTooltip = $('<div>').addClass('tooltip ' + ttPos);
|
||||||
@@ -43,6 +46,8 @@ var Button = {
|
|||||||
return el;
|
return el;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
saveCooldown: true,
|
||||||
|
|
||||||
setDisabled: function(btn, disabled) {
|
setDisabled: function(btn, disabled) {
|
||||||
if(btn) {
|
if(btn) {
|
||||||
if(!disabled && !btn.data('onCooldown')) {
|
if(!disabled && !btn.data('onCooldown')) {
|
||||||
@@ -61,29 +66,57 @@ var Button = {
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
cooldown: function(btn) {
|
cooldown: function(btn, option) {
|
||||||
var cd = btn.data("cooldown");
|
var cd = btn.data("cooldown");
|
||||||
|
var id = 'cooldown.'+ btn.attr('id');
|
||||||
if(cd > 0) {
|
if(cd > 0) {
|
||||||
milliseconds = cd * 1000;
|
// param "start" takes value from cooldown time if not specified
|
||||||
if (Engine.options.doubleTime){
|
var start, left;
|
||||||
milliseconds /= 2;
|
switch(option){
|
||||||
|
// a switch will allow for several uses of cooldown function
|
||||||
|
case 'state':
|
||||||
|
if(!$SM.get(id)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
start = Math.min($SM.get(id), cd);
|
||||||
|
left = (start / cd).toFixed(4);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
start = cd;
|
||||||
|
left = 1;
|
||||||
}
|
}
|
||||||
|
Button.clearCooldown(btn);
|
||||||
$('div.cooldown', btn).stop(true, true).width("100%").animate({width: '0%'}, milliseconds, 'linear', function() {
|
if(Button.saveCooldown){
|
||||||
var b = $(this).closest('.button');
|
$SM.set(id,start);
|
||||||
b.data('onCooldown', false);
|
// residual value is measured in seconds
|
||||||
if(!b.data('disabled')) {
|
// saves program performance
|
||||||
b.removeClass('disabled');
|
btn.data('countdown', Engine.setInterval(function(){
|
||||||
}
|
$SM.set(id, $SM.get(id, true) - 0.5, true);
|
||||||
|
},500));
|
||||||
|
}
|
||||||
|
var time = start;
|
||||||
|
if (Engine.options.doubleTime){
|
||||||
|
time /= 2;
|
||||||
|
}
|
||||||
|
$('div.cooldown', btn).width(left * 100 +"%").animate({width: '0%'}, time * 1000, 'linear', function() {
|
||||||
|
Button.clearCooldown(btn, true);
|
||||||
});
|
});
|
||||||
btn.addClass('disabled');
|
btn.addClass('disabled');
|
||||||
btn.data('onCooldown', true);
|
btn.data('onCooldown', true);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
clearCooldown: function(btn) {
|
clearCooldown: function(btn, ended) {
|
||||||
$('div.cooldown', btn).stop(true, true);
|
var ended = ended || false;
|
||||||
|
if(!ended){
|
||||||
|
$('div.cooldown', btn).stop(true, true);
|
||||||
|
}
|
||||||
btn.data('onCooldown', false);
|
btn.data('onCooldown', false);
|
||||||
|
if(btn.data('countdown')){
|
||||||
|
window.clearInterval(btn.data('countdown'));
|
||||||
|
$SM.remove('cooldown.'+ btn.attr('id'));
|
||||||
|
btn.removeData('countdown');
|
||||||
|
}
|
||||||
if(!btn.data('disabled')) {
|
if(!btn.data('disabled')) {
|
||||||
btn.removeClass('disabled');
|
btn.removeClass('disabled');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -955,6 +955,7 @@ var Events = {
|
|||||||
Engine.event('game event', 'event');
|
Engine.event('game event', 'event');
|
||||||
Engine.keyLock = true;
|
Engine.keyLock = true;
|
||||||
Engine.tabNavigation = false;
|
Engine.tabNavigation = false;
|
||||||
|
Button.saveCooldown = false;
|
||||||
Events.eventStack.unshift(event);
|
Events.eventStack.unshift(event);
|
||||||
event.eventPanel = $('<div>').attr('id', 'event').addClass('eventPanel').css('opacity', '0');
|
event.eventPanel = $('<div>').attr('id', 'event').addClass('eventPanel').css('opacity', '0');
|
||||||
if(options != null && options.width != null) {
|
if(options != null && options.width != null) {
|
||||||
@@ -988,6 +989,7 @@ var Events = {
|
|||||||
Engine.log(Events.eventStack.length + ' events remaining');
|
Engine.log(Events.eventStack.length + ' events remaining');
|
||||||
Engine.keyLock = false;
|
Engine.keyLock = false;
|
||||||
Engine.tabNavigation = true;
|
Engine.tabNavigation = true;
|
||||||
|
Button.saveCooldown = true;
|
||||||
if (Events.BLINK_INTERVAL) {
|
if (Events.BLINK_INTERVAL) {
|
||||||
Events.stopTitleBlink();
|
Events.stopTitleBlink();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -171,6 +171,8 @@ var Outside = {
|
|||||||
cooldown: Outside._GATHER_DELAY,
|
cooldown: Outside._GATHER_DELAY,
|
||||||
width: '80px'
|
width: '80px'
|
||||||
}).appendTo('div#outsidePanel');
|
}).appendTo('div#outsidePanel');
|
||||||
|
|
||||||
|
Outside.updateTrapButton();
|
||||||
},
|
},
|
||||||
|
|
||||||
getMaxPopulation: function() {
|
getMaxPopulation: function() {
|
||||||
|
|||||||
@@ -28,17 +28,18 @@ var StateManager = {
|
|||||||
|
|
||||||
//create categories
|
//create categories
|
||||||
var cats = [
|
var cats = [
|
||||||
'features', //big features like buildings, location availability, unlocks, etc
|
'features', // big features like buildings, location availability, unlocks, etc
|
||||||
'stores', //little stuff, items, weapons, etc
|
'stores', // little stuff, items, weapons, etc
|
||||||
'character', //this is for player's character stats such as perks
|
'character', // this is for player's character stats such as perks
|
||||||
'income',
|
'income',
|
||||||
'timers',
|
'timers',
|
||||||
'game', //mostly location related: fire temp, workers, population, world map, etc
|
'game', // mostly location related: fire temp, workers, population, world map, etc
|
||||||
'playStats', //anything play related: play time, loads, etc
|
'playStats', // anything play related: play time, loads, etc
|
||||||
'previous', // prestige, score, trophies (in future), achievements (again, not yet), etc
|
'previous', // prestige, score, trophies (in future), achievements (again, not yet), etc
|
||||||
'outfit', // used to temporarily store the items to be taken on the path
|
'outfit', // used to temporarily store the items to be taken on the path
|
||||||
'config',
|
'config',
|
||||||
'wait' // mysterious wanderers are coming back
|
'wait', // mysterious wanderers are coming back
|
||||||
|
'cooldown' // residual values for cooldown buttons
|
||||||
];
|
];
|
||||||
|
|
||||||
for(var which in cats) {
|
for(var which in cats) {
|
||||||
|
|||||||
+86
-86
@@ -1,5 +1,5 @@
|
|||||||
var World = {
|
var World = {
|
||||||
|
|
||||||
RADIUS: 30,
|
RADIUS: 30,
|
||||||
VILLAGE_POS: [30, 30],
|
VILLAGE_POS: [30, 30],
|
||||||
TILE: {
|
TILE: {
|
||||||
@@ -101,7 +101,7 @@ var World = {
|
|||||||
cost: { 'bolas': 1 }
|
cost: { 'bolas': 1 }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
name: 'World',
|
name: 'World',
|
||||||
options: {}, // Nothing for now
|
options: {}, // Nothing for now
|
||||||
init: function(options) {
|
init: function(options) {
|
||||||
@@ -109,12 +109,12 @@ var World = {
|
|||||||
this.options,
|
this.options,
|
||||||
options
|
options
|
||||||
);
|
);
|
||||||
|
|
||||||
// Setup probabilities. Sum must equal 1.
|
// Setup probabilities. Sum must equal 1.
|
||||||
World.TILE_PROBS[World.TILE.FOREST] = 0.15;
|
World.TILE_PROBS[World.TILE.FOREST] = 0.15;
|
||||||
World.TILE_PROBS[World.TILE.FIELD] = 0.35;
|
World.TILE_PROBS[World.TILE.FIELD] = 0.35;
|
||||||
World.TILE_PROBS[World.TILE.BARRENS] = 0.5;
|
World.TILE_PROBS[World.TILE.BARRENS] = 0.5;
|
||||||
|
|
||||||
// Setpiece definitions
|
// Setpiece definitions
|
||||||
World.LANDMARKS[World.TILE.OUTPOST] = { num: 0, minRadius: 0, maxRadius: 0, scene: 'outpost', label: _('An Outpost') };
|
World.LANDMARKS[World.TILE.OUTPOST] = { num: 0, minRadius: 0, maxRadius: 0, scene: 'outpost', label: _('An Outpost') };
|
||||||
World.LANDMARKS[World.TILE.IRON_MINE] = { num: 1, minRadius: 5, maxRadius: 5, scene: 'ironmine', label: _('Iron Mine') };
|
World.LANDMARKS[World.TILE.IRON_MINE] = { num: 1, minRadius: 5, maxRadius: 5, scene: 'ironmine', label: _('Iron Mine') };
|
||||||
@@ -128,12 +128,12 @@ var World = {
|
|||||||
World.LANDMARKS[World.TILE.BOREHOLE] = { num: 10, minRadius: 15, maxRadius: World.RADIUS * 1.5, scene: 'borehole', label: _('A Borehole')};
|
World.LANDMARKS[World.TILE.BOREHOLE] = { num: 10, minRadius: 15, maxRadius: World.RADIUS * 1.5, scene: 'borehole', label: _('A Borehole')};
|
||||||
World.LANDMARKS[World.TILE.BATTLEFIELD] = { num: 5, minRadius: 18, maxRadius: World.RADIUS * 1.5, scene: 'battlefield', label: _('A Battlefield')};
|
World.LANDMARKS[World.TILE.BATTLEFIELD] = { num: 5, minRadius: 18, maxRadius: World.RADIUS * 1.5, scene: 'battlefield', label: _('A Battlefield')};
|
||||||
World.LANDMARKS[World.TILE.SWAMP] = { num: 1, minRadius: 15, maxRadius: World.RADIUS * 1.5, scene: 'swamp', label: _('A Murky Swamp')};
|
World.LANDMARKS[World.TILE.SWAMP] = { num: 1, minRadius: 15, maxRadius: World.RADIUS * 1.5, scene: 'swamp', label: _('A Murky Swamp')};
|
||||||
|
|
||||||
// Only add the cache if there is prestige data
|
// Only add the cache if there is prestige data
|
||||||
if($SM.get('previous.stores')) {
|
if($SM.get('previous.stores')) {
|
||||||
World.LANDMARKS[World.TILE.CACHE] = { num: 1, minRadius: 10, maxRadius: World.RADIUS * 1.5, scene: 'cache', label: _('A Destroyed Village')};
|
World.LANDMARKS[World.TILE.CACHE] = { num: 1, minRadius: 10, maxRadius: World.RADIUS * 1.5, scene: 'cache', label: _('A Destroyed Village')};
|
||||||
}
|
}
|
||||||
|
|
||||||
if(typeof $SM.get('features.location.world') == 'undefined') {
|
if(typeof $SM.get('features.location.world') == 'undefined') {
|
||||||
$SM.set('features.location.world', true);
|
$SM.set('features.location.world', true);
|
||||||
$SM.setM('game.world', {
|
$SM.setM('game.world', {
|
||||||
@@ -141,37 +141,37 @@ var World = {
|
|||||||
mask: World.newMask()
|
mask: World.newMask()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the World panel
|
// Create the World panel
|
||||||
this.panel = $('<div>').attr('id', "worldPanel").addClass('location').appendTo('#outerSlider');
|
this.panel = $('<div>').attr('id', "worldPanel").addClass('location').appendTo('#outerSlider');
|
||||||
|
|
||||||
// Create the shrink wrapper
|
// Create the shrink wrapper
|
||||||
var outer = $('<div>').attr('id', 'worldOuter').appendTo(this.panel);
|
var outer = $('<div>').attr('id', 'worldOuter').appendTo(this.panel);
|
||||||
|
|
||||||
// Create the bag panel
|
// Create the bag panel
|
||||||
$('<div>').attr('id', 'bagspace-world').append($('<div>')).appendTo(outer);
|
$('<div>').attr('id', 'bagspace-world').append($('<div>')).appendTo(outer);
|
||||||
$('<div>').attr('id', 'backpackTitle').appendTo(outer);
|
$('<div>').attr('id', 'backpackTitle').appendTo(outer);
|
||||||
$('<div>').attr('id', 'backpackSpace').appendTo(outer);
|
$('<div>').attr('id', 'backpackSpace').appendTo(outer);
|
||||||
$('<div>').attr('id', 'healthCounter').appendTo(outer);
|
$('<div>').attr('id', 'healthCounter').appendTo(outer);
|
||||||
|
|
||||||
Engine.updateOuterSlider();
|
Engine.updateOuterSlider();
|
||||||
|
|
||||||
// Map the ship and show compass tooltip
|
// Map the ship and show compass tooltip
|
||||||
World.ship = World.mapSearch(World.TILE.SHIP,$SM.get('game.world.map'),1);
|
World.ship = World.mapSearch(World.TILE.SHIP,$SM.get('game.world.map'),1);
|
||||||
World.dir = World.compassDir(World.ship[0]);
|
World.dir = World.compassDir(World.ship[0]);
|
||||||
// compass tooltip text
|
// compass tooltip text
|
||||||
Room.compassTooltip(World.dir);
|
Room.compassTooltip(World.dir);
|
||||||
|
|
||||||
//subscribe to stateUpdates
|
//subscribe to stateUpdates
|
||||||
$.Dispatch('stateUpdate').subscribe(World.handleStateUpdates);
|
$.Dispatch('stateUpdate').subscribe(World.handleStateUpdates);
|
||||||
},
|
},
|
||||||
|
|
||||||
clearDungeon: function() {
|
clearDungeon: function() {
|
||||||
Engine.event('progress', 'dungeon cleared');
|
Engine.event('progress', 'dungeon cleared');
|
||||||
World.state.map[World.curPos[0]][World.curPos[1]] = World.TILE.OUTPOST;
|
World.state.map[World.curPos[0]][World.curPos[1]] = World.TILE.OUTPOST;
|
||||||
World.drawRoad();
|
World.drawRoad();
|
||||||
},
|
},
|
||||||
|
|
||||||
drawRoad: function() {
|
drawRoad: function() {
|
||||||
var findClosestRoad = function(startPos) {
|
var findClosestRoad = function(startPos) {
|
||||||
// We'll search in a spiral to find the closest road tile
|
// We'll search in a spiral to find the closest road tile
|
||||||
@@ -226,7 +226,7 @@ var World = {
|
|||||||
xIntersect = closestRoad[0] + xDist;
|
xIntersect = closestRoad[0] + xDist;
|
||||||
yIntersect = closestRoad[1];
|
yIntersect = closestRoad[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
for(var x = 0; x < Math.abs(xDist); x++) {
|
for(var x = 0; x < Math.abs(xDist); x++) {
|
||||||
if(World.isTerrain(World.state.map[closestRoad[0] + (xDir*x)][yIntersect])) {
|
if(World.isTerrain(World.state.map[closestRoad[0] + (xDir*x)][yIntersect])) {
|
||||||
World.state.map[closestRoad[0] + (xDir*x)][yIntersect] = World.TILE.ROAD;
|
World.state.map[closestRoad[0] + (xDir*x)][yIntersect] = World.TILE.ROAD;
|
||||||
@@ -239,14 +239,14 @@ var World = {
|
|||||||
}
|
}
|
||||||
World.drawMap();
|
World.drawMap();
|
||||||
},
|
},
|
||||||
|
|
||||||
updateSupplies: function() {
|
updateSupplies: function() {
|
||||||
var supplies = $('div#bagspace-world > div');
|
var supplies = $('div#bagspace-world > div');
|
||||||
|
|
||||||
if(!Path.outfit) {
|
if(!Path.outfit) {
|
||||||
Path.outfit = {};
|
Path.outfit = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add water
|
// Add water
|
||||||
var water = $('div#supply_water');
|
var water = $('div#supply_water');
|
||||||
if(World.water > 0 && water.length === 0) {
|
if(World.water > 0 && water.length === 0) {
|
||||||
@@ -257,7 +257,7 @@ var World = {
|
|||||||
} else {
|
} else {
|
||||||
water.remove();
|
water.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
var total = 0;
|
var total = 0;
|
||||||
for(var k in Path.outfit) {
|
for(var k in Path.outfit) {
|
||||||
var item = $('div#supply_' + k.replace(' ', '-'), supplies);
|
var item = $('div#supply_' + k.replace(' ', '-'), supplies);
|
||||||
@@ -278,18 +278,18 @@ var World = {
|
|||||||
item.remove();
|
item.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update label
|
// Update label
|
||||||
var t = _('pockets');
|
var t = _('pockets');
|
||||||
if($SM.get('stores.rucksack', true) > 0) {
|
if($SM.get('stores.rucksack', true) > 0) {
|
||||||
t = _('rucksack');
|
t = _('rucksack');
|
||||||
}
|
}
|
||||||
$('#backpackTitle').text(t);
|
$('#backpackTitle').text(t);
|
||||||
|
|
||||||
// Update bagspace
|
// Update bagspace
|
||||||
$('#backpackSpace').text(_('free {0}/{1}', Math.floor(Path.getCapacity() - total) , Path.getCapacity()));
|
$('#backpackSpace').text(_('free {0}/{1}', Math.floor(Path.getCapacity() - total) , Path.getCapacity()));
|
||||||
},
|
},
|
||||||
|
|
||||||
setWater: function(w) {
|
setWater: function(w) {
|
||||||
World.water = w;
|
World.water = w;
|
||||||
if(World.water > World.getMaxWater()) {
|
if(World.water > World.getMaxWater()) {
|
||||||
@@ -297,7 +297,7 @@ var World = {
|
|||||||
}
|
}
|
||||||
World.updateSupplies();
|
World.updateSupplies();
|
||||||
},
|
},
|
||||||
|
|
||||||
setHp: function(hp) {
|
setHp: function(hp) {
|
||||||
if(typeof hp == 'number' && !isNaN(hp)) {
|
if(typeof hp == 'number' && !isNaN(hp)) {
|
||||||
World.health = hp;
|
World.health = hp;
|
||||||
@@ -307,35 +307,35 @@ var World = {
|
|||||||
$('#healthCounter').text(_('hp: {0}/{1}', World.health , World.getMaxHealth()));
|
$('#healthCounter').text(_('hp: {0}/{1}', World.health , World.getMaxHealth()));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
createItemDiv: function(name, num) {
|
createItemDiv: function(name, num) {
|
||||||
var div = $('<div>').attr('id', 'supply_' + name.replace(' ', '-'))
|
var div = $('<div>').attr('id', 'supply_' + name.replace(' ', '-'))
|
||||||
.addClass('supplyItem')
|
.addClass('supplyItem')
|
||||||
.text(_('{0}:{1}',_(name), num));
|
.text(_('{0}:{1}',_(name), num));
|
||||||
|
|
||||||
return div;
|
return div;
|
||||||
},
|
},
|
||||||
|
|
||||||
moveNorth: function() {
|
moveNorth: function() {
|
||||||
Engine.log('North');
|
Engine.log('North');
|
||||||
if(World.curPos[1] > 0) World.move(World.NORTH);
|
if(World.curPos[1] > 0) World.move(World.NORTH);
|
||||||
},
|
},
|
||||||
|
|
||||||
moveSouth: function() {
|
moveSouth: function() {
|
||||||
Engine.log('South');
|
Engine.log('South');
|
||||||
if(World.curPos[1] < World.RADIUS * 2) World.move(World.SOUTH);
|
if(World.curPos[1] < World.RADIUS * 2) World.move(World.SOUTH);
|
||||||
},
|
},
|
||||||
|
|
||||||
moveWest: function() {
|
moveWest: function() {
|
||||||
Engine.log('West');
|
Engine.log('West');
|
||||||
if(World.curPos[0] > 0) World.move(World.WEST);
|
if(World.curPos[0] > 0) World.move(World.WEST);
|
||||||
},
|
},
|
||||||
|
|
||||||
moveEast: function() {
|
moveEast: function() {
|
||||||
Engine.log('East');
|
Engine.log('East');
|
||||||
if(World.curPos[0] < World.RADIUS * 2) World.move(World.EAST);
|
if(World.curPos[0] < World.RADIUS * 2) World.move(World.EAST);
|
||||||
},
|
},
|
||||||
|
|
||||||
move: function(direction) {
|
move: function(direction) {
|
||||||
var oldTile = World.state.map[World.curPos[0]][World.curPos[1]];
|
var oldTile = World.state.map[World.curPos[0]][World.curPos[1]];
|
||||||
World.curPos[0] += direction[0];
|
World.curPos[0] += direction[0];
|
||||||
@@ -352,7 +352,7 @@ var World = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
keyDown: function(event) {
|
keyDown: function(event) {
|
||||||
switch(event.which) {
|
switch(event.which) {
|
||||||
case 38: // Up
|
case 38: // Up
|
||||||
@@ -412,14 +412,14 @@ var World = {
|
|||||||
World.moveEast();
|
World.moveEast();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
checkDanger: function() {
|
checkDanger: function() {
|
||||||
World.danger = typeof World.danger == 'undefined' ? false: World.danger;
|
World.danger = typeof World.danger == 'undefined' ? false: World.danger;
|
||||||
if(!World.danger) {
|
if(!World.danger) {
|
||||||
if($SM.get('stores["i armour"]', true) === 0 && World.getDistance() >= 8) {
|
if($SM.get('stores["i armour"]', true) === 0 && World.getDistance() >= 8) {
|
||||||
World.danger = true;
|
World.danger = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if($SM.get('stores["s armour"]', true) === 0 && World.getDistance() >= 18) {
|
if($SM.get('stores["s armour"]', true) === 0 && World.getDistance() >= 18) {
|
||||||
World.danger = true;
|
World.danger = true;
|
||||||
return true;
|
return true;
|
||||||
@@ -436,7 +436,7 @@ var World = {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
useSupplies: function() {
|
useSupplies: function() {
|
||||||
World.foodMove++;
|
World.foodMove++;
|
||||||
World.waterMove++;
|
World.waterMove++;
|
||||||
@@ -501,15 +501,15 @@ var World = {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
meatHeal: function() {
|
meatHeal: function() {
|
||||||
return World.MEAT_HEAL * ($SM.hasPerk('gastronome') ? 2 : 1);
|
return World.MEAT_HEAL * ($SM.hasPerk('gastronome') ? 2 : 1);
|
||||||
},
|
},
|
||||||
|
|
||||||
medsHeal: function() {
|
medsHeal: function() {
|
||||||
return World.MEDS_HEAL;
|
return World.MEDS_HEAL;
|
||||||
},
|
},
|
||||||
|
|
||||||
checkFight: function() {
|
checkFight: function() {
|
||||||
World.fightMove = typeof World.fightMove == 'number' ? World.fightMove : 0;
|
World.fightMove = typeof World.fightMove == 'number' ? World.fightMove : 0;
|
||||||
World.fightMove++;
|
World.fightMove++;
|
||||||
@@ -522,7 +522,7 @@ var World = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
doSpace: function() {
|
doSpace: function() {
|
||||||
var curTile = World.state.map[World.curPos[0]][World.curPos[1]];
|
var curTile = World.state.map[World.curPos[0]][World.curPos[1]];
|
||||||
|
|
||||||
@@ -538,17 +538,17 @@ var World = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getDistance: function(from, to) {
|
getDistance: function(from, to) {
|
||||||
from = from || World.curPos;
|
from = from || World.curPos;
|
||||||
to = to || World.VILLAGE_POS;
|
to = to || World.VILLAGE_POS;
|
||||||
return Math.abs(from[0] - to[0]) + Math.abs(from[1] - to[1]);
|
return Math.abs(from[0] - to[0]) + Math.abs(from[1] - to[1]);
|
||||||
},
|
},
|
||||||
|
|
||||||
getTerrain: function() {
|
getTerrain: function() {
|
||||||
return World.state.map[World.curPos[0]][World.curPos[1]];
|
return World.state.map[World.curPos[0]][World.curPos[1]];
|
||||||
},
|
},
|
||||||
|
|
||||||
narrateMove: function(oldTile, newTile) {
|
narrateMove: function(oldTile, newTile) {
|
||||||
var msg = null;
|
var msg = null;
|
||||||
switch(oldTile) {
|
switch(oldTile) {
|
||||||
@@ -587,7 +587,7 @@ var World = {
|
|||||||
Notifications.notify(World, msg);
|
Notifications.notify(World, msg);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
newMask: function() {
|
newMask: function() {
|
||||||
var mask = new Array(World.RADIUS * 2 + 1);
|
var mask = new Array(World.RADIUS * 2 + 1);
|
||||||
for(var i = 0; i <= World.RADIUS * 2; i++) {
|
for(var i = 0; i <= World.RADIUS * 2; i++) {
|
||||||
@@ -596,33 +596,33 @@ var World = {
|
|||||||
World.lightMap(World.RADIUS, World.RADIUS, mask);
|
World.lightMap(World.RADIUS, World.RADIUS, mask);
|
||||||
return mask;
|
return mask;
|
||||||
},
|
},
|
||||||
|
|
||||||
lightMap: function(x, y, mask) {
|
lightMap: function(x, y, mask) {
|
||||||
var r = World.LIGHT_RADIUS;
|
var r = World.LIGHT_RADIUS;
|
||||||
r *= $SM.hasPerk('scout') ? 2 : 1;
|
r *= $SM.hasPerk('scout') ? 2 : 1;
|
||||||
World.uncoverMap(x, y, r, mask);
|
World.uncoverMap(x, y, r, mask);
|
||||||
return mask;
|
return mask;
|
||||||
},
|
},
|
||||||
|
|
||||||
uncoverMap: function(x, y, r, mask) {
|
uncoverMap: function(x, y, r, mask) {
|
||||||
mask[x][y] = true;
|
mask[x][y] = true;
|
||||||
for(var i = -r; i <= r; i++) {
|
for(var i = -r; i <= r; i++) {
|
||||||
for(var j = -r + Math.abs(i); j <= r - Math.abs(i); j++) {
|
for(var j = -r + Math.abs(i); j <= r - Math.abs(i); j++) {
|
||||||
if(y + j >= 0 && y + j <= World.RADIUS * 2 &&
|
if(y + j >= 0 && y + j <= World.RADIUS * 2 &&
|
||||||
x + i <= World.RADIUS * 2 &&
|
x + i <= World.RADIUS * 2 &&
|
||||||
x + i >= 0) {
|
x + i >= 0) {
|
||||||
mask[x+i][y+j] = true;
|
mask[x+i][y+j] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
applyMap: function() {
|
applyMap: function() {
|
||||||
var x = Math.floor(Math.random() * (World.RADIUS * 2) + 1);
|
var x = Math.floor(Math.random() * (World.RADIUS * 2) + 1);
|
||||||
var y = Math.floor(Math.random() * (World.RADIUS * 2) + 1);
|
var y = Math.floor(Math.random() * (World.RADIUS * 2) + 1);
|
||||||
World.uncoverMap(x, y, 5, $SM.get('game.world.mask'));
|
World.uncoverMap(x, y, 5, $SM.get('game.world.mask'));
|
||||||
},
|
},
|
||||||
|
|
||||||
generateMap: function() {
|
generateMap: function() {
|
||||||
var map = new Array(World.RADIUS * 2 + 1);
|
var map = new Array(World.RADIUS * 2 + 1);
|
||||||
for(var i = 0; i <= World.RADIUS * 2; i++) {
|
for(var i = 0; i <= World.RADIUS * 2; i++) {
|
||||||
@@ -647,11 +647,11 @@ var World = {
|
|||||||
x = World.RADIUS - r;
|
x = World.RADIUS - r;
|
||||||
y = World.RADIUS + (7 * r) - t;
|
y = World.RADIUS + (7 * r) - t;
|
||||||
}
|
}
|
||||||
|
|
||||||
map[x][y] = World.chooseTile(x, y, map);
|
map[x][y] = World.chooseTile(x, y, map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Place landmarks
|
// Place landmarks
|
||||||
for(var k in World.LANDMARKS) {
|
for(var k in World.LANDMARKS) {
|
||||||
var landmark = World.LANDMARKS[k];
|
var landmark = World.LANDMARKS[k];
|
||||||
@@ -659,10 +659,10 @@ var World = {
|
|||||||
var pos = World.placeLandmark(landmark.minRadius, landmark.maxRadius, k, map);
|
var pos = World.placeLandmark(landmark.minRadius, landmark.maxRadius, k, map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
},
|
},
|
||||||
|
|
||||||
mapSearch: function(target,map,required){
|
mapSearch: function(target,map,required){
|
||||||
var max = World.LANDMARKS[target].num;
|
var max = World.LANDMARKS[target].num;
|
||||||
if(!max){
|
if(!max){
|
||||||
@@ -681,7 +681,7 @@ var World = {
|
|||||||
// items are listed as they appear in the map, tl-br
|
// items are listed as they appear in the map, tl-br
|
||||||
// each item has relative coordinates and a compass-type direction
|
// each item has relative coordinates and a compass-type direction
|
||||||
targets[index] = {
|
targets[index] = {
|
||||||
x : i - World.RADIUS,
|
x : i - World.RADIUS,
|
||||||
y : j - World.RADIUS,
|
y : j - World.RADIUS,
|
||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
@@ -694,7 +694,7 @@ var World = {
|
|||||||
}
|
}
|
||||||
return targets;
|
return targets;
|
||||||
},
|
},
|
||||||
|
|
||||||
compassDir: function(pos){
|
compassDir: function(pos){
|
||||||
var dir = '';
|
var dir = '';
|
||||||
var horz = pos.x < 0 ? 'west' : 'east';
|
var horz = pos.x < 0 ? 'west' : 'east';
|
||||||
@@ -708,9 +708,9 @@ var World = {
|
|||||||
}
|
}
|
||||||
return dir;
|
return dir;
|
||||||
},
|
},
|
||||||
|
|
||||||
placeLandmark: function(minRadius, maxRadius, landmark, map) {
|
placeLandmark: function(minRadius, maxRadius, landmark, map) {
|
||||||
|
|
||||||
var x = World.RADIUS, y = World.RADIUS;
|
var x = World.RADIUS, y = World.RADIUS;
|
||||||
while(!World.isTerrain(map[x][y])) {
|
while(!World.isTerrain(map[x][y])) {
|
||||||
var r = Math.floor(Math.random() * (maxRadius - minRadius)) + minRadius;
|
var r = Math.floor(Math.random() * (maxRadius - minRadius)) + minRadius;
|
||||||
@@ -728,20 +728,20 @@ var World = {
|
|||||||
map[x][y] = landmark;
|
map[x][y] = landmark;
|
||||||
return [x, y];
|
return [x, y];
|
||||||
},
|
},
|
||||||
|
|
||||||
isTerrain: function(tile) {
|
isTerrain: function(tile) {
|
||||||
return tile == World.TILE.FOREST || tile == World.TILE.FIELD || tile == World.TILE.BARRENS;
|
return tile == World.TILE.FOREST || tile == World.TILE.FIELD || tile == World.TILE.BARRENS;
|
||||||
},
|
},
|
||||||
|
|
||||||
chooseTile: function(x, y, map) {
|
chooseTile: function(x, y, map) {
|
||||||
|
|
||||||
var adjacent = [
|
var adjacent = [
|
||||||
y > 0 ? map[x][y-1] : null,
|
y > 0 ? map[x][y-1] : null,
|
||||||
y < World.RADIUS * 2 ? map[x][y+1] : null,
|
y < World.RADIUS * 2 ? map[x][y+1] : null,
|
||||||
x < World.RADIUS * 2 ? map[x+1][y] : null,
|
x < World.RADIUS * 2 ? map[x+1][y] : null,
|
||||||
x > 0 ? map[x-1][y] : null
|
x > 0 ? map[x-1][y] : null
|
||||||
];
|
];
|
||||||
|
|
||||||
var chances = {};
|
var chances = {};
|
||||||
var nonSticky = 1;
|
var nonSticky = 1;
|
||||||
for(var i in adjacent) {
|
for(var i in adjacent) {
|
||||||
@@ -764,7 +764,7 @@ var World = {
|
|||||||
chances[tile] = cur;
|
chances[tile] = cur;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var list = [];
|
var list = [];
|
||||||
for(var t in chances) {
|
for(var t in chances) {
|
||||||
list.push(chances[t] + '' + t);
|
list.push(chances[t] + '' + t);
|
||||||
@@ -774,7 +774,7 @@ var World = {
|
|||||||
var n2 = parseFloat(b.substring(0, b.length - 1));
|
var n2 = parseFloat(b.substring(0, b.length - 1));
|
||||||
return n2 - n1;
|
return n2 - n1;
|
||||||
});
|
});
|
||||||
|
|
||||||
var c = 0;
|
var c = 0;
|
||||||
var r = Math.random();
|
var r = Math.random();
|
||||||
for(var i in list) {
|
for(var i in list) {
|
||||||
@@ -784,14 +784,14 @@ var World = {
|
|||||||
return prob.charAt(prob.length - 1);
|
return prob.charAt(prob.length - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return World.TILE.BARRENS;
|
return World.TILE.BARRENS;
|
||||||
},
|
},
|
||||||
|
|
||||||
markVisited: function(x, y) {
|
markVisited: function(x, y) {
|
||||||
World.state.map[x][y] = World.state.map[x][y] + '!';
|
World.state.map[x][y] = World.state.map[x][y] + '!';
|
||||||
},
|
},
|
||||||
|
|
||||||
drawMap: function() {
|
drawMap: function() {
|
||||||
var map = $('#map');
|
var map = $('#map');
|
||||||
if(map.length === 0) {
|
if(map.length === 0) {
|
||||||
@@ -840,7 +840,7 @@ var World = {
|
|||||||
}
|
}
|
||||||
map.html(mapString);
|
map.html(mapString);
|
||||||
},
|
},
|
||||||
|
|
||||||
die: function() {
|
die: function() {
|
||||||
if(!World.dead) {
|
if(!World.dead) {
|
||||||
World.dead = true;
|
World.dead = true;
|
||||||
@@ -858,8 +858,8 @@ var World = {
|
|||||||
Engine.activeModule = Room;
|
Engine.activeModule = Room;
|
||||||
$('div.headerButton').removeClass('selected');
|
$('div.headerButton').removeClass('selected');
|
||||||
Room.tab.addClass('selected');
|
Room.tab.addClass('selected');
|
||||||
Engine.setTimeout(function(){
|
Engine.setTimeout(function(){
|
||||||
Room.onArrival();
|
Room.onArrival();
|
||||||
$('#outerSlider').animate({opacity:'1'}, 600, 'linear');
|
$('#outerSlider').animate({opacity:'1'}, 600, 'linear');
|
||||||
Button.cooldown($('#embarkButton'));
|
Button.cooldown($('#embarkButton'));
|
||||||
Engine.keyLock = false;
|
Engine.keyLock = false;
|
||||||
@@ -868,7 +868,7 @@ var World = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
goHome: function() {
|
goHome: function() {
|
||||||
// Home safe! Commit the changes.
|
// Home safe! Commit the changes.
|
||||||
$SM.setM('game.world', World.state);
|
$SM.setM('game.world', World.state);
|
||||||
@@ -889,31 +889,29 @@ var World = {
|
|||||||
Engine.event('progress', 'ship');
|
Engine.event('progress', 'ship');
|
||||||
}
|
}
|
||||||
World.state = null;
|
World.state = null;
|
||||||
|
|
||||||
// Clear the embark cooldown
|
|
||||||
var btn = Button.clearCooldown($('#embarkButton'));
|
|
||||||
if(Path.outfit['cured meat'] > 0) {
|
if(Path.outfit['cured meat'] > 0) {
|
||||||
Button.setDisabled(btn, false);
|
Button.setDisabled($('#embarkButton'), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(var k in Path.outfit) {
|
for(var k in Path.outfit) {
|
||||||
$SM.add('stores["'+k+'"]', Path.outfit[k]);
|
$SM.add('stores["'+k+'"]', Path.outfit[k]);
|
||||||
if(World.leaveItAtHome(k)) {
|
if(World.leaveItAtHome(k)) {
|
||||||
Path.outfit[k] = 0;
|
Path.outfit[k] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#outerSlider').animate({left: '0px'}, 300);
|
$('#outerSlider').animate({left: '0px'}, 300);
|
||||||
Engine.activeModule = Path;
|
Engine.activeModule = Path;
|
||||||
Path.onArrival();
|
Path.onArrival();
|
||||||
Engine.restoreNavigation = true;
|
Engine.restoreNavigation = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
leaveItAtHome: function(thing) {
|
leaveItAtHome: function(thing) {
|
||||||
return thing != 'cured meat' && thing != 'bullets' && thing != 'energy cell' && thing != 'charm' && thing != 'medicine' &&
|
return thing != 'cured meat' && thing != 'bullets' && thing != 'energy cell' && thing != 'charm' && thing != 'medicine' &&
|
||||||
typeof World.Weapons[thing] == 'undefined' && typeof Room.Craftables[thing] == 'undefined';
|
typeof World.Weapons[thing] == 'undefined' && typeof Room.Craftables[thing] == 'undefined';
|
||||||
},
|
},
|
||||||
|
|
||||||
getMaxHealth: function() {
|
getMaxHealth: function() {
|
||||||
if($SM.get('stores["s armour"]', true) > 0) {
|
if($SM.get('stores["s armour"]', true) > 0) {
|
||||||
return World.BASE_HEALTH + 35;
|
return World.BASE_HEALTH + 35;
|
||||||
@@ -924,14 +922,14 @@ var World = {
|
|||||||
}
|
}
|
||||||
return World.BASE_HEALTH;
|
return World.BASE_HEALTH;
|
||||||
},
|
},
|
||||||
|
|
||||||
getHitChance: function() {
|
getHitChance: function() {
|
||||||
if($SM.hasPerk('precise')) {
|
if($SM.hasPerk('precise')) {
|
||||||
return World.BASE_HIT_CHANCE + 0.1;
|
return World.BASE_HIT_CHANCE + 0.1;
|
||||||
}
|
}
|
||||||
return World.BASE_HIT_CHANCE;
|
return World.BASE_HIT_CHANCE;
|
||||||
},
|
},
|
||||||
|
|
||||||
getMaxWater: function() {
|
getMaxWater: function() {
|
||||||
if($SM.get('stores["water tank"]', true) > 0) {
|
if($SM.get('stores["water tank"]', true) > 0) {
|
||||||
return World.BASE_WATER + 50;
|
return World.BASE_WATER + 50;
|
||||||
@@ -942,23 +940,25 @@ var World = {
|
|||||||
}
|
}
|
||||||
return World.BASE_WATER;
|
return World.BASE_WATER;
|
||||||
},
|
},
|
||||||
|
|
||||||
outpostUsed: function(x, y) {
|
outpostUsed: function(x, y) {
|
||||||
x = typeof x == 'number' ? x : World.curPos[0];
|
x = typeof x == 'number' ? x : World.curPos[0];
|
||||||
y = typeof y == 'number' ? y : World.curPos[1];
|
y = typeof y == 'number' ? y : World.curPos[1];
|
||||||
var used = World.usedOutposts[x + ',' + y];
|
var used = World.usedOutposts[x + ',' + y];
|
||||||
return typeof used != 'undefined' && used === true;
|
return typeof used != 'undefined' && used === true;
|
||||||
},
|
},
|
||||||
|
|
||||||
useOutpost: function() {
|
useOutpost: function() {
|
||||||
Notifications.notify(null, _('water replenished'));
|
Notifications.notify(null, _('water replenished'));
|
||||||
World.setWater(World.getMaxWater());
|
World.setWater(World.getMaxWater());
|
||||||
// Mark this outpost as used
|
// Mark this outpost as used
|
||||||
World.usedOutposts[World.curPos[0] + ',' + World.curPos[1]] = true;
|
World.usedOutposts[World.curPos[0] + ',' + World.curPos[1]] = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
onArrival: function() {
|
onArrival: function() {
|
||||||
Engine.tabNavigation = false;
|
Engine.tabNavigation = false;
|
||||||
|
// Clear the embark cooldown
|
||||||
|
Button.clearCooldown($('#embarkButton'));
|
||||||
Engine.keyLock = false;
|
Engine.keyLock = false;
|
||||||
// Explore in a temporary world-state. We'll commit the changes if you return home safe.
|
// Explore in a temporary world-state. We'll commit the changes if you return home safe.
|
||||||
World.state = $.extend(true, {}, $SM.get('game.world'));
|
World.state = $.extend(true, {}, $SM.get('game.world'));
|
||||||
@@ -977,16 +977,16 @@ var World = {
|
|||||||
World.updateSupplies();
|
World.updateSupplies();
|
||||||
$('#bagspace-world').width($('#map').width());
|
$('#bagspace-world').width($('#map').width());
|
||||||
},
|
},
|
||||||
|
|
||||||
setTitle: function() {
|
setTitle: function() {
|
||||||
document.title = _('A Barren World');
|
document.title = _('A Barren World');
|
||||||
},
|
},
|
||||||
|
|
||||||
copyPos: function(pos) {
|
copyPos: function(pos) {
|
||||||
return [pos[0], pos[1]];
|
return [pos[0], pos[1]];
|
||||||
},
|
},
|
||||||
|
|
||||||
handleStateUpdates: function(e){
|
handleStateUpdates: function(e){
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user