Example #1
0
  // Validate a HEART command
  function validateHeart (data, command) {
    var invalidMsg  = 'Invalid Command - (' + command.member.displayName() + ' HEART): ';
    var memberHeart = _.findValue(command.member, 'heart.name');
    var heart       = _.find(data.heart, { name : memberHeart });
    var ability;

    if (!command.name) {
      throw new Error(invalidMsg + 'command must include a heart ability name.');
    } else if (!heart) {
      throw new Error(invalidMsg + 'heart data not found.');
    } else if (_.includes(command.member.abilities, command.name)) {
      throw new Error(invalidMsg + 'ability ' + command.name + ' has already been used.');
    } else if (!command.target.name) {
      throw new Error(invalidMsg + 'command must include a target.');
    }
    
    ability = _.find(heart.abilities, { name : command.name });
    if (!ability) {
      throw new Error(invalidMsg + 'ability ' + command.name + ' not found for heart ' + heart.name);
    } else {
      command.ability = ability;
      switch (ability.type) {
        case 'ITEM':
          var item = new Item();
          if (!item.findItem(ability.name, data)) {
            throw new Error(invalidMsg + 'item name ' + ability.name + ' not found.');
          }
          break;
        case 'SKILL':
          var skill = new Skill();
          if (!skill.findSkill(ability.name, data)) {
            throw new Error(invalidMsg + 'skill name ' + ability.name + ' not found.');
          }
          break;
        case 'SPELL':
          var spell = new Spell();
          if (!spell.findSpell(ability.name, data)) {
            throw new Error(invalidMsg + 'spell name ' + ability.name + ' not found.');
          }
          break;
        default:
          throw new Error(invalidMsg + 'unknown heart ability type ' + ability.type);
          break;
      }
    }

    return true;
  }
Example #2
0
  // Validate an ITEM command
  function validateItem (data, command) {
    var invalidMsg = 'Invalid Command - (' + command.member.displayName() + ' ITEM): ';
    var item       = new Item(command.name, data);
    var ability;

    if (!command.name) {
      throw new Error(invalidMsg + 'command must include an item name.');
    } else if (!item.is_set) {
      throw new Error(invalidMsg + 'item ' + command.name + ' not found.');
    } else if (!item.hasItem(command.member)) {
      throw new Error(invalidMsg + 'inventory or equipment does not contain item ' + command.name);
    } else if (!command.target.name && item.target !== 'none') {
      throw new Error(invalidMsg + 'command must include a target');
    }

    ability = item.ability;
    if (ability) {
      switch (ability.type) {
        case 'SKILL':
          var skill = new Skill();
          if (!skill.findSkill(ability.name, data)) {
            throw new Error(invalidMsg + 'skill name ' + ability.name + ' not found.');
          }
          break;
        case 'SPELL':
          var spell = new Spell();
          if (!spell.findSpell(ability.name, data)) {
            throw new Error(invalidMsg + 'spell name ' + ability.name + ' not found.');
          }
          break;
        default:
          throw new Error(invalidMsg + 'unknown item ability type ' + ability.type);
          break;
      }
    }

    return true;
  }