mirror of
https://github.com/doublespeakgames/adarkroom.git
synced 2026-05-28 00:01:54 +08:00
99800f1abd
Refactoring of Outside.js to take better advantage of $SM and simplify
the code.
Includes a small bug fix to Room update handler
Also changed instances of escaped single quote (\') to double (") for
readability and simplicity.
====state changes====
//these were changed for the opposite reason the Room states were. These
seem like states that other locations and events may very well want to
interact with and possibly alter themselves
game.outside.buildings >> game.buildings
game.outside.population >> game.population
game.outside.workders >> game.workers
====functions removed====
Outside.numBuilding // just a $SM.get, no shortcut really needed since
Outside.numBuilding is a pretty long name
Outside.getPopulation // same here
Outside.addBuilding // just an add
Outside.addBuildings // just addM, but wasn't even actually used
====functions refactored====
Outside.killVillagers //moved updates to handler
Outside.updateWorkersView //added local to reduce gets
Outside.increasePopulation //updates moved to handler
Outside.increaseWorker // updates moved to handler
Outside.decreaseWorkder // updates moved to handler
241 lines
5.8 KiB
JavaScript
241 lines
5.8 KiB
JavaScript
/**
|
|
* Events that can occur when the Outside module is active
|
|
**/
|
|
Events.Outside = [
|
|
{ /* Ruined traps */
|
|
title: 'A Ruined Trap',
|
|
isAvailable: function() {
|
|
return Engine.activeModule == Outside && $SM.get('game.buildings["trap"]', true) > 0;
|
|
},
|
|
scenes: {
|
|
'start': {
|
|
text: [
|
|
'some of the traps have been torn apart.',
|
|
'large prints lead away, into the forest.'
|
|
],
|
|
onLoad: function() {
|
|
var numWrecked = Math.floor(Math.random() * $SM.get('game.buildings["trap"]', true)) + 1;
|
|
$SM.add('game.buildings["trap"]', -numWrecked);
|
|
Outside.updateVillage();
|
|
Outside.updateTrapButton();
|
|
},
|
|
notification: 'some traps have been destroyed',
|
|
buttons: {
|
|
'track': {
|
|
text: 'track them',
|
|
nextScene: {0.5: 'nothing', 1: 'catch'}
|
|
},
|
|
'ignore': {
|
|
text: 'ignore them',
|
|
nextScene: 'end'
|
|
}
|
|
}
|
|
},
|
|
'nothing': {
|
|
text: [
|
|
'the tracks disappear after just a few minutes.',
|
|
'the forest is silent.'
|
|
],
|
|
buttons: {
|
|
'end': {
|
|
text: 'go home',
|
|
nextScene: 'end'
|
|
}
|
|
}
|
|
},
|
|
'catch': {
|
|
text: [
|
|
'not far from the village lies a large beast, its fur matted with blood.',
|
|
'it puts up little resistance before the knife.'
|
|
],
|
|
reward: {
|
|
fur: 100,
|
|
meat: 100,
|
|
teeth: 10
|
|
},
|
|
buttons: {
|
|
'end': {
|
|
text: 'go home',
|
|
nextScene: 'end'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
|
|
{ /* Sickness */
|
|
title: 'Sickness',
|
|
isAvailable: function() {
|
|
return Engine.activeModule == Outside && $SM.get('game.population', true) > 10 && $SM.get('game.population', true) < 50;
|
|
},
|
|
scenes: {
|
|
'start': {
|
|
text: [
|
|
'a sickness is spreading through the village.',
|
|
'medicine is needed immediately.'
|
|
],
|
|
buttons: {
|
|
'heal': {
|
|
text: '1 medicine',
|
|
cost: { 'medicine' : 1 },
|
|
nextScene: {1: 'healed'}
|
|
},
|
|
'ignore': {
|
|
text: 'ignore it',
|
|
nextScene: {1: 'death'}
|
|
}
|
|
}
|
|
},
|
|
'healed': {
|
|
text: [
|
|
'the sickness is cured in time.'
|
|
],
|
|
buttons: {
|
|
'end': {
|
|
text: 'go home',
|
|
nextScene: 'end'
|
|
}
|
|
}
|
|
},
|
|
'death': {
|
|
text: [
|
|
'the sickness spreads through the village.',
|
|
'the days are spent with burials.',
|
|
'the nights are rent with screams.'
|
|
],
|
|
onLoad: function() {
|
|
var numKilled = Math.floor(Math.random() * 20) + 1;
|
|
Outside.killVillagers(numKilled);
|
|
},
|
|
buttons: {
|
|
'end': {
|
|
text: 'go home',
|
|
nextScene: 'end'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
|
|
{ /* Plague */
|
|
title: 'Plague',
|
|
isAvailable: function() {
|
|
return Engine.activeModule == Outside && $SM.get('game.population', true) > 50;
|
|
},
|
|
scenes: {
|
|
'start': {
|
|
text: [
|
|
'a terrible plague is fast spreading through the village.',
|
|
'medicine is needed immediately.'
|
|
],
|
|
buttons: {
|
|
'heal': {
|
|
text: '5 medicine',
|
|
cost: { 'medicine' : 5 },
|
|
nextScene: {1: 'healed'}
|
|
},
|
|
'ignore': {
|
|
text: 'do nothing',
|
|
nextScene: {1: 'death'}
|
|
}
|
|
}
|
|
},
|
|
'healed': {
|
|
text: [
|
|
'the plague is kept from spreading.',
|
|
'only a few die.',
|
|
'the rest bury them.'
|
|
],
|
|
onLoad: function() {
|
|
var numKilled = Math.floor(Math.random() * 5) + 2;
|
|
Outside.killVillagers(numKilled);
|
|
},
|
|
buttons: {
|
|
'end': {
|
|
text: 'go home',
|
|
nextScene: 'end'
|
|
}
|
|
}
|
|
},
|
|
'death': {
|
|
text: [
|
|
'the plague rips through the village.',
|
|
'the nights are rent with screams.',
|
|
'the only hope is a quick death.'
|
|
],
|
|
onLoad: function() {
|
|
var numKilled = Math.floor(Math.random() * 80) + 10;
|
|
Outside.killVillagers(numKilled);
|
|
},
|
|
buttons: {
|
|
'end': {
|
|
text: 'go home',
|
|
nextScene: 'end'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
|
|
{ /* Beast attack */
|
|
title: 'A Beast Attack',
|
|
isAvailable: function() {
|
|
return Engine.activeModule == Outside && $SM.get('game.population', true) > 0;
|
|
},
|
|
scenes: {
|
|
'start': {
|
|
text: [
|
|
'a pack of snarling beasts pours out of the trees.',
|
|
'the fight is short and bloody, but the beasts are repelled.',
|
|
'the villagers retreat to mourn the dead.'
|
|
],
|
|
onLoad: function() {
|
|
var numKilled = Math.floor(Math.random() * 10) + 1;
|
|
Outside.killVillagers(numKilled);
|
|
},
|
|
reward: {
|
|
fur: 100,
|
|
meat: 100,
|
|
teeth: 10
|
|
},
|
|
buttons: {
|
|
'end': {
|
|
text: 'go home',
|
|
nextScene: 'end'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
|
|
{ /* Soldier attack */
|
|
title: 'A Military Raid',
|
|
isAvailable: function() {
|
|
return Engine.activeModule == Outside && $SM.get('game.population', true) > 0 && $SM.get('game.cityCleared');;
|
|
},
|
|
scenes: {
|
|
'start': {
|
|
text: [
|
|
'a gunshot rings through the trees.',
|
|
'well armed men charge out of the forest, firing into the crowd.',
|
|
'after a skirmish they are driven away, but not without losses.'
|
|
],
|
|
onLoad: function() {
|
|
var numKilled = Math.floor(Math.random() * 40) + 1;
|
|
Outside.killVillagers(numKilled);
|
|
},
|
|
reward: {
|
|
bullets: 10,
|
|
'cured meat': 50
|
|
},
|
|
buttons: {
|
|
'end': {
|
|
text: 'go home',
|
|
nextScene: 'end'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
];
|
|
|