Files
adarkroom/script/events/outside.js
T
LucidCrux db4a346d21 create StateManager, change all State calls to managed calls
Introduced state_manager.js almost all State gets/sets are now run
through the manager (alias $SM). For now it was a simple, mostly
straightforward replacement of calls. This means that there are
redundancies and a lot of now unneeded code for things the SM will
handle. However, since I had trouble with making those changes as well
as introducing the manager all at once my first attempt, I am taking the
wiser approach and making "one change" at a time like I should have
instead of being too sure of myself.

At this point, it seems to work, but there may be bugs I didn't catch.
There was also no attempt made to update old saves to work with this. In
theory, it shouldn't be too hard. (included is a list of all state
changes)

TODO:
Save Update.
Refactor: a lot, many many redundancies now.
Refactor: "location centric" to "global centric".
Relocate all calls to different update functions to event listeners
where possible.

======================================================

The changes to State are as follows:

.room (exists) > features.location.room
.room > game.room
.room.builder > game.room.builder
.room.temperature > game.room.temperature
.room.fire > game.room.fire
.room.buttons > game.room.buttons

.outside (exists) > features.location.outside
.outside > game.outside
.outside.population > game.outside.population
.outside.buildings > game.outside.buildings
.outside.workers > game.outside.workers
.outside.seenForest > game.outside.seenForest

.world (exists) > features.location.world
.world > game.world
.world.map > game.world.map
.world.mask > game.world.mask
.starved > character.starved
.dehydrated > character.dehydrated

.ship (exists) > featuers.location.spaceShip
.ship > game.spaceShip
.ship.hull > game.spaceShip.hull
.ship.thrusters > game.spaceShip.thrusters
.ship.seenWarning > game.spaceShip.seenWarning
.ship.seenShip > game.spaceShip.seenShip

.punches > character.punches
.perks > character.perks

.thieves > game.thieves
.stolen > game.stolen
.cityCleared > game.cityCleared

.stores > stores
.income > income
2013-07-23 01:24:47 -06:00

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 && Outside.numBuilding('trap') > 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() * Outside.numBuilding('trap')) + 1;
Outside.addBuilding('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 && Outside.getPopulation() > 10 && Outside.getPopulation() < 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 && Outside.getPopulation() > 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 && Outside.getPopulation() > 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 && Outside.getPopulation() > 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'
}
}
}
}
}
];