Merge pull request #227 from Tipx-L/PR-Branch

Add the ability for lib.init.parsex to remove all comments before parsing, and fix recasting related errors.
This commit is contained in:
Spmario233 2023-08-22 21:55:59 +08:00 committed by GitHub
commit 7c5eac9734
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 52 additions and 45 deletions

View File

@ -494,13 +494,14 @@ game.import('card',function(lib,game,ui,get,ai,_status){
usable:1,
content:function(){
player.recast(cards,null,(player,cards)=>{
const cardsToGain=[];
var cardsToGain=[];
for(let repetition=0;repetition<cards.length;repetition++){
const card=get.cardPile(card=>get.type(card,'trick')=='trick');
var card=get.cardPile(card=>get.type(card,'trick')=='trick');
if(card) cardsToGain.push(card);
}
if(cardsToGain.length) player.gain(cardsToGain,'draw');
if(cards.length-cardsToGain.length) player.draw(cards.length-cardsToGain.length).log=false;
return cardsToGain;
});
},
ai:{

View File

@ -117,7 +117,7 @@ game.import('character',function(lib,game,ui,get,ai,_status){
target.useCard(result.targets,card,event.links);
}
else{
target.recast(event.links,(player,cards)=>game.cardsDiscard(cards));
target.recast(event.links,(player,cards)=>game.cardsDiscard(cards).cards);
}
'step 4'
for(var card of cards){

View File

@ -580,25 +580,20 @@ game.import('character',function(lib,game,ui,get,ai,_status){
player.logSkill('dcjini');
player.addTempSkill('dcjini_counted');
player.addMark('dcjini_counted',cards.length,false);
player.recast(cards);
event.recast=player.recast(cards);
}
else event.finish();
'step 2'
if(trigger.source&&trigger.source.isIn()&&Array.isArray(result)){
for(var i of result){
if(get.name(i,player)=='sha'&&get.owner(i)==player&&get.position(i)=='h'){
player.chooseToUse(function(card,player,event){
if(get.name(card)!='sha') return false;
return lib.filter.filterCard.apply(this,arguments);
},'击逆:是否对'+get.translation(trigger.source)+'使用一张不可被响应的杀?').set('complexSelect',true).set('filterTarget',function(card,player,target){
if(target!=_status.event.sourcex&&!ui.selected.targets.contains(_status.event.sourcex)) return false;
return lib.filter.targetEnabled.apply(this,arguments);
}).set('sourcex',trigger.source).set('oncard',()=>{
_status.event.directHit.addArray(game.players);
});
break;
}
}
if(trigger.source&&trigger.source.isIn()&&player.hasHistory('gain',evt=>evt.getParent(2)==event.recast&&evt.cards.some(value=>get.name(value)=='sha'))){
player.chooseToUse(function(card){
if(get.name(card)!='sha') return false;
return lib.filter.filterCard.apply(this,arguments);
},'击逆:是否对'+get.translation(trigger.source)+'使用一张不可被响应的杀?').set('complexSelect',true).set('filterTarget',function(card,player,target){
if(target!=_status.event.sourcex&&!ui.selected.targets.contains(_status.event.sourcex)) return false;
return lib.filter.targetEnabled.apply(this,arguments);
}).set('sourcex',trigger.source).set('oncard',()=>{
_status.event.directHit.addArray(game.players);
});
}
},
subSkill:{

View File

@ -4149,18 +4149,10 @@ game.import('character',function(lib,game,ui,get,ai,_status){
reyanyu2:{
trigger:{player:'phaseUseEnd'},
direct:true,
filter:function(event,player){
return player.getHistory('lose',function(evt){
var evt2=evt.getParent();
return evt2.name=='useSkill'&&evt2.skill=='reyanyu'&&evt.getParent(3)==event;
}).length>0;
},
filter:(event,player)=>player.hasHistory('useSkill',evt=>evt.skill=='reyanyu'&&evt.event.getParent(2)==event),
content:function(){
'step 0'
event.num=Math.min(3,player.getHistory('lose',function(evt){
var evt2=evt.getParent();
return evt2.name=='useSkill'&&evt2.skill=='reyanyu'&&evt.getParent(3)==trigger;
}).length);
event.num=Math.min(3,player.getHistory('useSkill',evt=>evt.skill=='reyanyu'&&evt.event.getParent(2)==trigger).length);
player.chooseTarget(get.prompt('reyanyu'),'令一名男性角色摸'+get.cnNumber(event.num)+'张牌',function(card,player,target){
return target.hasSex('male')&&target!=player;
}).set('ai',function(target){

View File

@ -9714,9 +9714,11 @@
localStorage.removeItem(lib.configprefix+'background');
}
},
//by 诗笺
//by 诗笺、Tipx-L
parsex:function(func){
var str=func.toString();
//Remove all comments
//移除所有注释
var str=func.toString().replace(/((?:(?:^[ \t]*)?(?:\/\*[^*]*\*+(?:[^\/*][^*]*\*+)*\/(?:[ \t]*\r?\n(?=[ \t]*(?:\r?\n|\/\*|\/\/)))?|\/\/(?:[^\\]|\\(?:\r?\n)?)*?(?:\r?\n(?=[ \t]*(?:\r?\n|\/\*|\/\/))|(?=\r?\n))))+)|("(?:\\[\S\s]|[^"\\])*"|'(?:\\[\S\s]|[^'\\])*'|(?:\r?\n|[\S\s])[^\/"'\\\s]*)/mg,'$2').trim();
//获取第一个 { 后的所有字符
str=str.slice(str.indexOf('{')+1);
//func中要写步骤的话必须要写step 0
@ -9750,7 +9752,6 @@
}
str=`if(event.step==${k}){event.finish();return;}`+str;
}
str=`"use strict";\n${str}`;
return (new Function('event','step','source','player','target','targets',
'card','cards','skill','forced','num','trigger','result',
'_status','lib','game','ui','get','ai',str));
@ -10704,11 +10705,20 @@
recast:()=>{
'step 0'
game.log(player,'重铸了',cards);
if(typeof event.recastingLose=='function') event.recastingLose(player,cards);
if(typeof event.recastingLose=='function') event.recastingLostCards=event.recastingLose(player,cards);
'step 1'
event.trigger('recast');
'step 2'
if(typeof event.recastingGain=='function') event.recastingGain(player,cards);
if(typeof event.recastingGain!='function') return;
event.recastingGainedCards=event.recastingGain(player,cards);
if(get.itemtype(event.recastingGainedCards)=='card') event.recastingGainedCards=[event.recastingGainedCards];
'step 3'
event.result=[];
if(get.itemtype(event.recastingGainedCards)=='cards') event.result.addArray(event.recastingGainedCards);
if(get.itemtype(result.cards)=='card') event.result.push(result.cards);
else if(get.itemtype(result.cards)=='cards') event.result.addArray(result.cards);
if(get.itemtype(result)=='card') event.result.push(result);
else if(get.itemtype(result)=='cards') event.result.addArray(result);
},
//装备栏相关
disableEquip:function(){
@ -18263,7 +18273,7 @@
if(get.itemtype(cards)=='card') recast.cards=[cards];
else if(get.itemtype(cards)=='cards'&&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') recastingLose=(player,cards)=>player.loseToDiscardpile(cards).set("log",false).cards;
recast.recastingLose=recastingLose;
if(typeof recastingGain!='function') recastingGain=(player,cards)=>player.draw(cards.length).log=false;
recast.recastingGain=recastingGain;
@ -29943,30 +29953,39 @@
delay:false,
content:function(){
player.recast(cards,null,(player,cards)=>{
let numberOfCardsToDraw=cards.length;
var numberOfCardsToDraw=cards.length, cardsToGain=[];
cards.forEach(value=>{
if(lib.config.mode=='stone'&&_status.mode=='deck'&&!player.isMin()&&get.type(value).indexOf('stone')==0){
const stonecard=get.stonecard(1,player.career);
numberOfCardsToDraw--;
if(stonecard.length) player.gain(game.createCard(stonecard.randomGet()),'draw');
var stonecard=get.stonecard(1,player.career);
if(stonecard.length){
numberOfCardsToDraw-=stonecard.length;
var card=game.createCard(stonecard.randomGet());
player.gain(card,'draw');
cardsToGain.push(card);
}
else player.draw({
drawDeck:1
}).log=false;
}
else if(get.subtype(value)=='spell_gold'){
const libCard=get.libCard(info=>info.subtype=='spell_silver');
var libCard=get.libCard(info=>info.subtype=='spell_silver');
if(!libCard.length) return;
numberOfCardsToDraw--;
player.gain(game.createCard(libCard.randomGet()),'draw');
var card=game.createCard(libCard.randomGet());
player.gain(card,'draw');
cardsToGain.push(card);
}
else if(get.subtype(value)=='spell_silver'){
const libCard=get.libCard(info=>info.subtype=='spell_bronze');
var libCard=get.libCard(info=>info.subtype=='spell_bronze');
if(!libCard.length) return;
numberOfCardsToDraw--;
player.gain(game.createCard(libCard.randomGet()),'draw');
var card=game.createCard(libCard.randomGet());
player.gain(card,'draw');
cardsToGain.push(card);
}
});
if(numberOfCardsToDraw) player.draw(numberOfCardsToDraw).log=false;
return cardsToGain;
});
},
ai:{

View File

@ -1741,8 +1741,8 @@ div:not(.handcards)>.card>.info>span,
position: relative;
margin-top: 8px;
margin-bottom: 8px;
margin-left: 4px;
margin-right: 4px;
margin-left: auto;
margin-right: auto;
}
.content>.caption + .buttons:not(*:last-child){
margin-top: 0;