Commit 593de382 authored by Chunchi Che's avatar Chunchi Che

fix chaining

parent f89dedac
...@@ -12,7 +12,7 @@ export default (_chainEnd: ygopro.StocGameMessage.MsgChainEnd) => { ...@@ -12,7 +12,7 @@ export default (_chainEnd: ygopro.StocGameMessage.MsgChainEnd) => {
if (target) { if (target) {
target.chainIndex = undefined; target.chainIndex = undefined;
} else { } else {
console.warn(`<ChainEnd>target is null`); console.warn(`<ChainEnd>target from ${chain} is null`);
} }
} }
}; };
import { ygopro } from "@/api"; import { ygopro } from "@/api";
import { useConfig } from "@/config"; import { useConfig } from "@/config";
import { sleep } from "@/infra"; import { sleep } from "@/infra";
import { fetchEsHintMeta, matStore } from "@/stores"; import { cardStore, fetchEsHintMeta, matStore } from "@/stores";
export default async (chaining: ygopro.StocGameMessage.MsgChaining) => { export default async (chaining: ygopro.StocGameMessage.MsgChaining) => {
fetchEsHintMeta({ fetchEsHintMeta({
...@@ -9,15 +9,20 @@ export default async (chaining: ygopro.StocGameMessage.MsgChaining) => { ...@@ -9,15 +9,20 @@ export default async (chaining: ygopro.StocGameMessage.MsgChaining) => {
cardID: chaining.code, cardID: chaining.code,
}); });
await matStore.setChaining(chaining.location, chaining.code, true); await cardStore.setChaining(chaining.location, chaining.code, true);
await sleep(useConfig().ui.chainingDelay); await sleep(useConfig().ui.chainingDelay);
const location = chaining.location; const location = chaining.location;
// 恢复成非`chaining`状态 // 恢复成非`chaining`状态
await matStore.setChaining(location, chaining.code, false); await cardStore.setChaining(location, chaining.code, false);
// 将`location`添加到连锁栈 // 将`location`添加到连锁栈
matStore.chains.push(location); matStore.chains.push(location);
// 设置被连锁状态 // 设置被连锁状态
matStore.setChained(location, matStore.chains.length); const target = cardStore.find(location);
if (target) {
target.chainIndex = matStore.chains.length;
} else {
console.warn(`<chaining>target from ${location} is null`);
}
}; };
...@@ -65,6 +65,25 @@ class CardStore { ...@@ -65,6 +65,25 @@ class CardStore {
find(location: ygopro.CardLocation): CardType | undefined { find(location: ygopro.CardLocation): CardType | undefined {
return this.at(location.location, location.controler, location.sequence); return this.at(location.location, location.controler, location.sequence);
} }
async setChaining(location: ygopro.CardLocation, code: number, isChaining: boolean): Promise<void> {
const target = this.find(location);
if (target) {
target.chaining = isChaining;
if (isChaining) {
// 目前需要判断`isChaining`为ture才设置meta,因为有些手坑发效果后会move到墓地,
// 运行到这里的时候已经和原来的位置对不上了,这时候不设置meta
const meta = await fetchCard(code);
target.code = meta.id;
target.data = meta.data;
target.text = meta.text;
}
if (target.zone == ygopro.CardZone.HAND) {
target.position = isChaining
? ygopro.CardPosition.FACEUP_ATTACK
: ygopro.CardPosition.FACEDOWN_ATTACK;
}
}
}
} }
export const cardStore = proxy(new CardStore()); export const cardStore = proxy(new CardStore());
......
...@@ -62,6 +62,7 @@ const hint: MatState["hint"] = proxy({ ...@@ -62,6 +62,7 @@ const hint: MatState["hint"] = proxy({
*/ */
export const matStore: MatState = proxy<MatState>({ export const matStore: MatState = proxy<MatState>({
chains: [], chains: [],
blocks: [],
timeLimits: { timeLimits: {
// 时间限制 // 时间限制
......
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