Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0
// getVerbAgreement.js
/*global adventurejs A*/

/**
 * This is a method for setting verbs in agreement with current subject.
 * @memberOf adventurejs
 * @method adventurejs#getVerbAgreement
 * @param {String} verb_name The name of a verb.
 * @returns {String} Returns the verb, in agreement with the subject of the current turn.
 */
adventurejs.getVerbAgreement = function Adventurejs_getVerbAgreement(
  verb_name
) {
  console.warn("getVerbAgreement", verb_name);
  if (!verb_name) return "";

  const player = this.game.getPlayer();
  const subject = this.game.getInput().getSubject();
  const subject_has_propername =
    subject && subject.id !== player.id && subject.propername;

  if (
    subject_has_propername ||
    ["nonhuman", "male", "female"].includes(
      this.game.getInput().getSubject().pronouns
    )
  ) {
    if (
      verb_name.endsWith("ch") ||
      verb_name.endsWith("sh") ||
      verb_name.endsWith("x") ||
      verb_name.endsWith("s") ||
      verb_name.endsWith("z") ||
      verb_name.endsWith("o")
    ) {
      return verb_name + "es";
    } else if (verb_name.endsWith("y") && !/[aeiou]y$/.test(verb_name)) {
      return verb_name.slice(0, -1) + "ies"; // Change "y" to "ies"
    } else {
      return verb_name + "s"; // Default case
    }
  } else {
    return verb_name;
  }
};