Commit e0e5c7a6 authored by Chunchi Che's avatar Chunchi Che

fix package-lock.json and format code

parent 85196568
Pipeline #28219 passed with stages
in 10 minutes and 39 seconds
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -30,7 +30,7 @@ export async function predictDuel(
): Promise<PredictResp | undefined> {
const headers = {
...agentHeader(),
'Content-Type': 'application/json',
"Content-Type": "application/json",
};
const resp = await fetch(`${agentServer}/${apiPath(duelId)}`, {
......
import { ygopro, CardMeta } from "@/api";
import { CardType } from "@/stores/cardStore";
import { CardMeta, ygopro } from "@/api";
import { extraCardTypes } from "@/common";
import { CardType } from "@/stores/cardStore";
import GM = ygopro.StocGameMessage;
......@@ -48,7 +48,7 @@ enum Controller {
Opponent = "opponent",
}
//
//
enum Location {
Deck = "deck",
Extra = "extra",
......@@ -114,7 +114,10 @@ function convertOverlaySequence(cl: ygopro.CardLocation): number {
return cl.is_overlay ? cl.overlay_sequence : -1;
}
function convertCardLocation(cl: ygopro.CardLocation, player: number): CardLocation {
function convertCardLocation(
cl: ygopro.CardLocation,
player: number,
): CardLocation {
return {
controller: convertController(cl.controller, player),
location: cardZoneToLocation(cl.zone),
......@@ -138,7 +141,6 @@ enum Position {
Defense = "defense",
}
function convertPosition(position: ygopro.CardPosition): Position {
switch (position) {
case ygopro.CardPosition.FACEUP_ATTACK:
......@@ -154,7 +156,7 @@ function convertPosition(position: ygopro.CardPosition): Position {
case ygopro.CardPosition.FACEDOWN:
return Position.Facedown;
case ygopro.CardPosition.ATTACK:
return Position.Attack;
return Position.Attack;
case ygopro.CardPosition.DEFENSE:
return Position.Defense;
default:
......@@ -162,7 +164,6 @@ function convertPosition(position: ygopro.CardPosition): Position {
}
}
/**
* none for N/A or unknown or token.
*/
......@@ -200,32 +201,58 @@ enum Race {
// TODO (ygo-agent): replace literal numbers with constants
function numberToRace(raceNumber: number): Race {
switch (raceNumber) {
case 0x0: return Race.None;
case 0x1: return Race.Warrior;
case 0x2: return Race.Spellcaster;
case 0x4: return Race.Fairy;
case 0x8: return Race.Fiend;
case 0x10: return Race.Zombie;
case 0x20: return Race.Machine;
case 0x40: return Race.Aqua;
case 0x80: return Race.Pyro;
case 0x100: return Race.Rock;
case 0x200: return Race.Windbeast;
case 0x400: return Race.Plant;
case 0x800: return Race.Insect;
case 0x1000: return Race.Thunder;
case 0x2000: return Race.Dragon;
case 0x4000: return Race.Beast;
case 0x8000: return Race.BeastWarrior;
case 0x10000: return Race.Dinosaur;
case 0x20000: return Race.Fish;
case 0x40000: return Race.SeaSerpent;
case 0x80000: return Race.Reptile;
case 0x100000: return Race.Psycho;
case 0x200000: return Race.Devine;
case 0x400000: return Race.CreatorGod;
case 0x800000: return Race.Wyrm;
case 0x1000000: return Race.Cyberse;
case 0x0:
return Race.None;
case 0x1:
return Race.Warrior;
case 0x2:
return Race.Spellcaster;
case 0x4:
return Race.Fairy;
case 0x8:
return Race.Fiend;
case 0x10:
return Race.Zombie;
case 0x20:
return Race.Machine;
case 0x40:
return Race.Aqua;
case 0x80:
return Race.Pyro;
case 0x100:
return Race.Rock;
case 0x200:
return Race.Windbeast;
case 0x400:
return Race.Plant;
case 0x800:
return Race.Insect;
case 0x1000:
return Race.Thunder;
case 0x2000:
return Race.Dragon;
case 0x4000:
return Race.Beast;
case 0x8000:
return Race.BeastWarrior;
case 0x10000:
return Race.Dinosaur;
case 0x20000:
return Race.Fish;
case 0x40000:
return Race.SeaSerpent;
case 0x80000:
return Race.Reptile;
case 0x100000:
return Race.Psycho;
case 0x200000:
return Race.Devine;
case 0x400000:
return Race.CreatorGod;
case 0x800000:
return Race.Wyrm;
case 0x1000000:
return Race.Cyberse;
default:
throw new Error(`Unknown race number: ${raceNumber}`);
}
......@@ -263,36 +290,61 @@ enum Type {
// TODO (ygo-agent): replace literal numbers with constants
function numberToType(typeNumber: number): Type {
switch (typeNumber) {
case 0x1: return Type.Monster;
case 0x2: return Type.Spell;
case 0x4: return Type.Trap;
case 0x10: return Type.Normal;
case 0x20: return Type.Effect;
case 0x40: return Type.Fusion;
case 0x80: return Type.Ritual;
case 0x100: return Type.TrapMonster;
case 0x200: return Type.Spirit;
case 0x400: return Type.Union;
case 0x800: return Type.Dual;
case 0x1000: return Type.Tuner;
case 0x2000: return Type.Synchro;
case 0x4000: return Type.Token;
case 0x10000: return Type.QuickPlay;
case 0x20000: return Type.Continuous;
case 0x40000: return Type.Equip;
case 0x80000: return Type.Field;
case 0x100000: return Type.Counter;
case 0x200000: return Type.Flip;
case 0x400000: return Type.Toon;
case 0x800000: return Type.Xyz;
case 0x1000000: return Type.Pendulum;
case 0x2000000: return Type.Special;
case 0x4000000: return Type.Link;
default: throw new Error(`Unknown type number: ${typeNumber}`);
case 0x1:
return Type.Monster;
case 0x2:
return Type.Spell;
case 0x4:
return Type.Trap;
case 0x10:
return Type.Normal;
case 0x20:
return Type.Effect;
case 0x40:
return Type.Fusion;
case 0x80:
return Type.Ritual;
case 0x100:
return Type.TrapMonster;
case 0x200:
return Type.Spirit;
case 0x400:
return Type.Union;
case 0x800:
return Type.Dual;
case 0x1000:
return Type.Tuner;
case 0x2000:
return Type.Synchro;
case 0x4000:
return Type.Token;
case 0x10000:
return Type.QuickPlay;
case 0x20000:
return Type.Continuous;
case 0x40000:
return Type.Equip;
case 0x80000:
return Type.Field;
case 0x100000:
return Type.Counter;
case 0x200000:
return Type.Flip;
case 0x400000:
return Type.Toon;
case 0x800000:
return Type.Xyz;
case 0x1000000:
return Type.Pendulum;
case 0x2000000:
return Type.Special;
case 0x4000000:
return Type.Link;
default:
throw new Error(`Unknown type number: ${typeNumber}`);
}
}
interface Card {
/**
* Card code from cards.cdb
......@@ -364,8 +416,8 @@ export function convertDeckCard(meta: CardMeta): Card {
negated: false,
attack: meta.data.atk ?? 0,
defense: meta.data.def ?? 0,
types: extraCardTypes(meta.data.type ?? 0).map(numberToType),
}
types: extraCardTypes(meta.data.type ?? 0).map(numberToType),
};
}
export function convertCard(card: CardType, player: number): Card {
......@@ -386,7 +438,7 @@ export function convertCard(card: CardType, player: number): Card {
attack: card.meta.data.atk ?? 0,
defense: card.meta.data.def ?? 0,
types: extraCardTypes(card.meta.data.type ?? 0).map(numberToType),
}
};
}
enum Phase {
......@@ -487,9 +539,9 @@ function convertMsgSelectCard(msg: GM.MsgSelectCard): MsgSelectCard {
cancelable: msg.cancelable,
min: msg.min,
max: msg.max,
cards: msg.cards.map(c => ({
cards: msg.cards.map((c) => ({
location: convertCardLocation(c.location, msg.player),
response: c.response
response: c.response,
})),
selected: [],
};
......@@ -507,7 +559,7 @@ interface MsgSelectTribute {
min: number;
max: number;
cards: SelectTributeCard[];
selected: number[];
selected: number[];
}
function convertMsgSelectTribute(msg: GM.MsgSelectTribute): MsgSelectTribute {
......@@ -516,7 +568,7 @@ function convertMsgSelectTribute(msg: GM.MsgSelectTribute): MsgSelectTribute {
cancelable: msg.cancelable,
min: msg.min,
max: msg.max,
cards: msg.selectable_cards.map(c => ({
cards: msg.selectable_cards.map((c) => ({
location: convertCardLocation(c.location, msg.player),
level: c.level,
response: c.response,
......@@ -546,24 +598,24 @@ export interface MsgSelectSum {
function convertMsgSelectSum(msg: GM.MsgSelectSum): MsgSelectSum {
return {
msg_type: "select_sum",
overflow: msg.overflow != 0,
overflow: msg.overflow !== 0,
level_sum: msg.level_sum,
min: msg.min,
max: msg.max,
cards: msg.selectable_cards.map(c => ({
cards: msg.selectable_cards.map((c) => ({
location: convertCardLocation(c.location, msg.player),
level1: c.level1,
level2: c.level2,
response: c.response,
})),
must_cards: msg.must_select_cards.map(c => ({
must_cards: msg.must_select_cards.map((c) => ({
location: convertCardLocation(c.location, msg.player),
level1: c.level1,
level2: c.level2,
response: c.response,
})),
selected: [],
}
};
}
interface CardInfo {
......@@ -640,18 +692,19 @@ function convertMsgSelectIdleCmd(msg: GM.MsgSelectIdleCmd): MsgSelectIdleCmd {
for (const data of cmd.idle_datas) {
const cmd_type = convertIdleCmdType(cmd.idle_type);
if (
cmd_type == IdleCmdType.Summon ||
cmd_type == IdleCmdType.SpSummon ||
cmd_type == IdleCmdType.Reposition ||
cmd_type == IdleCmdType.Mset ||
cmd_type == IdleCmdType.Set ||
cmd_type == IdleCmdType.Activate
cmd_type === IdleCmdType.Summon ||
cmd_type === IdleCmdType.SpSummon ||
cmd_type === IdleCmdType.Reposition ||
cmd_type === IdleCmdType.Mset ||
cmd_type === IdleCmdType.Set ||
cmd_type === IdleCmdType.Activate
) {
idle_cmds.push({
cmd_type,
data: {
card_info: convertCardInfo(data.card_info, msg.player),
effect_description: cmd_type == IdleCmdType.Activate ? data.effect_description : 0,
effect_description:
cmd_type === IdleCmdType.Activate ? data.effect_description : 0,
response: data.response,
},
});
......@@ -702,7 +755,7 @@ function convertMsgSelectChain(msg: GM.MsgSelectChain): MsgSelectChain {
return {
msg_type: "select_chain",
forced: msg.forced,
chains: msg.chains.map(c => convertChain(c, msg.player)),
chains: msg.chains.map((c) => convertChain(c, msg.player)),
};
}
......@@ -712,14 +765,16 @@ interface MsgSelectPosition {
positions: Position[];
}
function convertMsgSelectPosition(msg: GM.MsgSelectPosition): MsgSelectPosition {
function convertMsgSelectPosition(
msg: GM.MsgSelectPosition,
): MsgSelectPosition {
return {
msg_type: "select_position",
code: msg.code,
// response will be equal to POS_* from ocgcore
// POS_FACEUP_ATTACK: 0x1, POS_FACEDOWN_ATTACK: 0x2,
// POS_FACEUP_DEFENSE: 0x4, POS_FACEDOWN_DEFENSE: 0x8
positions: msg.positions.map(p => convertPosition(p.position)),
positions: msg.positions.map((p) => convertPosition(p.position)),
};
}
......@@ -743,7 +798,9 @@ interface MsgSelectEffectYn {
effect_description: number;
}
function convertMsgSelectEffectYn(msg: GM.MsgSelectEffectYn): MsgSelectEffectYn {
function convertMsgSelectEffectYn(
msg: GM.MsgSelectEffectYn,
): MsgSelectEffectYn {
// response is 1 for yes and 0 for no
return {
msg_type: "select_effectyn",
......@@ -789,7 +846,9 @@ interface MsgSelectBattleCmd {
battle_cmds: BattleCmd[];
}
function convertMsgSelectBattleCmd(msg: GM.MsgSelectBattleCmd): MsgSelectBattleCmd {
function convertMsgSelectBattleCmd(
msg: GM.MsgSelectBattleCmd,
): MsgSelectBattleCmd {
const battle_cmds: BattleCmd[] = [];
for (const cmd of msg.battle_cmds) {
const cmd_type = convertBattleCmdType(cmd.battle_type);
......@@ -818,13 +877,11 @@ function convertMsgSelectBattleCmd(msg: GM.MsgSelectBattleCmd): MsgSelectBattleC
};
}
interface SelectUnselectCard {
location: CardLocation;
response: number;
}
interface MsgSelectUnselectCard {
msg_type: "select_unselect_card";
finishable: boolean;
......@@ -835,7 +892,9 @@ interface MsgSelectUnselectCard {
selectable_cards: SelectUnselectCard[];
}
function convertMsgSelectUnselectCard(msg: GM.MsgSelectUnselectCard): MsgSelectUnselectCard {
function convertMsgSelectUnselectCard(
msg: GM.MsgSelectUnselectCard,
): MsgSelectUnselectCard {
return {
msg_type: "select_unselect_card",
// response is -1 for finish
......@@ -843,11 +902,11 @@ function convertMsgSelectUnselectCard(msg: GM.MsgSelectUnselectCard): MsgSelectU
cancelable: msg.cancelable,
min: msg.min,
max: msg.max,
selected_cards: msg.selected_cards.map(c => ({
selected_cards: msg.selected_cards.map((c) => ({
location: convertCardLocation(c.location, msg.player),
response: c.response,
})),
selectable_cards: msg.selectable_cards.map(c => ({
selectable_cards: msg.selectable_cards.map((c) => ({
location: convertCardLocation(c.location, msg.player),
response: c.response,
})),
......@@ -867,14 +926,13 @@ interface MsgSelectOption {
function convertMsgSelectOption(msg: GM.MsgSelectOption): MsgSelectOption {
return {
msg_type: "select_option",
options: msg.options.map(o => ({
options: msg.options.map((o) => ({
code: o.code,
response: o.response,
})),
};
}
interface Place {
controller: Controller;
location: Location;
......@@ -892,7 +950,7 @@ function convertMsgSelectPlace(msg: GM.MsgSelectPlace): MsgSelectPlace {
return {
msg_type: "select_place",
count: msg.count,
places: msg.places.map(p => ({
places: msg.places.map((p) => ({
// NOTICE: the response is the index of the place in the places array
controller: convertController(p.controller, msg.player),
location: cardZoneToLocation(p.zone),
......@@ -917,7 +975,7 @@ function convertMsgAnnounceAttrib(msg: GM.MsgAnnounce): MsgAnnounceAttrib {
msg_type: "announce_attrib",
count: msg.min,
// from api/ocgcore/ocgAdapter/stoc/stocGameMsg/announceAttrib.ts
attributes: msg.options.map(a => ({
attributes: msg.options.map((a) => ({
attribute: numberToAttribute(1 << a.code),
response: a.response,
})),
......@@ -939,7 +997,7 @@ function convertMsgAnnounceNumber(msg: GM.MsgAnnounce): MsgAnnounceNumber {
return {
msg_type: "announce_number",
count: msg.min,
numbers: msg.options.map(o => ({
numbers: msg.options.map((o) => ({
number: o.code,
response: o.response,
})),
......@@ -947,21 +1005,20 @@ function convertMsgAnnounceNumber(msg: GM.MsgAnnounce): MsgAnnounceNumber {
}
type ActionMsgData =
MsgSelectCard |
MsgSelectTribute |
MsgSelectSum |
MsgSelectIdleCmd |
MsgSelectChain |
MsgSelectPosition |
MsgSelectYesNo |
MsgSelectEffectYn |
MsgSelectBattleCmd |
MsgSelectUnselectCard |
MsgSelectOption |
MsgSelectPlace |
MsgAnnounceAttrib |
MsgAnnounceNumber;
| MsgSelectCard
| MsgSelectTribute
| MsgSelectSum
| MsgSelectIdleCmd
| MsgSelectChain
| MsgSelectPosition
| MsgSelectYesNo
| MsgSelectEffectYn
| MsgSelectBattleCmd
| MsgSelectUnselectCard
| MsgSelectOption
| MsgSelectPlace
| MsgAnnounceAttrib
| MsgAnnounceNumber;
interface ActionMsg {
data: ActionMsgData;
......@@ -1017,11 +1074,11 @@ export function convertActionMsg(msg: ygopro.StocGameMessage): ActionMsg {
data: convertMsgSelectPlace(msg),
};
} else if (msg instanceof GM.MsgAnnounce) {
if (msg.announce_type == GM.MsgAnnounce.AnnounceType.Attribute) {
if (msg.announce_type === GM.MsgAnnounce.AnnounceType.Attribute) {
return {
data: convertMsgAnnounceAttrib(msg),
};
} else if (msg.announce_type == GM.MsgAnnounce.AnnounceType.Number) {
} else if (msg.announce_type === GM.MsgAnnounce.AnnounceType.Number) {
return {
data: convertMsgAnnounceNumber(msg),
};
......
import {
PredictReq,
ygopro,
sendSelectBattleCmdResponse,
sendSelectEffectYnResponse,
sendSelectIdleCmdResponse,
sendSelectPlaceResponse,
sendSelectMultiResponse,
sendSelectSingleResponse,
sendSelectEffectYnResponse,
sendSelectPositionResponse,
sendSelectOptionResponse,
sendSelectBattleCmdResponse,
sendSortCardResponse,
sendSelectPlaceResponse,
sendSelectPositionResponse,
sendSelectSingleResponse,
ygopro,
} from "@/api";
import { cardStore, matStore } from "@/stores";
import { predictDuel } from "@/api/ygoAgent/predict";
import {
Global, convertPhase, convertCard, convertDeckCard,
parsePlayerFromMsg, convertActionMsg, Input, MultiSelectMsg, MsgSelectSum
convertActionMsg,
convertCard,
convertDeckCard,
convertPhase,
Global,
Input,
MsgSelectSum,
MultiSelectMsg,
parsePlayerFromMsg,
} from "@/api/ygoAgent/schema";
import { predictDuel } from "@/api/ygoAgent/predict";
import { cardStore, matStore } from "@/stores";
function computeSetDifference(a1: number[], a2: number[]): number[] {
const freq1 = new Map<number, number>();
......@@ -44,7 +50,6 @@ function computeSetDifference(a1: number[], a2: number[]): number[] {
return difference;
}
export function genInput(msg: ygopro.StocGameMessage): Input {
// 全局信息可以从 `matStore` 里面拿
const mat = matStore;
......@@ -66,23 +71,29 @@ export function genInput(msg: ygopro.StocGameMessage): Input {
const opponent = 1 - player;
const cards = cardStore.inner
.filter((card) =>
zones.includes(card.location.zone) &&
!(card.location.zone === ygopro.CardZone.DECK
&& card.location.controller === player
)
.filter(
(card) =>
zones.includes(card.location.zone) &&
!(
card.location.zone === ygopro.CardZone.DECK &&
card.location.controller === player
),
)
.map((card) => convertCard(card, player));
const cardCodesMe = cardStore.inner
.filter((card) =>
zones.includes(card.location.zone) && card.location.controller === player
.filter(
(card) =>
zones.includes(card.location.zone) &&
card.location.controller === player,
)
.map((card) => card.code);
const cardCodesMeDeck = computeSetDifference(mat.mainDeck, cardCodesMe);
const mainDeckCardMeta = mat.mainDeckCardMeta;
// TODO (ygo-agent): 临时方案,有很多边界情况未考虑
const deckCardsMe = cardCodesMeDeck.map((code) => convertDeckCard(mainDeckCardMeta.get(code)!));
const deckCardsMe = cardCodesMeDeck.map((code) =>
convertDeckCard(mainDeckCardMeta.get(code)!),
);
const turnPlayer = mat.currentPlayer;
const global: Global = {
......@@ -92,7 +103,7 @@ export function genInput(msg: ygopro.StocGameMessage): Input {
op_lp: mat.initInfo.of(opponent).life,
phase: convertPhase(mat.phase.currentPhase),
turn: mat.turnCount,
}
};
const actionMsg = convertActionMsg(msg);
......@@ -100,10 +111,9 @@ export function genInput(msg: ygopro.StocGameMessage): Input {
global: global,
cards: deckCardsMe.concat(cards),
action_msg: actionMsg,
}
};
}
async function sendRequest(req: PredictReq) {
console.log("Sending predict request:", req);
const duelId = matStore.duelId;
......@@ -111,8 +121,7 @@ async function sendRequest(req: PredictReq) {
console.log("Got predict response:", resp);
if (resp !== undefined) {
matStore.agentIndex = resp.index;
}
else {
} else {
throw new Error("Failed to get predict response");
}
......@@ -143,11 +152,11 @@ export async function sendAIPredictAsResponse(msg: ygopro.StocGameMessage) {
prev_action_idx: matStore.prevActionIndex,
};
const response = (await sendRequest(req)).response;
if (response != -1) {
if (response !== -1) {
selected.push(matStore.prevActionIndex);
responses.push(response);
}
if (response == -1 || selected.length == msg_.max) {
if (response === -1 || selected.length === msg_.max) {
sendSelectMultiResponse(responses);
break;
}
......@@ -169,7 +178,7 @@ export async function sendAIPredictAsResponse(msg: ygopro.StocGameMessage) {
prev_action_idx: matStore.prevActionIndex,
};
const pred = await sendRequest(req);
const idx = matStore.prevActionIndex
const idx = matStore.prevActionIndex;
selected.push(idx);
responses.push(pred.response);
if (pred.can_finish) {
......@@ -189,7 +198,7 @@ export async function sendAIPredictAsResponse(msg: ygopro.StocGameMessage) {
switch (msgName) {
case "announce_attrib":
case "announce_number":
sendSelectOptionResponse(response);
sendSelectOptionResponse(response);
break;
case "select_battlecmd":
sendSelectBattleCmdResponse(response);
......@@ -211,7 +220,8 @@ export async function sendAIPredictAsResponse(msg: ygopro.StocGameMessage) {
sendSelectPositionResponse(convertPositionResponse(response));
break;
case "select_place": {
const place = (msg as unknown as ygopro.StocGameMessage.MsgSelectPlace).places[response];
const place = (msg as unknown as ygopro.StocGameMessage.MsgSelectPlace)
.places[response];
sendSelectPlaceResponse({
controller: place.controller,
zone: place.zone,
......@@ -220,7 +230,7 @@ export async function sendAIPredictAsResponse(msg: ygopro.StocGameMessage) {
break;
}
case "select_unselect_card": {
if (response == -1) {
if (response === -1) {
sendSelectSingleResponse(-1);
} else {
sendSelectMultiResponse([response]);
......@@ -231,7 +241,6 @@ export async function sendAIPredictAsResponse(msg: ygopro.StocGameMessage) {
}
}
function argmax<T>(arr: T[], getValue: (item: T) => number): number {
if (arr.length === 0) {
throw new Error("Array is empty");
......@@ -251,14 +260,17 @@ function argmax<T>(arr: T[], getValue: (item: T) => number): number {
return maxIndex;
}
function convertPositionResponse(response: number): ygopro.CardPosition {
switch (response) {
case 0x1: return ygopro.CardPosition.FACEUP_ATTACK;
case 0x2: return ygopro.CardPosition.FACEDOWN_ATTACK;
case 0x4: return ygopro.CardPosition.FACEUP_DEFENSE;
case 0x8: return ygopro.CardPosition.FACEDOWN_DEFENSE;
case 0x1:
return ygopro.CardPosition.FACEUP_ATTACK;
case 0x2:
return ygopro.CardPosition.FACEDOWN_ATTACK;
case 0x4:
return ygopro.CardPosition.FACEUP_DEFENSE;
case 0x8:
return ygopro.CardPosition.FACEDOWN_DEFENSE;
default:
throw new Error(`Invalid position response: ${response}`);
}
}
\ No newline at end of file
}
import { fetchStrings, Region, ygopro } from "@/api";
import { displayOptionModal } from "@/ui/Duel/Message";
import MsgAnnounce = ygopro.StocGameMessage.MsgAnnounce;
import { displayAnnounceModal } from "@/ui/Duel/Message/AnnounceModal";
import { sendAIPredictAsResponse } from "@/service/duel/agent";
import { matStore } from "@/stores";
import { displayAnnounceModal } from "@/ui/Duel/Message/AnnounceModal";
export default async (announce: MsgAnnounce) => {
if (matStore.autoSelect) {
console.log("intercept announce");
await sendAIPredictAsResponse(announce as unknown as ygopro.StocGameMessage);
return;
await sendAIPredictAsResponse(
announce as unknown as ygopro.StocGameMessage,
);
return;
}
const type_ = announce.announce_type;
......
......@@ -20,7 +20,9 @@ export default async (selectBattleCmd: MsgSelectBattleCmd) => {
if (matStore.autoSelect) {
console.log("intercept selectBattleCmd");
await sendAIPredictAsResponse(selectBattleCmd as unknown as ygopro.StocGameMessage);
await sendAIPredictAsResponse(
selectBattleCmd as unknown as ygopro.StocGameMessage,
);
return;
}
......
import { sendSelectMultiResponse, ygopro } from "@/api";
import MsgSelectCard = ygopro.StocGameMessage.MsgSelectCard;
import { sendAIPredictAsResponse } from "@/service/duel/agent";
import { matStore } from "@/stores";
import { displaySelectActionsModal } from "@/ui/Duel/Message/SelectActionsModal";
import { fetchCheckCardMeta } from "../utils";
import { sendAIPredictAsResponse } from "@/service/duel/agent";
import { matStore } from "@/stores";
export default async (selectCard: MsgSelectCard) => {
const { cancelable, min, max, cards } = selectCard;
// TODO: handle release_param
if (matStore.autoSelect) {
console.log("intercept selectCard");
await sendAIPredictAsResponse(selectCard as unknown as ygopro.StocGameMessage);
await sendAIPredictAsResponse(
selectCard as unknown as ygopro.StocGameMessage,
);
return;
}
......@@ -26,7 +26,6 @@ export default async (selectCard: MsgSelectCard) => {
return;
}
const { selecteds, mustSelects, selectables } = await fetchCheckCardMeta(
cards,
);
......
import { sendSelectSingleResponse, ygopro } from "@/api";
import { sendAIPredictAsResponse } from "@/service/duel/agent";
import { ChainSetting, fetchSelectHintMeta, matStore } from "@/stores";
import { displaySelectActionsModal } from "@/ui/Duel/Message/SelectActionsModal";
import { fetchCheckCardMeta } from "../utils";
import { sendAIPredictAsResponse } from "@/service/duel/agent";
type MsgSelectChain = ygopro.StocGameMessage.MsgSelectChain;
export default async (selectChain: MsgSelectChain) => {
......@@ -69,10 +69,12 @@ export default async (selectChain: MsgSelectChain) => {
case 3: {
if (matStore.autoSelect) {
console.log("intercept selectChain");
await sendAIPredictAsResponse(selectChain as unknown as ygopro.StocGameMessage);
await sendAIPredictAsResponse(
selectChain as unknown as ygopro.StocGameMessage,
);
return;
}
// 处理强制发动的卡
fetchSelectHintMeta({
selectHintData: 203,
......
import { fetchStrings, Region, type ygopro } from "@/api";
import { CardMeta, fetchCard } from "@/api/cards";
import { displayYesNoModal } from "@/ui/Duel/Message";
import { sendAIPredictAsResponse } from "@/service/duel/agent";
import { matStore } from "@/stores";
import { displayYesNoModal } from "@/ui/Duel/Message";
type MsgSelectEffectYn = ygopro.StocGameMessage.MsgSelectEffectYn;
......@@ -10,7 +10,9 @@ type MsgSelectEffectYn = ygopro.StocGameMessage.MsgSelectEffectYn;
export default async (selectEffectYn: MsgSelectEffectYn) => {
if (matStore.autoSelect) {
console.log("intercept selectEffectYn");
await sendAIPredictAsResponse(selectEffectYn as unknown as ygopro.StocGameMessage);
await sendAIPredictAsResponse(
selectEffectYn as unknown as ygopro.StocGameMessage,
);
return;
}
......
import { ygopro } from "@/api";
import { sendAIPredictAsResponse } from "@/service/duel/agent";
import {
cardStore,
type Interactivity,
InteractType,
matStore,
} from "@/stores";
import { sendAIPredictAsResponse } from "@/service/duel/agent";
import MsgSelectIdleCmd = ygopro.StocGameMessage.MsgSelectIdleCmd;
......@@ -20,10 +20,12 @@ export default async (selectIdleCmd: MsgSelectIdleCmd) => {
if (matStore.autoSelect) {
console.log("intercept selectIdleCmd");
await sendAIPredictAsResponse(selectIdleCmd as unknown as ygopro.StocGameMessage);
await sendAIPredictAsResponse(
selectIdleCmd as unknown as ygopro.StocGameMessage,
);
return;
}
cmds.forEach((cmd) => {
const interactType = idleTypeToInteractType(cmd.idle_type);
......
......@@ -5,9 +5,9 @@ import {
sendSelectOptionResponse,
type ygopro,
} from "@/api";
import { displayOptionModal } from "@/ui/Duel/Message";
import { sendAIPredictAsResponse } from "@/service/duel/agent";
import { matStore } from "@/stores";
import { displayOptionModal } from "@/ui/Duel/Message";
export default async (selectOption: ygopro.StocGameMessage.MsgSelectOption) => {
const options = selectOption.options;
......@@ -18,7 +18,9 @@ export default async (selectOption: ygopro.StocGameMessage.MsgSelectOption) => {
if (matStore.autoSelect) {
console.log("intercept selectOption");
await sendAIPredictAsResponse(selectOption as unknown as ygopro.StocGameMessage);
await sendAIPredictAsResponse(
selectOption as unknown as ygopro.StocGameMessage,
);
return;
}
......
import { sendSelectPlaceResponse, ygopro } from "@/api";
import { InteractType, placeStore, matStore } from "@/stores";
import { sendAIPredictAsResponse } from "@/service/duel/agent";
import { InteractType, matStore, placeStore } from "@/stores";
type MsgSelectPlace = ygopro.StocGameMessage.MsgSelectPlace;
......@@ -12,7 +12,9 @@ export default async (selectPlace: MsgSelectPlace) => {
if (matStore.autoSelect) {
console.log("intercept selectPlace");
await sendAIPredictAsResponse(selectPlace as unknown as ygopro.StocGameMessage);
await sendAIPredictAsResponse(
selectPlace as unknown as ygopro.StocGameMessage,
);
return;
}
......
import { ygopro } from "@/api";
import { displayPositionModal } from "@/ui/Duel/Message";
import { sendAIPredictAsResponse } from "@/service/duel/agent";
import { matStore } from "@/stores";
import { displayPositionModal } from "@/ui/Duel/Message";
type MsgSelectPosition = ygopro.StocGameMessage.MsgSelectPosition;
export default async (selectPosition: MsgSelectPosition) => {
if (matStore.autoSelect) {
console.log("intercept selectPosition");
await sendAIPredictAsResponse(selectPosition as unknown as ygopro.StocGameMessage);
await sendAIPredictAsResponse(
selectPosition as unknown as ygopro.StocGameMessage,
);
return;
}
......
......@@ -10,7 +10,9 @@ import { matStore } from "@/stores";
export default async (selectSum: MsgSelectSum) => {
if (matStore.autoSelect) {
console.log("intercept selectSum");
await sendAIPredictAsResponse(selectSum as unknown as ygopro.StocGameMessage);
await sendAIPredictAsResponse(
selectSum as unknown as ygopro.StocGameMessage,
);
return;
}
......
......@@ -10,7 +10,9 @@ import { matStore } from "@/stores";
export default async (selectTribute: MsgSelectTribute) => {
if (matStore.autoSelect) {
console.log("intercept selectTribute");
await sendAIPredictAsResponse(selectTribute as unknown as ygopro.StocGameMessage);
await sendAIPredictAsResponse(
selectTribute as unknown as ygopro.StocGameMessage,
);
return;
}
......
......@@ -11,7 +11,9 @@ import { sendAIPredictAsResponse } from "@/service/duel/agent";
export default async (selectUnselectCards: MsgSelectUnselectCard) => {
if (matStore.autoSelect) {
console.log("intercept selectUnselectCards");
await sendAIPredictAsResponse(selectUnselectCards as unknown as ygopro.StocGameMessage);
await sendAIPredictAsResponse(
selectUnselectCards as unknown as ygopro.StocGameMessage,
);
return;
}
......
import { getStrings, ygopro } from "@/api";
import { displayYesNoModal } from "@/ui/Duel/Message";
import { sendAIPredictAsResponse } from "@/service/duel/agent";
import { matStore } from "@/stores";
import { displayYesNoModal } from "@/ui/Duel/Message";
type MsgSelectYesNo = ygopro.StocGameMessage.MsgSelectYesNo;
export default async (selectYesNo: MsgSelectYesNo) => {
if (matStore.autoSelect) {
console.log("intercept selectYesNo");
await sendAIPredictAsResponse(selectYesNo as unknown as ygopro.StocGameMessage);
await sendAIPredictAsResponse(
selectYesNo as unknown as ygopro.StocGameMessage,
);
return;
}
......
import { fetchCard, ygopro } from "@/api";
import { displaySortCardModal } from "@/ui/Duel/Message";
import { matStore } from "@/stores";
import { displaySortCardModal } from "@/ui/Duel/Message";
type MsgSortCard = ygopro.StocGameMessage.MsgSortCard;
......
import { flatten } from "lodash-es";
import { v4 as v4uuid } from "uuid";
import { createDuel, ygopro, fetchCard } from "@/api";
import { createDuel, fetchCard, ygopro } from "@/api";
import { useConfig } from "@/config";
import { sleep } from "@/infra";
import {
......@@ -92,13 +92,12 @@ export default async (start: ygopro.StocGameMessage.MsgStart) => {
const { duelId, index } = (await createDuel())!;
matStore.duelId = duelId;
matStore.agentIndex = index;
matStore.mainDeckCardMeta = matStore.mainDeck
.reduce((map, item) => {
if (!map.has(item)) {
map.set(item, fetchCard(item));
}
return map;
}, new Map());
matStore.mainDeckCardMeta = matStore.mainDeck.reduce((map, item) => {
if (!map.has(item)) {
map.set(item, fetchCard(item));
}
return map;
}, new Map());
if (replayStore.isReplay) {
replayStart();
......
......@@ -50,7 +50,7 @@ export interface MatState {
/** 根据自己的先后手判断是否是自己 */
isMe: (player: number) => boolean;
turnCount: number,
turnCount: number;
duelId: string;
agentIndex: number;
prevActionIndex: number;
......
......@@ -3,9 +3,9 @@ import {
CheckOutlined,
CloseCircleFilled,
MessageFilled,
StepForwardFilled,
RobotFilled,
RobotOutlined,
StepForwardFilled,
} from "@ant-design/icons";
import {
Button,
......
......@@ -27,12 +27,12 @@ import {
accountStore,
deckStore,
IDeck,
matStore,
Player,
resetUniverse,
RoomStage,
roomStore,
sideStore,
matStore,
} from "@/stores";
import { Background, IconFont, Select, SpecialButton } from "@/ui/Shared";
......
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