Commit 36cd55cd authored by timel's avatar timel

feat: add hint

parent c74ffee8
......@@ -75,7 +75,10 @@ export default async function (action: sqliteAction): Promise<sqliteResult> {
selectResult: constructCardMeta(code, dataResult, textResult),
};
} else {
console.warn("ygo db not init or id not provied!");
if (action.payload?.id !== 0) {
// 0是无效的卡片ID,不需要报错,返回空即可
console.warn("ygo db not init or id not provied!");
}
}
return {};
......
......@@ -4,6 +4,8 @@ import { fetchEsHintMeta } from "@/reducers/duel/hintSlice";
import { AppDispatch } from "@/store";
import { valtioStore } from "@/valtioStores";
const { matStore } = valtioStore;
export default (
draw: ygopro.StocGameMessage.MsgDraw,
dispatch: AppDispatch
......@@ -11,7 +13,5 @@ export default (
dispatch(fetchEsHintMeta({ originMsg: "玩家抽卡时" }));
dispatch(fetchHandsMeta({ controler: draw.player, codes: draw.cards }));
const matStore = valtioStore.matStore;
matStore.hands.add(draw.player, draw.cards);
};
......@@ -23,7 +23,7 @@ import { valtioStore } from "@/valtioStores";
import { REASON_MATERIAL } from "../../common";
const matStore = valtioStore.matStore;
const { matStore } = valtioStore;
const OVERLAY_STACK: { code: number; sequence: number }[] = [];
......
......@@ -12,7 +12,7 @@ import {
import { AppDispatch } from "@/store";
import { valtioStore } from "@/valtioStores";
const matStore = valtioStore.matStore;
const { matStore } = valtioStore;
export default (
start: ygopro.StocGameMessage.MsgStart,
......
......@@ -10,6 +10,7 @@ import type {
InitInfo,
PlayMatState,
} from "./types";
import { DESCRIPTION_LIMIT, fetchStrings, getStrings } from "@/api/strings";
/**
* 生成一个指定长度的卡片数组
......@@ -61,6 +62,48 @@ const initInfo: PlayMatState["initInfo"] = proxy({
},
});
const hint: PlayMatState["hint"] = proxy({
code: -1,
fetchCommonHintMeta: (hintData: number) => {
return fetchStrings("!system", hintData);
},
fetchSelectHintMeta: async (selectHintData: number, esHint?: string) => {
let selectHintMeta = "";
if (selectHintData > DESCRIPTION_LIMIT) {
// 针对`MSG_SELECT_PLACE`的特化逻辑
const cardMeta = await fetchCard(selectHintData, true);
selectHintMeta = fetchStrings("!system", 569).replace(
"[%ls]",
cardMeta.text.name || "[?]"
);
} else {
selectHintMeta = await getStrings(selectHintData);
}
return {
selectHintMeta,
esHint,
};
},
fetchEsHintMeta: async (
_originMsg: string | number,
location?: ygopro.CardLocation,
cardID?: number
) => {
const originMsg =
typeof _originMsg === "string"
? _originMsg
: fetchStrings("!system", _originMsg);
if (cardID) {
const cardMeta = await fetchCard(cardID);
return { originMsg, cardMeta, location };
} else {
return { originMsg, location };
}
},
});
/**
* 在决斗盘仓库之中,
* 给 `{me: [...], op: [...]}` 这种类型的对象添加一些方法。
......@@ -144,9 +187,7 @@ export const matStore = proxy<PlayMatState>({
initInfo,
selfType: ygopro.StocTypeChange.SelfType.UNKNOWN,
hint: {
code: -1,
},
hint,
currentPlayer: -1,
phase: {
currentPhase: "UNKNOWN", // TODO 当前的阶段 应该改成enum
......@@ -166,7 +207,7 @@ export const matStore = proxy<PlayMatState>({
const getWhom = (controller: number) =>
judgeSelf(controller, matStore.selfType) ? "me" : "op";
export function judgeSelf(player: number, selfType: number): boolean {
function judgeSelf(player: number, selfType: number): boolean {
switch (selfType) {
case 1:
// 自己是先攻
......
......@@ -44,7 +44,7 @@ export interface PlayMatState {
timeLimits: BothSide<number>; // 双方的时间限制
hint: HintState;
hint: HintState & HintMethods;
currentPlayer: number; // 当前的操作方
......@@ -132,12 +132,34 @@ export interface ExtraDeckState extends DuelFieldState {}
export interface TimeLimit {
leftTime: number;
}
export interface HintState {
code: number;
msg?: string;
esHint?: string;
esSelectHint?: string;
}
// 和hint相关的方法
export interface HintMethods {
fetchCommonHintMeta: (hintData: number) => string;
fetchSelectHintMeta: (
selectHintData: number,
esHint?: string
) => Promise<{
selectHintMeta: string;
esHint?: string;
}>;
fetchEsHintMeta: (
originMsg: string | number,
location?: ygopro.CardLocation,
cardID?: number
) => Promise<{
originMsg: string;
cardMeta?: CardMeta;
location?: ygopro.CardLocation;
}>;
}
export interface PhaseState {
currentPhase: string; // TODO 当前的阶段 应该改成enum
enableBp: boolean; // 允许进入战斗阶段
......
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