<commit_before>'use strict';
const Data = require('./data').Data,
  Skills   = require('./skills').Skills,
  crypto   = require('crypto'),
  ansi     = require('sty'),
  util     = require('util'),
  events   = require('events'),
  wrap     = require('wrap-ansi'),
  Random   = require('./random').Random,
  Feats    = require('./feats').Feats,
  _        = require('./helpers');

const npcs_scripts_dir = __dirname + '/../scripts/player/';
const l10n_dir         = __dirname + '/../l10n/scripts/player/';
const statusUtil       = require('./status');
const CombatUtil       = require('./combat_util').CombatUtil;

const Player = function PlayerConstructor(socket) {
  const self = this;

  self.name        = '';
  self.description = '';
  self.location    = null;
  self.locale      = null;
  self.accountName = '';

  self.prompt_string =
    '<cyan>PHYSICAL: </cyan>%health_condition <blue>|| </blue><cyan>MENTAL:</cyan> %sanity_condition<cyan> <blue>|| </blue>ENERGY:</cyan> %energy_condition\n<blue><bold>[</bold></blue>';
  self.combat_prompt =
    "<bold>|| <cyan>YOU: </cyan> %player_condition <blue>|VS.|</blue> %target_condition ||</bold>\r\n>";

  self.password  = <PASSWORD>;
  self.inventory = [];
  self.equipment = {};

  // In combat is either false or an NPC vnum
  self.inCombat  = false;

  // Attributes
  self.attributes = {

    max_health: 100,
    health:     90,
    max_sanity: 100,
    sanity:     90,
    max_energy: 100,
    energy:     90,

    stamina:    1,
    willpower:  1,
    quickness:  1,
    cleverness: 1,

    level:      1,
    experience: 0,
    mutagens:   0,
    attrPoints: 0,

    //TODO: Generated descs.
    description: 'A person.'
  };

  self.preferences = {
    target:    'body',
    wimpy:     30,
    stance:    'normal',
    roomdescs: 'default' //default = verbose 1st time, short after.
  };

  self.explored = [];
  self.killed   = { length: 0 };
  self.met      = { length: 0 };

  // Anything affecting the player
  self.effects = {};

  // Skills the players has
  self.skills = {};

  // Feats the player can use
  self.feats = {};

  // Training data
  self.training = { time: 0 };

  self.bodyParts = [
    'legs',
    'feet',
    'torso',
    'hands',
    'head'
  ];

  /**#@+
   * Mutators
   */
  self.getPrompt       = () => self.prompt_string;
  self.getCombatPrompt = () => self.combat_prompt;
  self.getLocale       = () => self.locale;
  self.getName         = () => self.name;
  self.getShortDesc    = () => self.name;
  self.getAccountName  = () => self.accountName;
  self.getDescription  = () => self.attributes.description;
  self.getLocation     = () => self.location;
  self.getBodyParts    = () => self.bodyParts;
  self.getSocket       = () => socket;
  self.getInventory    = () => self.inventory;
  self.getAttributes   = () => self.attributes || {};
  self.getGender       = () => self.gender;
  self.getRoom         = rooms => rooms ?
        rooms.getAt(self.getLocation()) : null;


  self.hasEnergy = cost =>
    self.getAttribute('energy') >= cost ?
              self.emit('action', cost) : false;

  self.noEnergy = () => self.say('You need to rest first.');

  self.getAttribute = attr => typeof self.attributes[attr] !== 'undefined' ?
    self.attributes[attr] : false;

  self.getPreference = pref => typeof self.preferences[pref] !== 'undefined' ?
    self.preferences[pref] : false;

  self.getPreferences = () => self.preferences;

  self.getFeats = feat => self.feats && self.feats[feat] ?
    self.feats[feat] : self.feats;

  self.gainFeat = feat => {
    self.feats[feat.id] = feat;
    if (feat.type === 'passive') { feat.activate(self); }
  }

  self.getPassword = () => self.password; // Returns hash.
  self.isInCombat  = () => !!self.inCombat.length;

  self.setPrompt       = str => self.prompt_string = str;
  self.setCombatPrompt = str => self.combat_prompt = str;
  self.setLocale       = locale => self.locale = locale;
  self.setName         = newname => self.name = newname;
  self.setAccountName  = accname => self.accountName = accname;
  self.setDescription  = newdesc => self.attributes.description = newdesc;

  self.setLocation = loc  => self.location = loc;
  self.setPassword = pass =>
    self.password  = crypto
      .createHash('md5')
      .update(pass)
      .digest('hex');

  self.setGender   = gender => self.gender = gender.toUpperCase();

  self.addItem     = item   => self.inventory.push(item);
  self.removeItem  = item   =>
    self.inventory = self.inventory.filter(i => item !== i);
  self.setInventory     = inv         => self.inventory = inv;

  self.setAttribute     = (attr, val) => self.attributes[attr]  = val;
  self.setPreference    = (pref, val) => self.preferences[pref] = val;

  self.fleeFromCombat   = ()          => self.inCombat = [];
  self.setInCombat      = combatant   => self.inCombat.push(combatant);
  self.removeFromCombat = combatant   => {
    const combatantIndex = self.inCombat.indexOf(combatant);
    if (combatantIndex === -1) { return; }
    self.inCombat.splice(combatantIndex, 1);
  }

  ///// ----- Skills and Training. ----- ///////<commit_msg>Add method to get combatants. :lightning:<commit_after>'use strict';
const Data = require('./data').Data,
  Skills   = require('./skills').Skills,
  crypto   = require('crypto'),
  ansi     = require('sty'),
  util     = require('util'),
  events   = require('events'),
  wrap     = require('wrap-ansi'),
  Random   = require('./random').Random,
  Feats    = require('./feats').Feats,
  _        = require('./helpers');

const npcs_scripts_dir = __dirname + '/../scripts/player/';
const l10n_dir         = __dirname + '/../l10n/scripts/player/';
const statusUtil       = require('./status');
const CombatUtil       = require('./combat_util').CombatUtil;

const Player = function PlayerConstructor(socket) {
  const self = this;

  self.name        = '';
  self.description = '';
  self.location    = null;
  self.locale      = null;
  self.accountName = '';

  self.prompt_string =
    '<cyan>PHYSICAL: </cyan>%health_condition <blue>|| </blue><cyan>MENTAL:</cyan> %sanity_condition<cyan> <blue>|| </blue>ENERGY:</cyan> %energy_condition\n<blue><bold>[</bold></blue>';
  self.combat_prompt =
    "<bold>|| <cyan>YOU: </cyan> %player_condition <blue>|VS.|</blue> %target_condition ||</bold>\r\n>";

  self.password  = <PASSWORD>;
  self.inventory = [];
  self.equipment = {};

  // In combat is either false or an NPC vnum
  self.inCombat  = false;

  // Attributes
  self.attributes = {

    max_health: 100,
    health:     90,
    max_sanity: 100,
    sanity:     90,
    max_energy: 100,
    energy:     90,

    stamina:    1,
    willpower:  1,
    quickness:  1,
    cleverness: 1,

    level:      1,
    experience: 0,
    mutagens:   0,
    attrPoints: 0,

    //TODO: Generated descs.
    description: 'A person.'
  };

  self.preferences = {
    target:    'body',
    wimpy:     30,
    stance:    'normal',
    roomdescs: 'default' //default = verbose 1st time, short after.
  };

  self.explored = [];
  self.killed   = { length: 0 };
  self.met      = { length: 0 };

  // Anything affecting the player
  self.effects = {};

  // Skills the players has
  self.skills = {};

  // Feats the player can use
  self.feats = {};

  // Training data
  self.training = { time: 0 };

  self.bodyParts = [
    'legs',
    'feet',
    'torso',
    'hands',
    'head'
  ];

  /**#@+
   * Mutators
   */
  self.getPrompt       = () => self.prompt_string;
  self.getCombatPrompt = () => self.combat_prompt;
  self.getLocale       = () => self.locale;
  self.getName         = () => self.name;
  self.getShortDesc    = () => self.name;
  self.getAccountName  = () => self.accountName;
  self.getDescription  = () => self.attributes.description;
  self.getLocation     = () => self.location;
  self.getBodyParts    = () => self.bodyParts;
  self.getSocket       = () => socket;
  self.getInventory    = () => self.inventory;
  self.getAttributes   = () => self.attributes || {};
  self.getGender       = () => self.gender;
  self.getRoom         = rooms => rooms ?
        rooms.getAt(self.getLocation()) : null;


  self.hasEnergy = cost =>
    self.getAttribute('energy') >= cost ?
              self.emit('action', cost) : false;

  self.noEnergy = () => self.say('You need to rest first.');

  self.getAttribute = attr => typeof self.attributes[attr] !== 'undefined' ?
    self.attributes[attr] : false;

  self.getPreference = pref => typeof self.preferences[pref] !== 'undefined' ?
    self.preferences[pref] : false;

  self.getPreferences = () => self.preferences;

  self.getFeats = feat => self.feats && self.feats[feat] ?
    self.feats[feat] : self.feats;

  self.gainFeat = feat => {
    self.feats[feat.id] = feat;
    if (feat.type === 'passive') { feat.activate(self); }
  }

  self.getPassword = () => self.password; // Returns hash.
  self.isInCombat  = () => !!self.inCombat.length;

  self.setPrompt       = str => self.prompt_string = str;
  self.setCombatPrompt = str => self.combat_prompt = str;
  self.setLocale       = locale => self.locale = locale;
  self.setName         = newname => self.name = newname;
  self.setAccountName  = accname => self.accountName = accname;
  self.setDescription  = newdesc => self.attributes.description = newdesc;

  self.setLocation = loc  => self.location = loc;
  self.setPassword = pass =>
    self.password  = crypto
      .createHash('md5')
      .update(pass)
      .digest('hex');

  self.setGender   = gender => self.gender = gender.toUpperCase();

  self.addItem     = item   => self.inventory.push(item);
  self.removeItem  = item   =>
    self.inventory = self.inventory.filter(i => item !== i);
  self.setInventory     = inv         => self.inventory = inv;

  self.setAttribute     = (attr, val) => self.attributes[attr]  = val;
  self.setPreference    = (pref, val) => self.preferences[pref] = val;

  self.fleeFromCombat   = ()          => self.inCombat = [];
  self.setInCombat      = combatant   => self.inCombat.push(combatant);
  self.getInCombat      = ()          => self.inCombat;
  self.removeFromCombat = combatant   => {
    const combatantIndex = self.inCombat.indexOf(combatant);
    if (combatantIndex === -1) { return; }
    self.inCombat.splice(combatantIndex, 1);
  }

  ///// ----- Skills and Training. ----- ///////
{'fraction_non_alphanumeric': 0.16795740561471442, 'fraction_numerical': 0.0069699903194578895, 'mean_word_length': 2.6249122807017544, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 132, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4499470', 'n_tokens_mistral': 3574, 'n_tokens_neox': 3431, 'n_words': 665}