gameEventPromise新增forResult方法,用于优化解构赋值写法
This commit is contained in:
parent
8c6852093b
commit
276aad6c34
|
@ -1579,14 +1579,15 @@ game.import('character',function(lib,game,ui,get,ai,_status){
|
||||||
},
|
},
|
||||||
async content(event,trigger,player){
|
async content(event,trigger,player){
|
||||||
const target=event.target;
|
const target=event.target;
|
||||||
const {result:{control}}=await target.chooseControl('heart2','diamond2','club2','spade2').set('ai',event=>{
|
const control=await target.chooseControl('heart2','diamond2','club2','spade2').set('ai',event=>{
|
||||||
switch(Math.floor(Math.random()*6)){
|
switch(Math.floor(Math.random()*6)){
|
||||||
case 0:return 'heart2';
|
case 0:return 'heart2';
|
||||||
case 1:case 4:case 5:return 'diamond2';
|
case 1:case 4:case 5:return 'diamond2';
|
||||||
case 2:return 'club2';
|
case 2:return 'club2';
|
||||||
case 3:return 'spade2';
|
case 3:return 'spade2';
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.forResultControl();
|
||||||
game.log(target,'选择了'+get.translation(control));
|
game.log(target,'选择了'+get.translation(control));
|
||||||
event.choice=control;
|
event.choice=control;
|
||||||
target.chat('我选'+get.translation(event.choice));
|
target.chat('我选'+get.translation(event.choice));
|
||||||
|
@ -1641,7 +1642,7 @@ game.import('character',function(lib,game,ui,get,ai,_status){
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
async content(event,trigger,player){
|
async content(event,trigger,player){
|
||||||
const {result:{bool,targets,cards}}=await player.chooseCardTarget({
|
const [bool,targets,cards]=await player.chooseCardTarget({
|
||||||
position:'he',
|
position:'he',
|
||||||
filterCard:lib.filter.cardDiscardable,
|
filterCard:lib.filter.cardDiscardable,
|
||||||
filterTarget:(card,player,target)=>{
|
filterTarget:(card,player,target)=>{
|
||||||
|
@ -1671,7 +1672,9 @@ game.import('character',function(lib,game,ui,get,ai,_status){
|
||||||
prompt2:'弃置一张牌,将此【杀】转移给攻击范围内的一名其他角色',
|
prompt2:'弃置一张牌,将此【杀】转移给攻击范围内的一名其他角色',
|
||||||
source:trigger.player,
|
source:trigger.player,
|
||||||
card:trigger.card,
|
card:trigger.card,
|
||||||
}).setHiddenSkill(event.name);
|
})
|
||||||
|
.setHiddenSkill(event.name)
|
||||||
|
.forResult('bool','targets','cards');
|
||||||
if(bool){
|
if(bool){
|
||||||
const target=targets[0];
|
const target=targets[0];
|
||||||
player.logSkill(event.name,target);
|
player.logSkill(event.name,target);
|
||||||
|
@ -2210,7 +2213,7 @@ game.import('character',function(lib,game,ui,get,ai,_status){
|
||||||
async content(event,trigger,player){
|
async content(event,trigger,player){
|
||||||
const list=['弃牌','摸牌','取消'];
|
const list=['弃牌','摸牌','取消'];
|
||||||
if(!player.countCards('he')) list.remove('弃牌');
|
if(!player.countCards('he')) list.remove('弃牌');
|
||||||
const {result:{control}}=await player.chooseControl(list,()=>{
|
const control=await player.chooseControl(list,()=>{
|
||||||
const player=_status.event.player;
|
const player=_status.event.player;
|
||||||
if(list.includes('弃牌')){
|
if(list.includes('弃牌')){
|
||||||
if(player.countCards('h')>3&&player.countCards('h','sha')>1){
|
if(player.countCards('h')>3&&player.countCards('h','sha')>1){
|
||||||
|
@ -2224,7 +2227,10 @@ game.import('character',function(lib,game,ui,get,ai,_status){
|
||||||
return '摸牌';
|
return '摸牌';
|
||||||
}
|
}
|
||||||
return 'cancel2';
|
return 'cancel2';
|
||||||
}).set('prompt',get.prompt2('new_jiangchi'));
|
})
|
||||||
|
.set('prompt',get.prompt2('new_jiangchi'))
|
||||||
|
.forResultControl();
|
||||||
|
|
||||||
if(control=='弃牌'){
|
if(control=='弃牌'){
|
||||||
player.chooseToDiscard(true,'he');
|
player.chooseToDiscard(true,'he');
|
||||||
player.addTempSkill('jiangchi2','phaseUseEnd');
|
player.addTempSkill('jiangchi2','phaseUseEnd');
|
||||||
|
|
|
@ -162,4 +162,95 @@ export class GameEventPromise extends Promise {
|
||||||
game.promises.prompt('debugger调试').then(inputCallback);
|
game.promises.prompt('debugger调试').then(inputCallback);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 直接获得result中的信息。
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ①
|
||||||
|
* let chooseCardResult = await player.chooseCard().forResult();
|
||||||
|
* 选择的卡牌:chooseCardResult.cards
|
||||||
|
* ②
|
||||||
|
* let cards = await player.chooseCard().forResult('cards');
|
||||||
|
* 选择的卡牌:cards
|
||||||
|
* ③
|
||||||
|
* let [success,cards,targets] = await player.chooseCardTarget().forResult('bool','cards','targets');
|
||||||
|
* success:是否做出选择。
|
||||||
|
* cards:选择的牌。
|
||||||
|
* targets:选择的目标。
|
||||||
|
*/
|
||||||
|
forResult(){
|
||||||
|
if(arguments.length == 0){
|
||||||
|
return this.then(event=>{
|
||||||
|
return Promise.resolve(event.result);
|
||||||
|
});
|
||||||
|
}else if(arguments.length == 1){
|
||||||
|
return this.then(event=>{
|
||||||
|
return Promise.resolve(event.result[arguments[0]]);
|
||||||
|
});
|
||||||
|
}else{
|
||||||
|
return this.then(event=>{
|
||||||
|
return Promise.resolve(Array.from(arguments).map(key=>event.result[key]));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回result中的bool项。
|
||||||
|
*
|
||||||
|
* @returns {boolean} 返回的bool项
|
||||||
|
*/
|
||||||
|
forResultBool(){
|
||||||
|
return this.forResult('bool');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回result中的targets项。
|
||||||
|
*
|
||||||
|
* @returns {lib.element.Player[]} 返回的targets项。
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
forResultTargets(){
|
||||||
|
return this.forResult('targets');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回result中的cards项
|
||||||
|
*
|
||||||
|
* @returns {lib.element.Card[]} 返回的cards项。
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
forResultCards(){
|
||||||
|
return this.forResult('cards');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回result中的card项
|
||||||
|
*
|
||||||
|
* @returns {lib.element.VCard|lib.element.Card} 返回的card项。
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
forResultCard(){
|
||||||
|
return this.forResult('card');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回result中的control项。
|
||||||
|
*
|
||||||
|
* @returns {string} 返回的control项。
|
||||||
|
*/
|
||||||
|
forResultControl(){
|
||||||
|
return this.forResult('control');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回result中的links项。
|
||||||
|
*
|
||||||
|
* @returns {Array<?>} 返回的links项。
|
||||||
|
*/
|
||||||
|
forResultLinks(){
|
||||||
|
return this.forResult('links');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue