mirror of
https://github.com/doublespeakgames/adarkroom.git
synced 2026-05-30 01:02:00 +08:00
Take all, take everything, leave if possible
Multiple fixes: 1. take all of a kind 2. take everything 3. if possible, leave 4. drop menu on hover 5. Same item not shown as drop option
This commit is contained in:
committed by
Blake Grotewold
parent
da0d39b579
commit
7208b845b1
+208
-98
@@ -46,13 +46,6 @@ var Events = {
|
||||
Events.activeScene = name;
|
||||
var scene = Events.activeEvent().scenes[name];
|
||||
|
||||
// Scene reward
|
||||
if(scene.reward) {
|
||||
$SM.addM('stores', scene.reward);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// onLoad
|
||||
if(scene.onLoad) {
|
||||
scene.onLoad();
|
||||
@@ -63,6 +56,11 @@ var Events = {
|
||||
Notifications.notify(null, scene.notification);
|
||||
}
|
||||
|
||||
// Scene reward
|
||||
if(scene.reward) {
|
||||
$SM.addM('stores', scene.reward);
|
||||
}
|
||||
|
||||
$('#description', Events.eventPanel()).empty();
|
||||
$('#buttons', Events.eventPanel()).empty();
|
||||
if(scene.combat) {
|
||||
@@ -221,6 +219,8 @@ var Events = {
|
||||
w.data('hp', hp);
|
||||
Events.updateFighterDiv(w);
|
||||
Events.drawFloatText('+' + World.meatHeal(), '#wanderer .hp');
|
||||
var takeETbutton = Events.setTakeAll();
|
||||
Events.canLeave(takeETbutton);
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -243,6 +243,8 @@ var Events = {
|
||||
w.data('hp', hp);
|
||||
Events.updateFighterDiv(w);
|
||||
Events.drawFloatText('+' + World.medsHeal(), '#wanderer .hp');
|
||||
var takeETbutton = Events.setTakeAll();
|
||||
Events.canLeave(takeETbutton);
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -454,23 +456,23 @@ var Events = {
|
||||
Engine.setTimeout(function() {
|
||||
try {
|
||||
var scene = Events.activeEvent().scenes[Events.activeScene];
|
||||
var leaveBtn = false;
|
||||
var desc = $('#description', Events.eventPanel());
|
||||
var btns = $('#buttons', Events.eventPanel());
|
||||
desc.empty();
|
||||
btns.empty();
|
||||
$('<div>').text(scene.deathMessage).appendTo(desc);
|
||||
|
||||
Events.drawLoot(scene.loot);
|
||||
var takeETbtn = Events.drawLoot(scene.loot);
|
||||
|
||||
if(scene.buttons) {
|
||||
// Draw the buttons
|
||||
Events.drawButtons(scene);
|
||||
leaveBtn = Events.drawButtons(scene);
|
||||
} else {
|
||||
Button.cooldown(new Button.Button({
|
||||
leaveBtn = new Button.Button({
|
||||
id: 'leaveBtn',
|
||||
cooldown: Events._LEAVE_COOLDOWN,
|
||||
click: function() {
|
||||
var scene = Events.activeEvent().scenes[Events.activeScene];
|
||||
if(scene.nextScene && scene.nextScene != 'end') {
|
||||
Events.loadScene(scene.nextScene);
|
||||
} else {
|
||||
@@ -478,13 +480,15 @@ var Events = {
|
||||
}
|
||||
},
|
||||
text: _('leave')
|
||||
}).appendTo(btns));
|
||||
});
|
||||
Button.cooldown(leaveBtn.appendTo(btns));
|
||||
|
||||
Events.createEatMeatButton(0).appendTo(btns);
|
||||
if((Path.outfit['medicine'] || 0) !== 0) {
|
||||
Events.createUseMedsButton(0).appendTo(btns);
|
||||
}
|
||||
}
|
||||
Events.allowLeave(takeETbtn, leaveBtn);
|
||||
} catch(e) {
|
||||
// It is possible to die and win if the timing is perfect. Just let it fail.
|
||||
}
|
||||
@@ -492,106 +496,212 @@ var Events = {
|
||||
});
|
||||
},
|
||||
|
||||
drawDrop:function(btn) {
|
||||
var name = btn.attr('id').substring(5).replace('-', ' ');
|
||||
var needsAppend = false;
|
||||
var weight = Path.getWeight(name);
|
||||
var freeSpace = Path.getFreeSpace();
|
||||
if(weight > freeSpace) {
|
||||
// Draw the drop menu
|
||||
Engine.log('drop menu');
|
||||
if($('#dropMenu').length){
|
||||
var dropMenu = $('#dropMenu');
|
||||
$('#dropMenu').empty();
|
||||
} else {
|
||||
var dropMenu = $('<div>').attr({'id': 'dropMenu', 'data-legend': _('drop:')});
|
||||
needsAppend = true;
|
||||
}
|
||||
for(var k in Path.outfit) {
|
||||
if(name == k) continue;
|
||||
var itemWeight = Path.getWeight(k);
|
||||
if(itemWeight > 0) {
|
||||
var numToDrop = Math.ceil((weight - freeSpace) / itemWeight);
|
||||
if(numToDrop > Path.outfit[k]) {
|
||||
numToDrop = Path.outfit[k];
|
||||
}
|
||||
if(numToDrop > 0) {
|
||||
var dropRow = $('<div>').attr('id', 'drop_' + k.replace(' ', '-'))
|
||||
.text(_(k) + ' x' + numToDrop)
|
||||
.data('thing', k)
|
||||
.data('num', numToDrop)
|
||||
.click(Events.dropStuff)
|
||||
.mouseenter(function(e){
|
||||
e.stopPropagation();
|
||||
});
|
||||
dropRow.appendTo(dropMenu);
|
||||
}
|
||||
}
|
||||
}
|
||||
$('<div>').attr('id','no_drop')
|
||||
.text(_('nothing'))
|
||||
.mouseenter(function(e){
|
||||
e.stopPropagation();
|
||||
})
|
||||
.click(function(e){
|
||||
e.stopPropagation();
|
||||
dropMenu.remove();
|
||||
})
|
||||
.appendTo(dropMenu);
|
||||
if(needsAppend){
|
||||
dropMenu.appendTo(btn);
|
||||
}
|
||||
btn.one("mouseleave", function() {
|
||||
$('#dropMenu').remove();
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
drawLootRow: function(name, num){
|
||||
var id = name.replace(' ', '-');
|
||||
var lootRow = $('<div>').attr('id','loot_' + id).data('item', name).addClass('lootRow');
|
||||
var take = new Button.Button({
|
||||
id: 'take_' + id,
|
||||
text: _(name) + ' [' + num + ']',
|
||||
click: Events.getLoot
|
||||
}).addClass('lootTake').data('numLeft', num).appendTo(lootRow);
|
||||
take.mouseenter(function(){
|
||||
Events.drawDrop(take);
|
||||
});
|
||||
var takeall = new Button.Button({
|
||||
id: 'all_take_' + id,
|
||||
text: _('take') + ' ',
|
||||
click: Events.takeAll
|
||||
}).addClass('lootTakeAll').appendTo(lootRow);
|
||||
$('<span>').insertBefore(takeall.children('.cooldown'));
|
||||
$('<div>').addClass('clear').appendTo(lootRow);
|
||||
return lootRow;
|
||||
},
|
||||
|
||||
drawLoot: function(lootList) {
|
||||
var desc = $('#description', Events.eventPanel());
|
||||
var lootButtons = $('<div>').attr('id', 'lootButtons');
|
||||
var lootButtons = $('<div>').attr({'id': 'lootButtons', 'data-legend': _('take:')});
|
||||
for(var k in lootList) {
|
||||
var loot = lootList[k];
|
||||
if(Math.random() < loot.chance) {
|
||||
var num = Math.floor(Math.random() * (loot.max - loot.min)) + loot.min;
|
||||
new Button.Button({
|
||||
id: 'loot_' + k.replace(' ', '-'),
|
||||
text: _(k) + ' [' + num + ']',
|
||||
click: Events.getLoot
|
||||
}).data('numLeft', num).appendTo(lootButtons);
|
||||
var lootRow = Events.drawLootRow(k, num);
|
||||
lootRow.appendTo(lootButtons);
|
||||
}
|
||||
}
|
||||
$('<div>').addClass('clear').appendTo(lootButtons);
|
||||
if(lootButtons.children().length > 1) {
|
||||
lootButtons.appendTo(desc);
|
||||
var takeAll = new Button.Button({
|
||||
id: 'loot_take_all',
|
||||
text: _('take all'),
|
||||
click: Events.takeAllLoot
|
||||
}).addClass('take-all-button').appendTo(lootButtons);
|
||||
lootButtons.appendTo(desc);
|
||||
if(lootButtons.children().length > 0) {
|
||||
var takeETrow = $('<div>').addClass('takeETrow');
|
||||
var takeET = new Button.Button({
|
||||
id: 'loot_takeEverything',
|
||||
text: '',
|
||||
click: Events.takeEverything
|
||||
}).appendTo(takeETrow);
|
||||
$('<span>').insertBefore(takeET.children('.cooldown'));
|
||||
$('<div>').addClass('clear').appendTo(takeETrow);
|
||||
takeETrow.appendTo(lootButtons);
|
||||
Events.setTakeAll(lootButtons);
|
||||
} else {
|
||||
var noLoot = $('<div>').addClass('noLoot').text( _('nothing to take') );
|
||||
noLoot.appendTo(lootButtons);
|
||||
}
|
||||
return takeET || false;
|
||||
},
|
||||
|
||||
setTakeAll: function(lootButtons){
|
||||
var lootButtons = lootButtons || $('#lootButtons');
|
||||
var canTakeSomething = false;
|
||||
var free = Path.getFreeSpace();
|
||||
var takeETbutton = lootButtons.find('#loot_takeEverything');
|
||||
lootButtons.children('.lootRow').each(function(i){
|
||||
var name = $(this).data('item');
|
||||
var take = $(this).children('.lootTake').first();
|
||||
var takeAll = $(this).children('.lootTakeAll').first();
|
||||
var numLeft = take.data('numLeft');
|
||||
var num = Math.min(Math.floor(Path.getFreeSpace() / Path.getWeight(name)), numLeft);
|
||||
takeAll.data('numLeft', num);
|
||||
free -= numLeft * Path.getWeight(name);
|
||||
if(num > 0){
|
||||
takeAll.removeClass('disabled');
|
||||
canTakeSomething = true;
|
||||
} else {
|
||||
takeAll.addClass('disabled');
|
||||
}
|
||||
if(num < numLeft){
|
||||
takeAll.children('span').first().text(num);
|
||||
} else {
|
||||
takeAll.children('span').first().text(_('all'));
|
||||
}
|
||||
});
|
||||
if(canTakeSomething){
|
||||
takeETbutton.removeClass('disabled');
|
||||
} else {
|
||||
takeETbutton.addClass('disabled');
|
||||
}
|
||||
takeETbutton.data('canTakeEverything', (free >= 0) ? true : false);
|
||||
return takeETbutton;
|
||||
},
|
||||
|
||||
allowLeave: function(takeETbtn, leaveBtn){
|
||||
if(takeETbtn){
|
||||
if(leaveBtn){
|
||||
takeETbtn.data('leaveBtn', leaveBtn);
|
||||
}
|
||||
Events.canLeave(takeETbtn);
|
||||
}
|
||||
},
|
||||
|
||||
takeAllLoot: function(){
|
||||
|
||||
var stoppedEarly = false;
|
||||
$('#lootButtons')
|
||||
.children('.button')
|
||||
.each(function(){
|
||||
if( $(this).hasClass('take-all-button') ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var weight = $(this).data('numLeft') * Path.getWeight($(this).attr('id').substring(5).replace('-', ' '));
|
||||
while( $(this).data('numLeft') > 0 && weight < Path.getFreeSpace() ){
|
||||
$(this).click();
|
||||
}
|
||||
|
||||
if(weight > Path.getFreeSpace()){
|
||||
stoppedEarly = true;
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
if( !stoppedEarly ){
|
||||
|
||||
$('#leave').click();
|
||||
$('#leaveBtn').click();
|
||||
|
||||
canLeave: function(btn){
|
||||
var basetext = _('take everything');
|
||||
var textbox = btn.children('span');
|
||||
var takeAndLeave = (btn.data('leaveBtn')) ? btn.data('canTakeEverything') : false;
|
||||
if(takeAndLeave){
|
||||
textbox.text( basetext + _(' and ') + _('leave') );
|
||||
btn.data('canLeave', true);
|
||||
} else {
|
||||
textbox.text( basetext );
|
||||
btn.data('canLeave', false)
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
dropStuff: function(e) {
|
||||
e.stopPropagation();
|
||||
var btn = $(this);
|
||||
var target = btn.closest('.button');
|
||||
var thing = btn.data('thing');
|
||||
var id = 'take_' + thing.replace(' ', '-');
|
||||
var num = btn.data('num');
|
||||
var lootButtons = $('#lootButtons');
|
||||
Engine.log('dropping ' + num + ' ' + thing);
|
||||
|
||||
var lootBtn = $('#loot_' + thing.replace(' ', '-'), lootButtons);
|
||||
var lootBtn = $('#' + id, lootButtons);
|
||||
if(lootBtn.length > 0) {
|
||||
var curNum = lootBtn.data('numLeft');
|
||||
curNum += num;
|
||||
lootBtn.text(_(thing) + ' [' + curNum + ']').data('numLeft', curNum);
|
||||
} else {
|
||||
new Button.Button({
|
||||
id: 'loot_' + thing.replace(' ', '-'),
|
||||
text: _(thing) + ' [' + num + ']',
|
||||
click: Events.getLoot
|
||||
}).data('numLeft', num).insertBefore($('.clear', lootButtons));
|
||||
var lootRow = Events.drawLootRow(thing, num);
|
||||
lootRow.insertBefore($('.takeETrow', lootButtons));
|
||||
}
|
||||
Path.outfit[thing] -= num;
|
||||
Events.getLoot(btn.closest('.button'));
|
||||
Events.getLoot(target);
|
||||
World.updateSupplies();
|
||||
},
|
||||
|
||||
getLoot: function(btn) {
|
||||
getLoot: function(btn, skipButtonSet) {
|
||||
var name = btn.attr('id').substring(5).replace('-', ' ');
|
||||
if(btn.data('numLeft') > 0) {
|
||||
var skipButtonSet = skipButtonSet || false;
|
||||
var weight = Path.getWeight(name);
|
||||
var freeSpace = Path.getFreeSpace();
|
||||
if(weight <= freeSpace) {
|
||||
var num = btn.data('numLeft');
|
||||
num--;
|
||||
btn.data('numLeft', num);
|
||||
// #dropMenu gets removed by this.
|
||||
btn.text(_(name) + ' [' + num + ']');
|
||||
if(num === 0) {
|
||||
Button.setDisabled(btn);
|
||||
btn.animate({'opacity':0}, 300, 'linear', function() {
|
||||
$(this).remove();
|
||||
$(this).parent().remove();
|
||||
if($('#lootButtons').children().length == 1) {
|
||||
$('#lootButtons').remove();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// #dropMenu gets removed by this.
|
||||
btn.text(_(name) + ' [' + num + ']');
|
||||
}
|
||||
var curNum = Path.outfit[name];
|
||||
curNum = typeof curNum == 'number' ? curNum : 0;
|
||||
@@ -599,39 +709,33 @@ var Events = {
|
||||
Path.outfit[name] = curNum;
|
||||
World.updateSupplies();
|
||||
|
||||
// Update weight and free space variables so we can decide
|
||||
// whether or not to bring up/update the drop menu.
|
||||
weight = Path.getWeight(name);
|
||||
freeSpace = Path.getFreeSpace();
|
||||
}
|
||||
|
||||
if(weight > freeSpace && btn.data('numLeft') > 0) {
|
||||
// Draw the drop menu
|
||||
Engine.log('drop menu');
|
||||
$('#dropMenu').remove();
|
||||
var dropMenu = $('<div>').attr('id', 'dropMenu');
|
||||
for(var k in Path.outfit) {
|
||||
var itemWeight = Path.getWeight(k);
|
||||
if(itemWeight > 0) {
|
||||
var numToDrop = Math.ceil((weight - freeSpace) / itemWeight);
|
||||
if(numToDrop > Path.outfit[k]) {
|
||||
numToDrop = Path.outfit[k];
|
||||
}
|
||||
if(numToDrop > 0) {
|
||||
var dropRow = $('<div>').attr('id', 'drop_' + k.replace(' ', '-'))
|
||||
.text(_(k) + ' x' + numToDrop)
|
||||
.data('thing', k)
|
||||
.data('num', numToDrop)
|
||||
.click(Events.dropStuff);
|
||||
dropRow.appendTo(dropMenu);
|
||||
}
|
||||
}
|
||||
if(!skipButtonSet){
|
||||
Events.setTakeAll();
|
||||
}
|
||||
dropMenu.appendTo(btn);
|
||||
btn.one("mouseleave", function() {
|
||||
$('#dropMenu').remove();
|
||||
});
|
||||
}
|
||||
if(!skipButtonSet){
|
||||
Events.drawDrop(btn);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
takeAll: function(btn){
|
||||
var target = $('#'+ btn.attr('id').substring(4));
|
||||
for(var k = 0; k < btn.data('numLeft'); k++){
|
||||
Events.getLoot(target, true);
|
||||
}
|
||||
Events.setTakeAll();
|
||||
},
|
||||
|
||||
takeEverything: function(btn){
|
||||
$('#lootButtons').children('.lootRow').each(function(i){
|
||||
var target = $(this).children('.lootTakeAll').first();
|
||||
if(!target.hasClass('disabled')){
|
||||
Events.takeAll(target);
|
||||
}
|
||||
});
|
||||
if(btn.data('canLeave')){
|
||||
btn.data('leaveBtn').click();
|
||||
}
|
||||
},
|
||||
|
||||
@@ -648,6 +752,7 @@ var Events = {
|
||||
startStory: function(scene) {
|
||||
// Write the text
|
||||
var desc = $('#description', Events.eventPanel());
|
||||
var leaveBtn = false;
|
||||
for(var i in scene.text) {
|
||||
$('<div>').text(scene.text[i]).appendTo(desc);
|
||||
}
|
||||
@@ -662,15 +767,18 @@ var Events = {
|
||||
|
||||
// Draw any loot
|
||||
if(scene.loot) {
|
||||
Events.drawLoot(scene.loot);
|
||||
var takeETbtn = Events.drawLoot(scene.loot);
|
||||
}
|
||||
|
||||
// Draw the buttons
|
||||
Events.drawButtons(scene);
|
||||
leaveBtn = Events.drawButtons(scene);
|
||||
|
||||
Events.allowLeave(takeETbtn, leaveBtn);
|
||||
},
|
||||
|
||||
drawButtons: function(scene) {
|
||||
var btns = $('#buttons', Events.eventPanel());
|
||||
var btnsList = [];
|
||||
for(var id in scene.buttons) {
|
||||
var info = scene.buttons[id];
|
||||
var b = new Button.Button({
|
||||
@@ -686,9 +794,11 @@ var Events = {
|
||||
if(typeof info.cooldown == 'number') {
|
||||
Button.cooldown(b);
|
||||
}
|
||||
btnsList.push(b);
|
||||
}
|
||||
|
||||
Events.updateButtons();
|
||||
return (btnsList.length == 1) ? btnsList[0] : false;
|
||||
},
|
||||
|
||||
updateButtons: function() {
|
||||
|
||||
Reference in New Issue
Block a user