猜杀猜闪函数业务拓展

新增形参rvt: return value type
可选'count'(估算数量)
'odds'(估算有的概率,可能是布尔值)
‘bool'(默认猜有无)
This commit is contained in:
157 2023-12-21 00:07:59 +08:00
parent f7495db4b2
commit 1a5138d3df
1 changed files with 66 additions and 44 deletions

View File

@ -28796,59 +28796,81 @@ export class Library extends Uninstantable {
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)
if (get.itemtype(viewer) !== 'player') viewer = _status.event.player; let count=0;
let cards, selected = get.copy(ui.selected.cards); if((this.hp>2||!this.isZhu&&this.hp>1)&&this.hasSkillTag('respondSha',true,type,true)){
if (get.itemtype(ignore) === 'cards') selected.addArray(ignore); if(rvt==='count') count++;
else if (get.itemtype(ignore) === 'card') selected.add(ignore); else return true;
/*if(this===viewer||get.itemtype(viewer)==='player'&&viewer.hasSkillTag('viewHandcard',null,this,true)) cards=this.getCards('h');
else cards=this.getShownCards();*/
if (this === viewer || get.itemtype(viewer) == 'player') {
cards = this.getKnownCards(viewer);
} else {
cards = this.getShownCards();
} }
if (cards.some(card => { if(get.itemtype(viewer)!=='player') viewer=_status.event.player;
if (selected.includes(card)) return false; let cards,selected=get.copy(ui.selected.cards);
let name = get.name(card, this); if(get.itemtype(ignore)==='cards') selected.addArray(ignore);
if (name == 'sha' || name == 'hufu' || name == 'yuchanqian') { else if(get.itemtype(ignore)==='card') selected.add(ignore);
if (type === 'use') return lib.filter.cardEnabled(card, this); if(this === viewer || get.itemtype(viewer) == 'player') cards = this.getKnownCards(viewer);
if (type === 'respond') return lib.filter.cardRespondable(card, this); else cards = this.getShownCards();
count+=cards.filter(card=>{
if(selected.includes(card)) return false;
let name=get.name(card,this);
if(name=='sha'||name=='hufu'||name=='yuchanqian'){
if(type==='use') return lib.filter.cardEnabled(card,this);
if(type==='respond') return lib.filter.cardRespondable(card,this);
return true; return true;
} }
return false; return false;
})) return true; }).length;
let hs = this.getCards('hs').filter(i => !cards.includes(i) && !selected.includes(i)).length; if(count&&rvt!=='count') return true;
if (hs === 0) return false; let hs=this.getCards('hs').filter(i=>!cards.includes(i)&&!selected.includes(i)).length;
return Math.pow(hs + (this.isPhaseUsing() ? 6 : 4), 2) > 100 * _status.event.getRand('mayHaveSha'); if(!hs){
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) { mayHaveShan(viewer,type,ignore,rvt){
if ((this.hp > 2 || !this.isZhu && this.hp > 1) && this.hasSkillTag('respondShan', true, type, true)) return true; //rvt: return value type 'count', 'odds', 'bool'(default)
if (get.itemtype(viewer) !== 'player') viewer = _status.event.player; let count=0;
let cards, selected = get.copy(ui.selected.cards); if((this.hp>2||!this.isZhu&&this.hp>1)&&this.hasSkillTag('respondShan',true,type,true)){
if (get.itemtype(ignore) === 'cards') selected.addArray(ignore); if(rvt==='count') count++;
else if (get.itemtype(ignore) === 'card') selected.add(ignore); else return true;
/*if(this===viewer||get.itemtype(viewer)==='player'&&viewer.hasSkillTag('viewHandcard',null,this,true)) cards=this.getCards('h');
else cards=this.getShownCards();*/
if (this === viewer || get.itemtype(viewer) == 'player') {
cards = this.getKnownCards(viewer);
} else {
cards = this.getShownCards();
} }
if (cards.some(card => { if(get.itemtype(viewer)!=='player') viewer=_status.event.player;
if (selected.includes(card)) return false; let cards,selected=get.copy(ui.selected.cards);
let name = get.name(card, this); if(get.itemtype(ignore)==='cards') selected.addArray(ignore);
if (name === 'shan' || name === 'hufu') { else if(get.itemtype(ignore)==='card') selected.add(ignore);
if (type === 'use') return lib.filter.cardEnabled(card, this, 'forceEnable'); if(this === viewer || get.itemtype(viewer) == 'player') cards = this.getKnownCards(viewer);
if (type === 'respond') return lib.filter.cardRespondable(card, this); else cards = this.getShownCards();
count+=cards.filter(card=>{
if(selected.includes(card)) return false;
let name=get.name(card,this);
if(name==='shan'||name==='hufu'){
if(type==='use') return lib.filter.cardEnabled(card,this,'forceEnable');
if(type==='respond') return lib.filter.cardRespondable(card,this);
return true; return true;
} }
return false; return false;
})) return true; }).length;
let hs = this.getCards('hs').filter(i => !cards.includes(i) && !selected.includes(i)).length; if(count&&rvt!=='count') return true;
if (hs === 0) return false; let hs=this.getCards('hs').filter(i=>!cards.includes(i)&&!selected.includes(i)).length;
return Math.pow(hs + (this.isPhaseUsing() ? 3 : 5), 2) > 100 * _status.event.getRand('mayHaveShan'); if(!hs){
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') {