user.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. };
  38. // 导出状态
  39. User.STATE = STATE;
  40. // 导出类
  41. module.exports = User;
  42. // 原型对象
  43. var proto = User.prototype;
  44. // 是否准备
  45. proto.isReady = function () {
  46. return this.state == STATE.READY;
  47. };
  48. //ts++ 是否二次准备
  49. proto.isReady2 = function () {
  50. return this.state2 == STATE.READY;
  51. };
  52. // 是否桌主
  53. proto.isOwner = function () {
  54. return (this.chairId != -1 && this.chairId == this.table.ownerId);
  55. };
  56. // 游戏中
  57. proto.isPlaying = function () {
  58. return this.state > STATE.READY;
  59. };
  60. // 是否断线
  61. proto.isOffline = function () {
  62. //return this.state == STATE.OFFLINE;
  63. return this.state2 == STATE.OFFLINE;
  64. };
  65. // TL++ 设置玩家经纬度
  66. proto.setJWDu = function (_longitude,_latitude) {
  67. this.longitude = _longitude; // 经度,浮点数,范围为180 ~ -180。
  68. this.latitude = _latitude; // 纬度,浮点数,范围为90 ~ -90
  69. };