// swing_from_to_on.js
(function () {
/*global adventurejs A*/
/**
* @augments {adventurejs.Verb}
* @class swing_from_to_on
* @ajsnode game.dictionary.verbs.swing_from_to_on
* @ajsconstruct MyGame.createVerb({ "name": "swing_from_to_on", [...] });
* @ajsconstructedby adventurejs.Dictionary#createVerb
* @hideconstructor
* @ajsinstanceof Verb
* @ajsnavheading DeprecatedVerbs
* @summary Summary.
* @tutorial Scripting_VerbSubscriptions
* @tutorial Verbs_VerbAnatomy
* @tutorial Verbs_VerbProcess
* @tutorial Verbs_ModifyVerbs
* @tutorial Verbs_WriteVerbs
* @classdesc
* <pre class="display border outline">
* <span class="input">> swing from branch to cliff on vine</span>
* You grab the vine and swing from the branch to the cliff.
* </pre>
* <p>
* <strong>Swing from</strong> one
* {@link adventurejs.Tangible|Tangible}
* {@link adventurejs.Asset|Asset} to another on a third.
* Requires that
* <li>
* character is holding noun3
* </li>
* <li>
* noun1 has its
* <a class="code" href="/doc/adventurejs.Tangible.html#property_can_swing_from">can.swing_from</a>
* property set to true
* </li>
* <li>
* noun2 has its
* <a class="code" href="/doc/adventurejs.Tangible.html#property_can_swing_to">can.swing_to</a>
* </li>
* <li>
* noun2's ID is listed in noun1's
* <a class="code" href="/doc/adventurejs.Tangible.html#property_things_player_can_swing_to_from_this">things_player_can_swing_to_from_this</a>
* </li>
* </p>
*/
A.Preverbs.swing_from_to_on = {
name: "swing_from_to_on",
prettyname: "swing",
synonyms: [],
verb_prep_noun_prep_noun_prep_noun: [
"swing from to with",
"swing from to on",
],
subject_must_be: {
not_on_floor: true,
not_constrained: true,
not_under: true,
not_behind: true,
not_nested_elsewhere: true,
},
phrase1: {
accepts_noun: true,
requires_noun: true,
//accepts_preposition: true,
//requires_preposition: true,
//accepts_these_prepositions: [ 'from' ], /* @todo */
noun_must_be: {
player_parent: true,
},
},
phrase2: {
accepts_noun: true,
requires_noun: true,
//accepts_preposition: true,
//requires_preposition: true,
//accepts_these_prepositions: [ 'to' ], /* @todo */
noun_must_be: {
known: true,
tangible: true,
present: true,
visible: true,
reachable: true,
not_player_parent: true,
},
},
phrase3: {
accepts_noun: true,
requires_noun: true,
//accepts_preposition: true,
//requires_preposition: true,
//accepts_these_prepositions: [ 'on' ], /* @todo */
noun_must_be: {
known: true,
tangible: true,
present: true,
visible: true,
reachable: true, // TODO check can.swing_to and things_player_can_swing_to_from_this
in_hands: true,
},
},
doTry: function () {
var input = this.game.getInput();
var character = input.getSubject();
var verb_phrase = input.verb_phrase;
var fromObject = this.game.world[input.parsedNoun1.qualified_object_id];
var toObject = this.game.world[input.parsedNoun2.qualified_object_id];
var onObject = this.game.world[input.parsedNoun3.qualified_object_id];
var nest_preposition = character.getNestPreposition();
var nest_parent_id = character.getNestId();
var nest_parent_object = character.getNestAsset();
// can't swing to
if (false === toObject.can.swing_to) {
console.log(
"swingto failed because " + toObject.name + ".can.swing_to is false."
);
var msg = "$(We) can't swing to " + toObject.articlename + ". ";
this.handleFailure(msg);
return null;
}
// can't swing to thing being held
if (toObject.id === onObject.id) {
var msg =
"$(We) can't swing to " +
toObject.articlename +
" on " +
onObject.articlename +
". ";
this.handleFailure(msg);
return null;
}
// can't swing from
if (false === fromObject.can.swing_from) {
var msg = "$(We) can't swing from " + fromObject.articlename + ". ";
if (
-1 <
fromObject.things_player_can_jump_to_from_this.indexOf(toObject.id)
) {
msg +=
"$(We) might be able to jump from " +
fromObject.articlename +
" to " +
toObject.articlename +
". ";
}
this.handleFailure(msg);
return null;
}
// no swinging between these objects
if (
-1 ===
fromObject.things_player_can_swing_to_from_this.indexOf(
toObject.id
) &&
-1 ===
fromObject.things_player_can_do_all_verbs_to_from_this.indexOf(
toObject.id
)
) {
var msg = "$(We) can't swing from " + fromObject.articlename + " to ";
+toObject.articlename + ". ";
if (
fromObject.can.jump_from &&
(-1 !==
fromObject.things_player_can_jump_to_from_this.indexOf(
toObject.id
) ||
-1 !==
fromObject.things_player_can_do_all_verbs_to_from_this.indexOf(
toObject.id
))
) {
msg +=
"$(We) might be able to jump from " +
fromObject.articlename +
" to " +
toObject.articlename +
". ";
}
this.handleFailure(msg);
return null;
}
// figure out y overlap
var range = toObject.getYRange();
// is character close enough on y?
if (
character.position.y > range.max ||
character.position.y < range.min
) {
var msg =
toObject.Articlename +
" is too far " +
(character.position.y > range.max ? "below" : "above") +
" your position on " +
(character.isNested()
? nest_parent_object.articlename
: "the floor") +
". ";
this.handleFailure(msg);
return null;
}
// TODO:
// is object an exit? eg "jump to hatch"
// for now just redirect to the exit
// this might need to be revisited
if (
toObject instanceof adventurejs.Exit ||
toObject instanceof adventurejs.Aperture
) {
this.game.dictionary.doVerb(toObject.direction);
return null;
}
return true;
},
doSuccess: function () {
var input = this.game.getInput();
var character = input.getSubject();
var verb_phrase = input.verb_phrase;
var fromObject = this.game.world[input.parsedNoun1.qualified_object_id];
var toObject = this.game.world[input.parsedNoun2.qualified_object_id];
var onObject = this.game.world[input.parsedNoun3.qualified_object_id];
var currentRoom = this.game.getCurrentRoom();
var nest_parent_id = character.getNestId();
var posture = toObject.default_posture_for_swing_to;
var preposition = toObject.default_aspect_for_swing_to;
var results;
// if character is nested, unnest
results = character.onUnnestThisFromThat(fromObject);
if ("undefined" !== typeof results) return results;
// if it isn't already nested, nest it
results = character.onNestThisToThat(toObject, preposition);
if ("undefined" !== typeof results) return results;
character.posture = posture;
// var msg = "$(We) swing from "
// + fromObject.articlename
// + " to "
// + toObject.articlename
// + " and "
// + posture
// + " "
// + preposition
// + " it.";
var msg =
"$(We) swing from " +
fromObject.articlename +
" and land, " +
character.getPostureGerund() +
" " +
preposition +
" " +
toObject.articlename +
". ";
// must.let_go_after_swing
if (
character.IOVisConnectedToAsset("hold", onObject, "dov") &&
onObject.must.let_go_after_swing
) {
results = onObject.onReleaseThis(character);
if ("undefined" !== typeof results) return results;
msg += onObject.Articlename + " slips out of $(our) hands. ";
}
// must.let_go_after_swing
else if (character.$has(onObject) && onObject.must.let_go_after_swing) {
msg += onObject.Articlename + " slips out of $(our) hands. ";
results = character.onRemoveThatFromThis(onObject);
if ("undefined" !== typeof results) return results;
results = currentRoom.onMoveThatToThis(onObject, "in");
if ("undefined" !== typeof results) return results;
}
if (toObject.position.y !== character.position.y) {
character.position.y = toObject.position.y;
}
// check if there's a custom msg
this.handleSuccess(msg, fromObject);
return true;
},
};
})(); // swing_from_to_on