Commit 23ff98cf authored by chechunchi's avatar chechunchi

add penetrate but remain bug

parent 26ff2f20
...@@ -19,6 +19,7 @@ import MsgSelectChainAdapter from "./selectChain"; ...@@ -19,6 +19,7 @@ import MsgSelectChainAdapter from "./selectChain";
import MsgSelectEffectYnAdapter from "./selectEffectYn"; import MsgSelectEffectYnAdapter from "./selectEffectYn";
import MsgSelectPositionAdapter from "./selectPosition"; import MsgSelectPositionAdapter from "./selectPosition";
import MsgSelectOptionAdapter from "./selectOption"; import MsgSelectOptionAdapter from "./selectOption";
import { penetrate } from "./penetrate";
/* /*
* STOC GameMsg * STOC GameMsg
...@@ -41,83 +42,86 @@ export default class GameMsgAdapter implements StocAdapter { ...@@ -41,83 +42,86 @@ export default class GameMsgAdapter implements StocAdapter {
const func = dataView.getUint8(0); const func = dataView.getUint8(0);
const gameData = exData.slice(1); const gameData = exData.slice(1);
const gameMsg = new ygopro.StocGameMessage({}); let gameMsg: any = new ygopro.StocGameMessage({}).toObject();
switch (func) { if (!penetrate(func, gameMsg, gameData)) {
case GAME_MSG.MSG_START: { switch (func) {
gameMsg.start = MsgStartAdapter(gameData); case GAME_MSG.MSG_START: {
gameMsg.start = MsgStartAdapter(gameData);
break;
} break;
case GAME_MSG.MSG_DRAW: { }
gameMsg.draw = MsgDrawAdapter(gameData); case GAME_MSG.MSG_DRAW: {
gameMsg.draw = MsgDrawAdapter(gameData);
break;
} break;
case GAME_MSG.MSG_NEW_TURN: { }
gameMsg.new_turn = MsgNewTurnAdapter(gameData); case GAME_MSG.MSG_NEW_TURN: {
gameMsg.new_turn = MsgNewTurnAdapter(gameData);
break;
} break;
case GAME_MSG.MSG_NEW_PHASE: { }
gameMsg.new_phase = MsgNewPhaseAdapter(gameData); case GAME_MSG.MSG_NEW_PHASE: {
gameMsg.new_phase = MsgNewPhaseAdapter(gameData);
break;
} break;
case GAME_MSG.MSG_HINT: { }
gameMsg.hint = MsgHintAdapter(gameData); case GAME_MSG.MSG_HINT: {
gameMsg.hint = MsgHintAdapter(gameData);
break;
} break;
case GAME_MSG.MSG_SELECT_IDLE_CMD: { }
gameMsg.select_idle_cmd = MsgSelectIdleCmdAdapter(gameData); case GAME_MSG.MSG_SELECT_IDLE_CMD: {
gameMsg.select_idle_cmd = MsgSelectIdleCmdAdapter(gameData);
break;
} break;
case GAME_MSG.MSG_SELECT_PLACE: { }
gameMsg.select_place = MsgSelectPlaceAdapter(gameData); case GAME_MSG.MSG_SELECT_PLACE: {
gameMsg.select_place = MsgSelectPlaceAdapter(gameData);
break;
} break;
case GAME_MSG.MSG_MOVE: { }
gameMsg.move = MsgMoveAdapter(gameData); // case GAME_MSG.MSG_MOVE: {
// // gameMsg.move = MsgMoveAdapter(gameData);
break; // gameMsg["move"] = MsgMoveAdapter(gameData);
} //
case GAME_MSG.MSG_SELECT_CARD: { // break;
gameMsg.select_card = MsgSelectCardAdapter(gameData); // }
case GAME_MSG.MSG_SELECT_CARD: {
break; gameMsg.select_card = MsgSelectCardAdapter(gameData);
}
case GAME_MSG.MSG_SELECT_CHAIN: { break;
gameMsg.select_chain = MsgSelectChainAdapter(gameData); }
case GAME_MSG.MSG_SELECT_CHAIN: {
break; gameMsg.select_chain = MsgSelectChainAdapter(gameData);
}
case GAME_MSG.MSG_SELECT_EFFECTYN: { break;
gameMsg.select_effect_yn = MsgSelectEffectYnAdapter(gameData); }
case GAME_MSG.MSG_SELECT_EFFECTYN: {
break; gameMsg.select_effect_yn = MsgSelectEffectYnAdapter(gameData);
}
case GAME_MSG.MSG_SELECT_POSITION: { break;
gameMsg.select_position = MsgSelectPositionAdapter(gameData); }
case GAME_MSG.MSG_SELECT_POSITION: {
break; gameMsg.select_position = MsgSelectPositionAdapter(gameData);
}
case GAME_MSG.MSG_SELECT_OPTION: { break;
gameMsg.select_option = MsgSelectOptionAdapter(gameData); }
case GAME_MSG.MSG_SELECT_OPTION: {
break; gameMsg.select_option = MsgSelectOptionAdapter(gameData);
}
default: { break;
console.log("Unhandled GameMessage function=", func); }
default: {
break; console.log("Unhandled GameMessage function=", func);
break;
}
} }
} }
return new ygopro.YgoStocMsg({ return new ygopro.YgoStocMsg({
stoc_game_msg: gameMsg, stoc_game_msg: new ygopro.StocGameMessage(gameMsg),
}); });
} }
} }
{
"50": {
"protoType": "move",
"fields": [
{
"fieldName": "code",
"fieldType": "uint32"
},
{
"fieldName": "from",
"fieldType": "CardLocation"
},
{
"fieldName": "to",
"fieldType": "CardLocation"
},
{
"fieldName": "reason",
"fieldType": "uint8"
}
]
}
}
//! 透传协议
import PenetrateData from "./penetrate.json";
import { BufferReader } from "../../bufferIO";
export interface penetrateType {
protoType: string;
fields: {
fieldName: string;
fieldType: string;
}[];
}
const PenetrateConfig = _objToMap(PenetrateData);
export function penetrate(
msgKey: number,
gameMsg: any,
gameData: Uint8Array
): boolean {
const config = PenetrateConfig.get(msgKey.toString());
const reader = new BufferReader(gameData, true);
if (config) {
const protoType = config.protoType;
const fields = config.fields;
let obj: any = {};
for (let field of fields) {
obj[field.fieldName] = readField(reader, field.fieldType);
}
gameMsg[protoType] = obj;
}
return config ? true : false;
}
function _objToMap(obj: any): Map<string, penetrateType> {
let map = new Map();
for (let key of Object.keys(obj)) {
map.set(key, obj[key]);
}
return map;
}
function readField(reader: BufferReader, fieldType: string): any {
switch (fieldType) {
case "uint8": {
return reader.readUint8();
}
case "uint32": {
return reader.readUint32();
}
case "CardLocation": {
return reader.readCardLocation();
}
default: {
return undefined;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment