默认参数额外加入判断

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

@ -1384,7 +1384,12 @@ declare interface Skill {
/** 规则技能 */ /** 规则技能 */
ruleSkill?: boolean; ruleSkill?: boolean;
zhuanhuanji?: 'number' | boolean | ((player: Player, skill: string) => any); zhuanhuanji?: 'number' | boolean | ((player: Player, skill: string) => any);
/**
*
*/
categories?: (skill: string, player: Player) => string[];
//日后还有很多属性要添加的 //日后还有很多属性要添加的
[key: string]: any; [key: string]: any;

View File

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

View File

@ -654,7 +654,14 @@ export class Player extends HTMLDivElement {
* @param { (card: Card) => boolean } [filter] * @param { (card: Card) => boolean } [filter]
*/ */
getKnownCards(other = _status.event.player, filter = card => true) { 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 this.getCards('h', card => {
return card.isKnownBy(other) && filter(card); return card.isKnownBy(other) && filter(card);
}); });
@ -664,6 +671,10 @@ export class Player extends HTMLDivElement {
* @param { Player } [other] * @param { Player } [other]
*/ */
isAllCardsKnown(other = _status.event.player) { 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; if (!other) other = this;
return this.countCards('h', card => { return this.countCards('h', card => {
return !card.isKnownBy(other); return !card.isKnownBy(other);
@ -675,7 +686,14 @@ export class Player extends HTMLDivElement {
* @param { (card: Card) => boolean } [filter] * @param { (card: Card) => boolean } [filter]
*/ */
hasKnownCards(other = _status.event.player, filter = card => true) { 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 this.countCards('h', card => {
return card.isKnownBy(other) && filter(card); return card.isKnownBy(other) && filter(card);
}) > 0; }) > 0;
@ -808,10 +826,16 @@ export class Player extends HTMLDivElement {
if (cards && !isArray) recast.cards = [cards]; if (cards && !isArray) recast.cards = [cards];
else if (isArray && cards.length) recast.cards = cards; else if (isArray && cards.length) recast.cards = cards;
else _status.event.next.remove(recast); 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.recastingLose = recastingLose;
recast.recastingLosingEvents = []; 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.recastingGain = recastingGain;
recast.recastingGainingEvents = []; recast.recastingGainingEvents = [];
recast.setContent('recast'); recast.setContent('recast');

View File

@ -9669,7 +9669,10 @@ export class Library extends Uninstantable {
* @param { boolean } [strict] * @param { boolean } [strict]
*/ */
cardRecastable: (card, player = get.owner(card), source, 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); const mod = game.checkMod(card, player, source, 'unchanged', 'cardRecastable', player);
if (!mod) return false; if (!mod) return false;
if (strict && mod == 'unchanged') { if (strict && mod == 'unchanged') {

View File

@ -1,14 +1,11 @@
export const nonameInitialized = localStorage.getItem('noname_inited'); export const nonameInitialized = localStorage.getItem('noname_inited');
export const assetURL = location.protocol.startsWith('http') || typeof nonameInitialized != 'string' || nonameInitialized == 'nodejs' ? '' : nonameInitialized; export const assetURL = location.protocol.startsWith('http') || typeof nonameInitialized != 'string' || nonameInitialized == 'nodejs' ? '' : nonameInitialized;
export const GeneratorFunction = (function* () { }).constructor; export const GeneratorFunction = (function* () {}).constructor;
export const AsyncFunction = (async function () { }).constructor; export const AsyncFunction = (async function () {}).constructor;
export const userAgent = navigator.userAgent.toLowerCase(); export const userAgent = navigator.userAgent.toLowerCase();
export { Mutex } from './mutex.js'; export { Mutex } from './mutex.js';
export const characterDefaultPicturePath = "image/character/default_silhouette_"; export const characterDefaultPicturePath = "image/character/default_silhouette_";
// 我靠循环引用问题在这?
// export * as config from './config.js'
/** /**
* 不能被new的类 * 不能被new的类
*/ */
@ -19,7 +16,7 @@ export class Uninstantable {
} }
/** /**
* * 暂停x毫秒
* @param { number } ms * @param { number } ms
* @returns { Promise<void> } * @returns { Promise<void> }
*/ */