Commit 5c9a4632 authored by Chunchi Che's avatar Chunchi Che

Merge branch 'optimize/chain' into 'main'

改造一下连锁的数据层实现

See merge request !283
parents 8d38baba d895da88
import { ygopro } from "@/api";
import { cardStore, matStore } from "@/stores";
import { cardStore, matStore, placeStore } from "@/stores";
export default (_chainEnd: ygopro.StocGameMessage.MsgChainEnd) => {
while (true) {
......@@ -8,11 +8,11 @@ export default (_chainEnd: ygopro.StocGameMessage.MsgChainEnd) => {
break;
}
const target = cardStore.find(chain);
if (target) {
target.chainIndex = undefined;
const block = placeStore.of(chain);
if (block) {
block.chainIndex.pop();
} else {
console.warn(`<ChainEnd>target from ${chain} is null`);
console.warn(`<ChainEnd>block from ${chain} is null`);
}
}
......
import { ygopro } from "@/api";
import { cardStore, matStore } from "@/stores";
import { matStore, placeStore } from "@/stores";
// FIXME: 处理连锁会存在三种结果:
// 1. Solved - 已处理;
......@@ -15,11 +15,11 @@ export default async (chainSolved: ygopro.StocGameMessage.MsgChainSolved) => {
.at(0);
if (location) {
// 设置被连锁状态为空,解除连锁
const target = cardStore.find(location);
if (target) {
target.chainIndex = undefined;
const block = placeStore.of(location);
if (block) {
block.chainIndex.pop();
} else {
console.warn(`<ChainSolved>target from ${location} is null`);
console.warn(`<ChainSolved>block from ${location} is null`);
}
} else {
console.warn(
......
import { fetchCard, ygopro } from "@/api";
import { cardStore, fetchEsHintMeta, matStore } from "@/stores";
import { cardStore, fetchEsHintMeta, matStore, placeStore } from "@/stores";
import { callCardFocus } from "@/ui/Duel/PlayMat/Card";
export default async (chaining: ygopro.StocGameMessage.MsgChaining) => {
......@@ -16,7 +16,12 @@ export default async (chaining: ygopro.StocGameMessage.MsgChaining) => {
const target = cardStore.find(location);
if (target) {
// 设置连锁序号
target.chainIndex = matStore.chains.length;
const block = placeStore.of(location);
if (block) {
block.chainIndex.push(matStore.chains.length);
} else {
console.warn(`<Chaining>block from ${location} is null`);
}
const meta = fetchCard(chaining.code);
// 这里不能设置`code`,因为存在一个场景:
......
......@@ -7,10 +7,12 @@ export default (fieldDisabled: MsgFieldDisabled) => {
switch (action.zone) {
case ygopro.CardZone.MZONE:
case ygopro.CardZone.SZONE:
placeStore.set(action.zone, action.controller, action.sequence, {
interactivity: undefined,
disabled: action.disabled,
});
const block = placeStore.of(action);
if (block) {
block.disabled = action.disabled;
} else {
console.warn("<FieldDisabled>block is undefined");
}
break;
default:
console.warn("<FieldDisabled>zone is not MZONE nor SZONE!");
......
......@@ -13,17 +13,17 @@ export default (selectPlace: MsgSelectPlace) => {
switch (place.zone) {
case ygopro.CardZone.MZONE:
case ygopro.CardZone.SZONE:
placeStore.set(place.zone, place.controller, place.sequence, {
interactivity: {
const block = placeStore.of(place);
if (block) {
block.interactivity = {
interactType: InteractType.PLACE_SELECTABLE,
response: {
controller: place.controller,
zone: place.zone,
sequence: place.sequence,
},
},
disabled: false,
});
};
}
break;
}
}
......
......@@ -22,8 +22,6 @@ export interface CardType {
}>; // 选择位置状态下的互动信息
counters: { [type: number]: number }; // 指示器
isToken: boolean; // 是否是token
chainIndex?: number /*连锁的序号,如果为空表示不在连锁
TODO: 目前是妥协的设计,因为其实一张卡是可以在同一个连锁链中被连锁多次的,这里为了避免太过复杂只保存最后的连锁序号*/;
selected: boolean; // 当前卡是否被选择成为效果的对象
}
......
......@@ -15,17 +15,19 @@ export type PlaceInteractivity =
}>
| undefined;
const { MZONE, SZONE } = ygopro.CardZone;
const { MZONE, SZONE, HAND, GRAVE, REMOVED } = ygopro.CardZone;
export interface BlockState {
interactivity?: PlaceInteractivity; // 互动性
disabled: boolean; // 是否被禁用
chainIndex: number[]; // 当前位置上的连锁序号。YGOPRO和MASTER DUEL的连锁都是和位置绑定的,因此在`PlaceStore`中记录连锁状态。
}
const genPLaces = (n: number): BlockState[] =>
Array.from({ length: n }).map(() => ({
interactivity: undefined,
disabled: false,
chainIndex: [],
}));
const initialState = {
......@@ -37,27 +39,35 @@ const initialState = {
me: genPLaces(6),
op: genPLaces(6),
},
[HAND]: {
me: genPLaces(100), // 给100个占位
op: genPLaces(100),
},
[GRAVE]: {
me: genPLaces(100),
op: genPLaces(100),
},
[REMOVED]: {
me: genPLaces(100),
op: genPLaces(100),
},
};
class PlaceStore implements NeosStore {
inner: {
[MZONE]: {
me: BlockState[];
op: BlockState[];
};
[SZONE]: {
[zone: number]: {
me: BlockState[];
op: BlockState[];
};
} = initialState;
set(
zone: ygopro.CardZone.MZONE | ygopro.CardZone.SZONE,
controller: number,
sequence: number,
state: BlockState,
) {
placeStore.inner[zone][matStore.isMe(controller) ? "me" : "op"][sequence] =
state;
of(location: {
zone: ygopro.CardZone;
controller: number;
sequence: number;
}): BlockState | undefined {
return placeStore.inner[location.zone][
matStore.isMe(location.controller) ? "me" : "op"
][location.sequence];
}
clearAllInteractivity() {
(["me", "op"] as const).forEach((who) => {
......
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