Commit b8cdf42f authored by Chunchi Che's avatar Chunchi Che

Merge branch 'feat/hp' into 'main'

Feat/hp

See merge request !123
parents f473b3e1 2eb352ac
Pipeline #20541 passed with stages
in 6 minutes and 50 seconds
Subproject commit 308767ca7ca67e28f99a45687a1cc8209e91453d
Subproject commit 43cd7f197670493f58f648e52fb49f918e12803a
This diff is collapsed.
......@@ -42,3 +42,6 @@ export const MSG_SELECT_POSITION = 19;
export const MSG_SELECT_OPTION = 14;
export const MSG_SELECT_BATTLE_CMD = 10;
export const MSG_SELECT_UNSELECT_CARD = 26;
export const MSG_DAMAGE = 91;
export const MSG_RECOVER = 92;
export const MSG_PAY_LP_COST = 100;
import { ygopro } from "../../../idl/ocgcore";
import { BufferReader } from "../../bufferIO";
/*
* Msg Damage
*
* @param player - 玩家编号
* @param value - 减少的Hp数值
* */
export default (data: Uint8Array) => {
const reader = new BufferReader(data, true);
const player = reader.readUint8();
const value = reader.readInt32();
return new ygopro.StocGameMessage.MsgUpdateHp({
player,
type_: ygopro.StocGameMessage.MsgUpdateHp.ActionType.DAMAGE,
value,
});
};
......@@ -20,6 +20,8 @@ import MsgSelectPositionAdapter from "./selectPosition";
import MsgSelectOptionAdapter from "./selectOption";
import MsgSelectBattleCmdAdapter from "./selectBattleCmd";
import MsgSelectUnselectCardAdapter from "./selectUnselectCard";
import MsgDamage from "./damage";
import MsgRecover from "./recover";
import PENETRATE from "./penetrate";
/*
......@@ -117,6 +119,17 @@ export default class GameMsgAdapter implements StocAdapter {
break;
}
case GAME_MSG.MSG_PAY_LP_COST:
case GAME_MSG.MSG_DAMAGE: {
gameMsg.update_hp = MsgDamage(gameData);
break;
}
case GAME_MSG.MSG_RECOVER: {
gameMsg.update_hp = MsgRecover(gameData);
break;
}
default: {
console.log("Unhandled GameMessage function=", func);
......
import { ygopro } from "../../../idl/ocgcore";
import { BufferReader } from "../../bufferIO";
/*
* Msg Recover
*
* @param player - 玩家编号
* @param value - 回复的Hp数值
* */
export default (data: Uint8Array) => {
const reader = new BufferReader(data, true);
const player = reader.readUint8();
const value = reader.readInt32();
return new ygopro.StocGameMessage.MsgUpdateHp({
player,
type_: ygopro.StocGameMessage.MsgUpdateHp.ActionType.RECOVER,
value,
});
};
import { PayloadAction, CaseReducer } from "@reduxjs/toolkit";
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { RootState } from "../../store";
import { DuelState } from "./mod";
import { judgeSelf } from "./util";
import MsgUpdateHp = ygopro.StocGameMessage.MsgUpdateHp;
export interface InitInfo {
masterRule?: string;
......@@ -25,5 +27,32 @@ export const infoInitImpl: CaseReducer<
}
};
export const updateHpImpl: CaseReducer<
DuelState,
PayloadAction<ygopro.StocGameMessage.MsgUpdateHp>
> = (state, action) => {
const player = action.payload.player;
const actionType = action.payload.type_;
const value = action.payload.value;
const info = judgeSelf(player, state) ? state.meInitInfo : state.opInitInfo;
if (info) {
switch (actionType) {
case MsgUpdateHp.ActionType.DAMAGE: {
info.life = info.life - value;
break;
}
case MsgUpdateHp.ActionType.RECOVER: {
info.life = info.life + value;
break;
}
default: {
break;
}
}
}
};
export const selectMeInitInfo = (state: RootState) => state.duel.meInitInfo;
export const selectOpInitInfo = (state: RootState) => state.duel.opInitInfo;
......@@ -4,7 +4,7 @@
* */
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { InitInfo, infoInitImpl } from "./initInfoSlice";
import { InitInfo, infoInitImpl, updateHpImpl } from "./initInfoSlice";
import { TimeLimit, updateTimeLimitImpl } from "./timeLimit";
import {
HandState,
......@@ -170,6 +170,7 @@ const duelSlice = createSlice({
state.selfType = action.payload;
},
infoInit: infoInitImpl,
updateHp: updateHpImpl,
updateTurn: newTurnImpl,
updateTimeLimit: updateTimeLimitImpl,
......@@ -268,6 +269,7 @@ const duelSlice = createSlice({
export const {
setSelfType,
infoInit,
updateHp,
updateTurn,
updatePhase,
setEnableBp,
......
......@@ -18,6 +18,7 @@ import onMsgSelectBattleCmd from "./selectBattleCmd";
import onMsgPosChange from "./posChange";
import onMsgSelectUnselectCard from "./selectUnselectCard";
import onMsgSelectYesNo from "./selectYesNo";
import onMsgUpdateHp from "./updateHp";
export default function handleGameMsg(pb: ygopro.YgoStocMsg) {
const dispatch = store.dispatch;
......@@ -114,6 +115,11 @@ export default function handleGameMsg(pb: ygopro.YgoStocMsg) {
break;
}
case "update_hp": {
onMsgUpdateHp(msg.update_hp, dispatch);
break;
}
default: {
break;
}
......
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { updateHp } from "../../reducers/duel/mod";
import { AppDispatch } from "../../store";
import MsgUpdateHp = ygopro.StocGameMessage.MsgUpdateHp;
export default (msgUpdateHp: MsgUpdateHp, dispatch: AppDispatch) => {
dispatch(updateHp(msgUpdateHp));
};
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