Initial medicine implementation. Needs more events.

This commit is contained in:
Zarkonnen
2013-07-08 19:16:16 +02:00
parent 54cea31db9
commit 4641b0b145
5 changed files with 787 additions and 51 deletions
+45
View File
@@ -7,6 +7,7 @@ var Events = {
_PANEL_FADE: 200,
_FIGHT_SPEED: 100,
_EAT_COOLDOWN: 5,
_MEDS_COOLDOWN: 7,
STUN_DURATION: 4000,
init: function(options) {
@@ -103,6 +104,7 @@ var Events = {
Events.createAttackButton('fists').prependTo(btns);
}
Events.createUseMedsButton().prependTo(btns);
Events.createEatMeatButton().prependTo(btns);
// Set up the enemy attack timer
@@ -129,6 +131,26 @@ var Events = {
return btn;
},
createUseMedsButton: function(cooldown) {
if (cooldown == null) {
cooldown = Events._MEDS_COOLDOWN;
}
var btn = new Button.Button({
id: 'meds',
text: 'use meds',
cooldown: cooldown,
click: Events.useMeds,
cost: { 'medicine': 1 }
});
if(Path.outfit['medicine'] == 0) {
Button.setDisabled(btn, true);
}
return btn;
},
createAttackButton: function(weaponName) {
var weapon = World.Weapons[weaponName];
var cd = weapon.cooldown;
@@ -192,6 +214,28 @@ var Events = {
}
},
useMeds: function() {
if(Path.outfit['medicine'] > 0) {
Path.outfit['medicine']--;
World.updateSupplies();
if(Path.outfit['medicine'] == 0) {
Button.setDisabled($('#meds'), true);
}
var hp = World.health;
hp += World.medsHeal();
hp = hp > World.getMaxHealth() ? World.getMaxHealth() : hp;
World.setHp(hp);
if(Events.activeEvent()) {
var w = $('#wanderer');
w.data('hp', hp);
Events.updateFighterDiv(w);
Events.drawFloatText('+' + World.medsHeal(), '#wanderer .hp');
}
}
},
useWeapon: function(btn) {
if(Events.activeEvent()) {
var weaponName = btn.attr('id').substring(7).replace('-', ' ');
@@ -426,6 +470,7 @@ var Events = {
}).appendTo(btns);
Events.createEatMeatButton(0).appendTo(btns);
Events.createUseMedsButton(0).appendTo(btns);
}
} catch(e) {
// It is possible to die and win if the timing is perfect. Just let it fail.