text: //战绩相关
  
  const _ = require('lodash');
  
  class MjRecord {
  
      constructor(opts = {}) {
          this.opts = opts;
          this.init(this.opts);
          this.game =opts.game;
  
      }
  
      init(opts) {
  
      }
  
      gameAction(uid, action, tile){
          let game =this.game;
          game.actionList.push(uid);
          game.actionList.push(action);
          if (tile) {
              game.actionList.push(tile);
          }
      }
  
      userAction (dataMap,type,target){
          let game = this.game;
          let d = {type: type, targets: []};
          if (target != null) {
              if (!_.isArray(target)){
                  d.targets.push(target);
              } else{
                  d.targets = target;
              }
          } else {
              for (let uid in game.tileDataMap){
                  if (!game.tileDataMap.hasOwnProperty(uid)) continue;
                  let tdm_u = game.tileDataMap[uid];
                  //血流成河，所有自摸，暗杠，弯杠，都算三家
                  if (uid != dataMap.uid && ((!tdm_u.hued && !game.isXL) || game.isXL && !game.tileDataMap[uid].surrendered)) {
                      d.targets.push(uid);
                  }
              }
          }
          dataMap.actions.push(d);
          return d;
      }
  
      userActionShown (type, times, score, myUid, targetUids, huData, roundDesc){
          //type 1刮风 -1被刮风 2下雨 -2被下雨 3胡 -3点炮 4自摸 -4被自摸
          //活动数据[type, times, score, location, desc]
          //locations 可以包含 -1上家， 1下家，0对家
          let locations = [];
          let self = this;
          let game = this.game;
          let myIdx = game.getPlayerIndex(myUid);
          function getTargetLocation(targetUid) {
              let location = -1;
              let targetIdx = game.getPlayerIndex(targetUid);
              let diff = targetIdx - myIdx;
              if (diff == 2 || diff == -2) {
                  location = 0;
              } else if (diff == -1 || diff == 3) {
                  location = -1
              } else {
                  location = 1;
              }
              if(game.rules.playType == 3 && location == 0){ //三人房在客户端显示没有对家，要改成上家
                  location = -1;
              }
              return location;
          }
  
          _.each(targetUids, function (tUid) {
              let l = getTargetLocation(tUid);
              locations.push(l);
          }.bind(this));
          game.tileDataMap[myUid].gold += parseInt(score);
          console.log(myUid+'now gold : ', game.tileDataMap[myUid].gold,'- ',roundDesc);
          let desc = roundDesc || '';
          game.tileDataMap[myUid].actionsShown.push([type, times, score, locations, desc, huData]);
          console.log(game.tileDataMap[myUid].actionsShown)
      }
  
  
      getUserActions  (actions) {
          let actionsRst = [];
          _.each(actions, function (a) {
              let aa = Math.abs(a[0]);
              if (aa > 0 && aa < 5) {
                  actionsRst.push(_.initial(a));
              }
          }.bind(this));
          return actionsRst;
      }
  }
  
  module.exports = MjRecord;
  