Commit 20a0a738 authored by chechunchi's avatar chechunchi

update selectIdleCmd service

parent bb439879
...@@ -54,14 +54,17 @@ export class BufferReader { ...@@ -54,14 +54,17 @@ export class BufferReader {
} }
readCardInfo(): ygopro.CardInfo { readCardInfo(): ygopro.CardInfo {
const cardInfo = new ygopro.CardInfo({}); const code = this.readUint32();
const controler = this.readUint8();
cardInfo.code = this.readUint32(); const location = numberToCardZone(this.readUint8());
cardInfo.controler = this.readUint8(); const sequence = this.readUint8();
cardInfo.location = this.readUint8();
cardInfo.sequence = this.readUint8();
return cardInfo; return new ygopro.CardInfo({
code,
controler,
location,
sequence,
});
} }
readCardLocation(overlay?: boolean): ygopro.CardLocation { readCardLocation(overlay?: boolean): ygopro.CardLocation {
......
import { ygopro } from "../../api/ocgcore/idl/ocgcore"; import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { AppDispatch } from "../../store"; import { AppDispatch } from "../../store";
import { InteractType } from "../../reducers/duel/generic"; import { Interactivity, InteractType } from "../../reducers/duel/generic";
import { import {
clearHandsIdleInteractivity, clearHandsIdleInteractivity,
addHandsIdleInteractivity, addHandsIdleInteractivity,
} from "../../reducers/duel/mod"; } from "../../reducers/duel/mod";
import MsgSelectIdleCmd = ygopro.StocGameMessage.MsgSelectIdleCmd; import MsgSelectIdleCmd = ygopro.StocGameMessage.MsgSelectIdleCmd;
import { ActionCreatorWithPayload } from "@reduxjs/toolkit";
export default (selectIdleCmd: MsgSelectIdleCmd, dispatch: AppDispatch) => { export default (selectIdleCmd: MsgSelectIdleCmd, dispatch: AppDispatch) => {
const player = selectIdleCmd.player; const player = selectIdleCmd.player;
...@@ -14,6 +15,45 @@ export default (selectIdleCmd: MsgSelectIdleCmd, dispatch: AppDispatch) => { ...@@ -14,6 +15,45 @@ export default (selectIdleCmd: MsgSelectIdleCmd, dispatch: AppDispatch) => {
// 先清掉之前的手牌互动性 // 先清掉之前的手牌互动性
dispatch(clearHandsIdleInteractivity(player)); dispatch(clearHandsIdleInteractivity(player));
const dispatcher = (
idleData: MsgSelectIdleCmd.IdleCmd.IdleData,
interactType: InteractType | undefined,
actionCreator: ActionCreatorWithPayload<
{
player: number;
sequence: number;
interactivity: Interactivity<number>;
},
string
>
) => {
const cardInfo = idleData.card_info;
if (interactType === InteractType.ACTIVATE) {
// 发动效果会多一个字段
dispatch(
actionCreator({
player,
sequence: cardInfo.sequence,
interactivity: {
interactType,
activateIndex: idleData.effect_description,
response: idleData.response,
},
})
);
} else if (interactType) {
dispatch(
actionCreator({
player,
sequence: cardInfo.sequence,
interactivity: { interactType, response: idleData.response },
})
);
} else {
console.log(`InteractType undefined`);
}
};
cmds.forEach((cmd) => { cmds.forEach((cmd) => {
const interactType = idleTypeToInteractType(cmd.idle_type); const interactType = idleTypeToInteractType(cmd.idle_type);
...@@ -21,31 +61,11 @@ export default (selectIdleCmd: MsgSelectIdleCmd, dispatch: AppDispatch) => { ...@@ -21,31 +61,11 @@ export default (selectIdleCmd: MsgSelectIdleCmd, dispatch: AppDispatch) => {
const cardInfo = data.card_info; const cardInfo = data.card_info;
switch (cardInfo.location) { switch (cardInfo.location) {
case ygopro.CardZone.HAND: { case ygopro.CardZone.HAND: {
if (interactType === InteractType.ACTIVATE) { dispatcher(data, interactType, addHandsIdleInteractivity);
// 发动效果会多一个字段
dispatch(
addHandsIdleInteractivity({
player,
sequence: cardInfo.sequence,
interactivity: {
interactType,
activateIndex: data.effect_description,
response: data.response,
},
})
);
} else if (interactType) {
dispatch(
addHandsIdleInteractivity({
player,
sequence: cardInfo.sequence,
interactivity: { interactType, response: data.response },
})
);
}
break; break;
} }
default: { default: {
} }
} }
......
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