Commit 55eba807 authored by Chunchi Che's avatar Chunchi Che Committed by WANG HE

handle deckcount

parent 3989ad51
...@@ -10,6 +10,8 @@ import { ...@@ -10,6 +10,8 @@ import {
STOC_SELECT_HAND, STOC_SELECT_HAND,
STOC_SELECT_TP, STOC_SELECT_TP,
STOC_HAND_RESULT, STOC_HAND_RESULT,
STOC_DECK_COUNT,
STOC_DUEL_START,
} from "./protoDecl"; } from "./protoDecl";
import StocChat from "./stoc/stocChat"; import StocChat from "./stoc/stocChat";
import StocJoinGame from "./stoc/stocJoinGame"; import StocJoinGame from "./stoc/stocJoinGame";
...@@ -19,6 +21,7 @@ import StocHsWatchChange from "./stoc/stocHsWatchChange"; ...@@ -19,6 +21,7 @@ import StocHsWatchChange from "./stoc/stocHsWatchChange";
import StocTypeChange from "./stoc/stocTypeChange"; import StocTypeChange from "./stoc/stocTypeChange";
import StocSelectHand from "./stoc/stocSelectHand"; import StocSelectHand from "./stoc/stocSelectHand";
import StocSelectTp from "./stoc/stocSelectTp"; import StocSelectTp from "./stoc/stocSelectTp";
import StocDeckCount from "./stoc/stocDeckCount";
/* /*
* 将[`ygoProPacket`]对象转换成[`ygopro.YgoStocMsg`]对象 * 将[`ygoProPacket`]对象转换成[`ygopro.YgoStocMsg`]对象
...@@ -74,6 +77,16 @@ export function adaptStoc(packet: ygoProPacket): ygopro.YgoStocMsg { ...@@ -74,6 +77,16 @@ export function adaptStoc(packet: ygoProPacket): ygopro.YgoStocMsg {
break; break;
} }
case STOC_DECK_COUNT: {
pb = new StocDeckCount(packet).upcast();
break;
}
case STOC_DUEL_START: {
// TODO
break;
}
default: { default: {
break; break;
} }
......
...@@ -19,3 +19,5 @@ export const STOC_TYPE_CHANGE = 19; ...@@ -19,3 +19,5 @@ export const STOC_TYPE_CHANGE = 19;
export const STOC_SELECT_HAND = 3; export const STOC_SELECT_HAND = 3;
export const STOC_SELECT_TP = 4; export const STOC_SELECT_TP = 4;
export const STOC_HAND_RESULT = 5; export const STOC_HAND_RESULT = 5;
export const STOC_DECK_COUNT = 9;
export const STOC_DUEL_START = 21;
import { ygopro } from "../../idl/ocgcore";
import { ygoProPacket, StocAdapter } from "../packet";
const LITTLE_ENDIAN = true;
const INT16_BYTE_OFFSET = 2;
/*
* STOC DeckCount
*
* @param see ocgcore.proto
*
* @usage - 展示双方卡组信息
* */
export default class deckCountAdapter implements StocAdapter {
packet: ygoProPacket;
constructor(packet: ygoProPacket) {
this.packet = packet;
}
upcast(): ygopro.YgoStocMsg {
const pb = new ygopro.StocDeckCount({});
const dataView = new DataView(this.packet.exData.buffer);
pb.meMain = dataView.getInt16(0 * INT16_BYTE_OFFSET, LITTLE_ENDIAN);
pb.meExtra = dataView.getInt16(1 * INT16_BYTE_OFFSET, LITTLE_ENDIAN);
pb.meSide = dataView.getInt16(2 * INT16_BYTE_OFFSET, LITTLE_ENDIAN);
pb.opMain = dataView.getInt16(3 * INT16_BYTE_OFFSET, LITTLE_ENDIAN);
pb.opExtra = dataView.getInt16(4 * INT16_BYTE_OFFSET, LITTLE_ENDIAN);
pb.opSide = dataView.getInt16(5 * INT16_BYTE_OFFSET, LITTLE_ENDIAN);
return new ygopro.YgoStocMsg({
stoc_deck_count: pb,
});
}
}
...@@ -14,7 +14,7 @@ export default class joinGameAdapter implements StocAdapter { ...@@ -14,7 +14,7 @@ export default class joinGameAdapter implements StocAdapter {
} }
upcast(): ygopro.YgoStocMsg { upcast(): ygopro.YgoStocMsg {
// todo // TODO
return new ygopro.YgoStocMsg({ return new ygopro.YgoStocMsg({
stoc_join_game: new ygopro.StocJoinGame({}), stoc_join_game: new ygopro.StocJoinGame({}),
}); });
......
...@@ -9,6 +9,13 @@ export interface Player { ...@@ -9,6 +9,13 @@ export interface Player {
name?: string; name?: string;
state?: string; state?: string;
isHost?: boolean; isHost?: boolean;
deckInfo?: deckInfo;
}
export interface deckInfo {
mainCnt: number;
extraCnt: number;
sideCnt: number;
} }
export interface playerState { export interface playerState {
...@@ -47,6 +54,12 @@ const playerSlice = createSlice({ ...@@ -47,6 +54,12 @@ const playerSlice = createSlice({
player1Leave: (state) => { player1Leave: (state) => {
state.player1 = {}; state.player1 = {};
}, },
player0DeckInfo: (state, action: PayloadAction<deckInfo>) => {
state.player0.deckInfo = action.payload;
},
player1DeckInfo: (state, action: PayloadAction<deckInfo>) => {
state.player1.deckInfo = action.payload;
},
hostChange: (state, action: PayloadAction<number>) => { hostChange: (state, action: PayloadAction<number>) => {
const i = action.payload; const i = action.payload;
...@@ -77,6 +90,8 @@ export const { ...@@ -77,6 +90,8 @@ export const {
player1Update, player1Update,
player0Leave, player0Leave,
player1Leave, player1Leave,
player0DeckInfo,
player1DeckInfo,
hostChange, hostChange,
observerIncrement, observerIncrement,
observerChange, observerChange,
......
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { store } from "../../store";
import { player0DeckInfo, player1DeckInfo } from "../../reducers/playerSlice";
// FIXME: player0 不一定是当前玩家
export default function handleDeckCount(pb: ygopro.YgoStocMsg) {
const dispath = store.dispatch;
const deckCount = pb.stoc_deck_count;
dispath(
player0DeckInfo({
mainCnt: deckCount.meMain,
extraCnt: deckCount.meExtra,
sideCnt: deckCount.meSide,
})
);
dispath(
player1DeckInfo({
mainCnt: deckCount.opMain,
extraCnt: deckCount.opExtra,
sideCnt: deckCount.opSide,
})
);
}
...@@ -12,6 +12,7 @@ import { ygoProPacket } from "../api/ocgcore/ocgAdapter/packet"; ...@@ -12,6 +12,7 @@ import { ygoProPacket } from "../api/ocgcore/ocgAdapter/packet";
import { adaptStoc } from "../api/ocgcore/ocgAdapter/adapter"; import { adaptStoc } from "../api/ocgcore/ocgAdapter/adapter";
import handleSelectHand from "./mora/selectHand"; import handleSelectHand from "./mora/selectHand";
import handleSelectTp from "./mora/selectTp"; import handleSelectTp from "./mora/selectTp";
import handleDeckCount from "./mora/deckCount";
/* /*
* 先将从长连接中读取到的二进制数据通过Adapter转成protobuf结构体, * 先将从长连接中读取到的二进制数据通过Adapter转成protobuf结构体,
...@@ -69,6 +70,17 @@ export default function handleSocketMessage(e: MessageEvent) { ...@@ -69,6 +70,17 @@ export default function handleSocketMessage(e: MessageEvent) {
break; break;
} }
case "stoc_deck_count": {
handleDeckCount(pb);
break;
}
case "stoc_duel_start": {
// TODO
console.log("TODO: handle STOC DuleStart.");
break;
}
default: { default: {
console.log(packet); console.log(packet);
......
...@@ -13,6 +13,7 @@ import { ...@@ -13,6 +13,7 @@ import {
selectTpSelectAble, selectTpSelectAble,
unSelectTpAble, unSelectTpAble,
} from "../reducers/moraSlice"; } from "../reducers/moraSlice";
import { selectPlayer0, selectPlayer1 } from "../reducers/playerSlice";
import { store } from "../store"; import { store } from "../store";
// TODO: 应该展示对手卡组信息和聊天信息 // TODO: 应该展示对手卡组信息和聊天信息
...@@ -20,6 +21,8 @@ export default function Mora() { ...@@ -20,6 +21,8 @@ export default function Mora() {
const dispatch = store.dispatch; const dispatch = store.dispatch;
const selectHandAble = useAppSelector(selectHandSelectAble); const selectHandAble = useAppSelector(selectHandSelectAble);
const selectTpAble = useAppSelector(selectTpSelectAble); const selectTpAble = useAppSelector(selectTpSelectAble);
const player0 = useAppSelector(selectPlayer0);
const player1 = useAppSelector(selectPlayer1);
const handleSelectScissors = () => { const handleSelectScissors = () => {
sendHandResult("scissors"); sendHandResult("scissors");
...@@ -63,6 +66,16 @@ export default function Mora() { ...@@ -63,6 +66,16 @@ export default function Mora() {
second second
</button> </button>
</div> </div>
<div className="item">
<p>
Me: main={player0.deckInfo?.mainCnt}, extra=
{player0.deckInfo?.extraCnt}, side={player0.deckInfo?.sideCnt}
</p>
<p>
Me: main={player1.deckInfo?.mainCnt}, extra=
{player1.deckInfo?.extraCnt}, side={player1.deckInfo?.sideCnt}
</p>
</div>
</div> </div>
); );
} }
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