Commit 20b60179 authored by Chunchi Che's avatar Chunchi Che

add surrender feature

parent eefa5f20
Pipeline #20766 passed with stages
in 13 minutes and 7 seconds
import { ygopro } from "../../idl/ocgcore";
import { YgoProPacket } from "../packet";
import { CTOS_SURRENDER } from "../protoDecl";
/*
* CTOS SURRENDER
*
* @param - null
*
* @usage - 告知服务端当前玩家投降
*
* */
export default class CtosSurrender extends YgoProPacket {
constructor(_: ygopro.YgoCtosMsg) {
super(1, CTOS_SURRENDER, new Uint8Array(0));
}
}
...@@ -12,6 +12,7 @@ export const CTOS_TP_RESULT = 4; ...@@ -12,6 +12,7 @@ export const CTOS_TP_RESULT = 4;
export const CTOS_TIME_CONFIRM = 21; export const CTOS_TIME_CONFIRM = 21;
export const CTOS_RESPONSE = 1; export const CTOS_RESPONSE = 1;
export const CTOS_CHAT = 22; export const CTOS_CHAT = 22;
export const CTOS_SURRENDER = 0x14;
export const STOC_JOIN_GAME = 18; export const STOC_JOIN_GAME = 18;
export const STOC_CHAT = 25; export const STOC_CHAT = 25;
......
...@@ -13,6 +13,7 @@ import HsStartAdapter from "./ocgAdapter/ctos/ctosHsStart"; ...@@ -13,6 +13,7 @@ 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"; import TimeConfirm from "./ocgAdapter/ctos/ctosTimeConfirm";
import Surrender from "./ocgAdapter/ctos/ctosSurrender";
import GameMsgResponse from "./ocgAdapter/ctos/ctosGameMsgResponse/mod"; import GameMsgResponse from "./ocgAdapter/ctos/ctosGameMsgResponse/mod";
import Chat from "./ocgAdapter/ctos/ctosChat"; import Chat from "./ocgAdapter/ctos/ctosChat";
...@@ -120,6 +121,15 @@ export function sendTimeConfirm() { ...@@ -120,6 +121,15 @@ export function sendTimeConfirm() {
socketMiddleWare({ cmd: socketCmd.SEND, payload }); socketMiddleWare({ cmd: socketCmd.SEND, payload });
} }
export function sendSurrender() {
const surrender = new ygopro.YgoCtosMsg({
ctos_surrender: new ygopro.CtosSurrender({}),
});
const payload = new Surrender(surrender).serialize();
socketMiddleWare({ cmd: socketCmd.SEND, payload });
}
export function sendChat(message: string) { export function sendChat(message: string) {
const chat = new ygopro.YgoCtosMsg({ const chat = new ygopro.YgoCtosMsg({
ctos_chat: new ygopro.CtosChat({ message }), ctos_chat: new ygopro.CtosChat({ message }),
......
import React from "react"; import React, { useState } from "react";
import { store } from "../../store"; import { store } from "../../store";
import { useAppSelector } from "../../hook"; import { useAppSelector } from "../../hook";
import { import {
...@@ -10,6 +10,7 @@ import { ...@@ -10,6 +10,7 @@ import {
import { import {
sendSelectBattleCmdResponse, sendSelectBattleCmdResponse,
sendSelectIdleCmdResponse, sendSelectIdleCmdResponse,
sendSurrender,
} from "../../api/ocgcore/ocgHelper"; } from "../../api/ocgcore/ocgHelper";
import { import {
clearAllIdleInteractivities, clearAllIdleInteractivities,
...@@ -17,7 +18,7 @@ import { ...@@ -17,7 +18,7 @@ import {
setEnableEp, setEnableEp,
setEnableM2, setEnableM2,
} from "../../reducers/duel/mod"; } from "../../reducers/duel/mod";
import { Button, Space } from "antd"; import { Button, Modal, Space } from "antd";
import Icon from "@ant-design/icons"; import Icon from "@ant-design/icons";
import { ReactComponent as BattleSvg } from "../../../neos-assets/crossed-swords.svg"; import { ReactComponent as BattleSvg } from "../../../neos-assets/crossed-swords.svg";
import { ReactComponent as Main2Svg } from "../../../neos-assets/sword-in-stone.svg"; import { ReactComponent as Main2Svg } from "../../../neos-assets/sword-in-stone.svg";
...@@ -51,6 +52,7 @@ const Phase = () => { ...@@ -51,6 +52,7 @@ const Phase = () => {
const enableM2 = useAppSelector(selectEnableM2); const enableM2 = useAppSelector(selectEnableM2);
const enableEp = useAppSelector(selectEnableEp); const enableEp = useAppSelector(selectEnableEp);
const currentPhase = useAppSelector(selectCurrentPhase); const currentPhase = useAppSelector(selectCurrentPhase);
const [modalOpen, setModalOpen] = useState(false);
const response = const response =
currentPhase === "BATTLE_START" || currentPhase === "BATTLE_START" ||
...@@ -82,7 +84,9 @@ const Phase = () => { ...@@ -82,7 +84,9 @@ const Phase = () => {
sendSelectIdleCmdResponse(response); sendSelectIdleCmdResponse(response);
dispatch(setEnableEp(false)); dispatch(setEnableEp(false));
}; };
const onSurrender = () => {}; const onSurrender = () => {
setModalOpen(true);
};
return ( return (
<Space wrap size={SpaceSize}> <Space wrap size={SpaceSize}>
...@@ -110,6 +114,30 @@ const Phase = () => { ...@@ -110,6 +114,30 @@ const Phase = () => {
text="投降" text="投降"
onClick={onSurrender} onClick={onSurrender}
/> />
<Modal
title="是否确认要投降?"
open={modalOpen}
closable={false}
footer={
<>
<Button
onClick={() => {
sendSurrender();
setModalOpen(false);
}}
>
Yes
</Button>
<Button
onClick={() => {
setModalOpen(false);
}}
>
No
</Button>
</>
}
/>
</Space> </Space>
); );
}; };
......
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