Commit c64ba78a authored by Chunchi Che's avatar Chunchi Che

add draw.ts and bufferIO.ts

parent 39e8bf88
const OFFSET_UINT8 = 1;
const OFFSET_INT8 = 1;
const OFFSET_UINT32 = 4;
export class BufferReader {
dataView: DataView;
littleEndian: boolean;
offset: number;
constructor(data: Uint8Array, littleEndian: boolean) {
this.dataView = new DataView(data.buffer);
this.littleEndian = littleEndian;
this.offset = 0;
}
readUint8(): number {
const ret = this.dataView.getUint8(this.offset);
this.offset += OFFSET_UINT8;
return ret;
}
readInt8(): number {
const ret = this.dataView.getInt8(this.offset);
this.offset += OFFSET_INT8;
return ret;
}
readUint32(): number {
const ret = this.dataView.getUint32(this.offset, this.littleEndian);
this.offset += OFFSET_UINT32;
return ret;
}
}
...@@ -24,3 +24,4 @@ export const STOC_DUEL_START = 21; ...@@ -24,3 +24,4 @@ export const STOC_DUEL_START = 21;
export const STOC_GAME_MSG = 1; export const STOC_GAME_MSG = 1;
export const MSG_START = 4; export const MSG_START = 4;
export const MSG_DRAW = 90;
import { ygopro } from "../../../idl/ocgcore";
import { BufferReader } from "../../bufferIO";
const LITTLE_ENDIAN = true;
/*
* MSG Draw
*
* @param player: char - 玩家编号
*
* @usage - 玩家抽卡内容
* */
export default (data: Uint8Array) => {
const reader = new BufferReader(data, LITTLE_ENDIAN);
const player = reader.readUint8();
const count = reader.readUint8();
let hands: number[] = [];
for (let i = 0; i < count; i++) {
hands.push(reader.readUint32());
}
// TODO
};
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
import { ygopro } from "../../../idl/ocgcore"; import { ygopro } from "../../../idl/ocgcore";
import { YgoProPacket, StocAdapter } from "../../packet"; import { YgoProPacket, StocAdapter } from "../../packet";
import { MSG_START } from "../../protoDecl"; import * as GAME_MSG from "../../protoDecl";
import MsgStartAdapter from "./start"; import MsgStartAdapter from "./start";
/* /*
...@@ -32,11 +32,16 @@ export default class GameMsgAdapter implements StocAdapter { ...@@ -32,11 +32,16 @@ export default class GameMsgAdapter implements StocAdapter {
const gameMsg = new ygopro.StocGameMessage({}); const gameMsg = new ygopro.StocGameMessage({});
switch (func) { switch (func) {
case MSG_START: { case GAME_MSG.MSG_START: {
gameMsg.start = MsgStartAdapter(gameData); gameMsg.start = MsgStartAdapter(gameData);
break; break;
} }
case GAME_MSG.MSG_DRAW: {
// TODO
break;
}
default: { default: {
console.log("Unhandled GameMessage function=", func); console.log("Unhandled GameMessage function=", func);
......
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