-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Description
While holding the frob, entering GIVE FROB (without an indirect object) will result in "There doesn't seem to be anything you might call 'frob' here."
I changed one line to add a check for when the length of npcs is 0:
new Cmd('Give', {
antiRegexes:[lang.regex.GiveTo],
matchItems:function(s) {
if (!this._test(s)) return
if (!this._testNot(s)) return
parser.msg("---------------------------------------------------------");
parser.msg("* Looking at candidate: " + this.name);
// this is a temporary set of data used while we parser one input
this.tmp.objectTexts = [],
this.tmp.objects = [],
this.tmp.score = this.score ? this.score : 10
this.tmp.error = undefined
let arr = this.tmp.regex.exec(s)
arr.shift() // first element is the whole match, so discard
const scope = world.scope
const npcs = scope.filter(el => (el.npc && el !== player))
const items = array.fromTokens(arr[0].split(' '), scope)
if (!items) return this.setError(parser.NO_OBJECT, lang.object_unknown_msg(arr[0]))
// The first item could be the NPC to give it to,
// and we want to pull that out.
// Disambiguation makes this tricky...
if (items[0].length === 1) {
// No need to disambig, only one item matched
if (items[0][0].npc) {
this.tmp.objects[1] = items[0]
items.shift()
this.tmp.objects[0] = items
}
else {
//if (npcs.length === 0) return this.setError(parser.NO_OBJECT, lang.object_unknown_msg(arr[0]))
if (npcs.length === 0 ) return this.setError(parser.NO_OBJECT, "There is no one here to give anything to.")
this.tmp.objects[1] = npcs
this.tmp.objects[0] = items
}
}
else {
// At least two items matched
// NPCs will take priority
const npcList = items[0].filter(el => el.npc)
if (npcList.length === 0) {
if (npcs.length === 0) return this.setError(parser.NO_OBJECT, lang.no_receiver)
this.tmp.objects[1] = npcs
this.tmp.objects[0] = items
}
else if (npcList.length === 1) {
this.tmp.objects[1] = [npcList[0]]
items.shift()
this.tmp.objects[0] = items
}
else {
this.tmp.objects[1] = [npcList]
items.shift()
this.tmp.objects[0] = items
}
}
// pre-disambig items in this.tmp.objects[0]
for (let i = 0; i < this.tmp.objects[0].length; i++) {
const el = this.tmp.objects[0][i]
if (el.length === 1) {
this.tmp.objects[0][i] = el[0]
}
else {
const held = el.filter(el => el.loc === player.name)
if (held.length === 1) {
this.tmp.objects[0][i] = held[0]
}
else if (held.length > 1) {
this.tmp.objects[0][i] = held
}
// otherwise, stick we hat we have
}
}
this.tmp.score = 10
parser.msg("..Base score: " + this.tmp.score)
},
script:function(objects) {
return handleGiveToNpc(player, objects)
},
})Metadata
Metadata
Assignees
Labels
No labels