| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- 'use strict';
- var quick = require('quick-pomelo');
- var P = quick.Promise;
- var C = require('../../share/constant');
- var logger = quick.logger.getLogger('user', __filename);
- // 玩家状态
- var STATE = { FREE: 1, READY: 2, PLAYING: 3, OFFLINE: 4 };//////刚刚进入坐下(也就是准备)之前 和 游戏结束之后 玩家的状态都是 free
- // 构造方法
- var User = function (game, player, table) {
- this.game = game;
- this.table = table;
- this.id = player._id;
- this.userId = player.userId;//////TL++,为了在玩家进入的时候给前端发送玩家的userID
- this.connectorId = player.connectorId;
- // let name=player.name;
- // if(player.name>4)
- // {
- // name=player.name.substr(0,4);
- // }
- // console.warn("玩家+++++",name);
- this.name = player.name;
- this.sex = player.sex;
- this.headurl = player.headurl;
- this.account = player.account;
- this.longitude = 0; // 经度,浮点数,范围为180 ~ -180。
- this.latitude = 0; // 纬度,浮点数,范围为90 ~ -90
- this.state = STATE.FREE;
- this.state2 = STATE.FREE;//ts++第二状态 用来第二次开始用
- this.chairId = -1;
- this.diamond = player.diamond;//钻石
- this.cost = player.cost;//消费 用来判断是否是第一次游戏
- this.spreadId = player.spreadId;//推荐人id
- this.createtime = Date.now();//创建时间
- this.offlinetime = 0;//ts++断线时间
- this.registerTime = player.registerTime;//TL++20200918
- this.lastLoginTime = player.lastLoginTime;//TL++20200918
- this.taskQuan = 0; //任务券数量
- this.drCount = 0;//带入分数(1分=10钻石,每日上限1w分)
- };
- // 导出状态
- User.STATE = STATE;
- // 导出类
- module.exports = User;
- // 原型对象
- var proto = User.prototype;
- // 是否准备
- proto.isReady = function () {
- // console.warn("是否准备 111 ",this.state , STATE.READY);
- return this.state == STATE.READY;
- };
- //ts++ 是否二次准备
- proto.isReady2 = function () {
- // console.warn("是否准备 222 ",this.state2 , STATE.READY);
- return this.state2 == STATE.READY;
- };
- // 是否桌主
- proto.isOwner = function () {
- return (this.chairId != -1 && this.id && this.table.ownerId && this.id == this.table.ownerId);
- };
- // 游戏中
- proto.isPlaying = function () {
- return this.state > STATE.READY;
- };
- // 是否断线
- proto.isOffline = function () {
- //return this.state == STATE.OFFLINE;
- return this.state2 == STATE.OFFLINE;
- };
- // TL++ 设置玩家经纬度
- proto.setJWDu = function (_longitude,_latitude) {
- this.longitude = _longitude; // 经度,浮点数,范围为180 ~ -180。
- this.latitude = _latitude; // 纬度,浮点数,范围为90 ~ -90
- };
|