Commit 75fdc88a authored by timel's avatar timel

fix: types

parent fcc09e9f
......@@ -36,29 +36,31 @@ export default (move: MsgMove, dispatch: AppDispatch) => {
const to = move.to;
const reason = move.reason;
// TODO: 如果后面做动画的话,要考虑DECK的情况。
// 现在不会对DECK做判断
switch (from.location) {
case ygopro.CardZone.MZONE:
case ygopro.CardZone.SZONE: {
// 魔陷和怪兽需要清掉占用、清掉超量素材
const target = matStore.getZone(from.location).at(from.controler)[
const target = matStore.in(from.location).of(from.controler)[
from.sequence
];
target.occupant = undefined;
target.overlay_materials = [];
break;
}
case ygopro.CardZone.HAND:
case ygopro.CardZone.REMOVED:
case ygopro.CardZone.GRAVE:
case ygopro.CardZone.HAND:
case ygopro.CardZone.EXTRA: {
// 其余区域就是在list删掉这张卡
matStore.getZone(from.location).remove(from.controler, from.sequence);
matStore.in(from.location).remove(from.controler, from.sequence);
break;
}
// 仅仅去除超量素材
case ygopro.CardZone.OVERLAY: {
const target = matStore.monsters.at(from.controler)[from.sequence];
const target = matStore.monsters.of(from.controler)[from.sequence];
if (target && target.overlay_materials) {
target.overlay_materials.splice(from.overlay_sequence, 1);
}
......@@ -81,23 +83,28 @@ export default (move: MsgMove, dispatch: AppDispatch) => {
FIXME_fetchOverlayMeta(to.controler, to.sequence, sorted);
// 设置Occupant,和魔陷区/其他区共用一个逻辑,特地不写break
}
case ygopro.CardZone.SZONE:
case ygopro.CardZone.DECK:
case ygopro.CardZone.REMOVED:
case ygopro.CardZone.GRAVE:
case ygopro.CardZone.HAND:
case ygopro.CardZone.EXTRA: {
case ygopro.CardZone.SZONE: {
matStore
.getZone(to.location)
.in(to.location)
.setOccupant(to.controler, to.sequence, code, to.position);
break;
// FIXME 这里逻辑不对...
}
case ygopro.CardZone.REMOVED:
case ygopro.CardZone.GRAVE:
case ygopro.CardZone.EXTRA:
case ygopro.CardZone.HAND: {
matStore.hands.insert(to.controler, to.sequence, code);
break;
}
case ygopro.CardZone.OVERLAY: {
if (reason == REASON_MATERIAL) {
// 超量素材在进行超量召唤时,若玩家未选择超量怪兽的位置,会“沉到决斗盘下面”,`reason`字段值是`REASON_MATERIAL`
// 这时候将它们放到一个栈中,待超量怪兽的Move消息到来时从栈中获取超量素材补充到状态中
OVERLAY_STACK.push({ code, sequence: to.overlay_sequence });
} else {
// 其他情况下,比如“宵星的机神 丁吉尔苏”的“补充超量素材”效果,直接更新状态中
FIXME_fetchOverlayMeta(to.controler, to.sequence, [code], true);
}
break;
}
default: {
......
......@@ -3,43 +3,47 @@ import { fetchEsHintMeta } from "@/reducers/duel/hintSlice";
import { setMagicPosition, setMonsterPosition } from "@/reducers/duel/mod";
import { AppDispatch } from "@/store";
import MsgPosChange = ygopro.StocGameMessage.MsgPosChange;
import { matStore } from "@/valtioStores";
import {
matStore,
fetchEsHintMeta as FIXME_fetchEsHintMeta,
} from "@/valtioStores";
export default (posChange: MsgPosChange, dispatch: AppDispatch) => {
const cardInfo = posChange.card_info;
const { location, controler, sequence } = posChange.card_info;
switch (cardInfo.location) {
switch (location) {
case ygopro.CardZone.MZONE: {
dispatch(
setMonsterPosition({
controler: cardInfo.controler,
sequence: cardInfo.sequence,
controler: controler,
sequence,
position: posChange.cur_position,
})
);
matStore.monsters.at(cardInfo.controler)[
cardInfo.sequence
].location.position = posChange.cur_position;
matStore.monsters.of(controler)[sequence].location.position =
posChange.cur_position;
break;
}
case ygopro.CardZone.SZONE: {
dispatch(
setMagicPosition({
controler: cardInfo.controler,
sequence: cardInfo.sequence,
controler: controler,
sequence,
position: posChange.cur_position,
})
);
matStore.magics.at(cardInfo.controler)[
cardInfo.sequence
].location.position = posChange.cur_position;
matStore.magics.of(controler)[sequence].location.position =
posChange.cur_position;
break;
}
default: {
console.log(`Unhandled zone ${cardInfo.location}`);
console.log(`Unhandled zone ${location}`);
}
}
dispatch(fetchEsHintMeta({ originMsg: 1600 }));
FIXME_fetchEsHintMeta({
originMsg: 1600,
});
};
......@@ -55,9 +55,9 @@ function reloadDuelField(
reload: true,
};
});
matStore.getZone(cardZone).at(controller).length = 0;
matStore.in(cardZone).of(controller).length = 0;
matStore
.getZone(cardZone)
.at(controller)
.in(cardZone)
.of(controller)
.push(...cards);
}
......@@ -87,7 +87,7 @@ export default (selectBattleCmd: MsgSelectBattleCmd, dispatch: AppDispatch) => {
const tmp = map[interactType];
if (tmp) {
matStore
.getZone(cardInfo.location)
.in(cardInfo.location)
.addIdleInteractivity(player, cardInfo.sequence, {
...tmp,
interactType,
......
......@@ -84,7 +84,7 @@ export default (selectIdleCmd: MsgSelectIdleCmd, dispatch: AppDispatch) => {
const tmp = map[interactType];
if (tmp) {
matStore
.getZone(cardInfo.location)
.in(cardInfo.location)
.addIdleInteractivity(player, cardInfo.sequence, {
...tmp,
interactType,
......
......@@ -24,6 +24,6 @@ export default (shuffleHand: MsgShuffleHand, dispatch: AppDispatch) => {
};
});
matStore.hands.at(controller).length = 0;
matStore.hands.at(controller).push(...metas);
matStore.hands.of(controller).length = 0;
matStore.hands.of(controller).push(...metas);
};
......@@ -71,10 +71,10 @@ export default (
// <<< 删除 <<<
// 上面的删除就可以了
matStore.monsters.at(0).forEach((x) => (x.location.controler = 0));
matStore.monsters.at(1).forEach((x) => (x.location.controler = 1));
matStore.magics.at(0).forEach((x) => (x.location.controler = 0));
matStore.magics.at(1).forEach((x) => (x.location.controler = 1));
matStore.monsters.of(0).forEach((x) => (x.location.controler = 0));
matStore.monsters.of(1).forEach((x) => (x.location.controler = 1));
matStore.magics.of(0).forEach((x) => (x.location.controler = 0));
matStore.magics.of(1).forEach((x) => (x.location.controler = 1));
matStore.decks.add(0, Array(start.deckSize1).fill(0));
matStore.decks.add(1, Array(start.deckSize2).fill(0));
......
......@@ -10,7 +10,7 @@ export default (updateData: MsgUpdateData, dispatch: AppDispatch) => {
const { player: controller, zone, actions } = updateData;
if (controller !== undefined && zone !== undefined && actions !== undefined) {
const field = matStore.getZone(zone).at(controller);
const field = matStore.in(zone).of(controller);
actions.forEach((action) => {
const sequence = action.location?.sequence;
if (typeof sequence !== "undefined") {
......
......@@ -12,11 +12,11 @@ export default (msgUpdateHp: MsgUpdateHp, dispatch: AppDispatch) => {
if (msgUpdateHp.type_ == MsgUpdateHp.ActionType.DAMAGE) {
dispatch(fetchEsHintMeta({ originMsg: "玩家收到伤害时" })); // TODO: i18n
FIXME_fetchEsHintMeta({ originMsg: "玩家收到伤害时" });
matStore.initInfo.at(msgUpdateHp.player).life -= msgUpdateHp.value;
matStore.initInfo.of(msgUpdateHp.player).life -= msgUpdateHp.value;
} else if (msgUpdateHp.type_ == MsgUpdateHp.ActionType.RECOVER) {
dispatch(fetchEsHintMeta({ originMsg: "玩家生命值回复时" })); // TODO: i18n
FIXME_fetchEsHintMeta({ originMsg: "玩家生命值回复时" });
matStore.initInfo.at(msgUpdateHp.player).life += msgUpdateHp.value;
matStore.initInfo.of(msgUpdateHp.player).life += msgUpdateHp.value;
}
dispatch(updateHp(msgUpdateHp)); // 可以删除了
......
import { ygopro, fetchCard } from "@/api";
import { matStore, getCardByLocation } from "@/valtioStores";
export const fetchCardMeta = async (
zone: ygopro.CardZone,
controler: number,
sequence: number,
code: number,
position?: ygopro.CardPosition
) => {
await matStore.getZone(zone).setOccupant(controler, sequence, code, position);
};
......@@ -102,7 +102,7 @@ export const fetchCheckCardMeta = async (
const newID =
code != 0
? code
: matStore.getZone(location.location).at(controller)[location.sequence]
: matStore.in(location.location).of(controller)[location.sequence]
?.occupant?.id || 0;
const newOption = {
meta: { id: newID, data: {}, text: {} },
......
......@@ -63,8 +63,8 @@ export const fetchEsHintMeta = async ({
if (location) {
const fieldMeta = matStore
.getZone(location.location)
.at(location.controler)
.in(location.location)
.of(location.controler)
.at(location.sequence);
if (fieldMeta?.occupant?.text.name) {
esHint = esHint.replace("[?]", fieldMeta.occupant.text.name);
......
......@@ -11,7 +11,7 @@ export const fetchOverlayMeta = async (
overlayCodes.map(async (id) => await fetchCard(id))
);
const target = matStore.monsters.at(controller)[sequence];
const target = matStore.monsters.of(controller)[sequence];
if (target && target.occupant) {
if (append) {
target.overlay_materials = (target.overlay_materials || []).concat(metas);
......
......@@ -2,7 +2,7 @@ import type { ygopro } from "@/api";
import { matStore } from "@/valtioStores";
export const getCardByLocation = (location: ygopro.CardLocation) => {
return matStore.getZone(location.location).at(location.controler)[
return matStore.in(location.location).of(location.controler)[
location.sequence
];
};
......@@ -39,11 +39,11 @@ const isMe = (player: number): boolean => {
}
};
const genDuel = <T>(obj: T) => {
const genDuel = <T>(obj: T): BothSide<T> => {
const res = proxy({
me: cloneDeep(obj),
op: cloneDeep(obj),
at: (controller: number) => res[getWhom(controller)],
of: (controller: number) => res[getWhom(controller)],
});
return res;
};
......@@ -106,17 +106,17 @@ const wrap = <T extends DuelFieldState>(
const res: CardsBothSide<T> = proxy({
...entity,
remove: (controller: number, sequence: number) => {
res.at(controller).splice(sequence, 1);
res.of(controller).splice(sequence, 1);
},
insert: async (controller: number, sequence: number, id: number) => {
const card = await genCard(controller, id);
res.at(controller).splice(sequence, 0, card);
res.of(controller).splice(sequence, 0, card);
},
add: async (controller: number, ids: number[]) => {
const cards = await Promise.all(
ids.map(async (id) => genCard(controller, id))
);
res.at(controller).splice(res.at(controller).length, 0, ...cards);
res.of(controller).splice(res.of(controller).length, 0, ...cards);
},
setOccupant: async (
controller: number,
......@@ -125,7 +125,7 @@ const wrap = <T extends DuelFieldState>(
position?: ygopro.CardPosition
) => {
const meta = await fetchCard(id);
const target = res.at(controller)[sequence];
const target = res.of(controller)[sequence];
target.occupant = meta;
if (position) {
target.location.position = position;
......@@ -136,17 +136,17 @@ const wrap = <T extends DuelFieldState>(
sequence: number,
interactivity: CardState["idleInteractivities"][number]
) => {
res.at(controller)[sequence].idleInteractivities.push(interactivity);
res.of(controller)[sequence].idleInteractivities.push(interactivity);
},
clearIdleInteractivities: (controller: number) => {
res.at(controller).forEach((card) => (card.idleInteractivities = []));
res.of(controller).forEach((card) => (card.idleInteractivities = []));
},
setPlaceInteractivityType: (
controller: number,
sequence: number,
interactType: InteractType
) => {
res.at(controller)[sequence].placeInteractivity = {
res.of(controller)[sequence].placeInteractivity = {
interactType: interactType,
response: {
controler: controller,
......@@ -157,7 +157,7 @@ const wrap = <T extends DuelFieldState>(
},
clearPlaceInteractivity: (controller: number) => {
res
.at(controller)
.of(controller)
.forEach((card) => (card.placeInteractivity = undefined));
},
});
......@@ -226,6 +226,6 @@ export const matStore: MatState = proxy<MatState>({
waiting: false,
unimplemented: 0,
// methods
getZone,
in: getZone,
isMe,
});
......@@ -6,12 +6,11 @@ import type { CardMeta } from "@/api/cards";
export interface BothSide<T> {
me: T;
op: T;
at: (controller: number) => T;
/** 根据controller返回对应的数组,op或者me */
of: (controller: number) => T;
}
export interface CardsBothSide<T extends DuelFieldState> extends BothSide<T> {
/** 根据controller返回对应的数组,op或者me */
at: (controller: number) => T;
/** 移除特定位置的卡片 */
remove: (player: number, sequence: number) => void;
/** 在末尾添加卡片 */
......@@ -81,8 +80,8 @@ export interface MatState {
unimplemented: number; // 未处理的`Message`
// >>> methods >>>
/** 根据zone获取hands/masters/gy... */
getZone: (zone: ygopro.CardZone) => CardsBothSide<DuelFieldState>;
/** 根据zone获取hands/masters/magics... */
in: (zone: ygopro.CardZone) => CardsBothSide<DuelFieldState>;
/** 根据自己的先后手判断是否是自己 */
isMe: (player: number) => boolean;
}
......
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