// verifySentenceStructure.js
(function () {
/*global adventurejs A*/
"use strict";
var p = adventurejs.Parser.prototype;
/**
* Verify that the active verb accepts the sentence structure.
* @memberOf adventurejs.Parser
* @method adventurejs.Parser#verifySentenceStructure
* @param {Object} input A reference to the current turn's input object.
* @param {Object} this_turn A reference to the current turn's input object.
*/
p.verifySentenceStructure = function Parser_verifySentenceStructure() {
var this_turn = this.input_history[0];
this.game.log(
"log",
"high",
"verifySentenceStructure.js > " + this_turn.verified_sentence_structure,
"Parser"
);
let verb_name = this_turn.getVerb(1);
if (
verb_name &&
this.game.dictionary.verbs[verb_name] &&
this.game.dictionary.verbs[verb_name].accepts_structures.length
) {
var verb = this.game.dictionary.verbs[verb_name];
var valid = verb.accepts_structures;
var structure = this_turn.verified_sentence_structure;
var found = false;
for (var j = 0; j < valid.length; j++) {
if (valid[j] === structure) {
found = true;
break;
}
}
if (!found) {
let msg = "";
msg += this.getUnparsedMessage(this_turn.input);
this.game.debug(
`F1199 | verifySentenceStructure.js | ${verb_name} doesn't accept structure > ${this_turn.verified_sentence_structure} `
);
this.game.print(msg);
return false;
}
}
return true;
}; // verifySentenceStructure
})();