Merge pull request #594 from universe-st/PR-Branch-k

添加知情牌机制,辅助AI判断行动收益。
This commit is contained in:
Spmario233 2023-10-28 15:04:49 +08:00 committed by GitHub
commit 1ed20090a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 113 additions and 5 deletions

View File

@ -242,6 +242,17 @@ game.import('card',function(lib,game,ui,get,ai,_status){
target:function(player,target){ target:function(player,target){
if(target.hasSkill('huogong2')||target.countCards('h')==0) return 0; if(target.hasSkill('huogong2')||target.countCards('h')==0) return 0;
if(player.countCards('h')<=1) return 0; if(player.countCards('h')<=1) return 0;
if(_status.event.player == player){
if(target.isAllCardsKnown(player)){
if(!target.countCards('h',card=>{
return player.countCards('h',card2=>{
return get.suit(card2) == get.suit(card);
});
})){
return 0;
}
}
}
if(target==player){ if(target==player){
if(typeof _status.event.filterCard=='function'&& if(typeof _status.event.filterCard=='function'&&
_status.event.filterCard({name:'huogong'},player,_status.event)){ _status.event.filterCard({name:'huogong'},player,_status.event)){

View File

@ -18050,6 +18050,7 @@
else{ else{
game.log(player,'展示了',cards); game.log(player,'展示了',cards);
} }
game.addCardKnower(cards,'everyone');
game.delayx(event.delay_time||2.5); game.delayx(event.delay_time||2.5);
game.addVideo('showCards',player,[event.str,get.cardsInfo(cards)]); game.addVideo('showCards',player,[event.str,get.cardsInfo(cards)]);
"step 1" "step 1"
@ -18058,6 +18059,7 @@
}, },
viewCards:function(){ viewCards:function(){
"step 0" "step 0"
game.addCardKnower(event.cards,player);
if(player==game.me){ if(player==game.me){
event.dialog=ui.create.dialog(event.str,event.cards); event.dialog=ui.create.dialog(event.str,event.cards);
if(event.isMine()){ if(event.isMine()){
@ -19256,7 +19258,9 @@
for(var i in map){ for(var i in map){
var owner=(_status.connectMode?lib.playerOL:game.playerMap)[i]; var owner=(_status.connectMode?lib.playerOL:game.playerMap)[i];
var next=owner.lose(map[i][0],ui.special).set('type','gain').set('forceDie',true).set('getlx',false); var next=owner.lose(map[i][0],ui.special).set('type','gain').set('forceDie',true).set('getlx',false);
if(event.visible==true) next.visible=true; if(event.visible==true){
next.visible=true;
}
event.relatedLose=next; event.relatedLose=next;
} }
} }
@ -19276,6 +19280,8 @@
var hs=source.getCards('hejsx'); var hs=source.getCards('hejsx');
if(hs.contains(cards[i])){ if(hs.contains(cards[i])){
cards.splice(i--,1); cards.splice(i--,1);
}else{
cards[i].addKnower(event.visible?'everyone':source);
} }
} }
} }
@ -19768,6 +19774,10 @@
event.js=js; event.js=js;
event.ss=ss; event.ss=ss;
event.xs=xs; event.xs=xs;
game.clearCardKnowers(hs);
if(hs.length && !event.visible){
this.getCards('h').forEach(hcard=>{hcard.clearKnowers();});
}
"step 2" "step 2"
if(num<cards.length){ if(num<cards.length){
if(event.es.contains(cards[num])){ if(event.es.contains(cards[num])){
@ -20610,6 +20620,8 @@
for(i=0;i<bottom.length;i++){ for(i=0;i<bottom.length;i++){
ui.cardPile.appendChild(bottom[i]); ui.cardPile.appendChild(bottom[i]);
} }
game.addCardKnower(top,player);
game.addCardKnower(bottom,player);
player.popup(get.cnNumber(top.length)+'上'+get.cnNumber(bottom.length)+'下'); player.popup(get.cnNumber(top.length)+'上'+get.cnNumber(bottom.length)+'下');
game.log(player,'将'+get.cnNumber(top.length)+'张牌置于牌堆顶'); game.log(player,'将'+get.cnNumber(top.length)+'张牌置于牌堆顶');
game.updateRoundNumber(); game.updateRoundNumber();
@ -20973,6 +20985,32 @@
return get.is.shownCard(card); return get.is.shownCard(card);
}); });
} }
//获取该角色被other所知的牌。
getKnownCards(other,filter){
if(!other)other = _status.event.player;
if(!other)other = this;
if(!filter)filter = (card)=>{return true};
return this.getCards('h',function(card){
return card.isKnownBy(other) && filter(card);
});
}
//判断此角色的手牌是否已经被看光了。
isAllCardsKnown(other){
if(!other)other = _status.event.player;
if(!other)other = this;
return this.countCards('h',function(card){
return !card.isKnownBy(other);
}) == 0;
}
//判断此角色是否有被知的牌。
hasKnownCards(other,filter){
if(!other)other = _status.event.player;
if(!other)other = this;
if(!filter)filter = (card)=>{return true};
return this.countCards('h',function(card){
return card.isKnownBy(other) && filter(card);
}) > 0;
}
//Execute the delay card effect //Execute the delay card effect
//执行延时锦囊牌效果 //执行延时锦囊牌效果
executeDelayCardEffect(card,target,judge,judge2){ executeDelayCardEffect(card,target,judge,judge2){
@ -28354,8 +28392,13 @@
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'&&viewer.hasSkillTag('viewHandcard',null,this,true)) cards=this.getCards('h');
else cards=this.getShownCards(); else cards=this.getShownCards();*/
if(this === viewer || get.itemtype(viewer) == 'player'){
cards = this.getKnownCards(viewer);
}else{
cards = this.getShownCards();
}
if(cards.some(card=>{ 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);
@ -28376,8 +28419,13 @@
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'&&viewer.hasSkillTag('viewHandcard',null,this,true)) cards=this.getCards('h');
else cards=this.getShownCards(); else cards=this.getShownCards();*/
if(this === viewer || get.itemtype(viewer) == 'player'){
cards = this.getKnownCards(viewer);
}else{
cards = this.getShownCards();
}
if(cards.some(card=>{ 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);
@ -30522,6 +30570,41 @@
aiexclude(){ aiexclude(){
_status.event._aiexclude.add(this); _status.event._aiexclude.add(this);
} }
//为此牌添加知情者。参数可为数组,若参数为字符串'everyone',则所有玩家均为知情者。
addKnower(player){
if(!this._knowers){
this._knowers = [];
}
if(typeof player == 'string'){
this._knowers.add(player);
}else{
let type = get.itemtype(player);
if(type == 'player'){
this._knowers.add(player.playerid);
}else if(type == 'players'){
player.forEach(p=>this._knowers.add(p.playerid));
}
}
}
//清除此牌的知情者。
clearKnowers(){
if(this._knowers)delete this._knowers;
}
//判断玩家对此牌是否知情。
isKnownBy(player){
if(['e','j'].includes(get.position(this)))return true;//装备区或者判定区的牌,必知情。
let owner = get.owner(this);
if(owner){
if(owner == player)return true;//是牌主,必知情。
if(player.hasSkillTag('viewHandcard',null,owner,true))return true;//有viewHandcard标签必知情。
if(owner.isUnderControl(true,player))return true;//被操控,必知情。
}
if(get.is.shownCard(this))return true;//此牌是明置牌,必知情。
if(this._knowers){
return this._knowers.includes('everyone') || this._knowers.includes(player.playerid);
}
return false;
}
getSource(name){ getSource(name){
if(this.name==name) return true; if(this.name==name) return true;
var info=lib.card[this.name]; var info=lib.card[this.name];
@ -36146,6 +36229,20 @@
if(i.storage.renku) i.markSkill('renku'); if(i.storage.renku) i.markSkill('renku');
} }
}, },
//为牌添加知情者。
addCardKnower:function(cards,players){
if(get.itemtype(cards) == 'card'){
cards = [cards];
}
cards.forEach(card=>card.addKnower(players));
},
//移除牌的所有知情者。
clearCardKnowers:function(cards){
if(get.itemtype(cards) == 'card'){
cards = [cards];
}
cards.forEach(card=>card.clearKnowers());
},
loseAsync:function(arg){ loseAsync:function(arg){
var next=game.createEvent('loseAsync'); var next=game.createEvent('loseAsync');
next.forceDie=true; next.forceDie=true;