Skip to content

Commit

Permalink
drop bug fixed added drop events for items and rooms
Browse files Browse the repository at this point in the history
  • Loading branch information
MoreOutput committed Jul 21, 2016
1 parent 9b1e025 commit 20b8497
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 30 deletions.
5 changes: 4 additions & 1 deletion areas/midgaard.js
Expand Up @@ -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",
Expand Down
91 changes: 62 additions & 29 deletions src/commands.js
Expand Up @@ -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.'
});
}
};

Expand Down Expand Up @@ -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, {
Expand All @@ -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 {
Expand Down Expand Up @@ -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'});
Expand Down

0 comments on commit 20b8497

Please sign in to comment.