Commit 3d388d93 authored by Chunchi Che's avatar Chunchi Che

impl reloadField

parent b5ea98a8
Pipeline #23324 passed with stages
in 13 minutes and 11 seconds
import { v4 as v4uuid } from "uuid";
import { ygopro } from "@/api";
import { cardStore, matStore } from "@/stores";
import { genCard } from "../utils";
type MsgReloadField = ygopro.StocGameMessage.MsgReloadField;
export default (_field: MsgReloadField) => {};
export default (field: MsgReloadField) => {
// 重置
cardStore.reset();
const actions = field.actions;
actions.forEach((action) => {
const controller = action.player;
// 更新生命值
matStore.initInfo.of(controller).life = action.lp;
// 更新卡片集合
const cards = action.zone_actions
.map((zoneAction) =>
Array.from({ length: zoneAction.overlay_count + 1 }).map(
(_, overlaySequence) =>
genCard({
uuid: v4uuid(),
code: 0,
location: new ygopro.CardLocation({
controller,
zone: zoneAction.zone,
sequence: zoneAction.sequence,
is_overlay: overlaySequence > 0,
overlay_sequence: Math.min(overlaySequence - 1, 0),
}),
counters: {},
idleInteractivities: [],
meta: { id: 0, data: {}, text: {} },
isToken: false,
selected: false,
}),
),
)
.flat();
cardStore.inner.push(...cards);
});
};
......@@ -71,7 +71,6 @@ export default async (start: ygopro.StocGameMessage.MsgStart) => {
sequence,
position: ygopro.CardPosition.FACEDOWN,
}),
originController: i < 3 ? 0 : 1,
counters: {},
idleInteractivities: [],
meta: {
......
......@@ -3,6 +3,7 @@ import { cardStore } from "@/stores";
import { callCardMove } from "@/ui/Duel/PlayMat/Card";
import MsgUpdateData = ygopro.StocGameMessage.MsgUpdateData;
import { TYPE_TOKEN } from "@/common";
export default async (updateData: MsgUpdateData) => {
const { player: controller, zone, actions } = updateData;
if (controller !== undefined && zone !== undefined && actions !== undefined) {
......@@ -35,6 +36,9 @@ export default async (updateData: MsgUpdateData) => {
}
if (action?.type_ >= 0) {
meta.data.type = action.type_;
if (action.type_ & TYPE_TOKEN) {
target.isToken = true;
}
}
if (action?.level >= 0) {
meta.data.level = action.level;
......
......@@ -5,6 +5,8 @@ import { fetchCard } from "@/api";
import { CardType } from "@/stores";
// 自动从code推断出meta
//
// TODO: 其实不是很推荐这样做,因为随着项目复杂度增加,这样可能会带来meta更新的时序问题
export const genCard = (card: CardType) => {
const t = proxy(card);
subscribeKey(t, "code", (code) => {
......
......@@ -13,7 +13,6 @@ export interface CardType {
code: number; // 卡号
meta: CardMeta; // 卡片元数据
location: ygopro.CardLocation;
originController: number; // 在卡组构建之中持有这张卡的玩家,方便reloadField的使用
idleInteractivities: Interactivity<number>[]; // IDLE状态下的互动信息
placeInteractivity?: Interactivity<{
controller: number;
......
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