mirror of
https://github.com/doublespeakgames/adarkroom.git
synced 2026-05-28 08:11:54 +08:00
refactor Engine.js for use with $SM
====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)
This commit is contained in:
+29
-19
@@ -41,7 +41,7 @@ var Events = {
|
||||
|
||||
// Scene reward
|
||||
if(scene.reward) {
|
||||
Engine.addStores(scene.reward, true);
|
||||
$SM.addM('stores', scene.reward);
|
||||
}
|
||||
|
||||
// onLoad
|
||||
@@ -157,7 +157,7 @@ var Events = {
|
||||
var weapon = World.Weapons[weaponName];
|
||||
var cd = weapon.cooldown;
|
||||
if(weapon.type == 'unarmed') {
|
||||
if(Engine.hasPerk('unarmed master')) {
|
||||
if($SM.hasPerk('unarmed master')) {
|
||||
cd /= 2;
|
||||
}
|
||||
}
|
||||
@@ -245,12 +245,12 @@ var Events = {
|
||||
if(weapon.type == 'unarmed') {
|
||||
if(!$SM.get('character.punches')) $SM.set('character.punches', 0);
|
||||
$SM.add('character.punches', 1);
|
||||
if($SM.get('character.punches') == 50 && !Engine.hasPerk('boxer')) {
|
||||
Engine.addPerk('boxer');
|
||||
} else if($SM.get('character.punches') == 150 && !Engine.hasPerk('martial artist')) {
|
||||
Engine.addPerk('martial artist');
|
||||
} else if($SM.get('character.punches') == 300 && !Engine.hasPerk('unarmed master')) {
|
||||
Engine.addPerk('unarmed master');
|
||||
if($SM.get('character.punches') == 50 && !$SM.hasPerk('boxer')) {
|
||||
$SM.addPerk('boxer');
|
||||
} else if($SM.get('character.punches') == 150 && !$SM.hasPerk('martial artist')) {
|
||||
$SM.addPerk('martial artist');
|
||||
} else if($SM.get('character.punches') == 300 && !$SM.hasPerk('unarmed master')) {
|
||||
$SM.addPerk('unarmed master');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -294,16 +294,16 @@ var Events = {
|
||||
if(Math.random() <= World.getHitChance()) {
|
||||
dmg = weapon.damage;
|
||||
if(typeof dmg == 'number') {
|
||||
if(weapon.type == 'unarmed' && Engine.hasPerk('boxer')) {
|
||||
if(weapon.type == 'unarmed' && $SM.hasPerk('boxer')) {
|
||||
dmg *= 2
|
||||
}
|
||||
if(weapon.type == 'unarmed' && Engine.hasPerk('martial artist')) {
|
||||
if(weapon.type == 'unarmed' && $SM.hasPerk('martial artist')) {
|
||||
dmg *= 3;
|
||||
}
|
||||
if(weapon.type == 'unarmed' && Engine.hasPerk('unarmed master')) {
|
||||
if(weapon.type == 'unarmed' && $SM.hasPerk('unarmed master')) {
|
||||
dmg *= 2;
|
||||
}
|
||||
if(weapon.type == 'melee' && Engine.hasPerk('barbarian')) {
|
||||
if(weapon.type == 'melee' && $SM.hasPerk('barbarian')) {
|
||||
dmg = Math.floor(dmg * 1.5);
|
||||
}
|
||||
}
|
||||
@@ -417,7 +417,7 @@ var Events = {
|
||||
|
||||
if(!$('#enemy').data('stunned')) {
|
||||
var toHit = scene.hit;
|
||||
toHit *= Engine.hasPerk('evasive') ? 0.8 : 1;
|
||||
toHit *= $SM.hasPerk('evasive') ? 0.8 : 1;
|
||||
var dmg = -1;
|
||||
if(Math.random() <= toHit) {
|
||||
dmg = scene.damage;
|
||||
@@ -646,7 +646,7 @@ var Events = {
|
||||
} else if(b.cost) {
|
||||
var disabled = false;
|
||||
for(var store in b.cost) {
|
||||
var num = Engine.activeModule == World ? Path.outfit[store] : Engine.getStore(store);
|
||||
var num = Engine.activeModule == World ? Path.outfit[store] : $SM.get('stores[\''+store+'\']', true);
|
||||
if(typeof num != 'number') num = 0;
|
||||
if(num < b.cost[store]) {
|
||||
// Too expensive
|
||||
@@ -665,7 +665,7 @@ var Events = {
|
||||
var costMod = {};
|
||||
if(info.cost) {
|
||||
for(var store in info.cost) {
|
||||
var num = Engine.activeModule == World ? Path.outfit[store] : Engine.getStore(store);
|
||||
var num = Engine.activeModule == World ? Path.outfit[store] : $SM.get('stores[\''+store+'\']', true);
|
||||
if(typeof num != 'number') num = 0;
|
||||
if(num < info.cost[store]) {
|
||||
// Too expensive
|
||||
@@ -679,7 +679,7 @@ var Events = {
|
||||
}
|
||||
World.updateSupplies();
|
||||
} else {
|
||||
Engine.addStores(costMod);
|
||||
$SM.addM('stores', costMod);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -689,7 +689,7 @@ var Events = {
|
||||
|
||||
// Reward
|
||||
if(info.reward) {
|
||||
Engine.addStores(info.reward);
|
||||
$SM.addM('stores', info.reward);
|
||||
}
|
||||
|
||||
Events.updateButtons();
|
||||
@@ -803,5 +803,15 @@ var Events = {
|
||||
// Force refocus on the body. I hate you, IE.
|
||||
$('body').focus();
|
||||
});
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
handleStateUpdates: function(e){
|
||||
//updates to run on stores changes if an event is active
|
||||
if(e.stateName.indexOf('stores') == 0 && Events.activeEvent() != null){
|
||||
Events.updateButtons();
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
//listener for StateManager update events
|
||||
$(Events).on('stateUpdate', Events.handleStateUpdates);
|
||||
Reference in New Issue
Block a user