Commit d8cfe6a5 authored by Chunchi Che's avatar Chunchi Che

add MsgMoveAdapter

parent e796acce
...@@ -33,3 +33,4 @@ export const MSG_NEW_PHASE = 41; ...@@ -33,3 +33,4 @@ export const MSG_NEW_PHASE = 41;
export const MSG_HINT = 2; export const MSG_HINT = 2;
export const MSG_SELECT_IDLE_CMD = 11; export const MSG_SELECT_IDLE_CMD = 11;
export const MSG_SELECT_PLACE = 18; export const MSG_SELECT_PLACE = 18;
export const MSG_MOVE = 50;
...@@ -13,6 +13,7 @@ import MsgNewPhaseAdapter from "./newPhase"; ...@@ -13,6 +13,7 @@ import MsgNewPhaseAdapter from "./newPhase";
import MsgHintAdapter from "./hint"; import MsgHintAdapter from "./hint";
import MsgSelectIdleCmdAdapter from "./selectIdleCmd"; import MsgSelectIdleCmdAdapter from "./selectIdleCmd";
import MsgSelectPlaceAdapter from "./selectPlace"; import MsgSelectPlaceAdapter from "./selectPlace";
import MsgMoveAdapter from "./move";
/* /*
* STOC GameMsg * STOC GameMsg
...@@ -73,6 +74,11 @@ export default class GameMsgAdapter implements StocAdapter { ...@@ -73,6 +74,11 @@ export default class GameMsgAdapter implements StocAdapter {
break; break;
} }
case GAME_MSG.MSG_MOVE: {
gameMsg.move = MsgMoveAdapter(gameData);
break;
}
default: { default: {
console.log("Unhandled GameMessage function=", func); console.log("Unhandled GameMessage function=", func);
......
import { ygopro } from "../../../idl/ocgcore";
import { BufferReader } from "../../bufferIO";
import { cardZoneToNumber, numberToCardZone } from "../../util";
import MsgMove = ygopro.StocGameMessage.MsgMove;
/*
* Msg Move
* @param - TODO
*
* @usage - 服务端告知前端/客户端卡牌移动信息
* */
export default (data: Uint8Array) => {
const reader = new BufferReader(data, true);
const code = reader.readUint32();
const readCardLocation = () => {
const controler = reader.readUint8();
const location = reader.readUint8();
const sequence = reader.readUint8();
const ss = reader.readUint8();
const cardLocation = new ygopro.CardLocation({
controler,
location: numberToCardZone(location),
sequence,
});
if (location != cardZoneToNumber(ygopro.CardZone.OVERLAY)) {
cardLocation.position = ss;
} else {
cardLocation.overlay_sequence = ss;
}
return cardLocation;
};
const fromLocation = readCardLocation();
const toLocation = readCardLocation();
return new MsgMove({
code,
from: fromLocation,
to: toLocation,
reason: reader.readUint8(),
});
};
...@@ -113,3 +113,46 @@ export function cardZoneToNumber(zone: ygopro.CardZone): number { ...@@ -113,3 +113,46 @@ export function cardZoneToNumber(zone: ygopro.CardZone): number {
} }
} }
} }
export function numberToCardZone(
location: number
): ygopro.CardZone | undefined {
switch (location) {
case 0x01: {
return ygopro.CardZone.DECK;
}
case 0x02: {
return ygopro.CardZone.HAND;
}
case 0x04: {
return ygopro.CardZone.MZONE;
}
case 0x08: {
return ygopro.CardZone.SZONE;
}
case 0x10: {
return ygopro.CardZone.GRAVE;
}
case 0x20: {
return ygopro.CardZone.REMOVED;
}
case 0x40: {
return ygopro.CardZone.EXTRA;
}
case 0x80: {
return ygopro.CardZone.OVERLAY;
}
case 0x0c: {
return ygopro.CardZone.ONFIELD;
}
case 0x100: {
return ygopro.CardZone.FZONE;
}
case 0x200: {
return ygopro.CardZone.PZONE;
}
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