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 mycard/Neos!231
parents d5270a03 3fac2e51
neos-protobuf @ 2caaa3aa
Subproject commit cd10e6a5f76cfda5ada5a39a9a7a526ca9c5e881 Subproject commit 2caaa3aa310f699ebf5b52a08413d0a555ac4065
...@@ -10766,7 +10766,7 @@ export namespace ygopro { ...@@ -10766,7 +10766,7 @@ export namespace ygopro {
constructor(data?: any[] | { constructor(data?: any[] | {
zone?: CardZone; zone?: CardZone;
from_locations?: CardLocation[]; from_locations?: CardLocation[];
to_locations?: CardLocation[]; overlay_locations?: CardLocation[];
}) { }) {
super(); super();
pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [2, 3], this.#one_of_decls); pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [2, 3], this.#one_of_decls);
...@@ -10777,8 +10777,8 @@ export namespace ygopro { ...@@ -10777,8 +10777,8 @@ export namespace ygopro {
if ("from_locations" in data && data.from_locations != undefined) { if ("from_locations" in data && data.from_locations != undefined) {
this.from_locations = data.from_locations; this.from_locations = data.from_locations;
} }
if ("to_locations" in data && data.to_locations != undefined) { if ("overlay_locations" in data && data.overlay_locations != undefined) {
this.to_locations = data.to_locations; this.overlay_locations = data.overlay_locations;
} }
} }
} }
...@@ -10794,16 +10794,16 @@ export namespace ygopro { ...@@ -10794,16 +10794,16 @@ export namespace ygopro {
set from_locations(value: CardLocation[]) { set from_locations(value: CardLocation[]) {
pb_1.Message.setRepeatedWrapperField(this, 2, value); pb_1.Message.setRepeatedWrapperField(this, 2, value);
} }
get to_locations() { get overlay_locations() {
return pb_1.Message.getRepeatedWrapperField(this, CardLocation, 3) as CardLocation[]; 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); pb_1.Message.setRepeatedWrapperField(this, 3, value);
} }
static fromObject(data: { static fromObject(data: {
zone?: CardZone; zone?: CardZone;
from_locations?: ReturnType<typeof CardLocation.prototype.toObject>[]; from_locations?: ReturnType<typeof CardLocation.prototype.toObject>[];
to_locations?: ReturnType<typeof CardLocation.prototype.toObject>[]; overlay_locations?: ReturnType<typeof CardLocation.prototype.toObject>[];
}): MsgShuffleSetCard { }): MsgShuffleSetCard {
const message = new MsgShuffleSetCard({}); const message = new MsgShuffleSetCard({});
if (data.zone != null) { if (data.zone != null) {
...@@ -10812,8 +10812,8 @@ export namespace ygopro { ...@@ -10812,8 +10812,8 @@ export namespace ygopro {
if (data.from_locations != null) { if (data.from_locations != null) {
message.from_locations = data.from_locations.map(item => CardLocation.fromObject(item)); message.from_locations = data.from_locations.map(item => CardLocation.fromObject(item));
} }
if (data.to_locations != null) { if (data.overlay_locations != null) {
message.to_locations = data.to_locations.map(item => CardLocation.fromObject(item)); message.overlay_locations = data.overlay_locations.map(item => CardLocation.fromObject(item));
} }
return message; return message;
} }
...@@ -10821,7 +10821,7 @@ export namespace ygopro { ...@@ -10821,7 +10821,7 @@ export namespace ygopro {
const data: { const data: {
zone?: CardZone; zone?: CardZone;
from_locations?: ReturnType<typeof CardLocation.prototype.toObject>[]; 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) { if (this.zone != null) {
data.zone = this.zone; data.zone = this.zone;
...@@ -10829,8 +10829,8 @@ export namespace ygopro { ...@@ -10829,8 +10829,8 @@ export namespace ygopro {
if (this.from_locations != null) { if (this.from_locations != null) {
data.from_locations = this.from_locations.map((item: CardLocation) => item.toObject()); data.from_locations = this.from_locations.map((item: CardLocation) => item.toObject());
} }
if (this.to_locations != null) { if (this.overlay_locations != null) {
data.to_locations = this.to_locations.map((item: CardLocation) => item.toObject()); data.overlay_locations = this.overlay_locations.map((item: CardLocation) => item.toObject());
} }
return data; return data;
} }
...@@ -10842,8 +10842,8 @@ export namespace ygopro { ...@@ -10842,8 +10842,8 @@ export namespace ygopro {
writer.writeEnum(1, this.zone); writer.writeEnum(1, this.zone);
if (this.from_locations.length) if (this.from_locations.length)
writer.writeRepeatedMessage(2, this.from_locations, (item: CardLocation) => item.serialize(writer)); writer.writeRepeatedMessage(2, this.from_locations, (item: CardLocation) => item.serialize(writer));
if (this.to_locations.length) if (this.overlay_locations.length)
writer.writeRepeatedMessage(3, this.to_locations, (item: CardLocation) => item.serialize(writer)); writer.writeRepeatedMessage(3, this.overlay_locations, (item: CardLocation) => item.serialize(writer));
if (!w) if (!w)
return writer.getResultBuffer(); return writer.getResultBuffer();
} }
...@@ -10860,7 +10860,7 @@ export namespace ygopro { ...@@ -10860,7 +10860,7 @@ export namespace ygopro {
reader.readMessage(message.from_locations, () => pb_1.Message.addToRepeatedWrapperField(message, 2, CardLocation.deserialize(reader), CardLocation)); reader.readMessage(message.from_locations, () => pb_1.Message.addToRepeatedWrapperField(message, 2, CardLocation.deserialize(reader), CardLocation));
break; break;
case 3: 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; break;
default: reader.skipField(); default: reader.skipField();
} }
......
...@@ -33,7 +33,7 @@ import MsgSelectPositionAdapter from "./selectPosition"; ...@@ -33,7 +33,7 @@ import MsgSelectPositionAdapter from "./selectPosition";
import MsgSelectSum from "./selectSum"; import MsgSelectSum from "./selectSum";
import MsgSelectTributeAdapter from "./selectTribute"; import MsgSelectTributeAdapter from "./selectTribute";
import MsgSelectUnselectCardAdapter from "./selectUnselectCard"; import MsgSelectUnselectCardAdapter from "./selectUnselectCard";
import MsgShuffleSetCard from "./shuffle_set_card"; import MsgShuffleSetCard from "./shuffleSetCard";
import MsgSortCard from "./sortCard"; import MsgSortCard from "./sortCard";
import MsgStartAdapter from "./start"; import MsgStartAdapter from "./start";
import MsgTossAdapter from "./toss"; import MsgTossAdapter from "./toss";
......
...@@ -16,17 +16,17 @@ export default (data: Uint8Array) => { ...@@ -16,17 +16,17 @@ export default (data: Uint8Array) => {
const zone = numberToCardZone(reader.inner.readUint8()); const zone = numberToCardZone(reader.inner.readUint8());
const count = reader.inner.readUint8(); const count = reader.inner.readUint8();
const from_locations = []; const from_locations = [];
const to_locations = []; const overlay_locations = []; // TODO: 这个字段是否有用?
for (let i = 0; i < count; i++) { for (let i = 0; i < count; i++) {
from_locations.push(reader.readCardLocation()); from_locations.push(reader.readCardLocation());
} }
for (let i = 0; i < count; i++) { for (let i = 0; i < count; i++) {
to_locations.push(reader.readCardLocation()); overlay_locations.push(reader.readCardLocation());
} }
return new MsgShuffleSetCard({ return new MsgShuffleSetCard({
zone, zone,
from_locations, from_locations,
to_locations, overlay_locations,
}); });
}; };
...@@ -3,29 +3,48 @@ import { eventbus, Task } from "@/infra"; ...@@ -3,29 +3,48 @@ import { eventbus, Task } from "@/infra";
import { cardStore } from "@/stores"; import { cardStore } from "@/stores";
import MsgShuffleSetCard = ygopro.StocGameMessage.MsgShuffleSetCard; import MsgShuffleSetCard = ygopro.StocGameMessage.MsgShuffleSetCard;
// 后端传过来的`from_locations`的列表是切洗前场上卡的location,它们在列表里面按照切洗后的顺序排列
export default async (shuffleSetCard: MsgShuffleSetCard) => { export default async (shuffleSetCard: MsgShuffleSetCard) => {
const from_locations = shuffleSetCard.from_locations; const from_locations = shuffleSetCard.from_locations;
const to_locations = shuffleSetCard.to_locations; const overlay_locations = shuffleSetCard.overlay_locations;
if (from_locations.length != to_locations.length) { if (from_locations.length == 0) {
console.error("<ShuffleSetCard>from_locations is empty");
return;
}
if (from_locations.length != overlay_locations.length) {
console.error( 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; const count = from_locations.length;
for (let i = 0; i < count; i++) { for (let i = 0; i < count; i++) {
const from = from_locations[i]; const from = from_locations[i];
const to = to_locations[i];
// TODO: 需要考虑超量么
const target = cardStore.at(from.zone, from.controller, from.sequence); const target = cardStore.at(from.zone, from.controller, from.sequence);
if (target) { if (target) {
// 更新位置 // 设置code为0,洗切后的code会由`UpdateData`指定
target.location = to; target.code = 0;
// 渲染动画 target.meta.id = 0;
await eventbus.call(Task.Move, target.uuid); target.meta.text.id = 0;
} else { } else {
console.warn(`<ShuffleSetCard>target from ${from} is null`); 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 MsgUpdateData = ygopro.StocGameMessage.MsgUpdateData;
import { eventbus, Task } from "@/infra"; import { eventbus, Task } from "@/infra";
...@@ -15,12 +15,14 @@ export default async (updateData: MsgUpdateData) => { ...@@ -15,12 +15,14 @@ export default async (updateData: MsgUpdateData) => {
.filter((card) => card.location.sequence == sequence) .filter((card) => card.location.sequence == sequence)
.at(0); .at(0);
if (target) { if (target) {
const meta = target.meta;
// 目前只更新以下字段 // 目前只更新以下字段
if (action?.code >= 0) { if (action?.code >= 0) {
meta.id = action.code; const newMeta = await fetchCard(action.code);
meta.text.id = action.code; target.code = action.code;
target.meta = newMeta;
} }
const meta = target.meta;
if (action.location !== undefined) { if (action.location !== undefined) {
if (target.location.position != action.location.position) { if (target.location.position != action.location.position) {
// Currently only update 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