Commit d1dc97f1 authored by Chunchi Che's avatar Chunchi Che

fix updateData

parent 27941bf4
import { ygopro } from "@/api"; import { ygopro } from "@/api";
import MsgUpdateData = ygopro.StocGameMessage.MsgUpdateData; import MsgUpdateData = ygopro.StocGameMessage.MsgUpdateData;
import { matStore } from "@/stores"; import { cardStore } from "@/stores";
export default (updateData: MsgUpdateData) => { export default (updateData: MsgUpdateData) => {
const { player: controller, zone, actions } = updateData; const { player: controller, zone, actions } = updateData;
if (controller !== undefined && zone !== undefined && actions !== undefined) { if (controller !== undefined && zone !== undefined && actions !== undefined) {
const field = matStore.in(zone).of(controller); const field = cardStore.at(zone, controller);
actions.forEach((action) => { actions.forEach((action) => {
const sequence = action.location?.sequence; const sequence = action.location?.sequence;
if (typeof sequence !== "undefined") { if (typeof sequence !== "undefined") {
const target = field[sequence]; const target = field.at(sequence);
if (target && (target.occupant || target.reload)) { if (target) {
if (target.occupant === undefined) { const meta = target.meta;
target.occupant = { id: action.code!, data: {}, text: {} };
}
const occupant = target.occupant;
// 目前只更新以下字段 // 目前只更新以下字段
if (action.code !== undefined && action.code >= 0) { if (action.code !== undefined && action.code >= 0) {
occupant.id = action.code; meta.id = action.code;
occupant.text.id = action.code; meta.text.id = action.code;
} }
if (action.location !== undefined) { if (action.location !== undefined) {
target.location.position = action.location.position; target.position = action.location.position;
} }
if (action.type_ !== undefined && action.type_ >= 0) { if (action.type_ !== undefined && action.type_ >= 0) {
occupant.data.type = action.type_; meta.data.type = action.type_;
} }
if (action.level !== undefined && action.level >= 0) { if (action.level !== undefined && action.level >= 0) {
occupant.data.level = action.level; meta.data.level = action.level;
} }
if (action.attribute !== undefined && action.attribute >= 0) { if (action.attribute !== undefined && action.attribute >= 0) {
occupant.data.attribute = action.attribute; meta.data.attribute = action.attribute;
} }
if (action.race !== undefined && action.race >= 0) { if (action.race !== undefined && action.race >= 0) {
occupant.data.race = action.race; meta.data.race = action.race;
} }
if (action.attack !== undefined && action.attack >= 0) { if (action.attack !== undefined && action.attack >= 0) {
occupant.data.atk = action.attack; meta.data.atk = action.attack;
} }
if (action.defense !== undefined && action.defense >= 0) { if (action.defense !== undefined && action.defense >= 0) {
occupant.data.def = action.defense; meta.data.def = action.defense;
} }
// TODO: counters // TODO: counters
} else {
console.warn(
`<UpdateData>target from zone=${zone}, controller=${controller}, sequence=${sequence} is null`
);
} }
if (target?.reload) { if (target?.reload) {
target.reload = false; target.reload = false;
......
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