Commit a4236002 authored by timel's avatar timel Committed by Chunchi Che

feat: cardstore attack logic

parent cf7b89fb
import { ygopro } from "@/api";
import { sleep } from "@/infra";
import { fetchEsHintMeta, matStore } from "@/stores";
import { cardStore, fetchEsHintMeta, matStore } from "@/stores";
export default async (attack: ygopro.StocGameMessage.MsgAttack) => {
fetchEsHintMeta({
......@@ -8,10 +8,16 @@ export default async (attack: ygopro.StocGameMessage.MsgAttack) => {
location: attack.attacker_location,
});
const attacker = matStore
.in(attack.attacker_location.location)
.of(attack.attacker_location.controler)
.at(attack.attacker_location.sequence);
// const attacker = matStore
// .in(attack.attacker_location.location)
// .of(attack.attacker_location.controler)
// .at(attack.attacker_location.sequence);
const attacker = cardStore.at(
attack.attacker_location.location,
attack.attacker_location.controler,
attack.attacker_location.sequence
);
if (attacker) {
if (attack.direct_attack) {
......@@ -20,14 +26,20 @@ export default async (attack: ygopro.StocGameMessage.MsgAttack) => {
await sleep(500);
attacker.directAttack = false;
} else {
const target = matStore
.in(attack.target_location.location)
.of(attack.target_location.controler)
.at(attack.target_location.sequence);
// const target = matStore
// .in(attack.target_location.location)
// .of(attack.target_location.controler)
// .at(attack.target_location.sequence);
const target = cardStore.at(
attack.target_location.location,
attack.target_location.controler,
attack.target_location.sequence
);
if (target) {
attacker.attackTarget = {
sequence: attack.target_location.sequence,
sequence: attack.target_location.sequence, // FIXME: 确实会覆盖,代码这样没错吗
opponent: !matStore.isMe(attack.target_location.controler),
...target,
};
......
......@@ -3,8 +3,7 @@ import { proxy } from "valtio";
import type { Interactivity } from "./matStore/types";
/**
* 场上某位置的状态,
* 以后会更名为 BlockState
* 场上某位置的状态
*/
export interface CardType {
uuid: number; // 一张卡的唯一标识
......@@ -27,6 +26,14 @@ export interface CardType {
counters: { [type: number]: number }; // 指示器
reload?: boolean; // 这个字段会在收到MSG_RELOAD_FIELD的时候设置成true,在收到MSG_UPDATE_DATE的时候设置成false
isToken: boolean; // 是否是token
// 新的字段(从matstore之中搬过来的)
focus: boolean; // 用于实现动画效果,当这个字段为true时,该张卡片会被放大并在屏幕中央展示
chaining: boolean; // 是否在连锁中
chainIndex?: number /*连锁的序号,如果为空表示不在连锁
TODO: 目前是妥协的设计,因为其实一张卡是可以在同一个连锁链中被连锁多次的,这里为了避免太过复杂只保存最后的连锁序号*/;
directAttack: boolean; // 是否正在直接攻击为玩家
attackTarget?: CardType & { sequence: number; opponent: boolean }; // 攻击目标。(嵌套结构可行么?)
}
class CardStore {
......
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