user.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. 'use strict';
  2. var quick = require('quick-pomelo');
  3. var P = quick.Promise;
  4. var C = require('../../share/constant');
  5. var logger = quick.logger.getLogger('user', __filename);
  6. // 玩家状态
  7. var STATE = { FREE: 1, READY: 2, PLAYING: 3, OFFLINE: 4 };//////刚刚进入坐下(也就是准备)之前 和 游戏结束之后 玩家的状态都是 free
  8. // 构造方法
  9. var User = function (game, player, table) {
  10. this.game = game;
  11. this.table = table;
  12. this.id = player._id;
  13. this.userId = player.userId;//////TL++,为了在玩家进入的时候给前端发送玩家的userID
  14. this.connectorId = player.connectorId;
  15. // let name=player.name;
  16. // if(player.name>4)
  17. // {
  18. // name=player.name.substr(0,4);
  19. // }
  20. // console.warn("玩家+++++",name);
  21. this.name = player.name;
  22. this.sex = player.sex;
  23. this.headurl = player.headurl;
  24. this.account = player.account;
  25. this.longitude = 0; // 经度,浮点数,范围为180 ~ -180。
  26. this.latitude = 0; // 纬度,浮点数,范围为90 ~ -90
  27. this.state = STATE.FREE;
  28. this.state2 = STATE.FREE;//ts++第二状态 用来第二次开始用
  29. this.chairId = -1;
  30. this.diamond = player.diamond;//钻石
  31. this.cost = player.cost;//消费 用来判断是否是第一次游戏
  32. this.spreadId = player.spreadId;//推荐人id
  33. this.createtime = Date.now();//创建时间
  34. this.offlinetime = 0;//ts++断线时间
  35. this.registerTime = player.registerTime;//TL++20200918
  36. this.lastLoginTime = player.lastLoginTime;//TL++20200918
  37. this.taskQuan = 0; //任务券数量
  38. this.drCount = 0;//带入分数(1分=10钻石,每日上限1w分)
  39. };
  40. // 导出状态
  41. User.STATE = STATE;
  42. // 导出类
  43. module.exports = User;
  44. // 原型对象
  45. var proto = User.prototype;
  46. // 是否准备
  47. proto.isReady = function () {
  48. // console.warn("是否准备 111 ",this.state , STATE.READY);
  49. return this.state == STATE.READY;
  50. };
  51. //ts++ 是否二次准备
  52. proto.isReady2 = function () {
  53. // console.warn("是否准备 222 ",this.state2 , STATE.READY);
  54. return this.state2 == STATE.READY;
  55. };
  56. // 是否桌主
  57. proto.isOwner = function () {
  58. return (this.chairId != -1 && this.id && this.table.ownerId && this.id == this.table.ownerId);
  59. };
  60. // 游戏中
  61. proto.isPlaying = function () {
  62. return this.state > STATE.READY;
  63. };
  64. // 是否断线
  65. proto.isOffline = function () {
  66. //return this.state == STATE.OFFLINE;
  67. return this.state2 == STATE.OFFLINE;
  68. };
  69. // TL++ 设置玩家经纬度
  70. proto.setJWDu = function (_longitude,_latitude) {
  71. this.longitude = _longitude; // 经度,浮点数,范围为180 ~ -180。
  72. this.latitude = _latitude; // 纬度,浮点数,范围为90 ~ -90
  73. };