123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- var Global = require("Global")
- var ProtocolGameServer = require("ProtocolGameServer")
- var GameProtocol = require("CachetaGameProtocol")
- cc.Class({
- extends: cc.Component,
- properties: {
- },
- statics: {
- makeGameData(m, s, data) {
- switch (m) {
- case ProtocolGameServer.MDM_GF_FRAME: {
- return this.makeFrameGameData(s, data);
- }
- break;
- case ProtocolGameServer.MDM_GF_GAME: {
- return this.makeGFGameData(s, data);
- }
- break;
- case ProtocolGameServer.MDM_GR_PRIVATE: {
- return this.makePrivateGameData(s, data);
- }
- break;
- default:
- break;
- }
- return null;
- },
- makePrivateGameData(s, data) {
- switch (s) {
- case ProtocolGameServer.SUB_GR_PRIVATE_DISMISS: {
- return this.makePrivateDismiss(data);
- }
- break;
- default:
- break;
- }
- return null;
- },
- makeFrameGameData(s, data) {
- switch (s) {
- case ProtocolGameServer.SUB_GR_TABLE_TALK: {
- return this.makeTableTalk(data);
- }
- case ProtocolGameServer.SUB_GR_TABLE_VOICE: {
- return this.makeTabelVoice(data);
- }
- default:
- break;
- }
- return null;
- },
- makeGFGameData(s, data) {
- switch (s) {
- case GameProtocol.SUB_C_GET_CARD: {//玩家抓牌
- return this.makeGetCard(data);
- }
- break;
- case GameProtocol.SUB_C_OUT_CARD: {//玩家出牌
- return this.makeOutCard(data);
- }
- break;
- case GameProtocol.SUB_C_HU_CARD: {//
- return this.makeHuCard(data);
- }
- break;
- case GameProtocol.SUB_C_TEST_CARD:{
- return this.makeTestCard(data);
- }
- case GameProtocol.SUB_C_MING_CARD:{
- return this.makeMingCard(data);
- }
- case GameProtocol.SUB_C_CANCEL_TRUSTEE:{
- return this.makeTrustee(data);
- }
- break;
- default:
- break;
- }
- return null;
- },
- makeTableTalk: function (data) {//SUB_GR_TABLE_TALK
- var arrayBuffer = new ArrayBuffer(138 + data.TalkSize + 8);
- var dv = new DataView(arrayBuffer);
- dv.pos = 8;
- Global.SetUint8(dv, data.Type);
- Global.SetUint8(dv, data.ChairID);
- Global.WriteChar(dv, data.String, 128);
- Global.SetUint32(dv, data.TalkSize);
- for (let index = 0; index < data.TalkSize; index++) {
- // if(index < data.TalkSize) {
- // }
- // else{
- // Global.SetUint8(dv, 0);
- // }
- Global.SetUint8(dv, data.TalkData[index]);
- }
- return dv;
- },
- makeTabelVoice: function (data) {//
- var str = Global.ToUTF_8(data.SerVerID, true);
- var len = str.length - 2 + 4;
- var arrayBuffer = new ArrayBuffer(len + 1 + 8);
- var dv = new DataView(arrayBuffer);
- dv.pos = 8;
- Global.SetUint8(dv, data.ChairID);
- Global.WriteString(dv, data.SerVerID);
- return dv;
- },
- makePrivateDismiss: function (data) { //SUB_GR_PRIVATE_DISMISS
- var arrayBuffer = new ArrayBuffer(1 + 8);
- var dv = new DataView(arrayBuffer);
- dv.pos = 8;
- Global.SetUint8(dv, data.Dismiss);
- return dv;
- },
- ///////////游戏逻辑
- makeGetCard: function (data) {//抓牌请求
- var arrayBuffer = new ArrayBuffer(8 + 1);
- var dv = new DataView(arrayBuffer);
- dv.pos = 8;
- Global.SetInt8(dv, data.bGetTableCard);
- return dv;
- },
- makeOutCard: function (data) {//出牌请求
- var arrayBuffer = new ArrayBuffer(8 + 1 + 1);
- var dv = new DataView(arrayBuffer);
- dv.pos = 8;
- Global.SetInt8(dv, data.cbOutCardData);
- Global.SetInt8(dv, data.bTing);
- return dv;
- },
- makeHuCard: function (data) {//
- var arrayBuffer = new ArrayBuffer(8);
- var dv = new DataView(arrayBuffer);
- dv.pos = 8;
- return dv;
- },
- makeMingCard(data) {
- var arrayBuffer = new ArrayBuffer(8);
- var dv = new DataView(arrayBuffer);
- dv.pos = 8;
- return dv;
- },
- makeTestCard: function (data) {//获取牌组
- var arrayBuffer = new ArrayBuffer(8+1*10+1);
- var dv = new DataView(arrayBuffer);
- dv.pos = 8;
- for(let i = 0; i < data.cbHandCard.length; ++i) {
- Global.SetInt8(dv, data.cbHandCard[i]);
- }
- // cbMagicCard
- Global.SetInt8(dv, data.cbMagicCard);
- return dv;
- },
- makeTrustee(data) {
- var arrayBuffer = new ArrayBuffer(8);
- var dv = new DataView(arrayBuffer);
- dv.pos = 8;
- return dv;
- },
-
- },
- start() {
- },
- });
|