Commit 3d2bc984 authored by Chunchi Che's avatar Chunchi Che

add selectCard adapter and service

parent b87313f2
Pipeline #19120 passed with stages
in 4 minutes and 45 seconds
import { ygopro } from "../idl/ocgcore"; import { ygopro } from "../idl/ocgcore";
import { numberToCardPosition, numberToCardZone } from "./util";
const OFFSET_UINT8 = 1; const OFFSET_UINT8 = 1;
const OFFSET_INT8 = 1; const OFFSET_INT8 = 1;
...@@ -62,6 +63,30 @@ export class BufferReader { ...@@ -62,6 +63,30 @@ export class BufferReader {
return cardInfo; return cardInfo;
} }
readCardLocation(overlay?: boolean): ygopro.CardLocation {
const controler = this.readUint8();
const location = this.readUint8();
const sequence = this.readUint8();
const ss = this.readUint8();
const cardLocation = new ygopro.CardLocation({
controler,
location: numberToCardZone(location),
sequence,
});
if (overlay) {
cardLocation.overlay_sequence = ss;
} else {
const position = numberToCardPosition(ss);
if (position) {
cardLocation.position = position;
}
}
return cardLocation;
}
} }
export class BufferWriter { export class BufferWriter {
......
...@@ -34,3 +34,4 @@ export const MSG_HINT = 2; ...@@ -34,3 +34,4 @@ 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; export const MSG_MOVE = 50;
export const MSG_SELECT_CARD = 15;
...@@ -14,6 +14,7 @@ import MsgHintAdapter from "./hint"; ...@@ -14,6 +14,7 @@ import MsgHintAdapter from "./hint";
import MsgSelectIdleCmdAdapter from "./selectIdleCmd"; import MsgSelectIdleCmdAdapter from "./selectIdleCmd";
import MsgSelectPlaceAdapter from "./selectPlace"; import MsgSelectPlaceAdapter from "./selectPlace";
import MsgMoveAdapter from "./move"; import MsgMoveAdapter from "./move";
import MsgSelectCardAdapter from "./selectCard";
/* /*
* STOC GameMsg * STOC GameMsg
...@@ -79,6 +80,11 @@ export default class GameMsgAdapter implements StocAdapter { ...@@ -79,6 +80,11 @@ export default class GameMsgAdapter implements StocAdapter {
break; break;
} }
case GAME_MSG.MSG_SELECT_CARD: {
gameMsg.select_card = MsgSelectCardAdapter(gameData);
break;
}
default: { default: {
console.log("Unhandled GameMessage function=", func); console.log("Unhandled GameMessage function=", func);
......
import { ygopro } from "../../../idl/ocgcore"; import { ygopro } from "../../../idl/ocgcore";
import { BufferReader } from "../../bufferIO"; import { BufferReader } from "../../bufferIO";
import {
cardZoneToNumber,
numberToCardPosition,
numberToCardZone,
} from "../../util";
import MsgMove = ygopro.StocGameMessage.MsgMove; import MsgMove = ygopro.StocGameMessage.MsgMove;
/* /*
...@@ -19,32 +14,8 @@ export default (data: Uint8Array) => { ...@@ -19,32 +14,8 @@ export default (data: Uint8Array) => {
const code = reader.readUint32(); const code = reader.readUint32();
const readCardLocation = () => { const fromLocation = reader.readCardLocation();
const controler = reader.readUint8(); const toLocation = reader.readCardLocation();
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)) {
const position = numberToCardPosition(ss);
if (position) {
cardLocation.position = position;
}
} else {
cardLocation.overlay_sequence = ss;
}
return cardLocation;
};
const fromLocation = readCardLocation();
const toLocation = readCardLocation();
return new MsgMove({ return new MsgMove({
code, code,
......
import { ygopro } from "../../../idl/ocgcore";
import { BufferReader } from "../../bufferIO";
import MsgSelectCard = ygopro.StocGameMessage.MsgSelectCard;
/*
* Msg Select Card
*
* @param - see: https://code.mycard.moe/mycard/neos-protobuf/-/blob/main/idl/ocgcore.neos-protobuf
* @usage - 玩家可选择的卡牌
* */
export default (data: Uint8Array) => {
const reader = new BufferReader(data, true);
const player = reader.readUint8();
const cancelable = reader.readUint8() != 0;
const min = reader.readUint8();
const max = reader.readUint8();
const count = reader.readUint8();
const msg = new MsgSelectCard({ player, cancelable, min, max });
for (let i = 0; i < count; i++) {
const code = reader.readUint32();
const location = reader.readCardLocation();
msg.cards.push(
new MsgSelectCard.SelectAbleCard({ code, location, response: i })
);
}
return msg;
};
...@@ -157,6 +157,7 @@ export function numberToCardZone( ...@@ -157,6 +157,7 @@ export function numberToCardZone(
} }
} }
// TODO: 需要考虑超量叠加情况下的位运算
export function numberToCardPosition( export function numberToCardPosition(
position: number position: number
): ygopro.CardPosition | undefined { ): ygopro.CardPosition | undefined {
......
...@@ -8,6 +8,7 @@ import onMsgHint from "./hint"; ...@@ -8,6 +8,7 @@ import onMsgHint from "./hint";
import onMsgSelectIdleCmd from "./selectIdleCmd"; import onMsgSelectIdleCmd from "./selectIdleCmd";
import onMsgSelectPlace from "./selectPlace"; import onMsgSelectPlace from "./selectPlace";
import onMsgMove from "./move"; import onMsgMove from "./move";
import onMsgSelectCard from "./selectCard";
export default function handleGameMsg(pb: ygopro.YgoStocMsg) { export default function handleGameMsg(pb: ygopro.YgoStocMsg) {
const dispatch = store.dispatch; const dispatch = store.dispatch;
...@@ -70,6 +71,13 @@ export default function handleGameMsg(pb: ygopro.YgoStocMsg) { ...@@ -70,6 +71,13 @@ export default function handleGameMsg(pb: ygopro.YgoStocMsg) {
break; break;
} }
case "select_card": {
const selectCard = msg.select_card;
onMsgSelectCard(selectCard, dispatch);
break;
}
default: { default: {
break; break;
} }
......
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { AppDispatch } from "../../store";
import MsgSelectCard = ygopro.StocGameMessage.MsgSelectCard;
export default (selectCard: MsgSelectCard, dispatch: AppDispatch) => {
console.log(selectCard);
// TODO
};
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