Merge pull request #714 from nonameShijian/PR-Branch
增加异步content以及GameEvent#toPromise,郭嘉和二张作为测试
This commit is contained in:
commit
909d62982e
|
@ -3952,9 +3952,9 @@ game.import('character',function(lib,game,ui,get,ai,_status){
|
||||||
if(target.isMin()) return false;
|
if(target.isMin()) return false;
|
||||||
return player!=target&&target.canEquip(card);
|
return player!=target&&target.canEquip(card);
|
||||||
},
|
},
|
||||||
content:function(){
|
async content(event, trigger, player){
|
||||||
target.equip(cards[0]);
|
await event.target.promises.equip(event.cards[0]);
|
||||||
player.draw();
|
await player.promises.draw();
|
||||||
},
|
},
|
||||||
discard:false,
|
discard:false,
|
||||||
lose:false,
|
lose:false,
|
||||||
|
|
|
@ -586,77 +586,72 @@ game.import('character',function(lib,game,ui,get,ai,_status){
|
||||||
trigger:{player:'damageEnd'},
|
trigger:{player:'damageEnd'},
|
||||||
frequent:true,
|
frequent:true,
|
||||||
filter:function(event){
|
filter:function(event){
|
||||||
return (event.num>0)
|
return event.num>0;
|
||||||
},
|
},
|
||||||
content:function(){
|
async content(event, trigger, player) {
|
||||||
'step 0'
|
event.count = trigger.num;
|
||||||
event.count=trigger.num;
|
// event.goto -> while
|
||||||
'step 1'
|
while (event.count > 0) {
|
||||||
event.count--;
|
event.count--;
|
||||||
event.cards=game.cardsGotoOrdering(get.cards(2)).cards;
|
const { cards } = await game.cardsGotoOrdering(get.cards(2)).toPromise();
|
||||||
if(_status.connectMode) game.broadcastAll(function(){_status.noclearcountdown=true});
|
if (_status.connectMode) game.broadcastAll(function () { _status.noclearcountdown = true });
|
||||||
event.given_map={};
|
event.given_map = {};
|
||||||
'step 2'
|
if (!cards.length) return;
|
||||||
if(event.cards.length>1){
|
// event.goto -> do while
|
||||||
player.chooseCardButton('遗计:请选择要分配的牌',true,event.cards,[1,event.cards.length]).set('ai',function(button){
|
do {
|
||||||
if(ui.selected.buttons.length==0) return 1;
|
const { result: { bool, links } } =
|
||||||
|
cards.length == 1 ?
|
||||||
|
{ result: { links: cards.slice(0), bool: true } } :
|
||||||
|
await player.promises.chooseCardButton('遗计:请选择要分配的牌', true, cards, [1, cards.length])
|
||||||
|
.set('ai', function (button) {
|
||||||
|
if (ui.selected.buttons.length == 0) return 1;
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
}
|
if (!bool) return;
|
||||||
else if(event.cards.length==1){
|
cards.removeArray(links);
|
||||||
event._result={links:event.cards.slice(0),bool:true};
|
event.togive = links.slice(0);
|
||||||
}
|
const { result: { targets } } = await player.promises.chooseTarget('选择一名角色获得' + get.translation(links), true)
|
||||||
else{
|
.set('ai', function (target) {
|
||||||
event.finish();
|
var att = get.attitude(_status.event.player, target);
|
||||||
}
|
if (_status.event.enemy) {
|
||||||
'step 3'
|
|
||||||
if(result.bool){
|
|
||||||
event.cards.removeArray(result.links);
|
|
||||||
event.togive=result.links.slice(0);
|
|
||||||
player.chooseTarget('选择一名角色获得'+get.translation(result.links),true).set('ai',function(target){
|
|
||||||
var att=get.attitude(_status.event.player,target);
|
|
||||||
if(_status.event.enemy){
|
|
||||||
return -att;
|
return -att;
|
||||||
}
|
}
|
||||||
else if(att>0){
|
else if (att > 0) {
|
||||||
return att/(1+target.countCards('h'));
|
return att / (1 + target.countCards('h'));
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
return att/100;
|
return att / 100;
|
||||||
}
|
}
|
||||||
}).set('enemy',get.value(event.togive[0],player,'raw')<0);
|
})
|
||||||
}
|
.set('enemy', get.value(event.togive[0], player, 'raw') < 0);
|
||||||
'step 4'
|
if (targets.length) {
|
||||||
if(result.targets.length){
|
const id = targets[0].playerid,
|
||||||
var id=result.targets[0].playerid,map=event.given_map;
|
map = event.given_map;
|
||||||
if(!map[id]) map[id]=[];
|
if (!map[id]) map[id] = [];
|
||||||
map[id].addArray(event.togive);
|
map[id].addArray(event.togive);
|
||||||
}
|
}
|
||||||
if(cards.length>0) event.goto(2);
|
} while (cards.length > 0);
|
||||||
'step 5'
|
if (_status.connectMode) {
|
||||||
if(_status.connectMode){
|
game.broadcastAll(function () { delete _status.noclearcountdown; game.stopCountChoose() });
|
||||||
game.broadcastAll(function(){delete _status.noclearcountdown;game.stopCountChoose()});
|
|
||||||
}
|
}
|
||||||
var list=[];
|
const list = [];
|
||||||
for(var i in event.given_map){
|
for (const i in event.given_map) {
|
||||||
var source=(_status.connectMode?lib.playerOL:game.playerMap)[i];
|
const source = (_status.connectMode ? lib.playerOL : game.playerMap)[i];
|
||||||
player.line(source,'green');
|
player.line(source, 'green');
|
||||||
list.push([source,event.given_map[i]]);
|
list.push([source, event.given_map[i]]);
|
||||||
}
|
}
|
||||||
game.loseAsync({
|
await game.loseAsync({
|
||||||
gain_list:list,
|
gain_list: list,
|
||||||
giver:player,
|
giver: player,
|
||||||
animate:'draw',
|
animate: 'draw',
|
||||||
}).setContent('gaincardMultiple');
|
}).toPromise().setContent('gaincardMultiple');
|
||||||
'step 6'
|
if (event.count > 0 && player.hasSkill(event.name) && !get.is.blocked(event.name, player)) {
|
||||||
if(event.count>0&&player.hasSkill(event.name)&&!get.is.blocked(event.name,player)){
|
const { result: { bool: repeat } } = await player.promises.chooseBool(get.prompt2(event.name)).set('frequentSkill', event.name);
|
||||||
player.chooseBool(get.prompt2(event.name)).set('frequentSkill',event.name);
|
if (repeat) {
|
||||||
}
|
|
||||||
else event.finish();
|
|
||||||
'step 7'
|
|
||||||
if(result.bool){
|
|
||||||
player.logSkill(event.name);
|
player.logSkill(event.name);
|
||||||
event.goto(1);
|
} else return;
|
||||||
|
}
|
||||||
|
else return;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ai:{
|
ai:{
|
||||||
|
|
434
game/game.js
434
game/game.js
|
@ -47,6 +47,7 @@ new Promise(resolve=>{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const GeneratorFunction=(function*(){}).constructor;
|
const GeneratorFunction=(function*(){}).constructor;
|
||||||
|
const AsyncFunction=(async function(){}).constructor;
|
||||||
// gnc: GeNCoroutine
|
// gnc: GeNCoroutine
|
||||||
const gnc={
|
const gnc={
|
||||||
of:fn=>gnc.is.generatorFunc(fn)?function genCoroutine(){
|
of:fn=>gnc.is.generatorFunc(fn)?function genCoroutine(){
|
||||||
|
@ -21030,6 +21031,22 @@ new Promise(resolve=>{
|
||||||
};
|
};
|
||||||
player.queueCount=0;
|
player.queueCount=0;
|
||||||
player.outCount=0;
|
player.outCount=0;
|
||||||
|
/**
|
||||||
|
* 这部分应该用d.ts写。目前只给出大概类型
|
||||||
|
* @type { {[key in keyof Player]: (...args) => Promise<GameEvent> & GameEvent} }
|
||||||
|
*/
|
||||||
|
player.promises=new Proxy({},{
|
||||||
|
get(target,prop){
|
||||||
|
const eventKeys=Object.keys(lib.element.player).filter(key=>typeof lib.element.player[key]=='function');
|
||||||
|
if (eventKeys.includes(prop)){
|
||||||
|
return function (...args) {
|
||||||
|
/** @type { GameEvent } */
|
||||||
|
const event=player[prop](...args);
|
||||||
|
return event.toPromise();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
buildEventListener(noclick){
|
buildEventListener(noclick){
|
||||||
let player = this;
|
let player = this;
|
||||||
|
@ -31288,6 +31305,14 @@ new Promise(resolve=>{
|
||||||
this._notrigger=[];
|
this._notrigger=[];
|
||||||
this._result={};
|
this._result={};
|
||||||
this._set=[];
|
this._set=[];
|
||||||
|
/**
|
||||||
|
* @type {boolean} 这个事件是否使用异步函数处理
|
||||||
|
**/
|
||||||
|
this.async=false;
|
||||||
|
/**
|
||||||
|
* @type {null|(event: GameEvent)=>any} 这个异步事件对应Promise的resolve函数
|
||||||
|
**/
|
||||||
|
this.resolve=null;
|
||||||
if(trigger!==false&&!game.online) this._triggered=0;
|
if(trigger!==false&&!game.online) this._triggered=0;
|
||||||
}
|
}
|
||||||
static initialGameEvent(){
|
static initialGameEvent(){
|
||||||
|
@ -31517,7 +31542,10 @@ new Promise(resolve=>{
|
||||||
switch(typeof item){
|
switch(typeof item){
|
||||||
case "object":
|
case "object":
|
||||||
case "function":
|
case "function":
|
||||||
this.content=lib.init.parsex(item);
|
if(item instanceof AsyncFunction){
|
||||||
|
this.content=item;
|
||||||
|
}
|
||||||
|
else this.content=lib.init.parsex(item);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
try{
|
try{
|
||||||
|
@ -32073,6 +32101,114 @@ new Promise(resolve=>{
|
||||||
this.unreal;
|
this.unreal;
|
||||||
throw new Error('Do not call this method');
|
throw new Error('Do not call this method');
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 事件转为Promise化
|
||||||
|
*
|
||||||
|
* @returns { Promise<GameEvent> & GameEvent }
|
||||||
|
*/
|
||||||
|
toPromise(){
|
||||||
|
if(this.async&&this.resolve){
|
||||||
|
throw new TypeError('This event has been converted into a promise');
|
||||||
|
}
|
||||||
|
return new lib.element.GameEventPromise(this);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 将事件Promise化以使用async异步函数来执行事件。
|
||||||
|
*
|
||||||
|
* 事件Promise化后,需要既能使用await等待事件完成,
|
||||||
|
* 又需要在执行之前对事件进行配置。
|
||||||
|
*
|
||||||
|
* 所以这个类的实例集成了事件和Promise二者的所有属性,
|
||||||
|
* 且Promise的原有属性无法被修改,一切对这个类实例的属性修改,删除,
|
||||||
|
* 再配置等操作都会转发到事件对应的属性中。
|
||||||
|
*
|
||||||
|
* @todo 需要完成异步事件的debugger方法
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* 使用toPromise()函数将普通事件转换为异步事件:
|
||||||
|
* ```js
|
||||||
|
* await game.xxx().toPromise().setContent('yyy').set(zzz, 'i');
|
||||||
|
* ```
|
||||||
|
* 使用player.promises.xxx()函数将对于player的普通事件转换为异步事件并执行:
|
||||||
|
* ```js
|
||||||
|
* await player.promises.draw(2);
|
||||||
|
* game.log('等待', player, '摸牌完成执行log');
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
GameEventPromise:class extends Promise{
|
||||||
|
// 我谢谢你,这里是必须有的
|
||||||
|
// 否则Promise的方法对其子类无效
|
||||||
|
static get [Symbol.species]() {
|
||||||
|
return Promise;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @param { GameEvent } event
|
||||||
|
* @returns { Promise<GameEvent> & GameEvent }
|
||||||
|
*/
|
||||||
|
constructor(event){
|
||||||
|
super(resolve=>{
|
||||||
|
// 设置为异步事件
|
||||||
|
event.async=true;
|
||||||
|
// 事件结束后触发resolve
|
||||||
|
event.resolve=resolve;
|
||||||
|
// 如果父级事件也是一个异步的话,那应该立即执行这个事件的
|
||||||
|
// 如果在AsyncFunction执行过程中在别的位置新建了一个异步事件,那也直接(等会set配置完)执行
|
||||||
|
if(_status.event.next.includes(event)&&_status.event.content instanceof AsyncFunction){
|
||||||
|
if (_status.event!=event) {
|
||||||
|
event.parent=_status.event;
|
||||||
|
_status.event=event;
|
||||||
|
game.getGlobalHistory('everything').push(event);
|
||||||
|
}
|
||||||
|
// 异步执行game.loop
|
||||||
|
// 不直接game.loop(event)是因为需要让别人可以手动set()和setContent()
|
||||||
|
// 再执行game.loop是因为原有的game.loop被await卡住了,
|
||||||
|
// 得新执行一个只执行这个异步事件的game.loop
|
||||||
|
Promise.resolve().then(()=>game.loop(event));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return new Proxy(this,{
|
||||||
|
get(target,prop,receiver){
|
||||||
|
const thisValue=Reflect.get(target,prop);
|
||||||
|
if(thisValue){
|
||||||
|
if(typeof thisValue=='function'){
|
||||||
|
return thisValue.bind(target);
|
||||||
|
}
|
||||||
|
return thisValue;
|
||||||
|
}
|
||||||
|
const eventValue=Reflect.get(event,prop);
|
||||||
|
// 返回值如果是event,则修改为GameEventPromise类实例
|
||||||
|
if(typeof eventValue=='function') return (function(...args){
|
||||||
|
const returnValue=eventValue.call(event,...args);
|
||||||
|
return returnValue==event?receiver:returnValue;
|
||||||
|
}).bind(event);
|
||||||
|
return eventValue;
|
||||||
|
},
|
||||||
|
set(target,prop,newValue){
|
||||||
|
return Reflect.set(event,prop,newValue);
|
||||||
|
},
|
||||||
|
deleteProperty(target,prop){
|
||||||
|
return Reflect.deleteProperty(event,prop);
|
||||||
|
},
|
||||||
|
defineProperty(target,prop,attributes){
|
||||||
|
return Reflect.defineProperty(event,prop,attributes);
|
||||||
|
},
|
||||||
|
has(target,prop){
|
||||||
|
return Reflect.has(event,prop);
|
||||||
|
},
|
||||||
|
ownKeys(target,prop){
|
||||||
|
return Reflect.ownKeys(event,prop);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* TODO: 实现debugger
|
||||||
|
*/
|
||||||
|
async debugger(){
|
||||||
|
return new Promise(resolve=>{
|
||||||
|
resolve(null);
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
Dialog:class extends HTMLDivElement{
|
Dialog:class extends HTMLDivElement{
|
||||||
constructor(){
|
constructor(){
|
||||||
|
@ -41263,217 +41399,213 @@ new Promise(resolve=>{
|
||||||
setTimeout(game.reload,15000)
|
setTimeout(game.reload,15000)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
loop:function(){
|
/**
|
||||||
while(true){
|
* @param { GameEvent } [belongAsyncEvent]
|
||||||
var event=_status.event;
|
*/
|
||||||
var step=event.step;
|
async loop(belongAsyncEvent){
|
||||||
var source=event.source;
|
if(belongAsyncEvent){
|
||||||
var player=event.player;
|
game.belongAsyncEvent=belongAsyncEvent;
|
||||||
var target=event.target;
|
}else if(game.belongAsyncEvent){
|
||||||
var targets=event.targets;
|
return game.loop(game.belongAsyncEvent);
|
||||||
var card=event.card;
|
}
|
||||||
var cards=event.cards;
|
while (true) {
|
||||||
var skill=event.skill;
|
let event = (belongAsyncEvent && belongAsyncEvent.parent == _status.event) ? belongAsyncEvent : _status.event;
|
||||||
var forced=event.forced;
|
let { step, source, player, target, targets, card, cards, skill, forced, num, _trigger: trigger, _result: result } = event;
|
||||||
var num=event.num;
|
const _resolve = () => {
|
||||||
var trigger=event._trigger;
|
if (event.async) {
|
||||||
var result=event._result;
|
if (typeof event.resolve == 'function') {
|
||||||
if(_status.paused2||_status.imchoosing){
|
event.resolve(event);
|
||||||
if(!lib.status.dateDelaying){
|
} else {
|
||||||
lib.status.dateDelaying=new Date();
|
throw new TypeError('异步事件的event.resolve未赋值,使用await时将会被永久等待');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(_status.paused||_status.paused2||_status.over){
|
};
|
||||||
|
if (_status.paused2 || _status.imchoosing) {
|
||||||
|
if (!lib.status.dateDelaying) {
|
||||||
|
lib.status.dateDelaying = new Date();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (_status.paused || _status.paused2 || _status.over) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(_status.paused3){
|
if (_status.paused3) {
|
||||||
_status.paused3='paused';
|
_status.paused3 = 'paused';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(lib.status.dateDelaying){
|
if (lib.status.dateDelaying) {
|
||||||
lib.status.dateDelayed+=lib.getUTC(new Date())-lib.getUTC(lib.status.dateDelaying);
|
lib.status.dateDelayed += lib.getUTC(new Date()) - lib.getUTC(lib.status.dateDelaying);
|
||||||
delete lib.status.dateDelaying;
|
delete lib.status.dateDelaying;
|
||||||
}
|
}
|
||||||
if(event.next.length>0){
|
if (event.next.length > 0) {
|
||||||
var next=event.next.shift();
|
var next = event.next.shift();
|
||||||
if(next.player&&next.player.skipList.contains(next.name)){
|
if (next.player && next.player.skipList.contains(next.name)) {
|
||||||
event.trigger(next.name+'Skipped');
|
event.trigger(next.name + 'Skipped');
|
||||||
next.player.skipList.remove(next.name);
|
next.player.skipList.remove(next.name);
|
||||||
if(lib.phaseName.contains(next.name)) next.player.getHistory('skipped').add(next.name);
|
if (lib.phaseName.contains(next.name)) next.player.getHistory('skipped').add(next.name);
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
next.parent=event;
|
next.parent = event;
|
||||||
_status.event=next;
|
_status.event = next;
|
||||||
game.getGlobalHistory('everything').push(next);
|
game.getGlobalHistory('everything').push(next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(event.finished){
|
else if (event.finished) {
|
||||||
if(event._triggered==1){
|
if (event._triggered == 1) {
|
||||||
if(event.type=='card') event.trigger('useCardToOmitted');
|
if (event.type == 'card') event.trigger('useCardToOmitted');
|
||||||
event.trigger(event.name+'Omitted');
|
event.trigger(event.name + 'Omitted');
|
||||||
event._triggered=4;
|
event._triggered = 4;
|
||||||
}
|
}
|
||||||
else if(event._triggered==2){
|
else if (event._triggered == 2) {
|
||||||
if(event.type=='card') event.trigger('useCardToEnd');
|
if (event.type == 'card') event.trigger('useCardToEnd');
|
||||||
event.trigger(event.name+'End');
|
event.trigger(event.name + 'End');
|
||||||
event._triggered=3;
|
event._triggered = 3;
|
||||||
}
|
}
|
||||||
else if(event._triggered==3){
|
else if (event._triggered == 3) {
|
||||||
if(event.type=='card') event.trigger('useCardToAfter');
|
if (event.type == 'card') event.trigger('useCardToAfter');
|
||||||
event.trigger(event.name+'After');
|
event.trigger(event.name + 'After');
|
||||||
event._triggered++;
|
event._triggered++;
|
||||||
}
|
}
|
||||||
else if(event.after&&event.after.length){
|
else if (event.after && event.after.length) {
|
||||||
var next=event.after.shift();
|
var next = event.after.shift();
|
||||||
if(next.player&&next.player.skipList.contains(next.name)){
|
if (next.player && next.player.skipList.contains(next.name)) {
|
||||||
event.trigger(next.name+'Skipped');
|
event.trigger(next.name + 'Skipped');
|
||||||
next.player.skipList.remove(next.name);
|
next.player.skipList.remove(next.name);
|
||||||
if(lib.phaseName.contains(next.name)) next.player.getHistory('skipped').add(next.name)
|
if (lib.phaseName.contains(next.name)) next.player.getHistory('skipped').add(next.name)
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
next.parent=event;
|
next.parent = event;
|
||||||
_status.event=next;
|
_status.event = next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
if(event.parent){
|
if (event.parent) {
|
||||||
if(event.result){
|
if (event.result) {
|
||||||
event.parent._result=event.result;
|
event.parent._result = event.result;
|
||||||
}
|
}
|
||||||
_status.event=event.parent;
|
_status.event = event.parent;
|
||||||
|
if (game.belongAsyncEvent == event) {
|
||||||
|
delete game.belongAsyncEvent;
|
||||||
|
//resolve();
|
||||||
}
|
}
|
||||||
else{
|
_resolve();
|
||||||
|
// 此时应该退出了
|
||||||
|
if (belongAsyncEvent && belongAsyncEvent.parent == _status.event) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
if (game.belongAsyncEvent == event) {
|
||||||
|
delete game.belongAsyncEvent;
|
||||||
|
//resolve();
|
||||||
}
|
}
|
||||||
else{
|
return _resolve();
|
||||||
if(event._triggered==0){
|
}
|
||||||
if(event.type=='card') event.trigger('useCardToBefore');
|
}
|
||||||
event.trigger(event.name+'Before');
|
}
|
||||||
|
else {
|
||||||
|
if (event._triggered == 0) {
|
||||||
|
if (event.type == 'card') event.trigger('useCardToBefore');
|
||||||
|
event.trigger(event.name + 'Before');
|
||||||
event._triggered++;
|
event._triggered++;
|
||||||
}
|
}
|
||||||
else if(event._triggered==1){
|
else if (event._triggered == 1) {
|
||||||
if(event.type=='card') event.trigger('useCardToBegin');
|
if (event.type == 'card') event.trigger('useCardToBegin');
|
||||||
event.trigger(event.name+'Begin');
|
event.trigger(event.name + 'Begin');
|
||||||
event._triggered++;
|
event._triggered++;
|
||||||
/*if(event.name=='phase'&&!event._begun){
|
|
||||||
var next=game.createEvent('phasing',false,event);
|
|
||||||
next.player=event.player;
|
|
||||||
next.skill=event.skill;
|
|
||||||
next.setContent('phasing');
|
|
||||||
event._begun=true;
|
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
event.trigger(event.name+'Begin');
|
event.callHandler(event.getDefaultHandlerType(), event, {
|
||||||
event._triggered++;
|
state: 'begin'
|
||||||
}*/
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
event.callHandler(event.getDefaultHandlerType(),event,{
|
|
||||||
state:'begin'
|
|
||||||
});
|
});
|
||||||
if(player&&player.classList.contains('dead')&&!event.forceDie&&event.name!='phaseLoop'){
|
const after = () => {
|
||||||
game.broadcastAll(function(){
|
event.clearStepCache();
|
||||||
while(_status.dieClose.length){
|
event.callHandler(event.getDefaultHandlerType(), event, {
|
||||||
|
state: 'end'
|
||||||
|
});
|
||||||
|
if (typeof event.step == "number") ++event.step;
|
||||||
|
};
|
||||||
|
if (player && player.classList.contains('dead') && !event.forceDie && event.name != 'phaseLoop') {
|
||||||
|
game.broadcastAll(function () {
|
||||||
|
while (_status.dieClose.length) {
|
||||||
_status.dieClose.shift().close();
|
_status.dieClose.shift().close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if(event._oncancel){
|
if (event._oncancel) {
|
||||||
event._oncancel();
|
event._oncancel();
|
||||||
}
|
}
|
||||||
event.finish();
|
event.finish();
|
||||||
|
after();
|
||||||
}
|
}
|
||||||
else if(player&&player.removed&&event.name!='phaseLoop'){
|
else if (player && player.removed && event.name != 'phaseLoop') {
|
||||||
event.finish();
|
event.finish();
|
||||||
|
after();
|
||||||
}
|
}
|
||||||
else if(player&&player.isOut()&&event.name!='phaseLoop'&&!event.includeOut){
|
else if (player && player.isOut() && event.name != 'phaseLoop' && !event.includeOut) {
|
||||||
if(event.name=='phase'&&player==_status.roundStart&&!event.skill){
|
if (event.name == 'phase' && player == _status.roundStart && !event.skill) {
|
||||||
_status.roundSkipped=true;
|
_status.roundSkipped = true;
|
||||||
}
|
}
|
||||||
event.finish();
|
event.finish();
|
||||||
|
after();
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
if(_status.withError||lib.config.compatiblemode||(_status.connectMode&&!lib.config.debug)){
|
await game.runContent(belongAsyncEvent).catch(e => {
|
||||||
try{
|
if (_status.withError || lib.config.compatiblemode || (_status.connectMode && !lib.config.debug)) {
|
||||||
if(event.content instanceof GeneratorFunction){
|
game.print('游戏出错:' + event.name);
|
||||||
if(!event.debugging){
|
|
||||||
if(event.generatorContent) event.generatorContent.return();
|
|
||||||
event.generatorContent=event.content(event,step,source,player,target,targets,
|
|
||||||
card,cards,skill,forced,num,trigger,result,
|
|
||||||
_status,lib,game,ui,get,ai);
|
|
||||||
}else{
|
|
||||||
delete event.debugging;
|
|
||||||
}
|
|
||||||
var next=event.generatorContent.next();
|
|
||||||
if(typeof next.value=='function'&&next.value.toString()=='code=>eval(code)'){
|
|
||||||
//触发debugger
|
|
||||||
var inputCallback=inputResult=>{
|
|
||||||
if(inputResult===false){
|
|
||||||
event.debugging=true;
|
|
||||||
game.resume2();
|
|
||||||
}else{
|
|
||||||
alert(get.stringify(next.value(inputResult)));
|
|
||||||
game.prompt('','debugger调试',inputCallback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
game.prompt('','debugger调试',inputCallback);
|
|
||||||
return game.pause2();
|
|
||||||
}
|
|
||||||
if(event.finished) event.generatorContent.return();
|
|
||||||
}else{
|
|
||||||
event.content(event,step,source,player,target,targets,
|
|
||||||
card,cards,skill,forced,num,trigger,result,
|
|
||||||
_status,lib,game,ui,get,ai);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(e){
|
|
||||||
game.print('游戏出错:'+event.name);
|
|
||||||
game.print(e.toString());
|
game.print(e.toString());
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
|
else throw e;
|
||||||
|
}).then(after);
|
||||||
}
|
}
|
||||||
else{
|
}
|
||||||
if(event.content instanceof GeneratorFunction){
|
}
|
||||||
if(!event.debugging){
|
}
|
||||||
if(event.generatorContent) event.generatorContent.return();
|
},
|
||||||
event.generatorContent=event.content(event,step,source,player,target,targets,
|
runContent(belongAsyncEvent) {
|
||||||
card,cards,skill,forced,num,trigger,result,
|
return new Promise(resolve=>{
|
||||||
_status,lib,game,ui,get,ai);
|
let event = (belongAsyncEvent && belongAsyncEvent.parent == _status.event) ? belongAsyncEvent : _status.event;
|
||||||
}else{
|
let { step, source, player, target, targets, card, cards, skill, forced, num, _trigger: trigger, _result: result } = event;
|
||||||
|
if (event.content instanceof GeneratorFunction) {
|
||||||
|
if (!event.debugging) {
|
||||||
|
if (event.generatorContent) event.generatorContent.return();
|
||||||
|
event.generatorContent = event.content(event, step, source, player, target, targets,
|
||||||
|
card, cards, skill, forced, num, trigger, result,
|
||||||
|
_status, lib, game, ui, get, ai);
|
||||||
|
} else {
|
||||||
delete event.debugging;
|
delete event.debugging;
|
||||||
}
|
}
|
||||||
var next=event.generatorContent.next();
|
var next = event.generatorContent.next();
|
||||||
if(typeof next.value=='function'&&next.value.toString()=='code=>eval(code)'){
|
if (typeof next.value == 'function' && next.value.toString() == 'code=>eval(code)') {
|
||||||
//触发debugger
|
//触发debugger
|
||||||
var inputCallback=inputResult=>{
|
var inputCallback = inputResult => {
|
||||||
if(inputResult===false){
|
if (inputResult === false) {
|
||||||
event.debugging=true;
|
event.debugging = true;
|
||||||
game.resume2();
|
game.resume2();
|
||||||
}else{
|
} else {
|
||||||
alert(get.stringify(next.value(inputResult)));
|
alert(get.stringify(next.value(inputResult)));
|
||||||
game.prompt('','debugger调试',inputCallback);
|
game.prompt('', 'debugger调试', inputCallback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
game.prompt('','debugger调试',inputCallback);
|
game.prompt('', 'debugger调试', inputCallback);
|
||||||
return game.pause2();
|
return game.pause2();
|
||||||
}
|
}
|
||||||
if(event.finished) event.generatorContent.return();
|
if (event.finished) event.generatorContent.return();
|
||||||
}else{
|
resolve();
|
||||||
event.content(event,step,source,player,target,targets,
|
|
||||||
card,cards,skill,forced,num,trigger,result,
|
|
||||||
_status,lib,game,ui,get,ai);
|
|
||||||
}
|
}
|
||||||
}
|
else if (event.content instanceof AsyncFunction) {
|
||||||
}
|
// _status,lib,game,ui,get,ai六个变量由game.import提供
|
||||||
event.clearStepCache();
|
event.content(event, trigger, player).then(() => {
|
||||||
event.callHandler(event.getDefaultHandlerType(),event,{
|
event.finish();
|
||||||
state:'end'
|
resolve();
|
||||||
});
|
});
|
||||||
if(typeof event.step=="number") ++event.step;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
event.content(event, step, source, player, target, targets,
|
||||||
|
card, cards, skill, forced, num, trigger, result,
|
||||||
|
_status, lib, game, ui, get, ai);
|
||||||
|
resolve();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
pause:function(){
|
pause:function(){
|
||||||
clearTimeout(_status.timeout);
|
clearTimeout(_status.timeout);
|
||||||
|
|
Loading…
Reference in New Issue