// A file of helper functions for getting player/npc status-related strings.
//TODO: Dry this up more.
module.exports = {
  getHealthText: getHealthText,
  getSanityText: getSanityText,
  getGenderNoun: getGenderNoun,
  getStatusColor: getStatusColor,
  getPercentage: getPercentage
};

function getHealthText(maxHealth, player, npc) {
  return function(health) {
    var locale = player ? player.getLocale() : 'en';
    var isPlayer = !npc;
    var percentage = getPercentage(health, maxHealth);
    var noun = isPlayer ? getGenderNoun(player.getGender()) : 'creature';
    var nounPhrase = isPlayer ? 'You are ' : npc.getShortDesc(locale) + ' is ';
    var color = getStatusColor(percentage);

    var healthStatus = {
      0: 'a dead ' + noun + ' walking',
      5: 'hanging by a thread',
      10: 'in excruciating pain',
      15: 'wracked by pain',
      25: 'maimed',
      35: 'gravely wounded',
      50: 'wounded',
      60: 'in awful shape',
      70: 'feeling poor',
      80: 'in average physical health',
      90: 'in good physical health',
      95: 'in great health',
      100: 'in perfect physical health'
    };

    for (var tier in healthStatus) {
      if (percentage <= parseInt(tier)) {
        return '<' + color + '>' + nounPhrase + healthStatus[tier] +
          '.</' + color + '>';
      }
    }
  }
}

function getSanityText(maxSanity, player) {
  return function(sanity) {
    var percentage = getPercentage(sanity, maxSanity);
    var sanityStatus = {
      0:  'consumed by madness',
      10: 'nearing insanity',
      15: 'feeling dysphoric',
      50: 'stressed to breaking',
      60: 'mentally unsound',
      70: 'feeling stressed',
      80: 'discontent',
      90: 'mentally well',
      95: 'quite stable',
      100: 'sharp as a knife'
    };

    var color = getStatusColor(percentage);
    for (var tier in sanityStatus) {
      if (percentage <= parseInt(tier)) {
        return '<' + color + '>You are ' + sanityStatus[tier] +
          '.</' + color + '>';
      }
    }
    return '<' + color + '>You are feeling strange.</' + color + '>';
  }
}

function getGenderNoun(gender) {
  var nouns = {
    M: 'man',
    F: 'woman',
    A: 'person'
  };
  return nouns[gender] || nouns.A;
}

function getStatusColor(percentage) {
  return percentage > 50 ? 'green' : 'red'
}

function getPercentage(numerator, denominator){
  return Math.floor((numerator / denominator) * 100);
}

@@ -2083,32 +2083,797 @@
 r + '%3E';%0A  %7D%0A%7D%0A%0A
+function getActionText(maxSanity, player) %7B%0A  return function(sanity) %7B%0A    var percentage = getPercentage(energy, maxEnergy);%0A    var energyStatus = %7B%0A      0:  'consumed by madness',%0A      10: 'nearing insanity',%0A      15: 'feeling dysphoric',%0A      50: 'stressed to breaking',%0A      60: 'mentally unsound',%0A      70: 'feeling stressed',%0A      80: 'discontent',%0A      90: 'mentally well',%0A      95: 'quite stable',%0A      100: 'sharp as a knife'%0A    %7D;%0A%0A    var color = getStatusColor(percentage);%0A    for (var tier in sanityStatus) %7B%0A      if (percentage %3C= parseInt(tier)) %7B%0A        return '%3C' + color + '%3EYou are ' + sanityStatus%5Btier%5D +%0A          '.%3C/' + color + '%3E';%0A      %7D%0A    %7D%0A    return '%3C' + color + '%3EYou are feeling strange.%3C/' + color + '%3E';%0A  %7D%0A%7D%0A%0A%0A
 function getGend

Add some statusy nonsense.