(function () {
A.Preverbs.fill = {
name: "fill",
prettyname: "fill",
past_tense: "filled",
synonyms: ["fill"],
gerund: "filling",
accepts_structures: [
"verb noun preposition noun",
"verb noun preposition noun preposition noun",
],
phrase1: {
accepts_noun: true,
requires_noun: true,
noun_must_be: {
known: true,
tangible: true,
present: true,
visible: true,
reachable: true,
},
},
phrase2: {
accepts_noun: true,
noun_must_be: {
known: true,
matter: true,
present_if_tangible: true,
},
accepts_preposition: true,
requires_preposition: true,
accepts_these_prepositions: ["with", "from"],
},
phrase3: {
accepts_noun: true,
accepts_preposition: true,
noun_must_be: {
known: true,
matter: true,
present: true,
visible: true,
reachable: true,
},
requires_preposition: true,
accepts_these_prepositions: ["from"],
},
with_params: {},
doTry: function () {
var input = this.game.getInput();
var subject = input.getSubject();
var verb_phrase = input.verb_phrase;
var target_asset = input.getAsset(1);
var source_asset = input.getAsset(2);
var preposition2 = input.getPreposition(2);
var source_asset2 = input.getAsset(3);
var preposition3 = input.getPreposition(3);
var substance_id = "";
var containers, container;
var msg = "";
var source_volume;
var source_vessel, target_vessel;
var source_aspect, target_aspect;
if ("with" === preposition2 && "from" === preposition3) {
substance_id = input.getParsedNoun(2).matches.substance;
if (!substance_id) {
this.game.debug(
`D1559 | ${this.name}.js | ${source_asset.id} is not a substance `
);
msg += `$(We) can't fill ${target_asset.articlename} with ${source_asset.articlename}. `;
this.handleFailure(msg);
return null;
}
if (!source_asset2.containsSubstance(substance_id)) {
this.game.debug(
`D1563 | ${this.name}.js | ${source_asset2.id} does not contain ${substance_id} `
);
msg += `${source_asset2.articlename} doesn't contain ${substance_id}. `;
this.handleFailure(msg);
return null;
}
input.setPhrase(2, input.getPhrase(3));
input.setPhrase(3, {});
source_asset = input.getAsset(2);
preposition2 = input.getPreposition(2);
} else if ("with" === preposition2) {
substance_id = input.getParsedNoun(2).matches.substance;
if (substance_id) {
containers = this.game.findSubstanceContainers(
substance_id,
this.game.getCurrentRoom(),
["Present", "Known", "Visible", "Reachable"]
);
if (!containers.length) {
this.game.debug(`D1565 | ${this.name}.js | no containers found `);
msg += `There's no ${
this.game.getAsset(substance_id).name
} to fill ${target_asset.articlename} with. `;
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.id === this.game.getCurrentRoom().id) {
container = asset;
break;
}
}
}
if (
!container &&
!this.game.settings.infer_containers_automatically_picks
) {
this.game.debug(
`D1564 | ${this.name}.js | multiple containers found, disambiguate `
);
input.setPreposition(2, "from");
input.setParsedNounMatchesQualified(2, containers);
this.game.parser.printNounDisambiguation({
parsedNoun: input.getParsedNoun(2),
nounIndex: 2,
});
return null;
}
}
if (!container) {
container = containers[0];
}
input.setPhrase(2, {});
input.setPreposition(2, "from");
input.setAsset(2, this.game.getAsset(container));
input.setInferred(2, true);
source_asset = input.getAsset(2);
preposition2 = "from";
this.game.printInferred(`from ${container.articlename}`);
}
else {
if (!source_asset.containsAnySubstance()) {
this.game.debug(
`D1566 | ${this.name}.js | "+${source_asset.id}+" does not contain anything `
);
msg += `${source_asset.Articlename} doesn't contain anything with which to fill ${target_asset.articlename}. `;
this.handleFailure(msg);
return null;
}
input.setPreposition(2, "from");
preposition2 = "from";
}
}
else if ("from" === preposition2) {
if (source_asset && !source_asset.containsAnySubstance()) {
this.game.debug(
`D1560 | ${this.name}.js | ${source_asset.id} does not contain anything `
);
msg += `${source_asset.Articlename} doesn't contain anything with which to fill ${target_asset.articlename}. `;
this.handleFailure(msg);
return null;
}
}
if (!target_asset.hasVessel()) {
this.game.debug(
`D1566 | ${this.name}.js | ${target_asset.id} has no substance container `
);
msg += `${target_asset.Articlename} can't be filled. `;
this.handleFailure(msg);
return null;
}
if (!target_asset.isWithin(subject) && !source_asset.isWithin(subject)) {
if (target_asset.isDOV("take") && source_asset.isDOV("take")) {
this.game.debug(
`D1567 | ${this.name}.js | neither ${target_asset.id} nor ${source_asset.id} are in subject `
);
msg += `$(We're) holding neither ${target_asset.articlename} nor ${source_asset.articlename}. `;
this.handleFailure(msg);
return null;
}
if (!target_asset.isDOV("take") && !source_asset.isDOV("take")) {
this.game.debug(
`D1569 | ${this.name}.js | both ${target_asset.id} and ${source_asset.id} are stationary `
);
msg += `$(We) try transferring ${
this.game.getAsset(source_asset.getAnySubstanceThisContains()).name
}
from ${target_asset.articlename} to ${
source_asset.articlename
} by hand, to little effect. `;
this.handleFailure(msg);
return null;
}
if (target_asset.isDOV("take") || source_asset.isDOV("take")) {
var unheld = target_asset.isDOV("take") ? target_asset : source_asset;
this.game.debug(
`D1570 | ${this.name}.js | ${unheld.id}.dov.take.enabled is true, but is unheld `
);
msg += `$(We're) not holding ${unheld.articlename}. `;
this.handleFailure(msg);
return null;
}
}
if (
(target_aspect === "in" &&
target_asset.isDOV("close") &&
target_asset.is.closed) ||
(source_aspect === "in" &&
source_asset.isDOV("close") &&
source_asset.is.closed)
) {
var closed = target_asset.is.closed ? target_asset : source_asset;
this.game.debug(
`D1471 | ${this.name}.js | ${closed.id}.is.closed is true `
);
msg += `${closed.Articlename_is} closed. `;
this.handleFailure(msg);
return null;
}
target_aspect = target_asset.getVesselPreposition();
source_aspect = source_asset.getVesselPreposition();
target_vessel = target_asset.getVesselAt(target_aspect);
source_vessel = source_asset.getVesselAt(source_aspect);
source_volume = source_vessel.getVolume();
if (0 >= source_volume) {
if (source_asset instanceof adventurejs.SubstanceEmitter) {
this.game.debug(
`D1572 | ${this.name}.js | ${source_asset.id} is class SubstanceEmitter, but .is_emitting is false `
);
msg += `Nothing is coming out of ${source_asset.articlename}. `;
this.handleFailure(msg);
return null;
} else {
this.game.debug(
`D1573 | ${this.name}.js | ${source_asset.id}.aspects.in.vessel.volume is 0 `
);
msg += `Nothing is coming out of ${source_asset.articlename}. `;
this.handleFailure(msg);
return null;
}
}
if (
target_vessel.getVolume() === target_vessel.maxvolume &&
target_vessel.substance_id === source_vessel.substance_id
) {
this.game.debug(
`D1574 | ${this.name}.js | ${target_asset.id}.aspects.${target_aspect}.vessel.volume is equal to .maxvolume `
);
msg += `${target_asset.Articlename_is} already full of ${
this.game.getAsset(target_vessel.substance_id).name
}. `;
this.handleFailure(msg);
return null;
}
return true;
},
doSuccess: function () {
var input = this.game.getInput();
var verb_phrase = input.verb_phrase;
var target_asset = input.getAsset(1);
var source_asset = input.getAsset(2);
var room = source_asset instanceof adventurejs.Room;
var msg = "";
var results;
var mixer;
mixer = new adventurejs.SubstanceMixer(this.game.game_name).set({
can_overflow_target: false,
source_input: source_asset.id,
source_aspect: source_asset.getVesselPreposition(),
source_substance_id: source_asset.getVesselPreposition().substance_id,
target_input: target_asset.id,
target_aspect: target_asset.getVesselPreposition(),
});
results = mixer.mix();
if (A.isFalseOrNull(results)) return results;
mixer.target_vessel.is_known = true;
msg = `$(We) fill ${mixer.target_asset.articlename} with ${
mixer.source_substance_asset.name
}${room ? "" : " from " + mixer.source_asset.articlename}`;
if (mixer.can_drain_target) {
msg += `, but it quickly drains away`;
}
else if (mixer.did_mix_substances) {
msg += `, resulting in ${mixer.output_substance_asset.name}`;
}
else if (mixer.did_displace_substance) {
msg += `, displacing the ${
this.game.getAsset(mixer.target_substance_id).name
} that was already there`;
}
msg += `. `;
return this.handleSuccess(msg, target_asset);
},
};
})();