Limited subset of commits:
* unified function for healing (Events.doHeal);
* unified function for attacks (Events.damage);
* check if health is max, and disable healing buttons (Events.setHeal and related calls)
* grouping buttons (attackButtons, healButtons and exitButtons for weapon attacks, meat & meds, continue/leave)
As some of them are related to each other, this commit involves a lot of updates.
* Autopause on blur. This is an idea I took from Gridland (!), if window loses focus the fight pauses (timed check courtesy of the enemy), and it restarts when the window has focus again (if the pause button is clicked, then the player must click again in order to resume).
* Delayed start for fights. This will allow players to read the description without the player attacking them. No way to cheat, buttons are not enabled. I used Events._LEAVE_COOLDOWN as cooldown time, not for laziness, but because I guess the two durations have the same purpose: to allow (force) the player to read stuff.
* Take everything and leave just by name. If the player can just take something, the text is "take all you can", if they can take everything but there are several options it's "take everything", if the option is only one the text is "take everything and X", where X is the verb of the only possible option (note: in the latter case, the button cools down together with the option itself).
* success/failure mechanics no longer relies upon try/catch, but on a simple mechanism: a variable taking a bool value, set to true when one of the end conditions happens. The precedence goes to the enemy (if the player kills and dies the fight is lost).
Events.setHeal() enables/disables eatMeat and useMeds buttons depending on player's HP.
The check is done in 4 cases:
* when a fight starts
* after an attack
* after healing
* in the loot screen
Events.damage method now groups all common lines for Events.animateRanged and Events.animateMelee.
Balance between success and failure is now determined by Events.lost. It is set to "true" when the player is killed and prevents Events.winFight() altogether.
Events.endFight() groups the 2 consistent actions in winFight and loseFight, i.e., pause unsetting and stopping the enemy.
Completely renewed trap method: instead of relying on a separate counter, enemy.data('stunned') now returns the number of remaining seconds of stunning. Enemy's timed attack decreases this value by the attack delay time (the enemy fights for its freedom).
This commit adds a pause button during the fight. It relies upon the new
Events.paused property: when set to true, no buttons will work except
the pause button itself, and cooldown on attack/healing buttons is
interrupted.
This commit also groups event buttons in different groups (attack,
healing, scene), so that the position of "eat meat" and "use meds" does
not depend on how many scene buttons are present (sometimes 1, other
times 2)
The change is somehow linguistic, rather than anything else.
"Take everything and leave" changes name and becomes "Take everything and X", where X is the verb of the command it impersonates.
This way after completing mines e.g. it is "Take everything and continue", acting like "continue" button.
It now also cools down if it impersonates a "leave" button (leave buttons cool down. IDK why).
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
Export dialog replaces selection dialog, rather than overlapping it.
Closing it exits the panel and returns to current game.
Aborting Import dialog returns the player to the selection screen, so that s/he can save before trying to load.
An event could produce different notifications or rewards according to different outcomes of the event itself (e.g. a negative event impacting on buildings and/or villagers, or a wanderer leaving items of some specific kind), but the notification is generated before the onLoad() call.
I'd say that this is the best action order:
1. event action
2. event notification
3. event reward (and possible additional notifications due to that)
Noticed when buying the compass.
I found it weird that *first* the compass points and *then* it appears in good condition.
Now event notification precedes event reward, and it should be corrected.
Cleans up global variable that was introduced in favor of a variable in
Events. Removes type checking from conditionals and instead sets
BLINK_INTERVAL variable to false when stopped.
Adding this cooldown prevents users from accidently clicking leave or
continue before they have a chance to eat or collect loot. This was
originally brought up in and resolves#8. May be of interest to #122 as
well
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
add $.Dispatch to handle object events
add subscribe calls to files
update SM fireUpdate to use new Dispatch
There are some NaN issues right now, no time to bug hunt right now, it
does kind of function though
====functions removed====
//I just removed these because most were simpler or at least equal as
direct $SM get/set/add calls, I realize the store ones are kind of
subjective since calls were about equal, but oh well. If someone
really feels we need the shortcut/named functions for manipulating
stores specifically, it shouldn't be crazy to reimplement in $SM
Engine.setStore >> $SM.set
Engine.setStores >> $SM.setM
Engine.addStore >> $SM.add
Engine.addStores >> $SM.addM
Engine.getStore >> $SM.get(requestZero = true)
Engine.storeAvailable >> $SM.get;
Engine.removeIncome >> $SM.remove //updates moved to handler
====functions moved====
//Any moved function I felt was more directly related to States or
didn't belong where it was
Engine.addPerk > $SM.addPerk //kept function for now because of notify
call inside, 'deep' state
Engine.hasPerk > $SM.hasPerk //kept function because of 'deep' state
name
Engine.setIncome > $SM.setIncome //kept because it has internal logic
**Engine.getIncome > $SM.getIncome //**easily removable with
Outside.updateVillageIncome refactor
Engine.openPath > Path.openPath //Since I'm refactoring anyways
Engine.addStolen > $SM.addStolen //internal logic
Engine.startThieves > $SM.startThieves //not sure $SM is a better place,
but Engine should be nice and clean by the end of this, handling
only engine mechanics
Engine.num > $SM.num //after Outside refacter, this is basically just a
fancy $SM.get
Engine.upgradeState > $SM.updateOldState
====functions refactored====
$SM.addPerk; //updates moved to event handler, no check/create new perk
$SM.hasPerk; //don't need to check exist and ==true
$SM.collectIncome //removed changed check, update calls now handled by
'stateUpdate' event listening
$SM.addStolen //fix to set stolen items in case a partial steal happens
$SM.startThieves //updates in handler
$SM.updateOldState //use $SM calls, add placeholder for updating to post
$SM state when more finalized
====functions affected (by removed)====
Engine.init (Engine.getStore, Engine.storeAvailable)
Engine.collectIncome (Engine.addStores)
Engine.num (Engine.getStore)
Engine.travelTo (Engine.storeAvailable)
Room.init (Engine.getStore)
Room.unlockForest (Engine.setStore)
Room.lightFire (Engine.setStore, Engine.getStore, Engine.storeAvailable)
Room.stokeFire (Engine.setStore, Engine.getStore, Engine.storeAvailable)
Room.coolFire (Engine.setStore)
Room.buy (Engine.setStores, Engine.addStore, Engine.getStore)
Room.build (Engine.setStores, Engine.getStore)
Room.craftUnlocked (Engine.getStore, Engine.storeAvailable)
Room.buyUnlocked (Engine.storeAvailable)
Room.updateButton (Engine.storeAvailable)
Outside.gatherWood (Engine.addStores)
Outside.checkTraps (Engine.addStores, Engine.getStore)
Outside.updateVillage (Engine.getStore)
Path.embark (Engine.addStore)
Path.getCapacity (Engine.getStore)
Path.updateOutfitting (Engine.getStore)
Path.createOutfittingRow (Engine.getStore)
Path.increaseSupply (Engine.getStore)
World.goHome (Engine.addStore)
World.updateSupplies (Engine.getStore)
World.checkDanger (Engine.getStore)
World.getMaxHealth (Engine.getStore)
World.getMaxWater (Engine.getStore)
Ship.reinforceHull (Engine.addStore, Engine.getStore)
Ship.upgradeEngine (Engine.addStore, Engine.getStore)
Events.loadScene (Engine.addStores)
Events.updateButtons (Engine.getStore)
Events.buttonClick (Engine.getStore)
Events.Global (Engine.addStores, Engine.removeIncome)
Events.Room (Engine.addStore, Engine.addStores, Engine.getStore,
Engine.storeAvailable)