Commit 296eaf09 authored by Chunchi Che's avatar Chunchi Che

add findCardByLocation

parent b8eca8c7
Pipeline #19750 passed with stages
in 4 minutes and 58 seconds
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
import { DuelState } from "./mod"; import { DuelState } from "./mod";
import { Draft } from "@reduxjs/toolkit"; import { Draft } from "@reduxjs/toolkit";
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { CardState } from "./generic";
/* /*
* 通过`player`和`selfType`判断是应该处理自己还是对手 * 通过`player`和`selfType`判断是应该处理自己还是对手
...@@ -22,3 +24,56 @@ export function judgeSelf(player: number, state: Draft<DuelState>): boolean { ...@@ -22,3 +24,56 @@ export function judgeSelf(player: number, state: Draft<DuelState>): boolean {
return false; return false;
} }
} }
/*
* 通过`controler`,`zone`和`sequence`获取卡牌状态*/
export function findCardByLocation(
state: Draft<DuelState>,
controler: number,
zone: ygopro.CardZone,
sequence: number
): CardState | undefined {
const finder = (_: any, idx: number) => idx == sequence;
switch (zone) {
case ygopro.CardZone.HAND: {
const hands = judgeSelf(controler, state) ? state.meHands : state.opHands;
return hands?.inner.find(finder);
}
case ygopro.CardZone.MZONE: {
const monsters = judgeSelf(controler, state)
? state.meMonsters
: state.opMonsters;
return monsters?.inner.find(finder);
}
case ygopro.CardZone.SZONE: {
const magics = judgeSelf(controler, state)
? state.meMagics
: state.opMagics;
return magics?.inner.find(finder);
}
case ygopro.CardZone.REMOVED: {
const exclusions = judgeSelf(controler, state)
? state.meExclusion
: state.opExclusion;
return exclusions?.inner.find(finder);
}
case ygopro.CardZone.GRAVE: {
const cemerety = judgeSelf(controler, state)
? state.meCemetery
: state.opCemetery;
return cemerety?.inner.find(finder);
}
case ygopro.CardZone.ONFIELD: {
const field = judgeSelf(controler, state) ? state.meField : state.opField;
if (sequence == 0) {
return field?.inner;
} else {
return undefined;
}
}
default: {
return undefined;
}
}
}
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