(function () {
A.Preverbs.detach = {
name: "detach",
prettyname: "detach",
past_tense: "detached",
synonyms: ["detach", "disconnect"],
unstate: "attached",
gerund: "detaching",
accepts_structures: [
"verb noun",
"verb noun preposition noun",
"verb noun preposition noun preposition noun",
],
phrase1: {
accepts_noun: true,
noun_must_be: {
known: true,
tangible: true,
present: true,
reachable: true,
},
},
phrase2: {
accepts_noun: true,
noun_must_be: {
known: true,
tangible: true,
present: true,
reachable: true,
},
accepts_preposition: true,
requires_preposition: true,
accepts_these_prepositions: ["from", "with"],
},
phrase3: {
accepts_noun: true,
noun_must_be: {
in_inventory_if_takeable: true,
known: true,
tangible: true,
present: true,
reachable: true,
},
accepts_preposition: true,
requires_preposition: true,
accepts_these_prepositions: ["from", "with"],
},
with_params: {},
doTry: function () {
var input = this.game.getInput();
var subject = input.getSubject();
var verb_phrase = input.verb_phrase;
var object1 = input.getAsset(1);
var object2, object2_preposition;
var tool, tool_preposition;
var results, results2;
var msg = "";
if (object1.is.worn && object1.isDOV("remove")) {
this.game.debug(
`D1522 | ${this.name}.js | ${object1.id}.is.worn, infer verb remove `
);
return this.game.dictionary.doVerb("remove");
}
if (
object1.getVerbConnectionCount("tie", "to_iov") &&
object1.isDOV("untie")
) {
this.game.debug(
`D1249 | ${this.name}.js | ${object1.id}.dov.untie, infer verb untie `
);
return this.game.dictionary.doVerb("untie");
}
if (input.hasStructure("verb noun")) {
if (object1.isPlacedAtAspect("attached")) {
object2 = object1.getPlaceAsset();
input.setAsset(2, object2);
input.setPreposition(2, "from");
input.setStructure("verb noun preposition noun");
this.game.printInferred(`from ${object2.articlename}`);
} else {
input.setStructure("verb noun preposition noun");
input.setPreposition(2, "from");
input.setSoftPrompt({
index: 2,
type: "noun",
noun2: true,
structure: "verb noun preposition noun",
});
this.game.debug(`D1520 | ${this.name}.js | soft prompt for noun2 `);
msg += `What would $(we) like to ${this.name} ${object1.articlename} from? `;
this.handleFailure(msg);
return null;
}
}
if (input.getPreposition(2) === input.getPreposition(3)) {
this.game.debug(
`D1251 | ${this.name}.js | expected A from B with C, received two identical prepositions `
);
msg += this.game.parser.getUnparsedMessage(this.game.getInput().input);
this.handleFailure(msg);
return null;
}
if (
"with" === input.getPreposition(2) &&
"from" === input.getPreposition(3)
) {
input.swapPhrases(2, 3);
}
if ("with" === input.getPreposition(2) && !input.hasPhrase(3)) {
input.swapPhrases(2, 3);
input.setPreposition(2, "from");
tool = input.getAsset(3);
tool_preposition = "from";
if (object1.isPlacedAtAspect("attached")) {
input.setAsset(2, object1.getPlaceAsset());
input.setStructure("verb noun preposition noun preposition noun");
this.game.printInferred(`from ${input.getAsset(2).articlename}`);
} else {
input.setSoftPrompt({
index: 2,
type: "noun",
noun2: true,
structure: "verb noun preposition noun preposition noun",
});
this.game.debug(`D1520 | ${this.name}.js | soft prompt for noun3 `);
msg += `What would $(we) like to ${this.name} ${object1.articlename} from with ${tool.articlename}? `;
this.handleFailure(msg);
return null;
}
}
object2 = input.getAsset(2);
object2_preposition = input.getPreposition(2);
if (!object1.isDOV(this.name) && !object2.isDOV(this.name)) {
this.game.debug(
`D1250 | ${this.name}.js | neither ${object1.id} nor ${object2.id}.dov.${this.name}.enabled `
);
msg += `${object1.Articlename} can't be ${this.past_tense} from ${object2.articlename}. `;
this.handleFailure(msg);
return null;
}
if (
!object1.isPlacedAtAspect("attached", object2) &&
!object2.isPlacedAtAspect("attached", object1)
) {
this.game.debug(
`D1353 | ${this.name}.js | neither asset is in the other's .aspects.attached.contents `
);
msg += `${object1.Articlename} and ${object2.articlename} aren't ${this.unstate}. `;
this.handleFailure(msg);
return null;
}
if (
!object1.isPlacedAtAspect("attached", object2) &&
object2.isPlacedAtAspect("attached", object1)
) {
input.swapNouns(1, 2);
object1 = input.getAsset(1);
object2 = input.getAsset(2);
}
tool = input.getAsset(3);
tool_preposition = input.getPreposition(3);
if (!tool) {
if (
!object1.allowVerbWithNothing(this.name, "dov") &&
!object2.allowVerbWithNothing(this.name, "dov")
) {
results = this.tryToInferIndirectObject({
direct_object: object1,
context: subject,
handle_input: false,
});
results2 = this.tryToInferIndirectObject({
direct_object: object2,
context: subject,
handle_input: false,
});
if (results.success || results2.success) {
var either_one = results.success
? results.success
: results2.success;
tool = either_one.indirect_object;
tool_preposition = "with";
input.setNewPhrase({
asset: tool,
preposition: tool_preposition,
});
input.setStructure("verb noun preposition noun preposition noun");
this.game.printInferred(`${tool_preposition} ${tool.articlename}`);
} else if (results.prompt || results2.prompt) {
input.setPreposition(3, "with");
input.setSoftPrompt({
index: 3,
type: "noun",
noun3: true,
structure: "verb noun preposition noun preposition noun",
});
input.setStructure("verb noun preposition noun preposition noun");
this.game.debug(`D1720 | ${this.name}.js | soft prompt for noun3 `);
msg += `What would $(we) like to ${this.name} ${object1.articlename} from ${object2.articlename} with? `;
this.handleFailure(msg);
return false;
}
}
}
if (input.hasStructure("verb noun preposition noun preposition noun")) {
if (object1.allowVerbWithAnything(this.name, "dov")) {
return true;
}
if (
object1.allowVerbWithNothing(this.name, "dov") &&
object2.allowVerbWithNothing(this.name, "dov")
) {
this.game.debug(
`D1518 | ${this.name}.js | ${object1.id} and ${object2.id}.dov.${this.name}.with_nothing `
);
msg += `${object1.Articlename} and ${object2.articlename} don't need another object to ${this.name} them. `;
this.handleFailure(msg);
return null;
}
if (
!object1.allowVerbWithAsset(this.name, tool, "dov") &&
!object2.allowVerbWithAsset(this.name, tool, "dov")
) {
this.game.debug(
`D1521 | ${this.name}.js | neither ${object1.id} nor ${object2.id}.dov.${this.name}.with_assets/with_classes includes ${tool.id} `
);
msg += `${tool.Articlename} can't be used to ${this.name} ${object1.articlename} from ${object2.articlename}. `;
this.handleFailure(msg);
return null;
}
}
return true;
},
doSuccess: function () {
var input = this.game.getInput();
var subject = input.getSubject();
var verb_phrase = input.verb_phrase;
var object1 = input.getAsset(1);
var object1_parent = object1.getPlaceAsset();
var object2 = input.getAsset(2);
var object2_preposition = input.getPreposition(2);
var tool = input.getAsset(3);
var tool_preposition = input.getPreposition(3);
var results;
var msg = "";
if (object2.id !== subject.id) {
results = object1.moveFrom(object2);
if ("undefined" !== typeof results) return results;
var target = object1.isDOV("take") ? subject : object2.getPlaceAsset();
var targetprep = object1.isDOV("take")
? "in"
: object2.getPlacePreposition();
results = object1.moveTo(targetprep, target);
if ("undefined" !== typeof results) return results;
}
msg += `$(We) ${this.agree()} ${object1.articlename}`;
msg += object2 ? ` from ${object2.articlename}` : ``;
msg += tool ? ` with ${tool.articlename}` : ``;
msg +=
target.id === subject.id
? ` and take it`
: ` and set it ${targetprep} ${target.articlename}`;
msg += `. `;
return this.handleSuccess(msg, object1);
},
};
})();