(function () {
A.Preverbs.empty = {
name: "empty",
prettyname: "empty",
past_tense: "emptied",
synonyms: ["empty"],
gerund: "emptying",
accepts_structures: ["verb 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,
},
},
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,
},
with_params: {},
doTry: function () {
var input = this.game.getInput();
var subject = input.getSubject();
var verb_phrase = input.verb_phrase;
var direct_object = input.getAsset(1);
var indirect_object = input.getAsset(2);
var indirect_preposition = input.getPreposition(2);
var substance = "";
var msg = "";
var empty_means_take_all;
var empty_means_unplug;
var empty_means_take_plug;
if (direct_object instanceof adventurejs.Tangible) {
if (direct_object.isDOV("open")) {
this.game.debug(
`D1741 | ${this.name}.js | ${direct_object.id}.is.closed `
);
msg += `${direct_object.Articlename_is} closed. `;
this.handleFailure(msg);
return null;
}
if (
!direct_object.containsAnySubstance() &&
!direct_object.containsAnyAsset()
) {
this.game.debug(
`D1551 | ${this.name}.js | ${direct_object.id}.containsAnySubstance and .containsAnyAsset are false `
);
msg += `${direct_object.Articlename_is} empty. `;
this.handleFailure(msg);
return null;
}
}
if (input.hasStructure("verb noun")) {
if (direct_object instanceof adventurejs.Substance) {
this.game.debug(
`D1742 | ${this.name}.js | ${direct_object.id} is a substance rather than a container `
);
msg += `$(We) $(don't) know how to empty ${direct_object.name}. `;
this.handleFailure(msg);
return null;
}
if (!direct_object.isDOV("take")) {
if (direct_object.containsAnyAssetAt("in")) {
var takeable_assets = [];
for (var i = 0; i < direct_object.aspects.in.contents.length; i++) {
var asset = this.game.getAsset(
direct_object.aspects.in.contents[i]
);
if (asset.isDOV("take")) {
takeable_assets.push(asset);
}
if (takeable_assets.length) {
empty_means_take_all = true;
input.verb_params.empty_means_take_all = true;
input.verb_params.takeable_assets = takeable_assets;
}
}
}
if (
!empty_means_take_all
) {
this.game.debug(
`D1744 | ${this.name}.js | ${direct_object.id}.dov.take.enabled is false and .aspects.in.contents is empty `
);
msg += `$(We) $(don't) know how to empty ${direct_object.articlename}. `;
this.handleFailure(msg);
return null;
}
} else {
indirect_object = subject.getNestOrPlaceAsset();
indirect_preposition = subject.getNestOrPlacePreposition();
input.setAsset(2, indirect_object);
input.setPreposition(2, indirect_preposition);
input.setInferred(2, true);
input.setStructure("verb noun preposition noun");
this.game.printInferred(
`${indirect_preposition} ${
indirect_object.hasClass("Room")
? "the floor"
: indirect_object.articlename
}`
);
}
}
if (input.hasStructure("verb noun preposition noun")) {
if (indirect_object instanceof adventurejs.Floor) {
indirect_object = this.game.getCurrentRoom();
input.setAsset(2, indirect_object);
}
if (!direct_object.isDOV("take")) {
this.game.debug(
`D1745 | ${this.name}.js | ${direct_object.id}.dov.take.enabled is false `
);
msg += `$(We) $(don't) know how to empty ${direct_object.articlename} ${indirect_preposition} ${indirect_object.articlename}. `;
this.handleFailure(msg);
return null;
}
if (direct_object.isDOV("take") && !direct_object.isWithin(subject)) {
this.game.debug(
`D1743 | ${this.name}.js | ${direct_object.id}.place not in subject `
);
msg += `$(We're) not carrying ${direct_object.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 direct_object = input.getAsset(1);
var indirect_object = input.getAsset(2);
var indirect_preposition = input.getPreposition(2);
var msg = "";
var results;
var room = indirect_object instanceof adventurejs.Room;
var target_object, target_preposition;
var emptied_count = 0;
var transferred = [];
var spillover = [];
var overflow = false;
var substance_asset;
var empty_this = false;
var mixer;
if (input.hasStructure("verb noun")) {
if (input.verb_params.empty_means_take_all) {
var takeable_assets = input.verb_params.takeable_assets;
for (var i = 0; i < takeable_assets.length; i++) {
var asset = takeable_assets[i];
results = asset.moveFrom(direct_object);
if ("undefined" !== typeof results) return results;
results = asset.moveTo("in", subject);
if ("undefined" !== typeof results) return results;
}
this.game.debug(`D1746 | ${this.name}.js | empty means take `);
msg += `$(We) take ${this.game.getPrintableObjectList({
objects: takeable_assets,
})} from ${direct_object.articlename}. `;
}
return this.handleSuccess(msg, direct_object);
}
if (input.hasStructure("verb noun preposition noun")) {
this.game.debug(`D1747 | ${this.name}.js | empty means pour `);
msg += `$(We) empty ${direct_object.articlename}`;
if (
"under" === indirect_preposition ||
"behind" === indirect_preposition
) {
msg += ` ${indirect_preposition} ${indirect_object.articlename}`;
} else {
msg += ` over ${room ? "the floor" : indirect_object.articlename}`;
}
msg += `. `;
if (direct_object.hasVesselAtAspect("in")) {
if (0 < direct_object.aspects.in.vessel.getVolume()) {
substance_asset = this.game.getAsset(
direct_object.aspects.in.vessel.substance_id
);
if (
room ||
"under" === indirect_preposition ||
"behind" === indirect_preposition
) {
msg += `${substance_asset.Name} spills to the floor. `;
empty_this = true;
} else if (
"on" === indirect_preposition &&
!indirect_object.hasVesselAtAspect(indirect_preposition)
) {
msg += `${substance_asset.Name} pours over ${indirect_object.articlename} and then drains away. `;
empty_this = true;
} else if (
indirect_object.hasVesselAtAspect(indirect_preposition)
) {
mixer = new adventurejs.SubstanceMixer(this.game.game_name).set({
source_input: direct_object.id,
source_aspect: "in",
source_substance_id:
direct_object.aspects.in.vessel.substance_id,
target_input: indirect_object.id,
target_aspect: indirect_preposition,
});
results = mixer.mix();
if (A.isFalseOrNull(results)) return results;
mixer.target_vessel.is_known = true;
msg += `${mixer.source_substance_asset.Name} pours from
${mixer.source_asset.articlename} ${indirect_preposition}
${
indirect_preposition === "in" || indirect_preposition === "on"
? " to"
: ""
}
${mixer.target_asset.articlename}`;
if (mixer.can_drain_target) {
msg += `, where it quickly drains away`;
} else if (mixer.did_overflow_target) {
msg += `, overflowing ${mixer.target_asset.articlename} with
${
mixer.did_mix_substances
? mixer.output_substance_asset.name
: mixer.source_substance_asset.name
}`;
} else if (mixer.did_fill_target) {
msg += `, filling ${mixer.target_asset.articlename} with
${
mixer.did_mix_substances
? mixer.output_substance_asset.name
: mixer.source_substance_asset.name
}`;
} else if (mixer.did_mix_substances) {
msg += `, resulting in ${mixer.output_substance_asset.name}`;
}
msg += `. `;
} else {
msg += `${substance_asset.Name} pours over ${indirect_object.articlename} and then spills to the floor. `;
empty_this = true;
}
}
if (
empty_this &&
isFinite(direct_object.aspects.in.vessel.getVolume())
) {
direct_object.aspects.in.vessel.setVolume(0);
}
}
if (0 < direct_object.aspects.in.contents.length) {
for (
var i = direct_object.aspects.in.contents.length - 1;
i > -1;
i--
) {
var content_object = this.game.getAsset(
direct_object.aspects.in.contents[i]
);
target_object = indirect_object;
target_preposition = indirect_preposition;
overflow = false;
emptied_count++;
if (room) {
transferred.push(content_object);
} else {
if (
indirect_object.canContainAssetAt(
content_object,
indirect_preposition
)
) {
transferred.push(content_object);
} else {
target_object = this.game.getCurrentRoom();
target_preposition = "in";
spillover.push(content_object);
overflow = true;
}
}
results = direct_object.onRemoveThatFromThis(content_object);
if ("undefined" !== typeof results) return results;
results = target_object.onMoveThatToThis(
content_object,
target_preposition
);
if ("undefined" !== typeof results) return results;
}
}
if (room) {
switch (emptied_count) {
case 0:
break;
case 1:
msg += "A single item tumbles out and falls to the floor. ";
break;
case 2:
msg += "Two items tumble out and fall to the floor. ";
break;
case 3:
msg += "Several items tumble out and fall to the floor. ";
break;
default:
msg += "A number of items tumble out and fall to the floor. ";
break;
}
} else {
var to_target =
indirect_preposition +
(indirect_preposition === "in" || indirect_preposition === "on"
? " to "
: " ") +
indirect_object.articlename;
switch (emptied_count) {
case 0:
break;
case 1:
msg += `A single item tumbles ${to_target}`;
switch (spillover.length) {
case 0:
msg += ". ";
break;
case 1:
msg += " then falls to the floor. ";
break;
}
break;
case 2:
msg += `Two items tumble ${to_target}`;
switch (spillover.length) {
case 0:
msg += ". ";
break;
case 1:
msg += ", and one falls to the floor. ";
break;
case 2:
msg += " then fall to the floor. ";
break;
}
break;
case 3:
msg += `Several items tumble ${to_target}`;
switch (spillover.length) {
case 0:
msg += ". ";
break;
case 1:
msg += ", and one falls to the floor. ";
break;
case 2:
msg += ", and a couple of them fall to the floor. ";
break;
case 3:
msg += " then fall to the floor. ";
break;
}
break;
default:
msg += `A number of items tumble ${to_target}`;
switch (spillover.length) {
case 0:
msg += ". ";
break;
case 1:
msg += ", and one falls to the floor. ";
break;
case 2:
msg += ", and a couple of them fall to the floor. ";
break;
case 3:
msg += ", and several fall to the floor. ";
break;
default:
msg += " and some fall to the floor. ";
break;
}
break;
}
}
}
return this.handleSuccess(msg, direct_object);
},
};
})();