Commit 99af0d62 authored by chechunchi's avatar chechunchi

fix shuffle_set_card

parent fcf02257
......@@ -33,7 +33,7 @@ import MsgSelectPositionAdapter from "./selectPosition";
import MsgSelectSum from "./selectSum";
import MsgSelectTributeAdapter from "./selectTribute";
import MsgSelectUnselectCardAdapter from "./selectUnselectCard";
import MsgShuffleSetCard from "./shuffle_set_card";
import MsgShuffleSetCard from "./shuffleSetCard";
import MsgSortCard from "./sortCard";
import MsgStartAdapter from "./start";
import MsgTossAdapter from "./toss";
......
......@@ -16,17 +16,16 @@ export default (data: Uint8Array) => {
const zone = numberToCardZone(reader.inner.readUint8());
const count = reader.inner.readUint8();
const from_locations = [];
const to_locations = [];
const _overlay_locations = []; // TODO: 这个字段是否有用?
for (let i = 0; i < count; i++) {
from_locations.push(reader.readCardLocation());
}
for (let i = 0; i < count; i++) {
to_locations.push(reader.readCardLocation());
_overlay_locations.push(reader.readCardLocation());
}
return new MsgShuffleSetCard({
zone,
from_locations,
to_locations,
});
};
......@@ -3,29 +3,53 @@ import { eventbus, Task } from "@/infra";
import { cardStore } from "@/stores";
import MsgShuffleSetCard = ygopro.StocGameMessage.MsgShuffleSetCard;
// 后端传过来的`from_locations`的列表是切洗前场上卡的location,它们在列表里面按照切洗后的顺序排列
export default async (shuffleSetCard: MsgShuffleSetCard) => {
const zone = shuffleSetCard.zone;
const from_locations = shuffleSetCard.from_locations;
const to_locations = shuffleSetCard.to_locations;
if (from_locations.length != to_locations.length) {
if (from_locations.length == 0) {
console.error("<ShuffleSetCard>from_locations is empty");
return;
}
const controller = from_locations[0].controller;
// 获取到场上对应zone的卡
const cards = cardStore.at(zone, controller);
// 获取场上卡当前所有sequence,并按大小排列
const sequences = cards
.map((card) => card.location.sequence)
.sort((a, b) => a - b);
if (sequences.length != from_locations.length) {
console.error(
"<ShuffleSetCard>length of from_locations and to_locations not matched"
"<ShuffleSetCard>length of sequences and from_locations not matched"
);
return;
}
const count = from_locations.length;
for (let i = 0; i < count; i++) {
const from = from_locations[i];
const to = to_locations[i];
const to_seq = sequences[i];
// TODO: 需要考虑超量么
const target = cardStore.at(from.zone, from.controller, from.sequence);
if (target) {
// 更新位置
target.location = to;
target.location.sequence = to_seq;
// 渲染动画
await eventbus.call(Task.Move, target.uuid);
} else {
console.warn(`<ShuffleSetCard>target from ${from} is null`);
}
// 同时更新超量素材的sequence(非overlay_sequence)
for (const overlay of cardStore.findOverlay(
from.zone,
from.controller,
from.sequence
)) {
overlay.location.sequence = to_seq;
await eventbus.call(Task.Move, overlay.uuid);
}
}
};
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