// step.js
(function () {
/*global adventurejs A*/
"use strict";
/**
* @augments {adventurejs.Verb}
* @class step
* @ajsnode game.dictionary.verbs.step
* @ajsconstruct MyGame.createVerb({ "name": "step", [...] });
* @ajsconstructedby adventurejs.Dictionary#createVerb
* @hideconstructor
* @ajsinstanceof Verb
* @ajsnavheading LocomotionVerbs
* @summary Verb meaning step, as in "step on ant" or "step over threshold".
* @tutorial Scripting_VerbSubscriptions
* @tutorial Verbs_VerbAnatomy
* @tutorial Verbs_VerbProcess
* @tutorial Verbs_ModifyVerbs
* @tutorial Verbs_WriteVerbs
* @classdesc
* <pre class="display border outline">
* <span class="input">> step over threshold</span>
* You step over the threshold, carrying your new bride, careful to
* avoid tripping over your own comically large feet. Your bride runs
* her gloved hand through your rainbow colored perm, tickling your nose
* with her colorful yellow and fuscia frill. She raises her head for
* a kiss, and you mash your brightly painted red lips into hers,
* commingling both your makeups into smears of red and white pancake.
* You part breathlessly, and she honks your foam nose in connubial bliss.
* </pre>
* <p>
* See
* <a href="/doc/Scripting_VerbPhases.html">Verb Phases</a>
* to learn how to customize this verb.
* </p>
* @ajsverbreactions
* @ajsverbphases doBeforeTry, doAfterTry, doBeforeSuccess, doAfterSuccess
*/
A.Preverbs.step = {
name: "step",
prettyname: "step",
past_tense: "stepped",
synonyms: ["step"],
player_must_be: {
not_constrained: true,
not_on_floor: true,
not_nested_elsewhere: true,
},
/**
* @memberof step
* @ajsverbphrase
* phrase1:
* {
* accepts_noun:true,
* noun_must_be:
* {
* known: true,
* matter: true,
* present_if_tangible: true,
* reachable_if_tangible: true,
* visible: true,
* not_worn: true,
* not_in_inventory: true,
* },
* accepts_preposition: true,
* requires_preposition: true,
* },
*/
phrase1: {
accepts_noun: true,
noun_must_be: {
known: true,
matter: true,
present_if_tangible: true,
reachable_if_tangible: true,
visible: true,
not_worn: true,
not_in_inventory: true,
},
accepts_preposition: true,
requires_preposition: true,
},
/**
* @memberof step
* @ajsverbparams
* with_params: {},
*/
with_params: {},
doTry: function () {
var input = this.game.getInput();
var direct_object = input.getAsset(1);
var direct_preposition = input.getPreposition(1);
var input = this.game.getInput();
var player = this.game.getPlayer();
var msg = "";
var containers;
if (!direct_object) {
this.game.debug(`F1648 | ${this.name}.js | no direct object `);
msg += `$(We) step. `;
this.handleFailure(msg);
return null;
}
// this can be a travel verb - is noun a direction?
if (direct_object.direction) {
if (
!direct_preposition ||
"through" === direct_preposition ||
"in" === direct_preposition
) {
this.game.debug(
`F1416 | ${this.name}.js | tryTravel ${direct_object.direction} `
);
this.game.tryTravel(direct_object.direction);
return null;
}
}
// no preposition
if (!direct_preposition) {
this.game.debug(`F1644 | ${this.name}.js | preposition required `);
msg += this.game.parser.getUnparsedMessage(input.input);
this.handleFailure(msg);
return null;
}
// did player input something like "step on sand" ?
// if so it must come from a substance container that
// is a reachable substance body
if (direct_object instanceof adventurejs.Substance) {
// get a list of available bodies of substance
containers = this.game.findSubstanceContainers(direct_object.id, [
"Present",
"Known",
"Visible",
"BodyOfSubstance",
]);
console.warn("containers", containers);
switch (containers.length) {
case 0:
this.game.debug(`F1649 | ${this.name}.js | no valid vessel found `);
msg += `There doesn't appear to be any ${
this.game.getAsset(direct_object.id).name
} to step ${direct_preposition}. `;
this.handleFailure(msg);
return null;
case 1:
// set container as direct_object
// and treat like "step in container"
direct_object = this.game.getAsset(containers[0]);
input.setAsset(1, direct_object);
if (direct_object.id === this.game.getCurrentRoom().id) {
this.game.debug(
`F1651 | ${this.name}.js | ${direct_object.id} is current room `
);
msg += `$(We're) standing in it. `;
this.handleFailure(msg);
return null;
}
break;
default:
this.game.debug(
`F1650 | ${this.name}.js | multiple containers found, disambiguate `
);
// disambiguate - need to set parsedNoun.matches
// save containers back to input for next turn disambiguation
input.setParsedNounMatchesQualified(1, containers);
this.game.parser.printNounDisambiguation({
parsedNoun: input.getParsedNoun(1),
nounIndex: 1,
});
return null;
} // switch containers.length
} // direct_object is substance
// did player mean to stand on the thing?
if (
direct_preposition === "on" &&
direct_object.quirks.step_on_means_stand_on
) {
this.game.debug(`F1645 | ${this.name}.js | doVerb stand `);
this.game.dictionary.doVerb("stand");
return null;
}
// did player input something like "step in tub" ?
// let them go
if (
direct_object.hasAspectAt(direct_preposition) &&
direct_object.getAspectAt(direct_preposition).player.can.enter
) {
this.game.debug(`F1646 | ${this.name}.js | doVerb go `);
input.setVerb("go");
this.game.dictionary.doVerb("go");
return null;
}
// did player input something like "step in tub" ?
// let them go
if (
direct_object.hasAspectAt(direct_preposition) &&
!direct_object.getAspectAt(direct_preposition).player.can.enter
) {
this.game.debug(`F1417 | ${this.name}.js | doVerb go `);
msg += `$(We) can't step ${direct_preposition} ${direct_object.articlename}. `;
this.handleFailure(msg);
return null;
}
// did player input something like "step in tub" ?
// but can't go in tub?
if (
"on" !== direct_preposition &&
(!direct_object.hasAspectAt(direct_preposition) ||
!direct_object.aspects[direct_preposition].player.can.enter)
) {
this.game.debug(`F1647 | ${this.name}.js | doVerb go `);
msg += `$(We) can't step ${direct_preposition} ${direct_object.articlename}. `;
this.handleFailure(msg);
return null;
}
if (
direct_object.getPlaceAssetId() !== player.getPlaceAssetId() &&
direct_object.getPlaceAssetId() !== player.getNestId()
) {
this.game.debug(
`F1652 | ${this.name}.js | ${
direct_object.id
} is ${direct_object.getPlacePreposition()} ${direct_object.getPlaceAssetId()} and player is ${player.getPlacePreposition()} ${player.getPlaceAssetId()}`
);
msg += `$(We) can't step ${direct_preposition} ${
direct_object.articlename
} ${direct_object.getPlacePreposition()} ${
direct_object.getPlaceAsset().articlename
}. `;
this.handleFailure(msg);
return null;
}
return true;
},
doSuccess: function () {
var input = this.game.getInput();
var direct_object = input.getAsset(1);
var direct_preposition = input.getPreposition(1);
var indirect_object = input.getAsset(2);
var indirect_preposition = input.getPreposition(2);
var player = this.game.getPlayer();
var results;
var msg = "";
this.game.debug(`F1418 | ${this.name}.js | print doSuccess `);
msg += `$(We) step ${direct_preposition} ${direct_object.articlename}. `;
// print output
this.handleSuccess(msg, direct_object);
return true;
},
}; // END step
})();