//import TsdkFacade from '../TSDK/TsdkFacade';
import BehaviorBase from '../Framework/BehaviorBase';
import DataModelManager from '../Framework/DataModelManager'

export default class EnterRoomBehavior extends BehaviorBase
{
    // 收到玩家坐下
    OnPlayerSitDownEvent(id, evt) {
        console.log("OnPlayerSitDownEvent");

        if (evt.OtherInfo.tvalue[0].tlv._subtype === tsdk.TSMsgPara.TSHuanLeGameSvr.TLV_TYPE.EM_DN_TLV_PLAYERDETAIL) {
            let pPlayerDetail = evt.OtherInfo.tvalue[0].tlv.tvalue;
            let nickname = pPlayerDetail.Nick.tvalue;
            let headurl = pPlayerDetail.HeadUrl.tvalue;
            let seatid = pPlayerDetail.SeatID.tvalue;
            let playerId = pPlayerDetail.PlayerID.tvalue;
            console.log("name: " + nickname + "  url: " + headurl + " playerid: " + playerId);
            //let playerModel = this.dmm.getModel("PlayerInfoModel");
            //playerModel.setNickName(seatid, nickname);
           // playerModel.setHeadUrl(seatid, headurl);
           // playerModel.setPlayerId(seatid, playerId);
        }
        else {
            console.log("no player detail.");
        }
    }

    // 注册监听
    registerHandlers() {
        // 房间事件注册
     //   let gameSoMgr = TsdkFacade.getGameSoManager();
     //   gameSoMgr.addRoomEventHandler(3, this.OnPlayerSitDownEvent.bind(this));
    }

    constructor()
    {
        super();

        this.dmm = DataModelManager;

        // this.tsdk = TsdkFacade.getCore();

        // this.registerHandlers();

        // this.m_capEnterRoom = new tsdk.TSMsgPara.TSHuanLeGameSvr.TTLVUNIT();
        // var tdr = this.m_capEnterRoom.tlv.setSelectedTypeTdr(tsdk.TSMsgPara.TSHuanLeGameSvr.TLV_TYPE.EM_DN_TLV_PLAYER_CAPABILITY);
        // tdr.ClientCapability.tvalue = tsdk.TSMsgPara.TSHuanLeGameSvr.PLAYER_CAPABILITY_DEF.EPCD_GAMEING_JOIN | tsdk.TSMsgPara.TSHuanLeGameSvr.PLAYER_CAPABILITY_DEF.EPCD_POINT_RESULT;

        // // TODO: 新好友房，如果要进入老的好友房客户端可能要做一层兼容，不带这个标记(虽然后台的老好友房svr目前没有更新，没有这个bitflag的逻辑，但是还是最好做一下)
        // tdr.ClientCapability.tvalue |= tsdk.TSMsgPara.TSHuanLeGameSvr.PLAYER_CAPABILITY_DEF.EPCD_NEW_PRIVATE_ROOM;
    }

    // 快速开始
    quickEnter()
    {
        console.log("quick enter.");

        let self = this;
        // this.tsdk.enterGameRoomBySceneID(1260, [this.m_capEnterRoom], function (ret, obj) {
        //     console.log("enterGameRoomBySceneID ret:" + ret);
        //     self.emit('quickEnterEnd',{'ret':ret,'obj':obj});
        // }.bind(this));
    }

    // 坐下
    sitdown()
    {
        console.log("sitdown.");

        // 经典房，只认sitFlag，其余值可忽略     
        var roomId = -1;
        var tableId = -1;
        var seatId = -1;
        var gameSvrTlv = [];
        var sitFlag = tsdk.TSMsgPara.TSHuanLeGameSvr.SITDOWN_FLAG.ESDF_SERVER_SELECT_SEAT | tsdk.TSMsgPara.TSHuanLeGameSvr.SITDOWN_FLAG.ESDF_STANDUP_BEFORE_SITDOWN;

        let self = this;

        // this.tsdk.sitDown(sitFlag, roomId, tableId, seatId, gameSvrTlv, function (ret, retObj) {
        //     console.log("sitdown.");

        //     if (ret === 0) {
        //         let playerModel = this.dmm.getModel("PlayerInfoModel");

        //         // 对局房间信息记录
        //         let roomid = retObj.RoomID.tvalue;
        //         let tableid = retObj.TableID.tvalue;
        //         playerModel.setRoomId(roomid);
        //         playerModel.setTableId(tableid);

        //         //playerModel.setPlayerId(retObj.SeatID.tvalue, playerId);

        //         // 桌子已坐下玩家信息记录
        //         for (let i = 0; i < retObj.TLVNum.tvalue; i++)
        //         {
        //             if (retObj.TLVInfo.tvalue[i].tlv._subtype === tsdk.TSMsgPara.TSHuanLeGameSvr.TLV_TYPE.EM_DN_TLV_PLAYERDETAIL)
        //             {
        //                 //
        //                 let pPlayerDetail = retObj.TLVInfo.tvalue[i].tlv.tvalue;
        //                 /*
        //                 let stCmd = new TSDKMessage.T2UMsgUserEnter();

        //                 stCmd.happyBean = pPlayerDetail.Money.tvalue;
        //                 stCmd.playerUin = pPlayerDetail.PlayerUin.tvalue;
        //                 stCmd.playerSvrStatus = pPlayerDetail.PlayerStatus.tvalue;
        //                 stCmd.tableId = pPlayerDetail.TableID.tvalue;
        //                 stCmd.seatId = pPlayerDetail.SeatID.tvalue;
        //                 stCmd.nickName = pPlayerDetail.Nick.tvalue;
        //                 stCmd.headPicUrl = pPlayerDetail.HeadUrl.tvalue;
        //                 stCmd.gender = pPlayerDetail.Gender.tvalue;
        //                 stCmd.bAlreadyIn = false;

        //                 mj.PersonInfoModel.setPersonBaseInfo(pPlayerDetail.PlayerUin.tvalue,
        //                                                      pPlayerDetail.ClientType.tvalue,
        //                                                      pPlayerDetail.AccountType.tvalue,
        //                                                      pPlayerDetail.Nick.tvalue,
        //                                                      pPlayerDetail.HeadUrl.tvalue);
        //                 */
        //                 let nickname = pPlayerDetail.Nick.tvalue;
        //                 let headurl = pPlayerDetail.HeadUrl.tvalue;
        //                 let seatid = pPlayerDetail.SeatID.tvalue;
        //                 let playerId = pPlayerDetail.PlayerID.tvalue;
        //                 console.log("name: " + nickname + "  url: " + headurl + " playerid: " + playerId);
        //                 playerModel.setNickName(seatid, nickname);
        //                 playerModel.setHeadUrl(seatid, headurl);
        //                 playerModel.setPlayerId(seatid, playerId);
        //             }
        //         }
        //     }

        //     self.emit('sitdownEnd',{'ret':ret,'obj':retObj});
        // }.bind(this));
    }
}