(function () {
A.Preverbs.drink = {
name: "drink",
prettyname: "drink",
past_tense: "drank",
synonyms: ["drink", "sip"],
gerund: "drinking",
accepts_structures: [
"verb noun",
"verb preposition noun",
"verb noun preposition noun",
],
phrase1: {
accepts_noun: true,
requires_noun: true,
noun_must_be: {
known: true,
matter: true,
present_if_tangible: true,
reachable_if_tangible: true,
},
accepts_preposition: true,
accepts_these_prepositions: ["from"],
},
phrase2: {
accepts_noun: true,
noun_must_be: {
known: true,
tangible: true,
present: true,
visible: true,
reachable: true,
},
accepts_preposition: true,
requires_preposition: true,
accepts_these_prepositions: ["from"],
},
with_params: {
on_drink_empty: false,
},
doTry: function () {
var input = this.game.getInput();
var subject = input.getSubject();
var verb_phrase = input.verb_phrase;
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 currentRoom = this.game.getCurrentRoom();
var containers, container;
var msg = "";
var results, hook;
var find_container_for_direct_object = false;
var find_substance_for_direct_object = false;
if (
input.hasStructure("verb noun") ||
input.hasStructure("verb preposition noun")
) {
if (direct_object instanceof adventurejs.Substance) {
if (this.game.settings.infer_containers) {
find_container_for_direct_object = true;
} else {
this.game.debug(
`D1173 | ${this.name}.js | this.game.settings.infer_containers is false `
);
msg += `What would $(we) like to ${this.name} ${direct_object.id} from? `;
input.setPreposition(2, "from");
input.setSoftPrompt({
index: 2,
type: "noun",
noun2: true,
});
input.setStructure(`${input.getStructure()} preposition noun`);
this.handleFailure(msg);
return null;
}
} else if (direct_object.containsAnySubstance()) {
find_substance_for_direct_object = true;
} else if (direct_object.canContainSubstance()) {
this.game.debug(
`D1575 | ${this.name}.js | ${direct_object.id} is empty `
);
msg += `${direct_object.Articlename_is} empty. `;
this.handleFailure(msg);
return null;
} else if (direct_object.isDOV("drink")) {
if (direct_object.isDOV("take") && !direct_object.isWithin(subject)) {
this.game.debug(
`D1748 | ${this.name}.js | ${direct_object.id} is not in subject `
);
msg += `$(We're) not carrying ${direct_object.articlename}. `;
this.handleFailure(msg);
return null;
}
input.verb_params.can_be_drunk = true;
return true;
} else {
this.game.debug(
`D1171 | ${this.name}.js | ${direct_object.id}.dov.drink.enabled is false `
);
msg += `${direct_object.Articlename} can't be drunk from. `;
this.handleFailure(msg);
return null;
}
}
if (find_container_for_direct_object) {
containers = this.game.findSubstanceContainers(
direct_object.id,
this.game.getCurrentRoom(),
["Present", "Known", "Visible", "Reachable"]
);
if (!containers.length) {
this.game.debug(`D1576 | ${this.name}.js | no containers found `);
msg += `$(We) $(don't) see any ${direct_object.name}. `;
this.handleFailure(msg);
return null;
}
if (containers.length > 1) {
if (this.game.settings.infer_containers_prefers_reservoir) {
for (var i = 0; i < containers.length; i++) {
let asset = this.game.getAsset(containers[i]);
if (asset.$is("reservoir")) {
container = asset;
break;
}
}
}
if (
!container &&
!this.game.settings.infer_containers_automatically_picks
) {
this.game.debug(
`D1578 | ${this.name}.js | multiple containers found, disambiguate `
);
input.setPreposition(1, "from");
input.setParsedNounMatchesQualified(1, containers);
this.game.parser.printNounDisambiguation({
parsedNoun: input.getParsedNoun(1),
nounIndex: 1,
});
return null;
}
}
if (!container) {
container = containers[0];
}
if (container.id === currentRoom.id) {
input.verb_params.drink_from_room = true;
}
input.setAsset(2, this.game.getAsset(container));
input.setPreposition(2, "from");
input.setInferred(2, true);
input.setStructure("verb noun preposition noun");
indirect_object = input.getAsset(2);
indirect_preposition = input.getPreposition(2);
this.game.printInferred(`from ${indirect_object.articlename}`);
}
if (find_substance_for_direct_object) {
indirect_object = direct_object;
direct_object = this.game.getAsset(
indirect_object.getAnySubstanceThisContains()
);
input.setAsset(1, direct_object);
input.setPreposition(1, "");
input.setAsset(2, indirect_object);
input.setPreposition(2, "from");
input.setStructure("verb noun preposition noun");
this.game.printInferred(
`${direct_object.name} from ${indirect_object.articlename}`
);
}
if (input.hasStructure("verb noun preposition noun")) {
if (!direct_object.isDOV("drink")) {
this.game.debug(
`D1577 | ${this.name}.js | ${direct_object.id}.dov.drink.enabled is false `
);
msg += `$(We) can't drink ${direct_object.name}. `;
this.handleFailure(msg);
return null;
}
if (!indirect_object.canContainSubstance()) {
this.game.debug(
`D1582 | ${this.name}.js | ${indirect_object.id} has no substance container `
);
msg += `${indirect_object.Articlename} can't be drunk from. `;
this.handleFailure(msg);
return null;
}
if (!indirect_object.containsAnySubstance()) {
if (indirect_object instanceof adventurejs.SubstanceEmitter) {
this.game.debug(
`D1580 | ${this.name}.js | "+${indirect_object.id}+" is class SubstanceEmitter and .is_emitting is false `
);
msg += `Nothing is coming out of ${indirect_object.articlename}. `;
} else {
this.game.debug(
`D1581 | ${this.name}.js | ${indirect_object.id}.aspects.in.vessel.volume is 0 `
);
msg += `${indirect_object.Articlename_is} empty. `;
}
this.handleFailure(msg);
return null;
}
if (
indirect_object.isDOV("take") &&
!indirect_object.isWithin(subject)
) {
this.game.debug(
`D1579 | ${this.name}.js | ${indirect_object.id} is not in subject `
);
msg += `$(We're) not holding ${indirect_object.articlename}. `;
this.handleFailure(msg);
return null;
}
if (
indirect_object.getVesselPreposition() === "in" &&
indirect_object.isDOV("open")
) {
this.game.debug(
`D1571 | ${this.name}.js | ${indirect_object.id}.is.closed `
);
msg += `${indirect_object.Articlename_is} closed. `;
this.handleFailure(msg);
return null;
}
if (!indirect_object.containsSubstance(direct_object.id)) {
this.game.debug(
`D1583 | ${this.name}.js | ${indirect_object.id} does not contain ${direct_object.id} `
);
msg += `${indirect_object.Articlename} doesn't contain any ${direct_object.name}. `;
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 direct_object = input.getAsset(1);
var direct_preposition = input.getPreposition(1);
var indirect_object = input.getAsset(2);
var indirect_preposition = input.getPreposition(2);
var msg = "";
var results;
var source_aspect;
var source_vessel;
var substance;
if (input.verb_params.can_be_drunk) {
if (input.hasStructure("verb")) {
}
if (input.hasStructure("verb noun")) {
}
msg += `$(We) drink ${direct_object.articlename}. `;
if (direct_object && direct_object.dov.drink?.then_destroy) {
direct_object.destroy();
}
} else if (input.hasStructure("verb noun")) {
} else if (input.hasStructure("verb preposition noun")) {
} else if (input.hasStructure("verb noun preposition noun")) {
source_aspect = indirect_object.getVesselPreposition();
source_vessel = indirect_object.getVesselAt(source_aspect);
substance = this.game.getAsset(source_vessel.substance_id);
if (indirect_object.iov.drink?.with_params.on_drink_empty) {
source_vessel.setVolume(0);
} else {
source_vessel.subtractVolume(this.game.settings.mouthful);
}
msg += `$(We) drink some ${substance.name} from ${indirect_object.articlename}`;
if (0 >= source_vessel.getVolume()) {
msg += `, emptying it in one gulp`;
}
msg += `. `;
}
return this.handleSuccess(msg, direct_object);
},
};
})();