Commit 9e5c6f5c authored by Chunchi Che's avatar Chunchi Che

use location in CardType

parent 4eda5276
Pipeline #22068 failed with stages
in 8 minutes and 34 seconds
...@@ -13,7 +13,7 @@ export default async (confirmCards: ygopro.StocGameMessage.MsgConfirmCards) => { ...@@ -13,7 +13,7 @@ export default async (confirmCards: ygopro.StocGameMessage.MsgConfirmCards) => {
const meta = await fetchCard(card.code); const meta = await fetchCard(card.code);
target.meta = meta; target.meta = meta;
// 设置`position`,否则会横放 // 设置`position`,否则会横放
target.position = ygopro.CardPosition.ATTACK; target.location.position = ygopro.CardPosition.ATTACK;
} else { } else {
console.warn(`card of ${card} is null`); console.warn(`card of ${card} is null`);
} }
......
...@@ -21,8 +21,8 @@ export default async (draw: ygopro.StocGameMessage.MsgDraw) => { ...@@ -21,8 +21,8 @@ export default async (draw: ygopro.StocGameMessage.MsgDraw) => {
const meta = await fetchCard(code); const meta = await fetchCard(code);
card.code = code; card.code = code;
card.meta = meta; card.meta = meta;
card.zone = ygopro.CardZone.HAND; card.location.zone = ygopro.CardZone.HAND;
card.sequence = Number(idx) + handsLength; card.location.sequence = Number(idx) + handsLength;
} }
if (cnt++ < 2) { if (cnt++ < 2) {
......
...@@ -95,23 +95,27 @@ export default async (move: MsgMove) => { ...@@ -95,23 +95,27 @@ export default async (move: MsgMove) => {
// 维护sequence // 维护sequence
// TODO: 这些逻辑是不是可以考虑沉淀到store里面 // TODO: 这些逻辑是不是可以考虑沉淀到store里面
if ([HAND, GRAVE, REMOVED, DECK, EXTRA].includes(fromZone)) if ([HAND, GRAVE, REMOVED, DECK, EXTRA].includes(fromZone))
fromCards.forEach((c) => c.sequence > from.sequence && c.sequence--); fromCards.forEach(
(c) => c.location.sequence > from.sequence && c.location.sequence--
);
if ([HAND, GRAVE, REMOVED, DECK, EXTRA].includes(toZone)) if ([HAND, GRAVE, REMOVED, DECK, EXTRA].includes(toZone))
toCards.forEach((c) => c.sequence >= to.sequence && c.sequence++); toCards.forEach(
(c) => c.location.sequence >= to.sequence && c.location.sequence++
);
// 更新信息 // 更新信息
target.zone = toZone; target.location.zone = toZone;
target.controller = to.controler; target.location.controler = to.controler;
target.sequence = to.sequence; target.location.sequence = to.sequence;
target.code = code; target.code = code;
target.position = to.position; target.location.position = to.position;
// 维护完了之后,开始动画 // 维护完了之后,开始动画
const promises: Promise<unknown>[] = []; const promises: Promise<unknown>[] = [];
promises.push(eventbus.call(Task.Move, target.uuid)); promises.push(eventbus.call(Task.Move, target.uuid));
// 如果from或者to是手卡,那么需要刷新除了这张卡之外,这个玩家的所有手卡 // 如果from或者to是手卡,那么需要刷新除了这张卡之外,这个玩家的所有手卡
if ([fromZone, toZone].includes(HAND)) { if ([fromZone, toZone].includes(HAND)) {
cardStore.at(HAND, target.controller).forEach((card) => { cardStore.at(HAND, target.location.controler).forEach((card) => {
if (card.uuid !== target.uuid) if (card.uuid !== target.uuid)
promises.push(eventbus.call(Task.Move, card.uuid)); promises.push(eventbus.call(Task.Move, card.uuid));
}); });
......
...@@ -7,7 +7,7 @@ export default async (posChange: MsgPosChange) => { ...@@ -7,7 +7,7 @@ export default async (posChange: MsgPosChange) => {
const target = cardStore.at(location, controler, sequence); const target = cardStore.at(location, controler, sequence);
if (target) { if (target) {
target.position = posChange.cur_position; target.location.position = posChange.cur_position;
// TODO: 暂时用`Move`动画,后续可以单独实现一个改变表示形式的动画 // TODO: 暂时用`Move`动画,后续可以单独实现一个改变表示形式的动画
await eventbus.call(Task.Move, target.uuid); await eventbus.call(Task.Move, target.uuid);
......
...@@ -17,7 +17,7 @@ export default (shuffleHand: MsgShuffleHand) => { ...@@ -17,7 +17,7 @@ export default (shuffleHand: MsgShuffleHand) => {
const sequence = hash.get(hand.code); const sequence = hash.get(hand.code);
if (sequence !== undefined) { if (sequence !== undefined) {
if (sequence >= 0) { if (sequence >= 0) {
hand.sequence = sequence; hand.location.sequence = sequence;
hash.set(hand.code, sequence - 1); hash.set(hand.code, sequence - 1);
} else { } else {
console.warn( console.warn(
......
...@@ -42,16 +42,19 @@ export default (start: ygopro.StocGameMessage.MsgStart) => { ...@@ -42,16 +42,19 @@ export default (start: ygopro.StocGameMessage.MsgStart) => {
genCard({ genCard({
uuid: v4uuid(), uuid: v4uuid(),
code: 0, code: 0,
controller: i < 3 ? 0 : 1, location: new ygopro.CardLocation({
controler: i < 3 ? 0 : 1,
zone: [
ygopro.CardZone.DECK,
ygopro.CardZone.EXTRA,
ygopro.CardZone.TZONE,
][i % 3],
sequence,
position: ygopro.CardPosition.FACEDOWN,
}),
originController: i < 3 ? 0 : 1, originController: i < 3 ? 0 : 1,
zone: [
ygopro.CardZone.DECK,
ygopro.CardZone.EXTRA,
ygopro.CardZone.TZONE,
][i % 3],
counters: {}, counters: {},
idleInteractivities: [], idleInteractivities: [],
sequence,
meta: { meta: {
id: 0, id: 0,
data: {}, data: {},
...@@ -59,7 +62,6 @@ export default (start: ygopro.StocGameMessage.MsgStart) => { ...@@ -59,7 +62,6 @@ export default (start: ygopro.StocGameMessage.MsgStart) => {
}, },
isToken: !((i + 1) % 3), isToken: !((i + 1) % 3),
overlayMaterials: [], overlayMaterials: [],
position: ygopro.CardPosition.FACEDOWN,
chaining: false, chaining: false,
directAttack: false, directAttack: false,
}) })
......
...@@ -10,7 +10,9 @@ export default (updateData: MsgUpdateData) => { ...@@ -10,7 +10,9 @@ export default (updateData: MsgUpdateData) => {
actions.forEach((action) => { actions.forEach((action) => {
const sequence = action.location?.sequence; const sequence = action.location?.sequence;
if (typeof sequence !== "undefined") { if (typeof sequence !== "undefined") {
const target = field.filter((card) => card.sequence == sequence).at(0); const target = field
.filter((card) => card.location.sequence == sequence)
.at(0);
if (target) { if (target) {
const meta = target.meta; const meta = target.meta;
// 目前只更新以下字段 // 目前只更新以下字段
...@@ -19,7 +21,7 @@ export default (updateData: MsgUpdateData) => { ...@@ -19,7 +21,7 @@ export default (updateData: MsgUpdateData) => {
meta.text.id = action.code; meta.text.id = action.code;
} }
if (action.location !== undefined) { if (action.location !== undefined) {
target.position = action.location.position; target.location.position = action.location.position;
} }
if (action?.type_ >= 0) { if (action?.type_ >= 0) {
meta.data.type = action.type_; meta.data.type = action.type_;
......
...@@ -11,11 +11,8 @@ export interface CardType { ...@@ -11,11 +11,8 @@ export interface CardType {
uuid: string; // 一张卡的唯一标识 uuid: string; // 一张卡的唯一标识
code: number; // 卡号 code: number; // 卡号
meta: CardMeta; // 卡片元数据 meta: CardMeta; // 卡片元数据
controller: number; // 控制这个位置的玩家,0或1 location: ygopro.CardLocation;
originController: number; // 在卡组构建之中持有这张卡的玩家,方便reloadField的使用 originController: number; // 在卡组构建之中持有这张卡的玩家,方便reloadField的使用
zone: ygopro.CardZone; // 怪兽区/魔法陷阱区/手牌/卡组/墓地/除外区
position: ygopro.CardPosition; // 卡片的姿势:攻击还是守备
sequence: number; // 卡片在区域中的序号
idleInteractivities: Interactivity<number>[]; // IDLE状态下的互动信息 idleInteractivities: Interactivity<number>[]; // IDLE状态下的互动信息
placeInteractivity?: Interactivity<{ placeInteractivity?: Interactivity<{
controler: number; controler: number;
...@@ -49,14 +46,15 @@ class CardStore { ...@@ -49,14 +46,15 @@ class CardStore {
return this.inner return this.inner
.filter( .filter(
(card) => (card) =>
card.zone === zone && card.location.zone === zone &&
card.controller === controller && card.location.controler === controller &&
card.sequence === sequence card.location.sequence === sequence
) )
.at(0); .at(0);
} else { } else {
return this.inner.filter( return this.inner.filter(
(card) => card.zone === zone && card.controller === controller (card) =>
card.location.zone === zone && card.location.controler === controller
); );
} }
} }
...@@ -80,8 +78,8 @@ class CardStore { ...@@ -80,8 +78,8 @@ class CardStore {
// target.code = meta.id; // target.code = meta.id;
target.meta = meta; target.meta = meta;
} }
if (target.zone == ygopro.CardZone.HAND) { if (target.location.zone == ygopro.CardZone.HAND) {
target.position = isChaining target.location.position = isChaining
? ygopro.CardPosition.FACEUP_ATTACK ? ygopro.CardPosition.FACEUP_ATTACK
: ygopro.CardPosition.FACEDOWN_ATTACK; : ygopro.CardPosition.FACEDOWN_ATTACK;
} }
......
...@@ -63,7 +63,7 @@ export const Card: FC<{ idx: number }> = React.memo(({ idx }) => { ...@@ -63,7 +63,7 @@ export const Card: FC<{ idx: number }> = React.memo(({ idx }) => {
}; };
useEffect(() => { useEffect(() => {
move(state.zone); move(state.location.zone);
}, []); }, []);
const [highlight, setHighlight] = useState(false); const [highlight, setHighlight] = useState(false);
...@@ -80,7 +80,7 @@ export const Card: FC<{ idx: number }> = React.memo(({ idx }) => { ...@@ -80,7 +80,7 @@ export const Card: FC<{ idx: number }> = React.memo(({ idx }) => {
eventbus.register(Task.Move, async (uuid: string) => { eventbus.register(Task.Move, async (uuid: string) => {
if (uuid === state.uuid) { if (uuid === state.uuid) {
await addToAnimation(() => move(state.zone)); await addToAnimation(() => move(state.location.zone));
} }
}); });
...@@ -112,9 +112,9 @@ export const Card: FC<{ idx: number }> = React.memo(({ idx }) => { ...@@ -112,9 +112,9 @@ export const Card: FC<{ idx: number }> = React.memo(({ idx }) => {
} as any as CSSProperties } as any as CSSProperties
} }
onClick={() => { onClick={() => {
if ([MZONE, SZONE, HAND].includes(state.zone)) { if ([MZONE, SZONE, HAND].includes(state.location.zone)) {
onCardClick(state); onCardClick(state);
} else if ([EXTRA, GRAVE, REMOVED].includes(state.zone)) { } else if ([EXTRA, GRAVE, REMOVED].includes(state.location.zone)) {
onFieldClick(state); onFieldClick(state);
} }
}} }}
...@@ -177,7 +177,10 @@ const onCardClick = (card: CardType) => { ...@@ -177,7 +177,10 @@ const onCardClick = (card: CardType) => {
}; };
const onFieldClick = (card: CardType) => { const onFieldClick = (card: CardType) => {
const displayStates = cardStore.at(card.zone, card.controller); const displayStates = cardStore.at(
card.location.zone,
card.location.controler
);
messageStore.cardListModal.list = displayStates.map((item) => ({ messageStore.cardListModal.list = displayStates.map((item) => ({
meta: { meta: {
id: item.code, id: item.code,
......
...@@ -11,9 +11,9 @@ import { asyncStart } from "./utils"; ...@@ -11,9 +11,9 @@ import { asyncStart } from "./utils";
export const focus = async (props: { card: CardType; api: SpringApi }) => { export const focus = async (props: { card: CardType; api: SpringApi }) => {
const { card, api } = props; const { card, api } = props;
const current = api.current[0].get(); const current = api.current[0].get();
if (card.zone === ygopro.CardZone.HAND) { if (card.location.zone === ygopro.CardZone.HAND) {
await asyncStart(api)({ await asyncStart(api)({
y: current.y + (matStore.isMe(card.controller) ? -1 : 1) * 200, // TODO: 放到config之中 y: current.y + (matStore.isMe(card.location.controler) ? -1 : 1) * 200, // TODO: 放到config之中
rz: 0, rz: 0,
}); });
await asyncStart(api)({ y: current.y, rz: current.rz }); await asyncStart(api)({ y: current.y, rz: current.rz });
......
...@@ -30,7 +30,8 @@ const { HAND, GRAVE, REMOVED, DECK, EXTRA, MZONE, SZONE, TZONE } = ...@@ -30,7 +30,8 @@ const { HAND, GRAVE, REMOVED, DECK, EXTRA, MZONE, SZONE, TZONE } =
export const moveToDeck = async (props: { card: CardType; api: SpringApi }) => { export const moveToDeck = async (props: { card: CardType; api: SpringApi }) => {
const { card, api } = props; const { card, api } = props;
// report // report
const { zone, sequence, controller, xyzMonster, position } = card; const { location, xyzMonster } = card;
const { controler, zone, sequence, position } = location;
const rightX = DECK_OFFSET_X.value + 2 * (BLOCK_WIDTH.value + COL_GAP.value); const rightX = DECK_OFFSET_X.value + 2 * (BLOCK_WIDTH.value + COL_GAP.value);
const leftX = -rightX; const leftX = -rightX;
...@@ -41,20 +42,20 @@ export const moveToDeck = async (props: { card: CardType; api: SpringApi }) => { ...@@ -41,20 +42,20 @@ export const moveToDeck = async (props: { card: CardType; api: SpringApi }) => {
2 * ROW_GAP.value - 2 * ROW_GAP.value -
BLOCK_HEIGHT_S.value; BLOCK_HEIGHT_S.value;
const topY = -bottomY; const topY = -bottomY;
let x = isMe(controller) ? rightX : leftX; let x = isMe(controler) ? rightX : leftX;
let y = isMe(controller) ? bottomY : topY; let y = isMe(controler) ? bottomY : topY;
if (zone === EXTRA) { if (zone === EXTRA) {
x = isMe(controller) ? leftX : rightX; x = isMe(controler) ? leftX : rightX;
} }
let rz = zone === EXTRA ? DECK_ROTATE_Z.value : -DECK_ROTATE_Z.value; let rz = zone === EXTRA ? DECK_ROTATE_Z.value : -DECK_ROTATE_Z.value;
rz += isMe(controller) ? 0 : 180; rz += isMe(controler) ? 0 : 180;
const z = sequence; const z = sequence;
api.start({ api.start({
x, x,
y, y,
z, z,
rz, rz,
ry: isMe(controller) ? (zone === DECK ? 180 : 0) : 180, ry: isMe(controler) ? (zone === DECK ? 180 : 0) : 180,
zIndex: z, zIndex: z,
height: DECK_CARD_HEIGHT.value, height: DECK_CARD_HEIGHT.value,
}); });
......
...@@ -33,11 +33,15 @@ export const moveToGround = async (props: { ...@@ -33,11 +33,15 @@ export const moveToGround = async (props: {
const { card, api } = props; const { card, api } = props;
// 如果是超量素材,那么,应该看超量素材所属的xyzMonster // 如果是超量素材,那么,应该看超量素材所属的xyzMonster
const targetCard = const targetCard = card.location.is_overlay
card.zone === OVERLAY ? (card.xyzMonster ? card.xyzMonster : card) : card; ? card.xyzMonster
? card.xyzMonster
: card
: card;
const { zone, sequence, controller, xyzMonster, position, overlayMaterials } = const { location, xyzMonster, overlayMaterials } = targetCard;
targetCard;
const { controler, zone, sequence, position } = location;
// 根据zone计算卡片的宽度 // 根据zone计算卡片的宽度
const cardWidth = const cardWidth =
...@@ -80,7 +84,7 @@ export const moveToGround = async (props: { ...@@ -80,7 +84,7 @@ export const moveToGround = async (props: {
} }
} }
if (!isMe(controller)) { if (!isMe(controler)) {
x = -x; x = -x;
y = -y; y = -y;
} }
...@@ -92,7 +96,7 @@ export const moveToGround = async (props: { ...@@ -92,7 +96,7 @@ export const moveToGround = async (props: {
ygopro.CardPosition.FACEUP_DEFENSE, ygopro.CardPosition.FACEUP_DEFENSE,
].includes(position ?? 5); ].includes(position ?? 5);
height = defence ? BLOCK_WIDTH.value : height; height = defence ? BLOCK_WIDTH.value : height;
let rz = isMe(controller) ? 0 : 180; let rz = isMe(controler) ? 0 : 180;
rz += defence ? 90 : 0; rz += defence ? 90 : 0;
// 动画 // 动画
......
...@@ -28,7 +28,7 @@ const { HAND, GRAVE, REMOVED, DECK, EXTRA, MZONE, SZONE, TZONE } = ...@@ -28,7 +28,7 @@ const { HAND, GRAVE, REMOVED, DECK, EXTRA, MZONE, SZONE, TZONE } =
export const moveToHand = async (props: { card: CardType; api: SpringApi }) => { export const moveToHand = async (props: { card: CardType; api: SpringApi }) => {
const { card, api } = props; const { card, api } = props;
const { zone, sequence, controller } = card; const { zone, sequence, controler } = card.location;
// 手卡会有很复杂的计算... // 手卡会有很复杂的计算...
const hand_circle_center_x = 0; const hand_circle_center_x = 0;
const hand_circle_center_y = const hand_circle_center_y =
...@@ -48,22 +48,22 @@ export const moveToHand = async (props: { card: CardType; api: SpringApi }) => { ...@@ -48,22 +48,22 @@ export const moveToHand = async (props: { card: CardType; api: SpringApi }) => {
) * ) *
0.9; 0.9;
// 接下来计算每一张手卡 // 接下来计算每一张手卡
const hands_length = cardStore.at(HAND, controller).length; const hands_length = cardStore.at(HAND, controler).length;
const angle = (sequence - (hands_length - 1) / 2) * THETA; const angle = (sequence - (hands_length - 1) / 2) * THETA;
const r = HAND_CIRCLE_CENTER_OFFSET_Y.value + HAND_CARD_HEIGHT.value / 2; const r = HAND_CIRCLE_CENTER_OFFSET_Y.value + HAND_CARD_HEIGHT.value / 2;
const negativeX = Math.sin(angle) * r; const negativeX = Math.sin(angle) * r;
const negativeY = Math.cos(angle) * r + HAND_CARD_HEIGHT.value / 2; const negativeY = Math.cos(angle) * r + HAND_CARD_HEIGHT.value / 2;
const x = hand_circle_center_x + negativeX * (isMe(controller) ? 1 : -1); const x = hand_circle_center_x + negativeX * (isMe(controler) ? 1 : -1);
const y = hand_circle_center_y - negativeY + 130; // 常量 是手动调的 这里肯定有问题 有空来修 const y = hand_circle_center_y - negativeY + 130; // 常量 是手动调的 这里肯定有问题 有空来修
const _rz = (angle * 180) / Math.PI; const _rz = (angle * 180) / Math.PI;
api.start({ api.start({
x: isMe(controller) ? x : -x, x: isMe(controler) ? x : -x,
y: isMe(controller) ? y : -y, y: isMe(controler) ? y : -y,
z: 0, z: 0,
rz: isMe(controller) ? _rz : 180 - _rz, rz: isMe(controler) ? _rz : 180 - _rz,
ry: isMe(controller) ? 0 : 180, ry: isMe(controler) ? 0 : 180,
height: HAND_CARD_HEIGHT.value, height: HAND_CARD_HEIGHT.value,
zIndex: sequence, zIndex: sequence,
// rx: -PLANE_ROTATE_X.value, // rx: -PLANE_ROTATE_X.value,
......
...@@ -32,12 +32,12 @@ export const moveToOutside = async (props: { ...@@ -32,12 +32,12 @@ export const moveToOutside = async (props: {
}) => { }) => {
const { card, api } = props; const { card, api } = props;
// report // report
const { zone, sequence, controller, xyzMonster, position, overlayMaterials } = const { xyzMonster, overlayMaterials } = card;
card; const { zone, sequence, controler, position } = card.location;
let x = (BLOCK_WIDTH.value + COL_GAP.value) * 3, let x = (BLOCK_WIDTH.value + COL_GAP.value) * 3,
y = zone === GRAVE ? BLOCK_HEIGHT_M.value + ROW_GAP.value : 0; y = zone === GRAVE ? BLOCK_HEIGHT_M.value + ROW_GAP.value : 0;
if (!isMe(controller)) { if (!isMe(controler)) {
x = -x; x = -x;
y = -y; y = -y;
} }
...@@ -46,7 +46,7 @@ export const moveToOutside = async (props: { ...@@ -46,7 +46,7 @@ export const moveToOutside = async (props: {
y, y,
z: 0, z: 0,
height: BLOCK_HEIGHT_S.value, height: BLOCK_HEIGHT_S.value,
rz: isMe(controller) ? 0 : 180, rz: isMe(controler) ? 0 : 180,
ry: [ygopro.CardPosition.FACEDOWN].includes(position) ? 180 : 0, ry: [ygopro.CardPosition.FACEDOWN].includes(position) ? 180 : 0,
}); });
}; };
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