Commit 7307fd14 authored by chechunchi's avatar chechunchi

add select battle cmd adapter and service

parent 084d4c3b
Pipeline #19616 passed with stages
in 7 minutes and 3 seconds
......@@ -39,3 +39,4 @@ export const MSG_SELECT_CHAIN = 16;
export const MSG_SELECT_EFFECTYN = 12;
export const MSG_SELECT_POSITION = 19;
export const MSG_SELECT_OPTION = 14;
export const MSG_SELECT_BATTLE_CMD = 10;
......@@ -18,6 +18,7 @@ import MsgSelectChainAdapter from "./selectChain";
import MsgSelectEffectYnAdapter from "./selectEffectYn";
import MsgSelectPositionAdapter from "./selectPosition";
import MsgSelectOptionAdapter from "./selectOption";
import MsgSelectBattleCmdAdapter from "./selectBattleCmd";
import PENETRATE from "./penetrate";
/*
......@@ -105,6 +106,11 @@ export default class GameMsgAdapter implements StocAdapter {
break;
}
case GAME_MSG.MSG_SELECT_BATTLE_CMD: {
gameMsg.select_battle_cmd = MsgSelectBattleCmdAdapter(gameData);
break;
}
default: {
console.log("Unhandled GameMessage function=", func);
......
import { ygopro } from "../../../idl/ocgcore";
import { BufferReader } from "../../bufferIO";
import MsgSelectBattleCmd = ygopro.StocGameMessage.MsgSelectBattleCmd;
/*
* Msg Select Battle Command
*
* @param - see: https://code.mycard.moe/mycard/neos-protobuf/-/blob/main/idl/ocgcore.proto
*
* @usage - 玩家在战斗阶段可选择的操作
* */
export default (data: Uint8Array) => {
const reader = new BufferReader(data, true);
const msg = new MsgSelectBattleCmd({});
msg.player = reader.readUint8();
// 可发动效果
const activateCmd = new MsgSelectBattleCmd.BattleCmd({
battle_type: MsgSelectBattleCmd.BattleCmd.BattleType.ACTIVATE,
battle_datas: [],
});
const activateCount = reader.readUint8();
for (let i = 0; i < activateCount; i++) {
const cardInfo = reader.readCardInfo();
const effectDescription = reader.readUint32();
const activateData = new MsgSelectBattleCmd.BattleCmd.BattleData({
card_info: cardInfo,
effect_description: effectDescription,
response: i << (16 + 0),
});
activateCmd.battle_datas.push(activateData);
}
// 可攻击
const attackCmd = new MsgSelectBattleCmd.BattleCmd({
battle_type: MsgSelectBattleCmd.BattleCmd.BattleType.ATTACK,
battle_datas: [],
});
const attackCount = reader.readUint8();
for (let i = 0; i < attackCount; i++) {
const cardInfo = reader.readCardInfo();
const directAttackAble = reader.readUint8();
const attackData = new MsgSelectBattleCmd.BattleCmd.BattleData({
card_info: cardInfo,
direct_attackable: directAttackAble == 1,
response: i << (16 + 1),
});
attackCmd.battle_datas.push(attackData);
}
msg.battle_cmds = [activateCmd, attackCmd];
// 是否可进入M2阶段
msg.enable_m2 = reader.readUint8() == 1;
//时是否可结束回合
msg.enable_ep = reader.readUint8() == 1;
return msg;
};
......@@ -14,6 +14,7 @@ import onMsgSelectEffectYn from "./selectEffectYn";
import onMsgSelectPosition from "./selectPosition";
import onMsgSelectOption from "./selectOption";
import onMsgShuffleHand from "./shuffleHand";
import onMsgSelectBattleCmd from "./selectBattleCmd";
export default function handleGameMsg(pb: ygopro.YgoStocMsg) {
const dispatch = store.dispatch;
......@@ -21,86 +22,77 @@ export default function handleGameMsg(pb: ygopro.YgoStocMsg) {
switch (msg.gameMsg) {
case "start": {
const start = msg.start;
onMsgStart(start, dispatch);
onMsgStart(msg.start, dispatch);
break;
}
case "draw": {
const draw = msg.draw;
onMsgDraw(draw, dispatch);
onMsgDraw(msg.draw, dispatch);
break;
}
case "new_turn": {
const newTurn = msg.new_turn;
onMsgNewTurn(newTurn, dispatch);
onMsgNewTurn(msg.new_turn, dispatch);
break;
}
case "new_phase": {
const newPhase = msg.new_phase;
onMsgNewPhase(newPhase, dispatch);
onMsgNewPhase(msg.new_phase, dispatch);
break;
}
case "hint": {
const hint = msg.hint;
onMsgHint(hint, dispatch);
onMsgHint(msg.hint, dispatch);
break;
}
case "select_idle_cmd": {
const selectIdleCmd = msg.select_idle_cmd;
onMsgSelectIdleCmd(selectIdleCmd, dispatch);
onMsgSelectIdleCmd(msg.select_idle_cmd, dispatch);
break;
}
case "select_place": {
const selectPlace = msg.select_place;
onMsgSelectPlace(selectPlace, dispatch);
onMsgSelectPlace(msg.select_place, dispatch);
break;
}
case "move": {
const move = msg.move;
onMsgMove(move, dispatch);
onMsgMove(msg.move, dispatch);
break;
}
case "select_card": {
const selectCard = msg.select_card;
onMsgSelectCard(selectCard, dispatch);
onMsgSelectCard(msg.select_card, dispatch);
break;
}
case "select_chain": {
const selectChain = msg.select_chain;
onMsgSelectChain(selectChain, dispatch);
onMsgSelectChain(msg.select_chain, dispatch);
break;
}
case "select_effect_yn": {
const selectEffectYn = msg.select_effect_yn;
onMsgSelectEffectYn(selectEffectYn, dispatch);
onMsgSelectEffectYn(msg.select_effect_yn, dispatch);
break;
}
case "select_position": {
const selectPosition = msg.select_position;
onMsgSelectPosition(selectPosition, dispatch);
onMsgSelectPosition(msg.select_position, dispatch);
break;
}
case "select_option": {
const selectOption = msg.select_option;
onMsgSelectOption(selectOption, dispatch);
onMsgSelectOption(msg.select_option, dispatch);
break;
}
case "shuffle_hand": {
const shuffleHand = msg.shuffle_hand;
onMsgShuffleHand(shuffleHand, dispatch);
onMsgShuffleHand(msg.shuffle_hand, dispatch);
break;
}
case "select_battle_cmd": {
onMsgSelectBattleCmd(msg.select_battle_cmd, dispatch);
break;
}
......
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { AppDispatch } from "../../store";
import MsgSelectBattleCmd = ygopro.StocGameMessage.MsgSelectBattleCmd;
export default (selectBattleCmd: MsgSelectBattleCmd, dispatch: AppDispatch) => {
console.log(selectBattleCmd);
};
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