Comparing version 0.0.3 to 0.0.4
@@ -7,3 +7,3 @@ /** | ||
* @license MIT License - See file 'LICENSE' in this project. | ||
* @version 0.0.3 | ||
* @version 0.0.4 | ||
*/ | ||
@@ -17,2 +17,3 @@ 'use strict'; | ||
var tokenizer = new natural.WordTokenizer(); | ||
var Parser = require('./parser'); | ||
@@ -214,16 +215,24 @@ var advtxt = {}; | ||
var self = this; | ||
command.command = tokenizer.tokenize(command.command.toLowerCase()); | ||
var parser = new Parser(command); | ||
if (!parser.fail) { | ||
command.command = parser.command; | ||
} | ||
else { | ||
command.reply(__.i18n("I don't know what you mean.")); | ||
} | ||
// make things less verbose | ||
var verb = command.command[0]; | ||
var obj = command.command[1]; | ||
var verb = command.command.verb; | ||
var object = command.command.object; | ||
var player = command.player; | ||
var room = player.room; | ||
var commands = parser.commands; | ||
// we need to check for reset commands first, so we don't ignore them from a | ||
// dead player | ||
if (verb === i18n.__('reset') && typeof obj === 'undefined') { | ||
if (verb === commands.RESET && object === '') { | ||
self.resetPlayer(command, false); | ||
} | ||
else if (verb === i18n.__('reset') && obj === i18n.__('all')) { | ||
else if (verb === commands.RESET && object === i18n.__('all')) { | ||
self.resetPlayer(command, true); | ||
@@ -234,10 +243,10 @@ } | ||
} | ||
else if (verb === i18n.__('get')) { | ||
else if (verb === commands.GET) { | ||
// would try to get an item | ||
if (typeof room.items[obj] !== 'undefined') { | ||
var available = room.items[obj].available(player); | ||
if (typeof room.items[object] !== 'undefined') { | ||
var available = room.items[object].available(player); | ||
if (available === true) { | ||
// that item was available. get the item | ||
player.items[obj] = room.items[obj].name; | ||
command.reply(room.items[obj].get(player)); | ||
player.items[object] = room.items[object].name; | ||
command.reply(room.items[object].get(player)); | ||
// update the player | ||
@@ -253,14 +262,14 @@ self.updatePlayerItems(command, self.finalize.bind(self)); | ||
else { | ||
command.reply(i18n.__('You can\'t find a "%s" in this room!', obj)); | ||
command.reply(i18n.__('You can\'t find a "%s" in this room!', object)); | ||
} | ||
} | ||
else if (verb === i18n.__('go')) { | ||
else if (verb === commands.GO) { | ||
// would try to move in a direction | ||
if (typeof room.exits[obj] !== 'undefined') { | ||
var available = room.exits[obj].available(player); | ||
if (typeof room.exits[object] !== 'undefined') { | ||
var available = room.exits[object].available(player); | ||
if (available === true) { | ||
// that direction was available, play the "go" message, then move them | ||
command.reply(room.exits[obj].go(player)); | ||
command.reply(room.exits[object].go(player)); | ||
// move the player | ||
self.movePlayer(command, obj); | ||
self.movePlayer(command, object); | ||
} | ||
@@ -275,3 +284,3 @@ // that direction wasn't available; give the reason | ||
// TODO give customized replies for actual directions | ||
command.reply(i18n.__('You can\'t go "%s", it just doesn\'t work.', obj)); | ||
command.reply(i18n.__('You can\'t go "%s", it just doesn\'t work.', object)); | ||
} | ||
@@ -284,3 +293,3 @@ } | ||
// if they asked for the exits, list them | ||
else if (verb === i18n.__('exits')) { | ||
else if (verb === commands.EXITS) { | ||
var exits = []; | ||
@@ -287,0 +296,0 @@ for (var key in room.exits) { |
{ | ||
"name": "advtxt", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "main": "index", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19930
8
508