猜杀猜闪函数业务拓展

新增形参rvt: return value type
可选'count'(估算数量)
'odds'(估算有的概率,可能是布尔值)
‘bool'(默认猜有无)
This commit is contained in:
PZ157 2023-12-04 17:27:51 +08:00
parent 6b2d351092
commit e20fb88219
1 changed files with 48 additions and 26 deletions

View File

@ -28790,20 +28790,20 @@ new Promise(resolve=>{
if(this.hasSkillTag('respondShan',true,null,true)) return true; if(this.hasSkillTag('respondShan',true,null,true)) return true;
return this.hasUsableCard('shan'); return this.hasUsableCard('shan');
} }
mayHaveSha(viewer,type,ignore){ mayHaveSha(viewer,type,ignore,rvt){
if((this.hp>2||!this.isZhu&&this.hp>1)&&this.hasSkillTag('respondSha',true,type,true)) return true; //rvt: return value type 'count', 'odds', 'bool'(default)
let count=0;
if((this.hp>2||!this.isZhu&&this.hp>1)&&this.hasSkillTag('respondSha',true,type,true)){
if(rvt==='count') count++;
else return true;
}
if(get.itemtype(viewer)!=='player') viewer=_status.event.player; if(get.itemtype(viewer)!=='player') viewer=_status.event.player;
let cards,selected=get.copy(ui.selected.cards); let cards,selected=get.copy(ui.selected.cards);
if(get.itemtype(ignore)==='cards') selected.addArray(ignore); if(get.itemtype(ignore)==='cards') selected.addArray(ignore);
else if(get.itemtype(ignore)==='card') selected.add(ignore); else if(get.itemtype(ignore)==='card') selected.add(ignore);
/*if(this===viewer||get.itemtype(viewer)==='player'&&viewer.hasSkillTag('viewHandcard',null,this,true)) cards=this.getCards('h'); if(this === viewer || get.itemtype(viewer) == 'player') cards = this.getKnownCards(viewer);
else cards=this.getShownCards();*/ else cards = this.getShownCards();
if(this === viewer || get.itemtype(viewer) == 'player'){ count+=cards.filter(card=>{
cards = this.getKnownCards(viewer);
}else{
cards = this.getShownCards();
}
if(cards.some(card=>{
if(selected.includes(card)) return false; if(selected.includes(card)) return false;
let name=get.name(card,this); let name=get.name(card,this);
if(name=='sha'||name=='hufu'||name=='yuchanqian'){ if(name=='sha'||name=='hufu'||name=='yuchanqian'){
@ -28812,25 +28812,36 @@ new Promise(resolve=>{
return true; return true;
} }
return false; return false;
})) return true; }).length;
if(count&&rvt!=='count') return true;
let hs=this.getCards('hs').filter(i=>!cards.includes(i)&&!selected.includes(i)).length; let hs=this.getCards('hs').filter(i=>!cards.includes(i)&&!selected.includes(i)).length;
if(hs===0) return false; if(!hs){
return Math.pow(hs+(this.isPhaseUsing()?6:4),2)>100*_status.event.getRand('mayHaveSha'); if(rvt==='count') return count;
return false;
}
if(rvt==='count'){
if(this.isPhaseUsing()) return count+hs/4;
return count+hs/4.8;
}
if(this.isPhaseUsing()) count+=Math.pow(2+hs,2)/40;
else count+=-1.5*Math.log(1-hs/10);
if(rvt==='odds') return Math.min(1,count);
return count>_status.event.getRand('mayHaveSha'+hs+this.playerid);
}
mayHaveShan(viewer,type,ignore,rvt){
//rvt: return value type 'count', 'odds', 'bool'(default)
let count=0;
if((this.hp>2||!this.isZhu&&this.hp>1)&&this.hasSkillTag('respondShan',true,type,true)){
if(rvt==='count') count++;
else return true;
} }
mayHaveShan(viewer,type,ignore){
if((this.hp>2||!this.isZhu&&this.hp>1)&&this.hasSkillTag('respondShan',true,type,true)) return true;
if(get.itemtype(viewer)!=='player') viewer=_status.event.player; if(get.itemtype(viewer)!=='player') viewer=_status.event.player;
let cards,selected=get.copy(ui.selected.cards); let cards,selected=get.copy(ui.selected.cards);
if(get.itemtype(ignore)==='cards') selected.addArray(ignore); if(get.itemtype(ignore)==='cards') selected.addArray(ignore);
else if(get.itemtype(ignore)==='card') selected.add(ignore); else if(get.itemtype(ignore)==='card') selected.add(ignore);
/*if(this===viewer||get.itemtype(viewer)==='player'&&viewer.hasSkillTag('viewHandcard',null,this,true)) cards=this.getCards('h'); if(this === viewer || get.itemtype(viewer) == 'player') cards = this.getKnownCards(viewer);
else cards=this.getShownCards();*/ else cards = this.getShownCards();
if(this === viewer || get.itemtype(viewer) == 'player'){ count+=cards.filter(card=>{
cards = this.getKnownCards(viewer);
}else{
cards = this.getShownCards();
}
if(cards.some(card=>{
if(selected.includes(card)) return false; if(selected.includes(card)) return false;
let name=get.name(card,this); let name=get.name(card,this);
if(name==='shan'||name==='hufu'){ if(name==='shan'||name==='hufu'){
@ -28839,10 +28850,21 @@ new Promise(resolve=>{
return true; return true;
} }
return false; return false;
})) return true; }).length;
if(count&&rvt!=='count') return true;
let hs=this.getCards('hs').filter(i=>!cards.includes(i)&&!selected.includes(i)).length; let hs=this.getCards('hs').filter(i=>!cards.includes(i)&&!selected.includes(i)).length;
if(hs===0) return false; if(!hs){
return Math.pow(hs+(this.isPhaseUsing()?3:5),2)>100*_status.event.getRand('mayHaveShan'); if(rvt==='count') return count;
return false;
}
if(rvt==='count'){
if(this.isPhaseUsing()) return count+hs/6;
return count+hs/3.5;
}
if(this.isPhaseUsing()) count+=-1.5*Math.log(1-hs/10);
else count+=2*hs/(5+hs);
if(rvt==='odds') return Math.min(1,count);
return count>_status.event.getRand('mayHaveShan'+hs+this.playerid);
} }
hasCard(name,position){ hasCard(name,position){
if(typeof name=='function'){ if(typeof name=='function'){