diff --git a/noname/get/index.js b/noname/get/index.js index 522e1fcc9..ae93d23e6 100644 --- a/noname/get/index.js +++ b/noname/get/index.js @@ -4657,6 +4657,17 @@ export class Get extends Uninstantable { if (eff > 0 && target.hujia > 0) return eff / 1.3; return eff; } + /** + * + * @param {any} source 如果参数是function,执行此函数并返回结果,传参为此方法剩余的参数。如果参数不是function,直接返回结果。 + * @returns 返回的结果 + */ + static dynamicVariable(source){ + if(typeof source == 'function'){ + return source.call(...(arguments.slice(1))); + } + return source; + } static recoverEffect(target, player, viewer) { if (target.hp == target.maxHp) return 0; if (!player) { diff --git a/noname/library/element/card.js b/noname/library/element/card.js index 02d8bb61e..a53f089d1 100644 --- a/noname/library/element/card.js +++ b/noname/library/element/card.js @@ -329,7 +329,7 @@ export class Card extends HTMLDivElement { if (info.cardimage) { bg = info.cardimage; } - var img = lib.card[bg].image; + var img = get.dynamicVariable(lib.card[bg].image,this); if (img) { if (img.startsWith('db:')) { img = img.slice(3); @@ -378,7 +378,7 @@ export class Card extends HTMLDivElement { } } } - else if (lib.card[bg].image == 'background') { + else if (get.dynamicVariable(lib.card[bg].image,this) == 'background') { if (card[3]) this.node.background.setBackground(bg + '_' + get.natureList(card[3])[0], 'card'); else this.node.background.setBackground(bg, 'card'); } @@ -393,12 +393,12 @@ export class Card extends HTMLDivElement { this.setBackgroundDB(img); } } - else if (lib.card[bg].image) { - if (lib.card[bg].image.startsWith('character:')) { - this.setBackground(lib.card[bg].image.slice(10), 'character'); + else if (get.dynamicVariable(lib.card[bg].image,this)) { + if (get.dynamicVariable(lib.card[bg].image,this).startsWith('character:')) { + this.setBackground(get.dynamicVariable(lib.card[bg].image,this).slice(10), 'character'); } else { - this.setBackground(lib.card[bg].image); + this.setBackground(get.dynamicVariable(lib.card[bg].image,this)); } } else { @@ -437,12 +437,12 @@ export class Card extends HTMLDivElement { this.node.avatar.setBackgroundDB(img); } } - else if (lib.card[bg].image) { - if (lib.card[bg].image.startsWith('character:')) { - this.node.avatar.setBackground(lib.card[bg].image.slice(10), 'character'); + else if (get.dynamicVariable(lib.card[bg].image,this)) { + if (get.dynamicVariable(lib.card[bg].image,this).startsWith('character:')) { + this.node.avatar.setBackground(get.dynamicVariable(lib.card[bg].image,this).slice(10), 'character'); } else { - this.node.avatar.setBackground(lib.card[bg].image); + this.node.avatar.setBackground(get.dynamicVariable(lib.card[bg].image,this)); } } else { @@ -455,11 +455,11 @@ export class Card extends HTMLDivElement { } } } - else if (lib.card[bg].image == 'card') { + else if (get.dynamicVariable(lib.card[bg].image,this) == 'card') { if (card[3]) this.setBackground(bg + '_' + get.natureList(card[3])[0], 'card'); else this.setBackground(bg, 'card'); } - else if (typeof lib.card[bg].image == 'string' && !lib.card[bg].fullskin) { + else if (typeof get.dynamicVariable(lib.card[bg].image,this) == 'string' && !lib.card[bg].fullskin) { if (img) { if (img.startsWith('ext:')) { this.setBackgroundImage(img.replace(/^ext:/, 'extension/')); @@ -470,7 +470,7 @@ export class Card extends HTMLDivElement { } } else { - this.setBackground(lib.card[bg].image); + this.setBackground(get.dynamicVariable(lib.card[bg].image,this)); } } else { diff --git a/noname/ui/create/index.js b/noname/ui/create/index.js index ef31b6cd9..594eba298 100644 --- a/noname/ui/create/index.js +++ b/noname/ui/create/index.js @@ -314,7 +314,7 @@ export class Create extends Uninstantable { } else bg = ui.create.div(node); node.classList.add('tempimage'); - let img = lib.card[cardName].image; + let img = get.dynamicVariable(lib.card[cardName].image,card); if (img) { if (img.startsWith('db:')) { img = img.slice(3); @@ -342,7 +342,7 @@ export class Create extends Uninstantable { } } } - else if (lib.card[cardName].image == 'background') { + else if (get.dynamicVariable(lib.card[cardName].image,card) == 'background') { if (cardNature) bg.setBackground(cardName + '_' + cardNature, 'card'); else bg.setBackground(cardName, 'card'); } @@ -356,12 +356,12 @@ export class Create extends Uninstantable { bg.setBackgroundDB(img); } } - else if (lib.card[cardName].image) { - if (lib.card[cardName].image.startsWith('character:')) { - bg.setBackground(lib.card[cardName].image.slice(10), 'character'); + else if (get.dynamicVariable(lib.card[cardName].image,card)) { + if (get.dynamicVariable(lib.card[cardName].image,card).startsWith('character:')) { + bg.setBackground(get.dynamicVariable(lib.card[cardName].image,card).slice(10), 'character'); } else { - bg.setBackground(lib.card[cardName].image); + bg.setBackground(get.dynamicVariable(lib.card[cardName].image,card)); } } else { @@ -374,11 +374,11 @@ export class Create extends Uninstantable { } } } - else if (lib.card[cardName].image == 'card') { + else if (get.dynamicVariable(lib.card[cardName].image,card) == 'card') { if (cardNature) bg.setBackground(cardName + '_' + cardNature, 'card'); else bg.setBackground(cardName, 'card'); } - else if (typeof lib.card[cardName].image == 'string' && !lib.card[cardName].fullskin) { + else if (typeof get.dynamicVariable(lib.card[cardName].image,card) == 'string' && !lib.card[cardName].fullskin) { if (img) { if (img.startsWith('ext:')) { bg.setBackgroundImage(img.replace(/^ext:/, 'extension/')); @@ -389,7 +389,7 @@ export class Create extends Uninstantable { } } else { - bg.setBackground(lib.card[cardName].image); + bg.setBackground(get.dynamicVariable(lib.card[cardName].image,card)); } } else {