// touch.js
(function () {
/*global adventurejs A*/
"use strict";
/**
* @augments {adventurejs.Verb}
* @class touch
* @ajsnode game.dictionary.verbs.touch
* @ajsconstruct MyGame.createVerb({ "name": "touch", [...] });
* @ajsconstructedby adventurejs.Dictionary#createVerb
* @hideconstructor
* @ajsinstanceof Verb
* @ajsnavheading SensationVerbs
* @summary Verb meaning touch, as in "touch blob of jelly".
* @tutorial Scripting_VerbSubscriptions
* @tutorial Verbs_VerbAnatomy
* @tutorial Verbs_VerbProcess
* @tutorial Verbs_ModifyVerbs
* @tutorial Verbs_WriteVerbs
* @classdesc
* <pre class="display border outline">
* <span class="input">> touch blob</span>
* You touch the blob. Ew, it's squishy! Oh! And it sticks! In fact,
* you can't get it off your finger. Oh, uh, and it's starting to burn.
* You shake your hand in a panic. Not only is the blob not dislodged,
* but it advances further up your finger, increasing the burning sensation.
* </pre>
* <p>
* <strong>Touch</strong> a
* {@link adventurejs.Tangible|Tangible}
* {@link adventurejs.Asset|Asset}.
* Requires that the Asset to be touched has
* asset.dov.touch.enabled
* set to true. If successful, returns the Asset's
* <code class="property">descriptions.touch</code> property.
* </p>
* @ajsverbreactions
* @ajsverbphases doBeforeTry, doAfterTry, doBeforeSuccess, doAfterSuccess
*/
A.Preverbs.touch = {
name: "touch",
prettyname: "touch",
past_tense: "touched",
synonyms: ["touch", "feel"],
/**
* @ajsverbstructures
* @memberof touch
*/
accepts_structures: ["verb noun", "verb noun preposition noun"],
/**
* @memberof touch
* @ajsverbphrase
* phrase1:
* {
* accepts_noun: true,
* requires_noun: true,
* noun_must_be:
* {
* known: true,
* matter: true,
* present_if_tangible: true,
* reachable_if_tangible: true,
* },
* },
*/
phrase1: {
accepts_noun: true,
requires_noun: true,
noun_must_be: {
known: true,
matter: true,
present_if_tangible: true,
reachable_if_tangible: true,
},
},
/**
* @memberof touch
* @ajsverbphrase
* phrase2:
* {
* accepts_noun: true,
* noun_must_be:
* {
* known: true,
* matter: true,
* present_if_tangible: true,
* reachable_if_tangible: true,
* },
* accepts_preposition: true,
* requires_preposition: true,
* },
*/
phrase2: {
accepts_noun: true,
noun_must_be: {
known: true,
matter: true,
present_if_tangible: true,
reachable_if_tangible: true,
},
accepts_preposition: true,
requires_preposition: true,
},
/**
* @memberof touch
* @ajsverbparams
* with_params: {},
*/
with_params: {},
doTry: function () {
var input = this.game.getInput();
var player = this.game.getPlayer();
var output_class = input.output_class;
var direct_object = input.getAsset(1);
var indirect_preposition = input.getPreposition(2);
var indirect_object = input.getAsset(2);
var currentRoom = this.game.getCurrentRoom();
var direct_substance;
var indirect_substance;
var results;
var msg = "";
direct_substance = direct_object instanceof adventurejs.Substance;
// parsed sentence structure: verb
if (input.hasStructure("verb")) {
}
// parsed sentence structure: verb noun
if (input.hasStructure("verb noun")) {
} // verb noun
// parsed sentence structure: verb noun
if (input.hasStructure("verb noun preposition noun")) {
indirect_substance = indirect_object instanceof adventurejs.Substance;
} // verb noun
if (!direct_object && input.input_verb === "feel") {
if (currentRoom.hasDescription("feel")) {
input.setAsset(1, currentRoom);
input.verb_params.source = currentRoom.descriptions.feel;
return true;
}
}
if (indirect_object) {
// did player try something like "touch sand in water" ?
// we don't handle it
if (direct_substance && indirect_substance) {
this.game.debug(
`F1641 | ${this.name}.js | both items are substances `
);
msg += `$(We) can't touch ${direct_object.name} ${indirect_preposition} ${indirect_object.name}. `;
this.handleFailure(msg);
return null;
}
if (
direct_substance &&
(!indirect_object.hasAspectAt(indirect_preposition) ||
indirect_object.getAspectAt(indirect_preposition).vessel
.substance_id !== direct_object.id)
) {
this.game.debug(
`F1643 | ${this.name}.js | ${indirect_object.id} does not contain ${direct_object.id} `
);
msg += `${indirect_object.Articlename} doesn't contain ${direct_object.name}. `;
this.handleFailure(msg);
return null;
}
// did player try to touch something in a non-existent aspect?
if (
!indirect_substance &&
!indirect_object.hasAspectAt(indirect_preposition)
) {
this.game.debug(
`F1639 | ${this.name}.js | ${indirect_object.id} has no aspect at ${indirect_preposition} `
);
msg += `There's nothing ${indirect_preposition} ${indirect_object.articlename}. `;
this.handleFailure(msg);
return null;
}
// did player try to touch something in a thing it's not in?
if (
!direct_substance &&
!indirect_substance &&
!direct_object.isIn(indirect_object)
) {
this.game.debug(
`F1640 | ${this.name}.js | ${direct_object.id} not in ${direct_object.id} `
);
msg += `${direct_object.Articlename} doesn't appear to be ${indirect_preposition} ${indirect_object.articlename}. `;
this.handleFailure(msg);
return null;
}
// did player try to touch something in a substance?
// like "touch toy in sand" ?
if (indirect_substance) {
// is direct_object inside an asset
// that also contains indirect_substance?
var daspect = direct_object.getPlaceAspect();
if (
!daspect ||
!daspect.vessel ||
daspect.vessel.substance_id !== indirect_object.id
) {
this.game.debug(
`F1642 | ${this.name}.js | ${direct_object.id} is not in something that contains ${indirect_object.id} `
);
msg += `${direct_object.Articlename} doesn't appear to be ${indirect_preposition} ${indirect_object.name}. `;
this.handleFailure(msg);
return null;
}
}
} // has indirect_object
if (!direct_object.isDOV("touch")) {
this.game.debug(
`F1452 | ${this.name}.js | ${direct_object.id}.dov.touch.enabled is false `
);
msg += `$(We) can't touch ${direct_object.articlename}. `;
this.handleFailure(msg);
return null;
}
if (!direct_object.hasDescription("touch")) {
this.game.debug(
`F1453 | ${this.name}.js | ${direct_object.id}.descriptions.touch is unset `
);
msg += `$(We) don't feel anything special. `;
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(`F1454 | ${this.name}.js | print doSuccess `);
// parsed sentence structure: verb
if (input.hasStructure("verb")) {
}
// parsed sentence structure: verb noun
if (input.hasStructure("verb noun")) {
} // verb noun
msg += `$(We) touch ${direct_object.articlename}. `;
if (input.verb_params.source) {
msg += A.getSAF.call(this.game, input.verb_params.source);
} else if (direct_object.hasDescription("touch")) {
msg += direct_object.getDescription("touch");
} else {
msg += `$(We) don't feel anything in particular. `;
}
// print output
this.handleSuccess(msg, direct_object);
return true;
},
};
})(); // touch