Commit feb483cc authored by Chunchi Che's avatar Chunchi Che

Merge branch 'fix/shuffle_set_card' into 'main'

Fix/shuffle set card

See merge request !231
parents d5270a03 3fac2e51
neos-protobuf @ 2caaa3aa
Subproject commit cd10e6a5f76cfda5ada5a39a9a7a526ca9c5e881
Subproject commit 2caaa3aa310f699ebf5b52a08413d0a555ac4065
......@@ -10766,7 +10766,7 @@ export namespace ygopro {
constructor(data?: any[] | {
zone?: CardZone;
from_locations?: CardLocation[];
to_locations?: CardLocation[];
overlay_locations?: CardLocation[];
}) {
super();
pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [2, 3], this.#one_of_decls);
......@@ -10777,8 +10777,8 @@ export namespace ygopro {
if ("from_locations" in data && data.from_locations != undefined) {
this.from_locations = data.from_locations;
}
if ("to_locations" in data && data.to_locations != undefined) {
this.to_locations = data.to_locations;
if ("overlay_locations" in data && data.overlay_locations != undefined) {
this.overlay_locations = data.overlay_locations;
}
}
}
......@@ -10794,16 +10794,16 @@ export namespace ygopro {
set from_locations(value: CardLocation[]) {
pb_1.Message.setRepeatedWrapperField(this, 2, value);
}
get to_locations() {
get overlay_locations() {
return pb_1.Message.getRepeatedWrapperField(this, CardLocation, 3) as CardLocation[];
}
set to_locations(value: CardLocation[]) {
set overlay_locations(value: CardLocation[]) {
pb_1.Message.setRepeatedWrapperField(this, 3, value);
}
static fromObject(data: {
zone?: CardZone;
from_locations?: ReturnType<typeof CardLocation.prototype.toObject>[];
to_locations?: ReturnType<typeof CardLocation.prototype.toObject>[];
overlay_locations?: ReturnType<typeof CardLocation.prototype.toObject>[];
}): MsgShuffleSetCard {
const message = new MsgShuffleSetCard({});
if (data.zone != null) {
......@@ -10812,8 +10812,8 @@ export namespace ygopro {
if (data.from_locations != null) {
message.from_locations = data.from_locations.map(item => CardLocation.fromObject(item));
}
if (data.to_locations != null) {
message.to_locations = data.to_locations.map(item => CardLocation.fromObject(item));
if (data.overlay_locations != null) {
message.overlay_locations = data.overlay_locations.map(item => CardLocation.fromObject(item));
}
return message;
}
......@@ -10821,7 +10821,7 @@ export namespace ygopro {
const data: {
zone?: CardZone;
from_locations?: ReturnType<typeof CardLocation.prototype.toObject>[];
to_locations?: ReturnType<typeof CardLocation.prototype.toObject>[];
overlay_locations?: ReturnType<typeof CardLocation.prototype.toObject>[];
} = {};
if (this.zone != null) {
data.zone = this.zone;
......@@ -10829,8 +10829,8 @@ export namespace ygopro {
if (this.from_locations != null) {
data.from_locations = this.from_locations.map((item: CardLocation) => item.toObject());
}
if (this.to_locations != null) {
data.to_locations = this.to_locations.map((item: CardLocation) => item.toObject());
if (this.overlay_locations != null) {
data.overlay_locations = this.overlay_locations.map((item: CardLocation) => item.toObject());
}
return data;
}
......@@ -10842,8 +10842,8 @@ export namespace ygopro {
writer.writeEnum(1, this.zone);
if (this.from_locations.length)
writer.writeRepeatedMessage(2, this.from_locations, (item: CardLocation) => item.serialize(writer));
if (this.to_locations.length)
writer.writeRepeatedMessage(3, this.to_locations, (item: CardLocation) => item.serialize(writer));
if (this.overlay_locations.length)
writer.writeRepeatedMessage(3, this.overlay_locations, (item: CardLocation) => item.serialize(writer));
if (!w)
return writer.getResultBuffer();
}
......@@ -10860,7 +10860,7 @@ export namespace ygopro {
reader.readMessage(message.from_locations, () => pb_1.Message.addToRepeatedWrapperField(message, 2, CardLocation.deserialize(reader), CardLocation));
break;
case 3:
reader.readMessage(message.to_locations, () => pb_1.Message.addToRepeatedWrapperField(message, 3, CardLocation.deserialize(reader), CardLocation));
reader.readMessage(message.overlay_locations, () => pb_1.Message.addToRepeatedWrapperField(message, 3, CardLocation.deserialize(reader), CardLocation));
break;
default: reader.skipField();
}
......
......@@ -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,17 @@ 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,
overlay_locations,
});
};
......@@ -3,29 +3,48 @@ import { eventbus, Task } from "@/infra";
import { cardStore } from "@/stores";
import MsgShuffleSetCard = ygopro.StocGameMessage.MsgShuffleSetCard;
// 后端传过来的`from_locations`的列表是切洗前场上卡的location,它们在列表里面按照切洗后的顺序排列
export default async (shuffleSetCard: MsgShuffleSetCard) => {
const from_locations = shuffleSetCard.from_locations;
const to_locations = shuffleSetCard.to_locations;
if (from_locations.length != to_locations.length) {
const overlay_locations = shuffleSetCard.overlay_locations;
if (from_locations.length == 0) {
console.error("<ShuffleSetCard>from_locations is empty");
return;
}
if (from_locations.length != overlay_locations.length) {
console.error(
"<ShuffleSetCard>length of from_locations and to_locations not matched"
"<ShuffleSetCard>length of from_locations and overlay_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];
// TODO: 需要考虑超量么
const target = cardStore.at(from.zone, from.controller, from.sequence);
if (target) {
// 更新位置
target.location = to;
// 渲染动画
await eventbus.call(Task.Move, target.uuid);
// 设置code为0,洗切后的code会由`UpdateData`指定
target.code = 0;
target.meta.id = 0;
target.meta.text.id = 0;
} else {
console.warn(`<ShuffleSetCard>target from ${from} is null`);
}
// 处理超量
const overlay_location = overlay_locations[i];
if (overlay_location.zone > 0) {
// 如果没有超量素材,后端会全传0
for (const overlay of cardStore.findOverlay(
from.zone,
from.controller,
from.sequence
)) {
// 更新sequence
overlay.location.sequence = overlay_location.sequence;
// 渲染动画
await eventbus.call(Task.Move, overlay.uuid);
// 这里其实有个疑惑,如果超量素材也跟着洗切的话,洗切的意义好像就没有了,感觉算是个k社没想好的设计?
}
}
}
};
import { ygopro } from "@/api";
import { fetchCard, ygopro } from "@/api";
import MsgUpdateData = ygopro.StocGameMessage.MsgUpdateData;
import { eventbus, Task } from "@/infra";
......@@ -15,12 +15,14 @@ export default async (updateData: MsgUpdateData) => {
.filter((card) => card.location.sequence == sequence)
.at(0);
if (target) {
const meta = target.meta;
// 目前只更新以下字段
if (action?.code >= 0) {
meta.id = action.code;
meta.text.id = action.code;
const newMeta = await fetchCard(action.code);
target.code = action.code;
target.meta = newMeta;
}
const meta = target.meta;
if (action.location !== undefined) {
if (target.location.position != action.location.position) {
// Currently only update position
......
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