Commit 6f2368cd authored by Chunchi Che's avatar Chunchi Che

add newPhase.ts

parent 41b63760
This source diff could not be displayed because it is too large. You can view the blob instead.
const OFFSET_UINT8 = 1;
const OFFSET_INT8 = 1;
const OFFSET_UINT16 = 2;
const OFFSET_UINT32 = 4;
export class BufferReader {
......@@ -27,6 +28,13 @@ export class BufferReader {
return ret;
}
readUint16(): number {
const ret = this.dataView.getUint16(this.offset);
this.offset += OFFSET_UINT16;
return ret;
}
readUint32(): number {
const ret = this.dataView.getUint32(this.offset, this.littleEndian);
this.offset += OFFSET_UINT32;
......
......@@ -26,3 +26,4 @@ export const STOC_GAME_MSG = 1;
export const MSG_START = 4;
export const MSG_DRAW = 90;
export const MSG_NEW_TURN = 40;
export const MSG_NEW_PHASE = 41;
import { ygopro } from "../../../idl/ocgcore";
import { BufferReader } from "../../bufferIO";
const LITTLE_ENDIAN = true;
/*
* Msg New Phase
*
* @param phase: uint16 - 下一个阶段
*
* @usage - 服务端告诉前端下一个阶段
* */
export default (data: Uint8Array) => {
const reader = new BufferReader(data, LITTLE_ENDIAN);
const player = reader.readUint16();
let phaseType = ygopro.StocGameMessage.MsgNewPhase.PhaseType.UNKNOWN;
switch (player) {
case 0x01: {
phaseType = ygopro.StocGameMessage.MsgNewPhase.PhaseType.DRAW;
break;
}
case 0x02: {
break;
}
case 0x04: {
phaseType = ygopro.StocGameMessage.MsgNewPhase.PhaseType.MAIN1;
break;
}
case 0x08: {
phaseType = ygopro.StocGameMessage.MsgNewPhase.PhaseType.BATTLE_START;
break;
}
case 0x10: {
phaseType = ygopro.StocGameMessage.MsgNewPhase.PhaseType.BATTLE_STEP;
break;
}
case 0x20: {
phaseType = ygopro.StocGameMessage.MsgNewPhase.PhaseType.DAMAGE;
break;
}
case 0x40: {
phaseType = ygopro.StocGameMessage.MsgNewPhase.PhaseType.DAMAGE_GAL;
break;
}
case 0x80: {
phaseType = ygopro.StocGameMessage.MsgNewPhase.PhaseType.BATTLE;
break;
}
case 0x100: {
phaseType = ygopro.StocGameMessage.MsgNewPhase.PhaseType.MAIN2;
break;
}
case 0x200: {
phaseType = ygopro.StocGameMessage.MsgNewPhase.PhaseType.END;
break;
}
default: {
break;
}
}
return new ygopro.StocGameMessage.MsgNewPhase({
phase_type: phaseType,
});
};
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