默认参数额外加入判断

This commit is contained in:
nonameShijian 2024-01-29 15:13:34 +08:00
parent 29bdea64c3
commit 35cf886018
5 changed files with 47 additions and 13 deletions

View File

@ -1386,6 +1386,11 @@ declare interface Skill {
zhuanhuanji?: 'number' | boolean | ((player: Player, skill: string) => any);
/**
*
*/
categories?: (skill: string, player: Player) => string[];
//日后还有很多属性要添加的
[key: string]: any;
}

View File

@ -265,8 +265,13 @@ export class Get extends Uninstantable {
}
return null;
}
/**
* @param { string } skill
* @param { Player } player
* @returns { string[] }
*/
static skillCategoriesOf(skill, player) {
var list = [], info = get.info(skill);
const list = [], info = get.info(skill);
if (!info) return list;
if (get.is.locked(skill, player)) list.add('锁定技');
if (info.zhuSkill) list.add('主公技');

View File

@ -654,7 +654,14 @@ export class Player extends HTMLDivElement {
* @param { (card: Card) => boolean } [filter]
*/
getKnownCards(other = _status.event.player, filter = card => true) {
if (!other) other = this;
if (!other) {
if (other === null) console.trace(`getKnownCards的other参数不应传入null,可以用void 0或undefined占位`);
other = _status.event.player || this;
}
if (!filter) {
if (other === null) console.trace(`getKnownCards的filter参数不应传入null,可以用void 0或undefined占位`);
filter = card => true;
}
return this.getCards('h', card => {
return card.isKnownBy(other) && filter(card);
});
@ -664,6 +671,10 @@ export class Player extends HTMLDivElement {
* @param { Player } [other]
*/
isAllCardsKnown(other = _status.event.player) {
if (!other) {
if (other === null) console.trace(`isAllCardsKnown的other参数不应传入null,可以用void 0或undefined占位`);
other = _status.event.player || this;
}
if (!other) other = this;
return this.countCards('h', card => {
return !card.isKnownBy(other);
@ -675,7 +686,14 @@ export class Player extends HTMLDivElement {
* @param { (card: Card) => boolean } [filter]
*/
hasKnownCards(other = _status.event.player, filter = card => true) {
if (!other) other = this;
if (!other) {
if (other === null) console.trace(`hasKnownCards的other参数不应传入null,可以用void 0或undefined占位`);
other = _status.event.player || this;
}
if (!filter) {
if (other === null) console.trace(`hasKnownCards的filter参数不应传入null,可以用void 0或undefined占位`);
filter = card => true;
}
return this.countCards('h', card => {
return card.isKnownBy(other) && filter(card);
}) > 0;
@ -808,10 +826,16 @@ export class Player extends HTMLDivElement {
if (cards && !isArray) recast.cards = [cards];
else if (isArray && cards.length) recast.cards = cards;
else _status.event.next.remove(recast);
if (typeof recastingLose != 'function') recastingLose = (player, cards) => player.loseToDiscardpile(cards).log = false;
if (typeof recastingLose != 'function') {
if (recastingLose === null) console.trace(`recast的recastingLose参数不应传入null,可以用void 0或undefined占位`);
recastingLose = (player, cards) => player.loseToDiscardpile(cards).log = false;
}
recast.recastingLose = recastingLose;
recast.recastingLosingEvents = [];
if (typeof recastingGain != 'function') recastingGain = (player, cards) => player.draw(cards.length).log = false;
if (typeof recastingGain != 'function') {
if (recastingLose === null) console.trace(`recast的recastingGain参数不应传入null,可以用void 0或undefined占位`);
recastingGain = (player, cards) => player.draw(cards.length).log = false;
}
recast.recastingGain = recastingGain;
recast.recastingGainingEvents = [];
recast.setContent('recast');

View File

@ -9669,7 +9669,10 @@ export class Library extends Uninstantable {
* @param { boolean } [strict]
*/
cardRecastable: (card, player = get.owner(card), source, strict) => {
// if (typeof player == 'undefined') player = get.owner(card);
if (!player) {
if (player === null) console.trace(`cardRecastable的player参数不应传入null,可以用void 0或undefined占位`);
player = get.owner(card);
}
const mod = game.checkMod(card, player, source, 'unchanged', 'cardRecastable', player);
if (!mod) return false;
if (strict && mod == 'unchanged') {

View File

@ -6,9 +6,6 @@ export const userAgent = navigator.userAgent.toLowerCase();
export { Mutex } from './mutex.js';
export const characterDefaultPicturePath = "image/character/default_silhouette_";
// 我靠循环引用问题在这?
// export * as config from './config.js'
/**
* 不能被new的类
*/
@ -19,7 +16,7 @@ export class Uninstantable {
}
/**
*
* 暂停x毫秒
* @param { number } ms
* @returns { Promise<void> }
*/