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

Merge branch 'optimize/chain' into 'main'

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

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