Commit 42d4cf52 authored by Chunchi Che's avatar Chunchi Che

fix token

parent fc8963d6
...@@ -16,7 +16,7 @@ const TYPE_UNION = 0x400; // ...@@ -16,7 +16,7 @@ const TYPE_UNION = 0x400; //
const TYPE_DUAL = 0x800; // const TYPE_DUAL = 0x800; //
const TYPE_TUNER = 0x1000; // const TYPE_TUNER = 0x1000; //
const TYPE_SYNCHRO = 0x2000; // const TYPE_SYNCHRO = 0x2000; //
const TYPE_TOKEN = 0x4000; // export const TYPE_TOKEN = 0x4000; //
const TYPE_QUICKPLAY = 0x10000; // const TYPE_QUICKPLAY = 0x10000; //
const TYPE_CONTINUOUS = 0x20000; // const TYPE_CONTINUOUS = 0x20000; //
const TYPE_EQUIP = 0x40000; // const TYPE_EQUIP = 0x40000; //
......
...@@ -2,7 +2,7 @@ import { fetchCard, ygopro } from "@/api"; ...@@ -2,7 +2,7 @@ import { fetchCard, ygopro } from "@/api";
import { eventbus, Task } from "@/infra"; import { eventbus, Task } from "@/infra";
import { cardStore, CardType } from "@/stores"; import { cardStore, CardType } from "@/stores";
import { REASON_MATERIAL } from "../../common"; import { REASON_MATERIAL, TYPE_TOKEN } from "../../common";
type MsgMove = ygopro.StocGameMessage.MsgMove; type MsgMove = ygopro.StocGameMessage.MsgMove;
const { HAND, GRAVE, REMOVED, DECK, EXTRA, MZONE, TZONE } = ygopro.CardZone; const { HAND, GRAVE, REMOVED, DECK, EXTRA, MZONE, TZONE } = ygopro.CardZone;
...@@ -10,7 +10,7 @@ const { HAND, GRAVE, REMOVED, DECK, EXTRA, MZONE, TZONE } = ygopro.CardZone; ...@@ -10,7 +10,7 @@ const { HAND, GRAVE, REMOVED, DECK, EXTRA, MZONE, TZONE } = ygopro.CardZone;
const overlayStack: ygopro.CardLocation[] = []; const overlayStack: ygopro.CardLocation[] = [];
/* /*
* 超量素材的`Location`: * * 超量素材的`Location`:
* - 位置是跟随超量怪兽的,通过`is_overlay`字段判断是否是超量素材,`overlay_sequence`是在某个超量怪兽下面的超量序列; * - 位置是跟随超量怪兽的,通过`is_overlay`字段判断是否是超量素材,`overlay_sequence`是在某个超量怪兽下面的超量序列;
* - 超量怪兽移动,超量素材需要跟着移动,并且需要前端自己维护这个关系,因为当超量怪兽移动时, * - 超量怪兽移动,超量素材需要跟着移动,并且需要前端自己维护这个关系,因为当超量怪兽移动时,
* 后端不会针对超量素材传`MSG_MOVE`; * 后端不会针对超量素材传`MSG_MOVE`;
...@@ -20,6 +20,13 @@ const overlayStack: ygopro.CardLocation[] = []; ...@@ -20,6 +20,13 @@ const overlayStack: ygopro.CardLocation[] = [];
* 因此前端需要自己维护,现在的做法采用了`入栈-出栈`的方式。 * 因此前端需要自己维护,现在的做法采用了`入栈-出栈`的方式。
* - 当场上的超量怪兽离开`MZONE`,比如送墓/除外时,超量素材会跟着超量怪兽移动,这时候它们的`sequence`还是一样的, * - 当场上的超量怪兽离开`MZONE`,比如送墓/除外时,超量素材会跟着超量怪兽移动,这时候它们的`sequence`还是一样的,
* 然后后端会传`MSG_MOVE`,对超量素材的位置进行修正。 * 然后后端会传`MSG_MOVE`,对超量素材的位置进行修正。
*
* * 衍生物的`Location`
* - 在neos视角中,衍生物放在`TZONE`区域;
* - 在ygopro后端视角中,衍生物放在`DECK`区域;
* - 当衍生物进场和离场的时候,from和to的zone都是`DECK`,因此这里手动修改;
* - 通过`meta.data.type`判断一张卡是否是衍生物。
*
* */ * */
export default async (move: MsgMove) => { export default async (move: MsgMove) => {
const code = move.code; const code = move.code;
...@@ -27,24 +34,25 @@ export default async (move: MsgMove) => { ...@@ -27,24 +34,25 @@ export default async (move: MsgMove) => {
const to = move.to; const to = move.to;
const reason = move.reason; const reason = move.reason;
const fromCards = cardStore.at(from.zone, from.controler); const meta = await fetchCard(code);
const toCards = cardStore.at(to.zone, to.controler); if (meta.data.type !== undefined && (meta.data.type & TYPE_TOKEN) > 0) {
// 衍生物
// TODO: if (from.zone == DECK) {
// 1. 是否能有更solid的衍生物判断方式? // 衍生物出场的场景,设置`from.zone`为`TZONE`
// 2. 应该判断是否是`TZONE`应该收敛到`readCardLocation`里面 from.zone = TZONE;
const fromZone = }
move.from.toArray().at(1) === undefined ? ygopro.CardZone.TZONE : from.zone; if (to.zone == DECK) {
let toZone = // 衍生物离开场上的场合,设置`to.zone`为`TZONE`
move.to.toArray().at(1) === undefined ? ygopro.CardZone.TZONE : to.zone; to.zone = TZONE;
}
}
// log出来看看,后期删掉即可 // log出来看看,后期删掉即可
await (async () => { await (async () => {
const { text } = await fetchCard(code);
console.color("green")( console.color("green")(
`${text.name} ${ygopro.CardZone[fromZone]}:${from.sequence}:${ `${meta.text.name} ${ygopro.CardZone[from.zone]}:${from.sequence}:${
from.is_overlay ? from.overlay_sequence : "" from.is_overlay ? from.overlay_sequence : ""
}${ygopro.CardZone[toZone]}:${to.sequence}:${ }${ygopro.CardZone[to.zone]}:${to.sequence}:${
to.is_overlay ? to.overlay_sequence : "" to.is_overlay ? to.overlay_sequence : ""
}` }`
); );
...@@ -52,14 +60,10 @@ export default async (move: MsgMove) => { ...@@ -52,14 +60,10 @@ export default async (move: MsgMove) => {
let target: CardType; let target: CardType;
// 处理token if (from.is_overlay) {
if (fromZone === TZONE) {
// 召唤 token
target = cardStore.at(TZONE, from.controler)[0]; // 必有,随便取一个没用到的token
} else if (from.is_overlay) {
// 超量素材的去除 // 超量素材的去除
const overlayMaterial = cardStore.at( const overlayMaterial = cardStore.at(
fromZone, from.zone,
from.controler, from.controler,
from.sequence, from.sequence,
from.overlay_sequence from.overlay_sequence
...@@ -68,33 +72,32 @@ export default async (move: MsgMove) => { ...@@ -68,33 +72,32 @@ export default async (move: MsgMove) => {
target = overlayMaterial; target = overlayMaterial;
} else { } else {
console.warn( console.warn(
`<Move>overlayMaterial from zone=${fromZone}, controller=${from.controler}, `<Move>overlayMaterial from zone=${from.zone}, controller=${from.controler},
sequence=${from.sequence}, overlay_sequence=${from.overlay_sequence} is null` sequence=${from.sequence}, overlay_sequence=${from.overlay_sequence} is null`
); );
return; return;
} }
} else { } else {
const card = cardStore.at(fromZone, from.controler, from.sequence); const card = cardStore.at(from.zone, from.controler, from.sequence);
if (card) { if (card) {
target = card; target = card;
} else { } else {
console.warn( console.warn(
`<Move>card from zone=${fromZone}, controller=${from.controler} sequence=${from.sequence} is null` `<Move>card from zone=${from.zone}, controller=${from.controler} sequence=${from.sequence} is null`
); );
console.info(cardStore.at(fromZone, from.controler)); console.info(cardStore.at(from.zone, from.controler));
return; return;
} }
} }
// 超量 // 超量
if (to.is_overlay && fromZone == MZONE) { if (to.is_overlay && from.zone == MZONE) {
// 准备超量召唤,超量素材入栈 // 准备超量召唤,超量素材入栈
if (reason == REASON_MATERIAL) { if (reason == REASON_MATERIAL) {
toZone = MZONE;
to.zone = MZONE; to.zone = MZONE;
overlayStack.push(to); overlayStack.push(to);
} }
} else if (toZone === MZONE && overlayStack.length) { } else if (to.zone === MZONE && overlayStack.length) {
// 超量召唤 // 超量召唤
console.color("grey")(`超量召唤!overlayStack=${overlayStack}`); console.color("grey")(`超量召唤!overlayStack=${overlayStack}`);
...@@ -123,11 +126,14 @@ export default async (move: MsgMove) => { ...@@ -123,11 +126,14 @@ export default async (move: MsgMove) => {
} }
// 维护sequence // 维护sequence
if ([HAND, GRAVE, REMOVED, DECK, EXTRA].includes(fromZone)) const fromCards = cardStore.at(from.zone, from.controler);
const toCards = cardStore.at(to.zone, to.controler);
if ([HAND, GRAVE, REMOVED, DECK, EXTRA, TZONE].includes(from.zone))
fromCards.forEach( fromCards.forEach(
(c) => c.location.sequence > from.sequence && c.location.sequence-- (c) => c.location.sequence > from.sequence && c.location.sequence--
); );
if ([HAND, GRAVE, REMOVED, DECK, EXTRA].includes(toZone)) if ([HAND, GRAVE, REMOVED, DECK, EXTRA, TZONE].includes(to.zone))
toCards.forEach( toCards.forEach(
(c) => c.location.sequence >= to.sequence && c.location.sequence++ (c) => c.location.sequence >= to.sequence && c.location.sequence++
); );
...@@ -153,7 +159,7 @@ export default async (move: MsgMove) => { ...@@ -153,7 +159,7 @@ export default async (move: MsgMove) => {
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 ([from.zone, to.zone].includes(HAND)) {
cardStore.at(HAND, target.location.controler).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));
...@@ -168,7 +174,7 @@ export default async (move: MsgMove) => { ...@@ -168,7 +174,7 @@ export default async (move: MsgMove) => {
from.controler, from.controler,
from.sequence from.sequence
)) { )) {
overlay.location.zone = toZone; overlay.location.zone = to.zone;
overlay.location.controler = to.controler; overlay.location.controler = to.controler;
overlay.location.sequence = to.sequence; overlay.location.sequence = to.sequence;
......
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