Commit 6811be94 authored by Chunchi Che's avatar Chunchi Che

Merge branch 'feat/service/select_card' into 'main'

Feat/service/select card

See merge request mycard/Neos!60
parents ae0cafb9 8ddec62c
neos-protobuf @ 07651117
Subproject commit 621489ace4b9d2ecb653fe0da25279b68154d206 Subproject commit 07651117cd5f99d81740c2419383a88904ba6557
This diff is collapsed.
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 && overlay) {
cardLocation.overlay_sequence = ss;
} else {
const position = numberToCardPosition(ss);
if (position) {
cardLocation.position = position;
}
}
return cardLocation;
}
} }
export class BufferWriter { export class BufferWriter {
......
...@@ -3,6 +3,7 @@ import { YgoProPacket } from "../../packet"; ...@@ -3,6 +3,7 @@ import { YgoProPacket } from "../../packet";
import { CTOS_RESPONSE } from "../../protoDecl"; import { CTOS_RESPONSE } from "../../protoDecl";
import adaptSelectIdleCmdResponse from "./selectIdleCmd"; import adaptSelectIdleCmdResponse from "./selectIdleCmd";
import adaptSelectPlaceResponse from "./selectPlace"; import adaptSelectPlaceResponse from "./selectPlace";
import adaptSelectCardResponse from "./selectCard";
/* /*
* CTOS CTOS_RESPONSE * CTOS CTOS_RESPONSE
...@@ -28,6 +29,11 @@ export default class CtosResponsePacket extends YgoProPacket { ...@@ -28,6 +29,11 @@ export default class CtosResponsePacket extends YgoProPacket {
break; break;
} }
case "select_card": {
extraData = adaptSelectCardResponse(response.select_card);
break;
}
default: { default: {
break; break;
} }
......
import { ygopro } from "../../../idl/ocgcore";
import { BufferWriter } from "../../bufferIO";
export default (response: ygopro.CtosGameMsgResponse.SelectCardResponse) => {
const array = new Uint8Array(1 + response.selected_ptrs.length);
const writer = new BufferWriter(array, true);
writer.writeUint8(response.selected_ptrs.length);
for (const ptr of response.selected_ptrs) {
writer.writeUint8(ptr);
}
return array;
};
...@@ -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 {
......
...@@ -150,3 +150,16 @@ export function sendSelectPlaceResponse(value: { ...@@ -150,3 +150,16 @@ export function sendSelectPlaceResponse(value: {
socketMiddleWare({ cmd: socketCmd.SEND, payload }); socketMiddleWare({ cmd: socketCmd.SEND, payload });
} }
export function sendSelectCardResponse(value: number[]) {
const response = new ygopro.YgoCtosMsg({
ctos_response: new ygopro.CtosGameMsgResponse({
select_card: new ygopro.CtosGameMsgResponse.SelectCardResponse({
selected_ptrs: value,
}),
}),
});
const payload = new GameMsgResponse(response).serialize();
socketMiddleWare({ cmd: socketCmd.SEND, payload });
}
...@@ -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
};
...@@ -34,7 +34,6 @@ const CardListModal = () => { ...@@ -34,7 +34,6 @@ const CardListModal = () => {
cover={<img alt={item.name} src={item.imgUrl} />} cover={<img alt={item.name} src={item.imgUrl} />}
> >
<Meta title={item.name} /> <Meta title={item.name} />
<p>{item.desc}</p>
</Card> </Card>
} }
> >
......
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