(function () {
var p = adventurejs.Parser.prototype;
p.handleWord = function Parser_handleWord() {
this.game.log(
"L1211",
"log",
"high",
"handleWord.js > Begin parse.",
"Parser"
);
var this_turn = this.input_history[0];
var one_word = this_turn.found_word;
var parsed_noun, verb_name;
var last_turn = this.input_history[1];
var number = Number(one_word);
var msg = "";
var found_match = false;
if (last_turn.soft_prompt.noun) parsed_noun = this.parseNoun(one_word);
for (let i = 1; i <= 3; i++) {
if (
last_turn.soft_prompt["preposition" + i] &&
this.game.dictionary.isPreposition(one_word)
) {
this_turn.verified_sentence_structure =
last_turn.soft_prompt.structure ||
last_turn.verified_sentence_structure;
this_turn.input_verb =
last_turn.soft_prompt.input_verb || last_turn.input_verb;
this_turn.verb_phrase =
last_turn.soft_prompt.verb_phrase || last_turn.verb_phrase;
this_turn.soft_prompt.satisfied = true;
this_turn.setOneWord({ ["preposition" + i]: one_word });
this.game.log(
"L1212",
"log",
"high",
`handleWord.js > last turn soft prompted for preposition${i} and ${one_word} recognized as preposition`,
"Parser"
);
return this.handleSentence();
}
}
verb_name = this.parseVerb(one_word);
this.game.log(
"L1213",
"log",
"high",
`handleWord.js > ${verb_name} `,
"Parser"
);
if (
verb_name &&
last_turn.soft_prompt.noun1 &&
this.game.dictionary.verbs[verb_name].type.direction
) {
this.game.log(
"L1214",
"log",
"high",
`handleWord.js > soft_prompt received ${one_word} which is direction+noun and satisfies ${last_turn.input_verb}`,
"Parser"
);
this_turn.setOneWord({ noun1: verb_name });
this_turn.input_verb =
last_turn.soft_prompt.input_verb || last_turn.input_verb;
this_turn.verb_phrase =
last_turn.soft_prompt.verb_phrase || last_turn.verb_phrase;
if (last_turn.soft_prompt.verb) {
this_turn.setOneWord({ verb: last_turn.soft_prompt.verb });
}
this.game.log(
"L1215",
"log",
"high",
`handleWord.js > handle soft prompt for noun1`,
"Parser"
);
this_turn.verified_sentence_structure =
last_turn.soft_prompt.structure ||
last_turn.verified_sentence_structure;
this_turn.soft_prompt.satisfied = true;
return this.handleSentence();
}
if (verb_name && !(parsed_noun && parsed_noun.matches.all.length)) {
let verb = this.qualifyParsedVerb({
parsed_verb_name: verb_name,
});
if (!verb) return false;
if (-1 === verb.accepts_structures.indexOf("verb")) {
this.game.debug(
`D1052 | handleWord.js | ${verb_name} doesn't accept structure > verb `
);
msg += `${verb.type.travel ? "Where" : "What"} did $(we) want to ${
verb.prettyname
}? `;
msg = msg || verb.msgNoObject;
this_turn.setSoftPrompt({
index: 1,
type: "noun",
verb: verb.name,
noun1: true,
structure: "verb noun",
});
this.game.print(msg, this_turn.output_class);
return false;
}
this_turn.setVerb(1, verb_name);
this_turn.setStructure("verb");
this.game.log(
"L1216",
"log",
"high",
`handleWord.js > ${verb_name} recognized as verb`,
"Parser"
);
this.game.dictionary.doVerb(verb_name);
return true;
}
if (Number.isInteger(number) && last_turn.disambiguate.index) {
this.game.display.appendClassesToLastInput("integer");
one_word = last_turn.getParsedNoun(last_turn.disambiguate.index).matches
.qualified[number - 1];
if (!one_word) {
this.game.debug(
`D1555 | handleWord.js | ${number} is not a valid choice`
);
msg += number + " doesn't seem to make sense. ";
if (msg) this.game.print(msg, this_turn.output_class);
return false;
}
found_match = one_word;
parsed_noun = new adventurejs.ParsedNoun(this.game.getAsset(one_word));
} else {
parsed_noun = this.parseNoun(one_word);
}
if (!parsed_noun.matches.all.length) {
this.game.log(
"L1217",
"log",
"high",
`handleWord.js > no matching key found in world_lookup `,
"Parser"
);
msg += this.game.settings.getUnparsedMessage(one_word);
this.game.print(msg, this_turn.output_class);
return false;
}
if (last_turn.disambiguate.enabled) {
this.game.log(
"L1218",
"log",
"high",
`handleWord.js > handle noun disambiguation`,
"Parser"
);
if (!found_match) {
found_match = this.findMatchIn(
parsed_noun.matches.qualified,
last_turn["parsedNoun" + last_turn.disambiguate.index].matches
.qualified
);
}
if (found_match) {
this_turn.verified_sentence_structure =
last_turn.verified_sentence_structure;
this_turn.strings = last_turn.strings;
let type = last_turn.disambiguate.container ? "container" : "noun";
this_turn.setOneWord({
[type + last_turn.disambiguate.index]: found_match,
[`parsedNoun${last_turn.disambiguate.index}`]: parsed_noun,
});
this_turn.input_verb = last_turn.input_verb;
this_turn.verb_phrase = last_turn.verb_phrase;
this.game.log(
"L1219",
"log",
"high",
`handleWord.js > disambiguate found_match ${found_match} `,
"Parser"
);
return this.handleSentence();
} else {
this.game.debug(`D1556 | handleWord.js | disambiguation failed`);
msg += `${number} doesn't seem to make sense. `;
if (msg) this.game.print(msg, this_turn.output_class);
return false;
}
}
if (last_turn.soft_prompt.enabled) {
this.game.log(
"L1220",
"log",
"high",
`handleWord.js > soft_prompt received ${one_word}`,
"Parser"
);
let p = last_turn.soft_prompt;
let found = p.noun1
? "noun1"
: p.noun2
? "noun2"
: p.noun3
? "noun3"
: p.container1
? "container1"
: p.container2
? "container2"
: p.container3
? "container3"
: p.preposition1
? "preposition1"
: p.preposition2
? "preposition2"
: p.preposition3
? "preposition3"
: false;
if (found) this_turn.setOneWord({ [found]: one_word });
this_turn.input_verb =
last_turn.soft_prompt.input_verb || last_turn.input_verb;
this_turn.verb_phrase =
last_turn.soft_prompt.verb_phrase || last_turn.verb_phrase;
if (last_turn.soft_prompt.verb) {
this_turn.setOneWord({ verb: last_turn.soft_prompt.verb });
}
this.game.log(
"L1221",
"log",
"high",
"handleWord.js > handle soft prompt for " + found,
"Parser"
);
this_turn.verified_sentence_structure =
last_turn.soft_prompt.structure ||
last_turn.verified_sentence_structure;
this_turn.soft_prompt.satisfied = true;
return this.handleSentence();
}
if (parsed_noun.object_id === "global_string") {
this.game.log(
"L1222",
"log",
"high",
`handleWord.js > received string`,
"Parser"
);
msg += this_turn.strings.toString() + "...?";
this.game.print(msg, this_turn.output_class);
return;
}
if (this.game.settings.if_input_is_an_asset_name_examine_it) {
this.game.log(
"L1223",
"log",
"high",
"handleWord.js > if_input_is_an_asset_name_examine_it",
"Parser"
);
parsed_noun = this.qualifyParsedNoun({
parsedNoun: parsed_noun,
parsedVerb: "examine",
nounIndex: "1",
});
if (false === parsed_noun) {
return false;
} else {
if (1 === parsed_noun.matches.qualified.length) {
this_turn.setParsedNoun(1, parsed_noun);
this.game.dictionary.doVerb("examine");
return;
}
}
}
msg += this.game.settings.getUnparsedMessage(one_word);
this.game.print(msg, this_turn.output_class);
return false;
};
})();