Commit e9163718 authored by Chunchi Che's avatar Chunchi Che

handle updateData

parent f0516423
Pipeline #20798 passed with stages
in 13 minutes and 56 seconds
......@@ -49,3 +49,4 @@ export const MSG_RECOVER = 92;
export const MSG_PAY_LP_COST = 100;
export const MSG_WIN = 5;
export const MSG_WAITING = 3;
export const MSG_UPDATE_DATA = 6;
......@@ -25,6 +25,7 @@ import MsgWaitAdapter from "./wait";
import MsgDamage from "./damage";
import MsgRecover from "./recover";
import MsgWin from "./win";
import MsgUpdateDataAdapter from "./updateData";
import PENETRATE from "./penetrate";
/*
......@@ -148,6 +149,11 @@ export default class GameMsgAdapter implements StocAdapter {
break;
}
case GAME_MSG.MSG_UPDATE_DATA: {
gameMsg.update_data = MsgUpdateDataAdapter(gameData);
break;
}
default: {
gameMsg.unimplemented = new ygopro.StocGameMessage.MsgUnimplemented({
command: func,
......
import {
QUERY_ALIAS,
QUERY_ATTACK,
QUERY_ATTRIBUTE,
QUERY_BASE_ATTACK,
QUERY_BASE_DEFENSE,
QUERY_CODE,
QUERY_COUNTERS,
QUERY_DEFENSE,
QUERY_EQUIP_CARD,
QUERY_LEVEL,
QUERY_LINK,
QUERY_LSCALE,
QUERY_OVERLAY_CARD,
QUERY_OWNER,
QUERY_POSITION,
QUERY_RACE,
QUERY_RANK,
QUERY_REASON,
QUERY_REASON_CARD,
QUERY_RSCALE,
QUERY_STATUS,
QUERY_TARGET_CARD,
QUERY_TYPE,
} from "../../../../../common";
import { ygopro } from "../../../idl/ocgcore";
import { BufferReaderExt } from "../../bufferIO";
import { numberToCardZone } from "../../util";
import MsgUpdateData = ygopro.StocGameMessage.MsgUpdateData;
/*
* Msg UpdateData
*
* @param - todo
*
* @usage - ygopro后端通知前端更新卡片元数据
* */
export default (data: Uint8Array) => {
const reader = new BufferReaderExt(data);
const player = reader.inner.readUint8();
const zone = numberToCardZone(reader.inner.readUint8());
const msg = new MsgUpdateData({
player,
zone,
actions: [],
});
try {
while (true) {
const len = reader.inner.readInt32();
if (len == 4) continue;
const pos = reader.inner.offset();
const action = _readUpdateAction(reader);
if (action) {
msg.actions.push(action);
}
reader.inner.setOffset(pos + len - 4);
}
} catch (e) {
// console.log(e)
}
};
function _readUpdateAction(
reader: BufferReaderExt
): MsgUpdateData.Action | undefined {
const flag = reader.inner.readInt32();
if (flag == 0) return undefined;
let code;
let location;
let alias;
let type_;
let level;
let rank;
let attribute;
let race;
let attack;
let defense;
let base_attack;
let base_defense;
let reason;
let reason_card;
let equip_card;
let target_cards = [];
let overlay_cards = [];
let counters = new Map<number, number>();
let owner;
let status;
let lscale;
let rscale;
let link;
if (flag & QUERY_CODE) {
code = reader.inner.readInt32();
}
if (flag & QUERY_POSITION) {
location = reader.readCardLocation();
}
if (flag & QUERY_ALIAS) {
alias = reader.inner.readInt32();
}
if (flag & QUERY_TYPE) {
type_ = reader.inner.readInt32();
}
if (flag & QUERY_LEVEL) {
level = reader.inner.readInt32();
}
if (flag & QUERY_RANK) {
rank = reader.inner.readInt32();
}
if (flag & QUERY_ATTRIBUTE) {
attribute = reader.inner.readInt32();
}
if (flag & QUERY_RACE) {
race = reader.inner.readInt32();
}
if (flag & QUERY_ATTACK) {
attack = reader.inner.readInt32();
}
if (flag & QUERY_DEFENSE) {
defense = reader.inner.readInt32();
}
if (flag & QUERY_BASE_ATTACK) {
base_attack = reader.inner.readInt32();
}
if (flag & QUERY_BASE_DEFENSE) {
base_defense = reader.inner.readInt32();
}
if (flag & QUERY_REASON) {
reason = reader.inner.readInt32();
}
if (flag & QUERY_REASON_CARD) {
reason_card = reader.inner.readInt32();
}
if (flag & QUERY_EQUIP_CARD) {
equip_card = reader.readCardLocation();
}
if (flag & QUERY_TARGET_CARD) {
const count = reader.inner.readInt32();
for (let i = 0; i < count; i += 1) {
target_cards.push(reader.readCardLocation());
}
}
if (flag & QUERY_OVERLAY_CARD) {
const count = reader.inner.readInt32();
for (let i = 0; i < count; i += 1) {
overlay_cards.push(reader.inner.readInt32());
}
}
if (flag & QUERY_COUNTERS) {
const count = reader.inner.readInt32();
for (let i = 0; i < count; i += 1) {
const ctype = reader.inner.readUint16();
const ccount = reader.inner.readUint16();
counters.set(ctype, ccount);
}
}
if (flag & QUERY_OWNER) {
owner = reader.inner.readInt32();
}
if (flag & QUERY_STATUS) {
status = reader.inner.readInt32();
}
if (flag & QUERY_LSCALE) {
lscale = reader.inner.readInt32();
}
if (flag & QUERY_RSCALE) {
rscale = reader.inner.readInt32();
}
if (flag & QUERY_LINK) {
link = reader.inner.readInt32();
}
return new MsgUpdateData.Action({
code,
location,
alias,
type_,
level,
rank,
attribute,
race,
attack,
defense,
base_attack,
base_defense,
reason,
reason_card,
equip_card,
target_cards,
overlay_cards,
counters,
owner,
status,
lscale,
rscale,
link,
});
}
......@@ -196,3 +196,27 @@ export const REASON_MATERIAL = 0x8; //
// const REASON_REVEAL = 0x8000000; //
// const REASON_LINK = 0x10000000; //
// const REASON_LOST_OVERLAY = 0x20000000; //
export const QUERY_CODE = 0x1;
export const QUERY_POSITION = 0x2;
export const QUERY_ALIAS = 0x4;
export const QUERY_TYPE = 0x8;
export const QUERY_LEVEL = 0x10;
export const QUERY_RANK = 0x20;
export const QUERY_ATTRIBUTE = 0x40;
export const QUERY_RACE = 0x80;
export const QUERY_ATTACK = 0x100;
export const QUERY_DEFENSE = 0x200;
export const QUERY_BASE_ATTACK = 0x400;
export const QUERY_BASE_DEFENSE = 0x800;
export const QUERY_REASON = 0x1000;
export const QUERY_REASON_CARD = 0x2000;
export const QUERY_EQUIP_CARD = 0x4000;
export const QUERY_TARGET_CARD = 0x8000;
export const QUERY_OVERLAY_CARD = 0x10000;
export const QUERY_COUNTERS = 0x20000;
export const QUERY_OWNER = 0x40000;
export const QUERY_STATUS = 0x80000;
export const QUERY_LSCALE = 0x200000;
export const QUERY_RSCALE = 0x400000;
export const QUERY_LINK = 0x800000;
......@@ -22,6 +22,7 @@ import onMsgUpdateHp from "./updateHp";
import onMsgWin from "./win";
import onMsgWait from "./wait";
import onUnimplemented from "./unimplemented";
import onMsgUpdateData from "./updateData";
import { setWaiting } from "../../reducers/duel/mod";
const ActiveList = [
......@@ -151,6 +152,11 @@ export default function handleGameMsg(pb: ygopro.YgoStocMsg) {
break;
}
case "update_data": {
onMsgUpdateData(msg.update_data, dispatch);
break;
}
case "unimplemented": {
onUnimplemented(msg.unimplemented, dispatch);
......
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { AppDispatch } from "../../store";
import MsgUpdateData = ygopro.StocGameMessage.MsgUpdateData;
export default (updateData: MsgUpdateData, dispatch: AppDispatch) => {
console.log(updateData);
};
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