Commit bde80f6a authored by biluo.shen's avatar biluo.shen

Use msg_type to replace msg_name

parent 437233f8
Pipeline #28122 failed with stages
in 26 seconds
...@@ -470,6 +470,7 @@ interface SelectAbleCard { ...@@ -470,6 +470,7 @@ interface SelectAbleCard {
} }
interface MsgSelectCard { interface MsgSelectCard {
msg_type: "select_card";
cancelable: boolean; cancelable: boolean;
min: number; min: number;
max: number; max: number;
...@@ -478,8 +479,9 @@ interface MsgSelectCard { ...@@ -478,8 +479,9 @@ interface MsgSelectCard {
} }
function convertMsgSelectCard(msg: GM.MsgSelectCard): MsgSelectCard { function convertMsgSelectCard(msg: GM.MsgSelectCard): MsgSelectCard {
// response is -1 for finish // response is -1 for finish
return { return {
msg_type: "select_card",
cancelable: msg.cancelable, cancelable: msg.cancelable,
min: msg.min, min: msg.min,
max: msg.max, max: msg.max,
...@@ -499,6 +501,7 @@ interface SelectTributeCard { ...@@ -499,6 +501,7 @@ interface SelectTributeCard {
} }
interface MsgSelectTribute { interface MsgSelectTribute {
msg_type: "select_tribute";
cancelable: boolean; cancelable: boolean;
min: number; min: number;
max: number; max: number;
...@@ -508,6 +511,7 @@ interface MsgSelectTribute { ...@@ -508,6 +511,7 @@ interface MsgSelectTribute {
function convertMsgSelectTribute(msg: GM.MsgSelectTribute): MsgSelectTribute { function convertMsgSelectTribute(msg: GM.MsgSelectTribute): MsgSelectTribute {
return { return {
msg_type: "select_tribute",
cancelable: msg.cancelable, cancelable: msg.cancelable,
min: msg.min, min: msg.min,
max: msg.max, max: msg.max,
...@@ -529,6 +533,7 @@ interface SelectSumCard { ...@@ -529,6 +533,7 @@ interface SelectSumCard {
} }
interface MsgSelectSum { interface MsgSelectSum {
msg_type: "select_sum";
overflow: boolean; overflow: boolean;
level_sum: number; level_sum: number;
min: number; min: number;
...@@ -540,6 +545,7 @@ interface MsgSelectSum { ...@@ -540,6 +545,7 @@ interface MsgSelectSum {
function convertMsgSelectSum(msg: GM.MsgSelectSum): MsgSelectSum { function convertMsgSelectSum(msg: GM.MsgSelectSum): MsgSelectSum {
return { return {
msg_type: "select_sum",
overflow: msg.overflow != 0, overflow: msg.overflow != 0,
level_sum: msg.level_sum, level_sum: msg.level_sum,
min: msg.min, min: msg.min,
...@@ -625,6 +631,7 @@ interface IdleCmd { ...@@ -625,6 +631,7 @@ interface IdleCmd {
} }
interface MsgSelectIdleCmd { interface MsgSelectIdleCmd {
msg_type: "select_idlecmd";
idle_cmds: IdleCmd[]; idle_cmds: IdleCmd[];
} }
...@@ -662,7 +669,10 @@ function convertMsgSelectIdleCmd(msg: GM.MsgSelectIdleCmd): MsgSelectIdleCmd { ...@@ -662,7 +669,10 @@ function convertMsgSelectIdleCmd(msg: GM.MsgSelectIdleCmd): MsgSelectIdleCmd {
// response will be 7 // response will be 7
idle_cmds.push({ cmd_type: IdleCmdType.ToEp }); idle_cmds.push({ cmd_type: IdleCmdType.ToEp });
} }
return { idle_cmds }; return {
msg_type: "select_idlecmd",
idle_cmds: idle_cmds,
};
} }
interface Chain { interface Chain {
...@@ -673,6 +683,7 @@ interface Chain { ...@@ -673,6 +683,7 @@ interface Chain {
} }
interface MsgSelectChain { interface MsgSelectChain {
msg_type: "select_chain";
forced: boolean; forced: boolean;
chains: Chain[]; chains: Chain[];
} }
...@@ -689,18 +700,21 @@ function convertChain(chain: GM.MsgSelectChain.Chain, player: number): Chain { ...@@ -689,18 +700,21 @@ function convertChain(chain: GM.MsgSelectChain.Chain, player: number): Chain {
function convertMsgSelectChain(msg: GM.MsgSelectChain): MsgSelectChain { function convertMsgSelectChain(msg: GM.MsgSelectChain): MsgSelectChain {
// response is -1 for cancel // response is -1 for cancel
return { return {
msg_type: "select_chain",
forced: msg.forced, forced: msg.forced,
chains: msg.chains.map(c => convertChain(c, msg.player)), chains: msg.chains.map(c => convertChain(c, msg.player)),
}; };
} }
interface MsgSelectPosition { interface MsgSelectPosition {
msg_type: "select_position";
code: number; code: number;
positions: Position[]; positions: Position[];
} }
function convertMsgSelectPosition(msg: GM.MsgSelectPosition): MsgSelectPosition { function convertMsgSelectPosition(msg: GM.MsgSelectPosition): MsgSelectPosition {
return { return {
msg_type: "select_position",
code: msg.code, code: msg.code,
// response will be equal to POS_* from ocgcore // response will be equal to POS_* from ocgcore
// POS_FACEUP_ATTACK: 0x1, POS_FACEDOWN_ATTACK: 0x2, // POS_FACEUP_ATTACK: 0x1, POS_FACEDOWN_ATTACK: 0x2,
...@@ -710,17 +724,20 @@ function convertMsgSelectPosition(msg: GM.MsgSelectPosition): MsgSelectPosition ...@@ -710,17 +724,20 @@ function convertMsgSelectPosition(msg: GM.MsgSelectPosition): MsgSelectPosition
} }
interface MsgSelectYesNo { interface MsgSelectYesNo {
msg_type: "select_yes_no";
effect_description: number; effect_description: number;
} }
function convertMsgSelectYesNo(msg: GM.MsgSelectYesNo): MsgSelectYesNo { function convertMsgSelectYesNo(msg: GM.MsgSelectYesNo): MsgSelectYesNo {
// response is 1 for yes and 0 for no // response is 1 for yes and 0 for no
return { return {
msg_type: "select_yes_no",
effect_description: msg.effect_description, effect_description: msg.effect_description,
}; };
} }
interface MsgSelectEffectYn { interface MsgSelectEffectYn {
msg_type: "select_effect_yn";
code: number; code: number;
location: CardLocation; location: CardLocation;
effect_description: number; effect_description: number;
...@@ -729,6 +746,7 @@ interface MsgSelectEffectYn { ...@@ -729,6 +746,7 @@ interface MsgSelectEffectYn {
function convertMsgSelectEffectYn(msg: GM.MsgSelectEffectYn): MsgSelectEffectYn { function convertMsgSelectEffectYn(msg: GM.MsgSelectEffectYn): MsgSelectEffectYn {
// response is 1 for yes and 0 for no // response is 1 for yes and 0 for no
return { return {
msg_type: "select_effect_yn",
code: msg.code, code: msg.code,
location: convertCardLocation(msg.location, msg.player), location: convertCardLocation(msg.location, msg.player),
effect_description: msg.effect_description, effect_description: msg.effect_description,
...@@ -767,6 +785,7 @@ interface BattleCmd { ...@@ -767,6 +785,7 @@ interface BattleCmd {
} }
interface MsgSelectBattleCmd { interface MsgSelectBattleCmd {
msg_type: "select_battlecmd";
battle_cmds: BattleCmd[]; battle_cmds: BattleCmd[];
} }
...@@ -792,7 +811,10 @@ function convertMsgSelectBattleCmd(msg: GM.MsgSelectBattleCmd): MsgSelectBattleC ...@@ -792,7 +811,10 @@ function convertMsgSelectBattleCmd(msg: GM.MsgSelectBattleCmd): MsgSelectBattleC
// response will be 3 // response will be 3
battle_cmds.push({ cmd_type: BattleCmdType.ToEp }); battle_cmds.push({ cmd_type: BattleCmdType.ToEp });
} }
return { battle_cmds }; return {
msg_type: "select_battlecmd",
battle_cmds,
};
} }
...@@ -803,6 +825,7 @@ interface SelectUnselectCard { ...@@ -803,6 +825,7 @@ interface SelectUnselectCard {
interface MsgSelectUnselectCard { interface MsgSelectUnselectCard {
msg_type: "select_unselect_card";
finishable: boolean; finishable: boolean;
cancelable: boolean; cancelable: boolean;
min: number; min: number;
...@@ -813,6 +836,7 @@ interface MsgSelectUnselectCard { ...@@ -813,6 +836,7 @@ interface MsgSelectUnselectCard {
function convertMsgSelectUnselectCard(msg: GM.MsgSelectUnselectCard): MsgSelectUnselectCard { function convertMsgSelectUnselectCard(msg: GM.MsgSelectUnselectCard): MsgSelectUnselectCard {
return { return {
msg_type: "select_unselect_card",
// response is -1 for finish // response is -1 for finish
finishable: msg.finishable, finishable: msg.finishable,
cancelable: msg.cancelable, cancelable: msg.cancelable,
...@@ -835,11 +859,13 @@ interface Option { ...@@ -835,11 +859,13 @@ interface Option {
} }
interface MsgSelectOption { interface MsgSelectOption {
msg_type: "select_option";
options: Option[]; options: Option[];
} }
function convertMsgSelectOption(msg: GM.MsgSelectOption): MsgSelectOption { function convertMsgSelectOption(msg: GM.MsgSelectOption): MsgSelectOption {
return { return {
msg_type: "select_option",
options: msg.options.map(o => ({ options: msg.options.map(o => ({
code: o.code, code: o.code,
response: o.response, response: o.response,
...@@ -855,15 +881,17 @@ interface Place { ...@@ -855,15 +881,17 @@ interface Place {
} }
interface MsgSelectPlace { interface MsgSelectPlace {
msg_type: "select_place";
count: number; count: number;
places: Place[]; places: Place[];
} }
function convertMsgSelectPlace(msg: GM.MsgSelectPlace): MsgSelectPlace { function convertMsgSelectPlace(msg: GM.MsgSelectPlace): MsgSelectPlace {
return { return {
msg_type: "select_place",
count: msg.count, count: msg.count,
places: msg.places.map(p => ({ places: msg.places.map(p => ({
// NOTICE: the response is all -1 // NOTICE: the response is the index of the place in the places array
controller: convertController(p.controller, msg.player), controller: convertController(p.controller, msg.player),
location: cardZoneToLocation(p.zone), location: cardZoneToLocation(p.zone),
sequence: p.sequence, sequence: p.sequence,
...@@ -879,12 +907,14 @@ interface AnnounceAttrib { ...@@ -879,12 +907,14 @@ interface AnnounceAttrib {
} }
interface MsgAnnounceAttrib { interface MsgAnnounceAttrib {
msg_type: "announce_attrib";
count: number; count: number;
attributes: AnnounceAttrib[]; attributes: AnnounceAttrib[];
} }
function convertMsgAnnounceAttrib(msg: GM.MsgAnnounce): MsgAnnounceAttrib { function convertMsgAnnounceAttrib(msg: GM.MsgAnnounce): MsgAnnounceAttrib {
return { return {
msg_type: "announce_attrib",
count: msg.min, count: msg.min,
// from api/ocgcore/ocgAdapter/stoc/stocGameMsg/announceAttrib.ts // from api/ocgcore/ocgAdapter/stoc/stocGameMsg/announceAttrib.ts
attributes: msg.options.map(a => ({ attributes: msg.options.map(a => ({
...@@ -900,12 +930,14 @@ interface AnnounceNumber { ...@@ -900,12 +930,14 @@ interface AnnounceNumber {
} }
interface MsgAnnounceNumber { interface MsgAnnounceNumber {
msg_type: "announce_number";
count: number; count: number;
numbers: AnnounceNumber[]; numbers: AnnounceNumber[];
} }
function convertMsgAnnounceNumber(msg: GM.MsgAnnounce): MsgAnnounceNumber { function convertMsgAnnounceNumber(msg: GM.MsgAnnounce): MsgAnnounceNumber {
return { return {
msg_type: "announce_number",
count: msg.min, count: msg.min,
numbers: msg.options.map(o => ({ numbers: msg.options.map(o => ({
number: o.code, number: o.code,
...@@ -930,99 +962,84 @@ type ActionMsgData = ...@@ -930,99 +962,84 @@ type ActionMsgData =
MsgAnnounceAttrib | MsgAnnounceAttrib |
MsgAnnounceNumber; MsgAnnounceNumber;
export enum ActionMsgName { // export enum ActionMsgName {
AnnounceAttrib = "announce_attrib", // AnnounceAttrib = "announce_attrib",
AnnounceNumber = "announce_number", // AnnounceNumber = "announce_number",
SelectBattlecmd = "select_battlecmd", // SelectBattlecmd = "select_battlecmd",
SelectCard = "select_card", // SelectCard = "select_card",
SelectChain = "select_chain", // SelectChain = "select_chain",
SelectDisfield = "select_disfield", // SelectDisfield = "select_disfield",
SelectEffectyn = "select_effectyn", // SelectEffectyn = "select_effectyn",
SelectIdlecmd = "select_idlecmd", // SelectIdlecmd = "select_idlecmd",
SelectOption = "select_option", // SelectOption = "select_option",
SelectPlace = "select_place", // SelectPlace = "select_place",
SelectPosition = "select_position", // SelectPosition = "select_position",
SelectSum = "select_sum", // SelectSum = "select_sum",
SelectTribute = "select_tribute", // SelectTribute = "select_tribute",
SelectUnselectCard = "select_unselect_card", // SelectUnselectCard = "select_unselect_card",
SelectYesno = "select_yesno", // SelectYesno = "select_yesno",
} // }
interface ActionMsg { interface ActionMsg {
data: ActionMsgData; data: ActionMsgData;
name: ActionMsgName;
} }
export function convertActionMsg(msg: ygopro.StocGameMessage): ActionMsg { export function convertActionMsg(msg: ygopro.StocGameMessage): ActionMsg {
if (msg instanceof GM.MsgSelectCard) { if (msg instanceof GM.MsgSelectCard) {
return { return {
name: ActionMsgName.SelectCard,
data: convertMsgSelectCard(msg), data: convertMsgSelectCard(msg),
}; };
} else if (msg instanceof GM.MsgSelectTribute) { } else if (msg instanceof GM.MsgSelectTribute) {
return { return {
name: ActionMsgName.SelectTribute,
data: convertMsgSelectTribute(msg), data: convertMsgSelectTribute(msg),
}; };
} else if (msg instanceof GM.MsgSelectSum) { } else if (msg instanceof GM.MsgSelectSum) {
return { return {
name: ActionMsgName.SelectSum,
data: convertMsgSelectSum(msg), data: convertMsgSelectSum(msg),
}; };
} else if (msg instanceof GM.MsgSelectIdleCmd) { } else if (msg instanceof GM.MsgSelectIdleCmd) {
return { return {
name: ActionMsgName.SelectIdlecmd,
data: convertMsgSelectIdleCmd(msg), data: convertMsgSelectIdleCmd(msg),
}; };
} else if (msg instanceof GM.MsgSelectChain) { } else if (msg instanceof GM.MsgSelectChain) {
return { return {
name: ActionMsgName.SelectChain,
data: convertMsgSelectChain(msg), data: convertMsgSelectChain(msg),
}; };
} else if (msg instanceof GM.MsgSelectPosition) { } else if (msg instanceof GM.MsgSelectPosition) {
return { return {
name: ActionMsgName.SelectPosition,
data: convertMsgSelectPosition(msg), data: convertMsgSelectPosition(msg),
}; };
} else if (msg instanceof GM.MsgSelectEffectYn) { } else if (msg instanceof GM.MsgSelectEffectYn) {
return { return {
name: ActionMsgName.SelectEffectyn,
data: convertMsgSelectEffectYn(msg), data: convertMsgSelectEffectYn(msg),
}; };
} else if (msg instanceof GM.MsgSelectYesNo) { } else if (msg instanceof GM.MsgSelectYesNo) {
return { return {
name: ActionMsgName.SelectYesno,
data: convertMsgSelectYesNo(msg), data: convertMsgSelectYesNo(msg),
}; };
} else if (msg instanceof GM.MsgSelectBattleCmd) { } else if (msg instanceof GM.MsgSelectBattleCmd) {
return { return {
name: ActionMsgName.SelectBattlecmd,
data: convertMsgSelectBattleCmd(msg), data: convertMsgSelectBattleCmd(msg),
}; };
} else if (msg instanceof GM.MsgSelectUnselectCard) { } else if (msg instanceof GM.MsgSelectUnselectCard) {
return { return {
name: ActionMsgName.SelectUnselectCard,
data: convertMsgSelectUnselectCard(msg), data: convertMsgSelectUnselectCard(msg),
}; };
} else if (msg instanceof GM.MsgSelectOption) { } else if (msg instanceof GM.MsgSelectOption) {
return { return {
name: ActionMsgName.SelectOption,
data: convertMsgSelectOption(msg), data: convertMsgSelectOption(msg),
}; };
} else if (msg instanceof GM.MsgSelectPlace) { } else if (msg instanceof GM.MsgSelectPlace) {
return { return {
name: ActionMsgName.SelectPlace,
data: convertMsgSelectPlace(msg), data: convertMsgSelectPlace(msg),
}; };
} else if (msg instanceof GM.MsgAnnounce) { } else if (msg instanceof GM.MsgAnnounce) {
if (msg.announce_type == GM.MsgAnnounce.AnnounceType.Attribute) { if (msg.announce_type == GM.MsgAnnounce.AnnounceType.Attribute) {
return { return {
name: ActionMsgName.AnnounceAttrib,
data: convertMsgAnnounceAttrib(msg), data: convertMsgAnnounceAttrib(msg),
}; };
} else if (msg.announce_type == GM.MsgAnnounce.AnnounceType.Number) { } else if (msg.announce_type == GM.MsgAnnounce.AnnounceType.Number) {
return { return {
name: ActionMsgName.AnnounceNumber,
data: convertMsgAnnounceNumber(msg), data: convertMsgAnnounceNumber(msg),
}; };
} else { } else {
......
...@@ -12,7 +12,7 @@ import { ...@@ -12,7 +12,7 @@ import {
sendSortCardResponse, sendSortCardResponse,
} from "@/api"; } from "@/api";
import { cardStore, matStore } from "@/stores"; import { cardStore, matStore } from "@/stores";
import { ActionMsgName, Global, convertPhase, convertCard, convertDeckCard, parsePlayerFromMsg, convertActionMsg, Input } from "@/api/ygoAgent/schema"; import { Global, convertPhase, convertCard, convertDeckCard, parsePlayerFromMsg, convertActionMsg, Input } from "@/api/ygoAgent/schema";
import { predictDuel } from "@/api/ygoAgent/predict"; import { predictDuel } from "@/api/ygoAgent/predict";
function computeSetDifference(a1: number[], a2: number[]): number[] { function computeSetDifference(a1: number[], a2: number[]): number[] {
...@@ -89,8 +89,7 @@ export function genPredictReq(msg: ygopro.StocGameMessage): PredictReq { ...@@ -89,8 +89,7 @@ export function genPredictReq(msg: ygopro.StocGameMessage): PredictReq {
my_lp: mat.initInfo.of(player).life, my_lp: mat.initInfo.of(player).life,
op_lp: mat.initInfo.of(opponent).life, op_lp: mat.initInfo.of(opponent).life,
phase: convertPhase(mat.phase.currentPhase), phase: convertPhase(mat.phase.currentPhase),
// TODO (ygo-agent): use real turn turn: mat.turn_count,
turn: 1,
} }
const actionMsg = convertActionMsg(msg); const actionMsg = convertActionMsg(msg);
...@@ -104,14 +103,13 @@ export function genPredictReq(msg: ygopro.StocGameMessage): PredictReq { ...@@ -104,14 +103,13 @@ export function genPredictReq(msg: ygopro.StocGameMessage): PredictReq {
return { return {
index: mat.agentIndex, index: mat.agentIndex,
input: input, input: input,
// TODO (ygo-agent): use real value
prev_action_idx: mat.prevActionIndex, prev_action_idx: mat.prevActionIndex,
} }
} }
export async function sendAIPredictAsResponse() { export async function sendAIPredictAsResponse(msg: ygopro.StocGameMessage) {
const msg = matStore.actionMsg; // const msg = matStore.actionMsg;
const req = genPredictReq(msg); const req = genPredictReq(msg);
console.log("Sending predict request:", req); console.log("Sending predict request:", req);
const duelId = matStore.duelId; const duelId = matStore.duelId;
...@@ -129,38 +127,50 @@ export async function sendAIPredictAsResponse() { ...@@ -129,38 +127,50 @@ export async function sendAIPredictAsResponse() {
const action_idx = argmax(preds, (r) => r.prob); const action_idx = argmax(preds, (r) => r.prob);
matStore.prevActionIndex = action_idx; matStore.prevActionIndex = action_idx;
const response = preds[action_idx].response; const response = preds[action_idx].response;
const msg_name = req.input.action_msg.name; const msg_name = req.input.action_msg.data.msg_type;
switch (msg_name) { switch (msg_name) {
case ActionMsgName.AnnounceAttrib: case "announce_attrib":
case ActionMsgName.AnnounceNumber: case "announce_number":
sendSelectOptionResponse(response); sendSelectOptionResponse(response);
break; break;
case ActionMsgName.SelectBattlecmd: case "select_battle_cmd":
sendSelectBattleCmdResponse(response); sendSelectBattleCmdResponse(response);
break; break;
case ActionMsgName.SelectChain: case "select_chain":
sendSelectSingleResponse(response); sendSelectSingleResponse(response);
break; break;
case ActionMsgName.SelectYesno: case "select_yes_no":
case ActionMsgName.SelectEffectyn: case "select_effect_yn":
sendSelectEffectYnResponse(response === 1); sendSelectEffectYnResponse(response === 1);
break; break;
case ActionMsgName.SelectIdlecmd: case "select_idle_cmd":
sendSelectIdleCmdResponse(response); sendSelectIdleCmdResponse(response);
break; break;
case ActionMsgName.SelectOption: case "select_option":
sendSelectOptionResponse(response); sendSelectOptionResponse(response);
break; break;
case ActionMsgName.SelectPosition: case "select_position":
sendSelectPositionResponse(convertPositionResponse(response)); sendSelectPositionResponse(convertPositionResponse(response));
break; break;
case ActionMsgName.SelectUnselectCard: case "select_place":
case ActionMsgName.SelectDisfield: const place = (msg as unknown as ygopro.StocGameMessage.MsgSelectPlace).places[response];
case ActionMsgName.SelectPlace: sendSelectPlaceResponse({
case ActionMsgName.SelectCard: controller: place.controller,
case ActionMsgName.SelectSum: zone: place.zone,
case ActionMsgName.SelectTribute: sequence: place.sequence,
default: });
break;
case "select_unselect_card":
case "select_card":
const msg_ = msg as unknown as ygopro.StocGameMessage.MsgSelectCard;
if (msg_.min === 1 && msg_.max === 1) {
sendSelectMultiResponse([response]);
} else {
throw new Error(`Unsupported select_card for min=${msg_.min}, max=${msg_.max}`);
}
break;
case "select_sum":
case "select_tribute":
throw new Error(`Unsupported msg_name: ${msg_name}`); throw new Error(`Unsupported msg_name: ${msg_name}`);
} }
} }
......
...@@ -2,8 +2,13 @@ import { fetchStrings, Region, ygopro } from "@/api"; ...@@ -2,8 +2,13 @@ import { fetchStrings, Region, ygopro } from "@/api";
import { displayOptionModal } from "@/ui/Duel/Message"; import { displayOptionModal } from "@/ui/Duel/Message";
import MsgAnnounce = ygopro.StocGameMessage.MsgAnnounce; import MsgAnnounce = ygopro.StocGameMessage.MsgAnnounce;
import { displayAnnounceModal } from "@/ui/Duel/Message/AnnounceModal"; import { displayAnnounceModal } from "@/ui/Duel/Message/AnnounceModal";
import { sendAIPredictAsResponse } from "@/service/duel/agent";
export default async (announce: MsgAnnounce) => { export default async (announce: MsgAnnounce) => {
console.log("intercept announce");
await sendAIPredictAsResponse(announce as unknown as ygopro.StocGameMessage);
return;
const type_ = announce.announce_type; const type_ = announce.announce_type;
let min = announce.min; let min = announce.min;
if ( if (
......
import { ygopro } from "@/api"; import { ygopro } from "@/api";
import { matStore, replayStore } from "@/stores"; import { replayStore } from "@/stores";
import { showWaiting } from "@/ui/Duel/Message"; import { showWaiting } from "@/ui/Duel/Message";
import onAnnounce from "./announce"; import onAnnounce from "./announce";
...@@ -100,74 +100,6 @@ export default async function handleGameMsg( ...@@ -100,74 +100,6 @@ export default async function handleGameMsg(
if (replayStore.isReplay && ReplayIgnoreMsg.includes(msg.gameMsg)) return; if (replayStore.isReplay && ReplayIgnoreMsg.includes(msg.gameMsg)) return;
console.log("Got " + msg.gameMsg);
switch (msg.gameMsg) {
case "announce": {
matStore.actionMsg = msg.announce;
console.log("intercept announce");
return;
}
case "select_battle_cmd": {
matStore.actionMsg = msg.select_battle_cmd;
console.log("intercept select_battle_cmd");
return;
}
case "select_chain": {
matStore.actionMsg = msg.select_chain;
console.log("intercept select_chain");
return;
}
case "select_yes_no": {
matStore.actionMsg = msg.select_yes_no;
console.log("intercept select_yes_no");
return;
}
case "select_effect_yn": {
matStore.actionMsg = msg.select_effect_yn;
console.log("intercept select_effect_yn");
return;
}
case "select_idle_cmd": {
matStore.actionMsg = msg.select_idle_cmd;
console.log("intercept select_idle_cmd");
return;
}
case "select_option": {
matStore.actionMsg = msg.select_option;
console.log("intercept select_option");
return;
}
case "select_position": {
matStore.actionMsg = msg.select_position;
console.log("intercept select_position");
return;
}
case "select_unselect_card": {
matStore.actionMsg = msg.select_unselect_card;
break;
}
case "select_place": {
matStore.actionMsg = msg.select_place;
break;
}
case "select_card": {
matStore.actionMsg = msg.select_card;
break;
}
case "select_sum": {
matStore.actionMsg = msg.select_sum;
break;
}
case "select_tribute": {
matStore.actionMsg = msg.select_tribute;
break;
}
default: {
break;
}
}
switch (msg.gameMsg) { switch (msg.gameMsg) {
case "start": { case "start": {
await onMsgStart(msg.start); await onMsgStart(msg.start);
......
...@@ -6,4 +6,5 @@ export default (newTurn: ygopro.StocGameMessage.MsgNewTurn) => { ...@@ -6,4 +6,5 @@ export default (newTurn: ygopro.StocGameMessage.MsgNewTurn) => {
playEffect(AudioActionType.SOUND_NEXT_TURN); playEffect(AudioActionType.SOUND_NEXT_TURN);
const player = newTurn.player; const player = newTurn.player;
matStore.currentPlayer = player; matStore.currentPlayer = player;
matStore.turn_count = matStore.turn_count + 1;
}; };
...@@ -7,8 +7,9 @@ import { ...@@ -7,8 +7,9 @@ import {
} from "@/stores"; } from "@/stores";
import MsgSelectBattleCmd = ygopro.StocGameMessage.MsgSelectBattleCmd; import MsgSelectBattleCmd = ygopro.StocGameMessage.MsgSelectBattleCmd;
import { sendAIPredictAsResponse } from "@/service/duel/agent";
export default (selectBattleCmd: MsgSelectBattleCmd) => { export default async (selectBattleCmd: MsgSelectBattleCmd) => {
const player = selectBattleCmd.player; const player = selectBattleCmd.player;
const cmds = selectBattleCmd.battle_cmds; const cmds = selectBattleCmd.battle_cmds;
...@@ -17,6 +18,10 @@ export default (selectBattleCmd: MsgSelectBattleCmd) => { ...@@ -17,6 +18,10 @@ export default (selectBattleCmd: MsgSelectBattleCmd) => {
card.idleInteractivities = []; card.idleInteractivities = [];
}); });
console.log("intercept selectBattleCmd");
await sendAIPredictAsResponse(selectBattleCmd as unknown as ygopro.StocGameMessage);
return;
cmds.forEach((cmd) => { cmds.forEach((cmd) => {
const interactType = battleTypeToInteracType(cmd.battle_type); const interactType = battleTypeToInteracType(cmd.battle_type);
......
...@@ -5,6 +5,8 @@ import { displaySelectActionsModal } from "@/ui/Duel/Message/SelectActionsModal" ...@@ -5,6 +5,8 @@ import { displaySelectActionsModal } from "@/ui/Duel/Message/SelectActionsModal"
import { fetchCheckCardMeta } from "../utils"; import { fetchCheckCardMeta } from "../utils";
import { sendAIPredictAsResponse } from "@/service/duel/agent";
export default async (selectCard: MsgSelectCard) => { export default async (selectCard: MsgSelectCard) => {
const { cancelable, min, max, cards } = selectCard; const { cancelable, min, max, cards } = selectCard;
...@@ -16,6 +18,12 @@ export default async (selectCard: MsgSelectCard) => { ...@@ -16,6 +18,12 @@ export default async (selectCard: MsgSelectCard) => {
return; return;
} }
if (min === 1 && max === 1) {
console.log("intercept selectCard");
await sendAIPredictAsResponse(selectCard as unknown as ygopro.StocGameMessage);
return;
}
const { selecteds, mustSelects, selectables } = await fetchCheckCardMeta( const { selecteds, mustSelects, selectables } = await fetchCheckCardMeta(
cards, cards,
); );
......
...@@ -3,6 +3,7 @@ import { ChainSetting, fetchSelectHintMeta, matStore } from "@/stores"; ...@@ -3,6 +3,7 @@ import { ChainSetting, fetchSelectHintMeta, matStore } from "@/stores";
import { displaySelectActionsModal } from "@/ui/Duel/Message/SelectActionsModal"; import { displaySelectActionsModal } from "@/ui/Duel/Message/SelectActionsModal";
import { fetchCheckCardMeta } from "../utils"; import { fetchCheckCardMeta } from "../utils";
import { sendAIPredictAsResponse } from "@/service/duel/agent";
type MsgSelectChain = ygopro.StocGameMessage.MsgSelectChain; type MsgSelectChain = ygopro.StocGameMessage.MsgSelectChain;
export default async (selectChain: MsgSelectChain) => { export default async (selectChain: MsgSelectChain) => {
...@@ -66,6 +67,10 @@ export default async (selectChain: MsgSelectChain) => { ...@@ -66,6 +67,10 @@ export default async (selectChain: MsgSelectChain) => {
} }
case 2: // 处理多张 case 2: // 处理多张
case 3: { case 3: {
console.log("intercept selectChain");
await sendAIPredictAsResponse(selectChain as unknown as ygopro.StocGameMessage);
return;
// 处理强制发动的卡 // 处理强制发动的卡
fetchSelectHintMeta({ fetchSelectHintMeta({
selectHintData: 203, selectHintData: 203,
......
import { fetchStrings, Region, type ygopro } from "@/api"; import { fetchStrings, Region, type ygopro } from "@/api";
import { CardMeta, fetchCard } from "@/api/cards"; import { CardMeta, fetchCard } from "@/api/cards";
import { displayYesNoModal } from "@/ui/Duel/Message"; import { displayYesNoModal } from "@/ui/Duel/Message";
import { sendAIPredictAsResponse } from "@/service/duel/agent";
type MsgSelectEffectYn = ygopro.StocGameMessage.MsgSelectEffectYn; type MsgSelectEffectYn = ygopro.StocGameMessage.MsgSelectEffectYn;
// 这里改成了 async 不知道有没有影响 // 这里改成了 async 不知道有没有影响
export default async (selectEffectYn: MsgSelectEffectYn) => { export default async (selectEffectYn: MsgSelectEffectYn) => {
console.log("intercept announce");
await sendAIPredictAsResponse(selectEffectYn as unknown as ygopro.StocGameMessage);
return;
const code = selectEffectYn.code; const code = selectEffectYn.code;
const location = selectEffectYn.location; const location = selectEffectYn.location;
const effect_description = selectEffectYn.effect_description; const effect_description = selectEffectYn.effect_description;
......
...@@ -5,11 +5,11 @@ import { ...@@ -5,11 +5,11 @@ import {
InteractType, InteractType,
matStore, matStore,
} from "@/stores"; } from "@/stores";
// import { sendAIPredictAsResponse } from "@/service/duel/agent"; import { sendAIPredictAsResponse } from "@/service/duel/agent";
import MsgSelectIdleCmd = ygopro.StocGameMessage.MsgSelectIdleCmd; import MsgSelectIdleCmd = ygopro.StocGameMessage.MsgSelectIdleCmd;
export default (selectIdleCmd: MsgSelectIdleCmd) => { export default async (selectIdleCmd: MsgSelectIdleCmd) => {
const player = selectIdleCmd.player; const player = selectIdleCmd.player;
const cmds = selectIdleCmd.idle_cmds; const cmds = selectIdleCmd.idle_cmds;
...@@ -18,9 +18,10 @@ export default (selectIdleCmd: MsgSelectIdleCmd) => { ...@@ -18,9 +18,10 @@ export default (selectIdleCmd: MsgSelectIdleCmd) => {
card.idleInteractivities = []; card.idleInteractivities = [];
}); });
// sendAIPredictAsResponse(selectIdleCmd as unknown as ygopro.StocGameMessage); console.log("intercept selectIdleCmd");
// return; await sendAIPredictAsResponse(selectIdleCmd as unknown as ygopro.StocGameMessage);
return;
cmds.forEach((cmd) => { cmds.forEach((cmd) => {
const interactType = idleTypeToInteractType(cmd.idle_type); const interactType = idleTypeToInteractType(cmd.idle_type);
......
...@@ -6,6 +6,7 @@ import { ...@@ -6,6 +6,7 @@ import {
type ygopro, type ygopro,
} from "@/api"; } from "@/api";
import { displayOptionModal } from "@/ui/Duel/Message"; import { displayOptionModal } from "@/ui/Duel/Message";
import { sendAIPredictAsResponse } from "@/service/duel/agent";
export default async (selectOption: ygopro.StocGameMessage.MsgSelectOption) => { export default async (selectOption: ygopro.StocGameMessage.MsgSelectOption) => {
const options = selectOption.options; const options = selectOption.options;
...@@ -18,6 +19,10 @@ export default async (selectOption: ygopro.StocGameMessage.MsgSelectOption) => { ...@@ -18,6 +19,10 @@ export default async (selectOption: ygopro.StocGameMessage.MsgSelectOption) => {
return; return;
} }
console.log("intercept selectOption");
await sendAIPredictAsResponse(selectOption as unknown as ygopro.StocGameMessage);
return;
await displayOptionModal( await displayOptionModal(
fetchStrings(Region.System, 556), fetchStrings(Region.System, 556),
options.map(({ code, response }) => ({ options.map(({ code, response }) => ({
......
import { sendSelectPlaceResponse, ygopro } from "@/api"; import { sendSelectPlaceResponse, ygopro } from "@/api";
import { InteractType, placeStore } from "@/stores"; import { InteractType, placeStore } from "@/stores";
import { sendAIPredictAsResponse } from "@/service/duel/agent";
type MsgSelectPlace = ygopro.StocGameMessage.MsgSelectPlace; type MsgSelectPlace = ygopro.StocGameMessage.MsgSelectPlace;
export default (selectPlace: MsgSelectPlace) => { export default async (selectPlace: MsgSelectPlace) => {
if (selectPlace.count !== 1) { if (selectPlace.count !== 1) {
console.warn(`Unhandled case: ${selectPlace}`); console.warn(`Unhandled case: ${selectPlace}`);
return; return;
...@@ -20,22 +21,26 @@ export default (selectPlace: MsgSelectPlace) => { ...@@ -20,22 +21,26 @@ export default (selectPlace: MsgSelectPlace) => {
return; return;
} }
for (const place of selectPlace.places) { console.log("intercept announce");
switch (place.zone) { await sendAIPredictAsResponse(selectPlace as unknown as ygopro.StocGameMessage);
case ygopro.CardZone.MZONE: return;
case ygopro.CardZone.SZONE:
const block = placeStore.of(place); // for (const place of selectPlace.places) {
if (block) { // switch (place.zone) {
block.interactivity = { // case ygopro.CardZone.MZONE:
interactType: InteractType.PLACE_SELECTABLE, // case ygopro.CardZone.SZONE:
response: { // const block = placeStore.of(place);
controller: place.controller, // if (block) {
zone: place.zone, // block.interactivity = {
sequence: place.sequence, // interactType: InteractType.PLACE_SELECTABLE,
}, // response: {
}; // controller: place.controller,
} // zone: place.zone,
break; // sequence: place.sequence,
} // },
} // };
// }
// break;
// }
// }
}; };
import { ygopro } from "@/api"; import { ygopro } from "@/api";
import { displayPositionModal } from "@/ui/Duel/Message"; import { displayPositionModal } from "@/ui/Duel/Message";
import { sendAIPredictAsResponse } from "@/service/duel/agent";
type MsgSelectPosition = ygopro.StocGameMessage.MsgSelectPosition; type MsgSelectPosition = ygopro.StocGameMessage.MsgSelectPosition;
export default async (selectPosition: MsgSelectPosition) => { export default async (selectPosition: MsgSelectPosition) => {
console.log("intercept announce");
await sendAIPredictAsResponse(selectPosition as unknown as ygopro.StocGameMessage);
return;
const _player = selectPosition.player; const _player = selectPosition.player;
const positions = selectPosition.positions.map( const positions = selectPosition.positions.map(
(position) => position.position, (position) => position.position,
......
import { getStrings, ygopro } from "@/api"; import { getStrings, ygopro } from "@/api";
import { displayYesNoModal } from "@/ui/Duel/Message"; import { displayYesNoModal } from "@/ui/Duel/Message";
import { sendAIPredictAsResponse } from "@/service/duel/agent";
type MsgSelectYesNo = ygopro.StocGameMessage.MsgSelectYesNo; type MsgSelectYesNo = ygopro.StocGameMessage.MsgSelectYesNo;
export default async (selectYesNo: MsgSelectYesNo) => { export default async (selectYesNo: MsgSelectYesNo) => {
console.log("intercept selectYesNo");
await sendAIPredictAsResponse(selectYesNo as unknown as ygopro.StocGameMessage);
return;
const _player = selectYesNo.player; const _player = selectYesNo.player;
const effect_description = selectYesNo.effect_description; const effect_description = selectYesNo.effect_description;
......
...@@ -93,6 +93,7 @@ const initialState: Omit<MatState, "reset"> = { ...@@ -93,6 +93,7 @@ const initialState: Omit<MatState, "reset"> = {
duelEnd: false, duelEnd: false,
// methods // methods
isMe, isMe,
turn_count: 0,
duelId: "", duelId: "",
agentIndex: 0, agentIndex: 0,
prevActionIndex: 0, prevActionIndex: 0,
...@@ -115,6 +116,7 @@ class MatStore implements MatState, NeosStore { ...@@ -115,6 +116,7 @@ class MatStore implements MatState, NeosStore {
tossResult = initialState.tossResult; tossResult = initialState.tossResult;
selectUnselectInfo = initialState.selectUnselectInfo; selectUnselectInfo = initialState.selectUnselectInfo;
duelEnd = initialState.duelEnd; duelEnd = initialState.duelEnd;
turn_count = initialState.turn_count;
duelId = initialState.duelId; duelId = initialState.duelId;
agentIndex = initialState.agentIndex; agentIndex = initialState.agentIndex;
prevActionIndex = initialState.prevActionIndex; prevActionIndex = initialState.prevActionIndex;
...@@ -150,6 +152,7 @@ class MatStore implements MatState, NeosStore { ...@@ -150,6 +152,7 @@ class MatStore implements MatState, NeosStore {
selectedList: [], selectedList: [],
}; };
this.duelEnd = false; this.duelEnd = false;
this.turn_count = 0;
this.duelId = ""; this.duelId = "";
this.agentIndex = 0; this.agentIndex = 0;
this.prevActionIndex = 0; this.prevActionIndex = 0;
......
...@@ -50,6 +50,8 @@ export interface MatState { ...@@ -50,6 +50,8 @@ export interface MatState {
/** 根据自己的先后手判断是否是自己 */ /** 根据自己的先后手判断是否是自己 */
isMe: (player: number) => boolean; isMe: (player: number) => boolean;
// TODO (ygo-agent): 检查实现是否正确
turn_count: number,
duelId: string; duelId: string;
agentIndex: number; agentIndex: number;
prevActionIndex: number; prevActionIndex: number;
......
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