From 92bee0717ed22a2bb307d78f3c5ec04db6256a45 Mon Sep 17 00:00:00 2001 From: kuangthree Date: Sat, 20 Jan 2024 11:11:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Egame.doAsyncInOrder=E6=96=B9?= =?UTF-8?q?=E6=B3=95=EF=BC=8C=E5=B9=B6=E4=BF=AE=E6=94=B9=E5=AD=99=E4=BC=91?= =?UTF-8?q?=E2=80=9C=E5=85=B4=E5=AD=A6=E2=80=9D=E4=B8=BA=E8=8C=83=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- character/yijiang.js | 71 ++++++++++++++++---------------------------- noname/game/index.js | 16 ++++++++++ 2 files changed, 42 insertions(+), 45 deletions(-) diff --git a/character/yijiang.js b/character/yijiang.js index 17b91c55f..bbdd467a1 100755 --- a/character/yijiang.js +++ b/character/yijiang.js @@ -8067,60 +8067,41 @@ game.import('character',function(lib,game,ui,get,ai,_status){ audio:2, trigger:{player:'phaseJieshuBegin'}, direct:true, - content:function(){ - 'step 0' + async content(event,trigger,player){ var num=player.hp; if(!player.hasSkill('yanzhu')){ num=player.maxHp; } - player.chooseTarget([1,num],get.prompt2('xingxue')).set('ai',function(target){ + const {result:{targets,bool}}= + await player.chooseTarget([1,num],get.prompt2('xingxue')).set('ai',function(target){ var att=get.attitude(_status.event.player,target); if(target.countCards('he')) return att; return att/10; }); - 'step 1' - if(result.bool){ - player.logSkill('xingxue',result.targets); - event.targets=result.targets; - event.targets.sort(lib.sort.seat); + if(bool){ + player.logSkill('xingxue',targets); + const chooseToPutCard = async function(target){ + await target.draw(); + if(target.countCards('he')){ + const {result:{cards,bool}} = + await target.chooseCard('选择一张牌置于牌堆顶','he',true); + if(bool){ + await target.lose(cards,ui.cardPile,'insert'); + } + game.broadcastAll(function(player){ + var cardx=ui.create.card(); + cardx.classList.add('infohidden'); + cardx.classList.add('infoflip'); + player.$throw(cardx,1000,'nobroadcast'); + },target); + if(player == game.me){ + game.delay(0.5); + } + } + }; + await game.doAsyncInOrder(targets,chooseToPutCard); } - else{ - event.finish(); - } - 'step 2' - if(event.targets.length){ - var target=event.targets.shift(); - target.draw(); - event.current=target; - } - else{ - event.finish(); - } - 'step 3' - if(event.current&&event.current.countCards('he')){ - event.current.chooseCard('选择一张牌置于牌堆顶','he',true); - } - else{ - event.goto(2); - } - 'step 4' - if(result&&result.cards){ - event.card=result.cards[0]; - event.current.lose(result.cards,ui.cardPile,'insert'); - game.broadcastAll(function(player){ - var cardx=ui.create.card(); - cardx.classList.add('infohidden'); - cardx.classList.add('infoflip'); - player.$throw(cardx,1000,'nobroadcast'); - },event.current); - } - else{ - event.card=null; - } - 'step 5' - if(event.current==game.me) game.delay(0.5); - event.goto(2); - } + }, }, yanzhu:{ audio:2, diff --git a/noname/game/index.js b/noname/game/index.js index 39e03eaf5..70a8799d2 100644 --- a/noname/game/index.js +++ b/noname/game/index.js @@ -8434,6 +8434,22 @@ export class Game extends Uninstantable { return true; }); } + + /** + * 此方法用于对所有targets按顺序执行一个async函数。 + * + * @param { Player[] } targets 需要执行async方法的目标 + * @param { AsyncFunction } asyncFunc 需要执行的async方法 + * @param { sort } function 排序器,默认为lib.sort.seat + */ + static async doAsyncInOrder(targets,asyncFunc,sort){ + if(!sort)sort = lib.sort.seat; + let sortedTargets = targets.sort(sort); + for(let i=0;i