Commit 09e86476 authored by Chunchi Che's avatar Chunchi Che

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

Feat/service/time limit confirm

See merge request mycard/Neos!38
parents de6a77e6 e7926dd5
neos-protobuf @ cd2ef52b
Subproject commit e79dc1f25c8daf84c19a367b263cb17f46a1f291 Subproject commit cd2ef52b2642e59cc021b44e9816fd8622b2a8cb
This diff is collapsed.
...@@ -13,6 +13,7 @@ import { ...@@ -13,6 +13,7 @@ import {
STOC_DECK_COUNT, STOC_DECK_COUNT,
STOC_DUEL_START, STOC_DUEL_START,
STOC_GAME_MSG, STOC_GAME_MSG,
STOC_TIME_LIMIT,
} from "./protoDecl"; } from "./protoDecl";
import StocChat from "./stoc/stocChat"; import StocChat from "./stoc/stocChat";
import StocJoinGame from "./stoc/stocJoinGame"; import StocJoinGame from "./stoc/stocJoinGame";
...@@ -23,6 +24,7 @@ import StocTypeChange from "./stoc/stocTypeChange"; ...@@ -23,6 +24,7 @@ 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"; import StocDeckCount from "./stoc/stocDeckCount";
import StocTimeLimit from "./stoc/stocTimeLimit";
import StocGameMsg from "./stoc/stocGameMsg/mod"; import StocGameMsg from "./stoc/stocGameMsg/mod";
/* /*
...@@ -94,6 +96,11 @@ export function adaptStoc(packet: YgoProPacket): ygopro.YgoStocMsg { ...@@ -94,6 +96,11 @@ export function adaptStoc(packet: YgoProPacket): ygopro.YgoStocMsg {
break; break;
} }
case STOC_TIME_LIMIT: {
pb = new StocTimeLimit(packet).upcast();
break;
}
default: { default: {
break; break;
} }
......
import { ygopro } from "../../idl/ocgcore";
import { YgoProPacket } from "../packet";
import { CTOS_TIME_CONFIRM } from "../protoDecl";
/*
* CTOS CTOS_TIME_CONFIRM
*
* @param - null
*
* @usage - 确认计时?
*
* */
export default class CtosTimeConfirm extends YgoProPacket {
constructor(_: ygopro.YgoCtosMsg) {
super(1, CTOS_TIME_CONFIRM, new Uint8Array(0));
}
}
...@@ -9,6 +9,7 @@ export const CTOS_HS_READY = 34; ...@@ -9,6 +9,7 @@ export const CTOS_HS_READY = 34;
export const CTOS_HS_START = 37; export const CTOS_HS_START = 37;
export const CTOS_HAND_RESULT = 3; export const CTOS_HAND_RESULT = 3;
export const CTOS_TP_RESULT = 4; export const CTOS_TP_RESULT = 4;
export const CTOS_TIME_CONFIRM = 21;
export const STOC_JOIN_GAME = 18; export const STOC_JOIN_GAME = 18;
export const STOC_CHAT = 25; export const STOC_CHAT = 25;
...@@ -22,6 +23,7 @@ export const STOC_HAND_RESULT = 5; ...@@ -22,6 +23,7 @@ export const STOC_HAND_RESULT = 5;
export const STOC_DECK_COUNT = 9; export const STOC_DECK_COUNT = 9;
export const STOC_DUEL_START = 21; export const STOC_DUEL_START = 21;
export const STOC_GAME_MSG = 1; export const STOC_GAME_MSG = 1;
export const STOC_TIME_LIMIT = 24;
export const MSG_START = 4; export const MSG_START = 4;
export const MSG_DRAW = 90; export const MSG_DRAW = 90;
......
import { ygopro } from "../../idl/ocgcore";
import { YgoProPacket, StocAdapter } from "../packet";
import { BufferReader } from "../bufferIO";
/*
* STOC TimeLimit
*
* @usage - 同时客户端/前端时间限制
* */
export default class TimeLimit implements StocAdapter {
packet: YgoProPacket;
constructor(packet: YgoProPacket) {
this.packet = packet;
}
upcast(): ygopro.YgoStocMsg {
const reader = new BufferReader(this.packet.exData, true);
const player = reader.readInt8();
const leftTime = reader.readUint16();
return new ygopro.YgoStocMsg({
stoc_time_limit: new ygopro.StocTimeLimit({
player,
left_time: leftTime,
}),
});
}
}
...@@ -12,6 +12,7 @@ import HsReadyAdapter from "./ocgAdapter/ctos/ctosHsReady"; ...@@ -12,6 +12,7 @@ import HsReadyAdapter from "./ocgAdapter/ctos/ctosHsReady";
import HsStartAdapter from "./ocgAdapter/ctos/ctosHsStart"; import HsStartAdapter from "./ocgAdapter/ctos/ctosHsStart";
import HandResult from "./ocgAdapter/ctos/ctosHandResult"; import HandResult from "./ocgAdapter/ctos/ctosHandResult";
import TpResult from "./ocgAdapter/ctos/ctosTpResult"; import TpResult from "./ocgAdapter/ctos/ctosTpResult";
import TimeConfirm from "./ocgAdapter/ctos/ctosTimeConfirm";
export function sendUpdateDeck(deck: IDeck) { export function sendUpdateDeck(deck: IDeck) {
const updateDeck = new ygopro.YgoCtosMsg({ const updateDeck = new ygopro.YgoCtosMsg({
...@@ -107,3 +108,12 @@ export function sendTpResult(isFirst: boolean) { ...@@ -107,3 +108,12 @@ export function sendTpResult(isFirst: boolean) {
socketMiddleWare({ cmd: socketCmd.SEND, payload }); socketMiddleWare({ cmd: socketCmd.SEND, payload });
} }
export function sendTimeConfirm() {
const timeConfirm = new ygopro.YgoCtosMsg({
ctos_time_confirm: new ygopro.CtosTimeConfirm({}),
});
const payload = new TimeConfirm(timeConfirm).serialize();
socketMiddleWare({ cmd: socketCmd.SEND, payload });
}
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import { createSlice, PayloadAction } from "@reduxjs/toolkit"; import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { InitInfo, infoInitImpl } from "./initInfoSlice"; import { InitInfo, infoInitImpl } from "./initInfoSlice";
import { TimeLimit, updateTimeLimitImpl } from "./timeLimit";
import { import {
Hands, Hands,
handsCase, handsCase,
...@@ -21,6 +22,8 @@ export interface DuelState { ...@@ -21,6 +22,8 @@ export interface DuelState {
opInitInfo?: InitInfo; // 对手的初始状态 opInitInfo?: InitInfo; // 对手的初始状态
meHands?: Hands; // 自己的手牌 meHands?: Hands; // 自己的手牌
opHands?: Hands; // 对手的手牌 opHands?: Hands; // 对手的手牌
meTimeLimit?: TimeLimit; // 自己的计时
opTimeLimit?: TimeLimit; // 对手的计时
currentPlayer?: number; // 当前的操作方 currentPlayer?: number; // 当前的操作方
currentPhase?: string; // 当前的阶段 currentPhase?: string; // 当前的阶段
} }
...@@ -37,6 +40,7 @@ const duelSlice = createSlice({ ...@@ -37,6 +40,7 @@ const duelSlice = createSlice({
infoInit: infoInitImpl, infoInit: infoInitImpl,
updateTurn: newTurnImpl, updateTurn: newTurnImpl,
updatePhase: newPhaseImpl, updatePhase: newPhaseImpl,
updateTimeLimit: updateTimeLimitImpl,
// 手牌相关`Reducer` // 手牌相关`Reducer`
clearHandsInteractivity: clearHandsInteractivityImpl, clearHandsInteractivity: clearHandsInteractivityImpl,
...@@ -54,6 +58,7 @@ export const { ...@@ -54,6 +58,7 @@ export const {
updatePhase, updatePhase,
clearHandsInteractivity, clearHandsInteractivity,
addHandsInteractivity, addHandsInteractivity,
updateTimeLimit,
} = duelSlice.actions; } = duelSlice.actions;
export const selectDuelHsStart = (state: RootState) => { export const selectDuelHsStart = (state: RootState) => {
return state.duel.meInitInfo != null; return state.duel.meInitInfo != null;
......
import { PayloadAction, CaseReducer } from "@reduxjs/toolkit";
import { DuelState } from "./mod";
import { judgeSelf } from "./util";
export interface TimeLimit {
leftTime: number;
}
// 更新计时
export const updateTimeLimitImpl: CaseReducer<
DuelState,
PayloadAction<[number, number]>
> = (state, action) => {
const player = action.payload[0];
const leftTime = action.payload[1];
if (judgeSelf(player, state)) {
state.meTimeLimit = { leftTime };
} else {
state.opTimeLimit = { leftTime };
}
};
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { store } from "../../store";
import { updateTimeLimit } from "../../reducers/duel/mod";
import { sendTimeConfirm } from "../../api/ocgcore/ocgHelper";
export default function handleTimeLimit(timeLimit: ygopro.StocTimeLimit) {
const dispatch = store.dispatch;
dispatch(updateTimeLimit([timeLimit.player, timeLimit.left_time]));
sendTimeConfirm();
}
...@@ -14,6 +14,7 @@ import handleSelectHand from "./mora/selectHand"; ...@@ -14,6 +14,7 @@ import handleSelectHand from "./mora/selectHand";
import handleSelectTp from "./mora/selectTp"; import handleSelectTp from "./mora/selectTp";
import handleDeckCount from "./mora/deckCount"; import handleDeckCount from "./mora/deckCount";
import handleGameMsg from "./duel/gameMsg"; import handleGameMsg from "./duel/gameMsg";
import handleTimeLimit from "./duel/timeLimit";
/* /*
* 先将从长连接中读取到的二进制数据通过Adapter转成protobuf结构体, * 先将从长连接中读取到的二进制数据通过Adapter转成protobuf结构体,
...@@ -87,6 +88,11 @@ export default function handleSocketMessage(e: MessageEvent) { ...@@ -87,6 +88,11 @@ export default function handleSocketMessage(e: MessageEvent) {
break; break;
} }
case "stoc_time_limit": {
handleTimeLimit(pb.stoc_time_limit);
break;
}
default: { default: {
console.log(packet); console.log(packet);
......
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