From 20b8497fa536031fa2e8797384b81bfd488f1e90 Mon Sep 17 00:00:00 2001 From: Rocky Bevins Date: Wed, 20 Jul 2016 21:44:34 -0400 Subject: [PATCH] drop bug fixed added drop events for items and rooms --- areas/midgaard.js | 5 ++- src/commands.js | 91 ++++++++++++++++++++++++++++++++--------------- 2 files changed, 66 insertions(+), 30 deletions(-) diff --git a/areas/midgaard.js b/areas/midgaard.js index 0e55e0a..83635b3 100644 --- a/areas/midgaard.js +++ b/areas/midgaard.js @@ -169,7 +169,10 @@ module.exports = { "lightDecay": 10, "flickerMsg": '', "extinguishMsg": '', - "flags": [] + "flags": [], + "beforeDrop": function(item, roomObj) { + return true; + } }, { "name": "Small Buckler", "short": "a small round buckler", diff --git a/src/commands.js b/src/commands.js index 2cbff68..7479f04 100644 --- a/src/commands.js +++ b/src/commands.js @@ -32,36 +32,46 @@ Cmd.prototype.buy = function(target, command) { canBuy = merchant.beforeSell(target, roomObj); } - item = Character.getItem(merchant, command); - - if (item) { - if (item.worth <= target.gold) { - target.gold -= item.worth; - merchant.gold += item.worth; + if (canBuy) { + item = Character.getItem(merchant, command); + + if (item) { + if (item.worth <= target.gold) { + target.gold -= item.worth; + merchant.gold += item.worth; - Character.removeItem(merchant, item); + Character.removeItem(merchant, item); - Character.addItem(target, item); + Character.addItem(target, item); - World.msgPlayer(target, { - msg: 'You buy something.' - }); + World.msgPlayer(target, { + msg: 'You buy ' + item.short + }); + + if (merchant.onSell) { + merchant.onSell(target, roomObj); + } + } else { + World.msgPlayer(target, { + msg: 'You do not enough gold.', + styleClass: 'yellow' + }); + } } else { World.msgPlayer(target, { - msg: 'Not enough Gold.', - styleClass: 'yellow' + msg: 'Should probably recheck the name again, this isn\'t registering with the merchant.' }); } - } else { - World.msgPlayer(target, { - msg: 'Should probably recheck the name again, this isn\'t registering with the merchant.' - }); } } else { - + World.msgPlayer(target, { + msg: 'There doesn\'t seem to be anyone selling anything here.' + }); } } else { - + World.msgPlayer(target, { + msg: 'Wake up first.' + }); } }; @@ -926,19 +936,30 @@ Cmd.prototype.drop = function(target, command, fn) { i = 0, itemLen, itemArr, + canDrop = true, item; if (target.position !== 'sleeping') { if (command.msg !== '' && target.items.length !== 0) { roomObj = World.getRoomObject(target.area, target.roomid); - + if (command.msg !== 'all') { item = World.search(target.items, command); if (item && !item.equipped) { - Character.removeItem(target, item); + if (item.beforeDrop) { + canDrop = item.beforeDrop(target, roomObj); + } + + if (canDrop) { + if (roomObj.beforeDrop) { + canDrop = roomObj.beforeDrop(target, item); + } + } + + if (canDrop) { + Character.removeItem(target, item); - if (item) { Room.addItem(roomObj, item); World.msgRoom(roomObj, { @@ -948,17 +969,29 @@ Cmd.prototype.drop = function(target, command, fn) { }); World.msgPlayer(target, { - msg: 'You drop a ' + item.short, + msg: 'You drop ' + item.short, styleClass: 'cmd-drop blue' }); - } else { - World.msgPlayer(target, {msg: 'Could not drop ' + item.short, styleClass: 'error'}); + + if (item.onDrop) { + item.onDrop(target, roomObj); + } + + if (roomObj.onDrop) { + roomObj.onDrop(target, item); + } } } else { - if (item && !item.equipped) { - World.msgPlayer(target, {msg: 'You do not have that item.', styleClass: 'error'}); + if (!item) { + World.msgPlayer(target, { + msg: 'You do not have that item.', + styleClass: 'error' + }); } else { - World.msgPlayer(target, {msg: 'You must remove ' + item.short + ' before you can drop it.', styleClass: 'error'}); + World.msgPlayer(target, { + msg: 'You must remove ' + item.short + ' before you can drop it.', + styleClass: 'error' + }); } } } else { @@ -991,7 +1024,7 @@ Cmd.prototype.drop = function(target, command, fn) { } } } else { - World.msgPlayer(target, {msg: 'Drop nothing? How do you drop nothing?', styleClass: 'error'}); + World.msgPlayer(target, {msg: 'You aren\'t carrying anything.', styleClass: 'error'}); } } else { World.msgPlayer(target, {msg: 'You are sleeping at the moment.', styleClass: 'error'});