Commit 20a0a738 authored by chechunchi's avatar chechunchi

update selectIdleCmd service

parent bb439879
Pipeline #19548 passed with stages
in 5 minutes and 25 seconds
......@@ -54,14 +54,17 @@ export class BufferReader {
}
readCardInfo(): ygopro.CardInfo {
const cardInfo = new ygopro.CardInfo({});
cardInfo.code = this.readUint32();
cardInfo.controler = this.readUint8();
cardInfo.location = this.readUint8();
cardInfo.sequence = this.readUint8();
const code = this.readUint32();
const controler = this.readUint8();
const location = numberToCardZone(this.readUint8());
const sequence = this.readUint8();
return cardInfo;
return new ygopro.CardInfo({
code,
controler,
location,
sequence,
});
}
readCardLocation(overlay?: boolean): ygopro.CardLocation {
......
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { AppDispatch } from "../../store";
import { InteractType } from "../../reducers/duel/generic";
import { Interactivity, InteractType } from "../../reducers/duel/generic";
import {
clearHandsIdleInteractivity,
addHandsIdleInteractivity,
} from "../../reducers/duel/mod";
import MsgSelectIdleCmd = ygopro.StocGameMessage.MsgSelectIdleCmd;
import { ActionCreatorWithPayload } from "@reduxjs/toolkit";
export default (selectIdleCmd: MsgSelectIdleCmd, dispatch: AppDispatch) => {
const player = selectIdleCmd.player;
......@@ -14,6 +15,45 @@ export default (selectIdleCmd: MsgSelectIdleCmd, dispatch: AppDispatch) => {
// 先清掉之前的手牌互动性
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) => {
const interactType = idleTypeToInteractType(cmd.idle_type);
......@@ -21,31 +61,11 @@ export default (selectIdleCmd: MsgSelectIdleCmd, dispatch: AppDispatch) => {
const cardInfo = data.card_info;
switch (cardInfo.location) {
case ygopro.CardZone.HAND: {
if (interactType === InteractType.ACTIVATE) {
// 发动效果会多一个字段
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 },
})
);
}
dispatcher(data, interactType, addHandsIdleInteractivity);
break;
}
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