revert: damn it...

This commit is contained in:
Rintim 2023-12-25 20:24:15 +08:00
parent facfe0ee0d
commit c9a8f3d6a3
No known key found for this signature in database
GPG Key ID: BE9E1EA615BACFCF
5 changed files with 111 additions and 30 deletions

View File

@ -16,7 +16,7 @@ import { Library as lib } from '../library/index.js';
import { status as _status } from '../status/index.js';
import { UI as ui } from '../ui/index.js';
import { GNC as gnc } from '../gnc/index.js';
import { userAgent, Uninstantable, GeneratorFunction, AsyncFunction } from "../util/index.js";
import { userAgent, Uninstantable, GeneratorFunction, AsyncFunction, delay } from "../util/index.js";
export class Game extends Uninstantable {
static online = false;
@ -5836,6 +5836,7 @@ export class Game extends Uninstantable {
let { step, source, player, target, targets, card, cards, skill, forced, num, _trigger: trigger, _result: result, _storeEvent } = event;
// 数组形式
if ("contents" in event && Array.isArray(event.contents)) {
/*
event.contents[step](event, trigger, player, _storeEvent).then((evt) => {
if (evt) event._storeEvent = evt;
if (game.executingAsyncEventMap.has(event.toEvent())) {
@ -5847,7 +5848,36 @@ export class Game extends Uninstantable {
if (event.step >= event.contents.length - 1) event.finish();
resolve();
}
})
});
*/
// 解决不了问题...就把问题统一
const run = async (event) => {
if (typeof event.step !== "number") event.step = 0;
while (event.step < event.contents.length && !event.finished) {
const evt = await event.contents[event.step](event, event._trigger, event.player, event._tmpStoreEvent);
if (evt) event._tmpStoreEvent = evt;
if (game.executingAsyncEventMap.has(event.toEvent())) {
await game.executingAsyncEventMap.get(_status.event.toEvent());
await game.executingAsyncEventMap.get(event.toEvent());
}
++event.step;
}
--event.step;
};
run(event).then(() => {
if (game.executingAsyncEventMap.has(event.toEvent())) {
game.executingAsyncEventMap.set(_status.event.toEvent(), game.executingAsyncEventMap.get(_status.event.toEvent()).then(() => {
event.finish();
resolve();
}));
} else {
event.finish();
resolve();
}
});
}
else if (event.content instanceof GeneratorFunction) {
if (!event.debugging) {
@ -5979,9 +6009,7 @@ export class Game extends Uninstantable {
time = time * lib.config.duration + time2;
if (lib.config.speed == 'vvfast') time /= 3;
//_status.timeout=setTimeout(game.resume,time);
return new Promise(resolve => {
setTimeout(resolve, time);
});
return delay(time);
}
/**
* 在async content中对game.delayx的代替使用方法

View File

@ -2704,6 +2704,9 @@ export default {
ui.clear();
event.goto(1);
},
/**
* @deprecated
*/
phaseDraw: function () {
"step 0";
game.log(player, '进入了摸牌阶段');

View File

@ -189,26 +189,29 @@ export default {
if (player.isIn() && event.num < event.phaseList.length) {
const phase = event.phaseList[event.num].split('|');
event.currentPhase = phase[0];
if (event.currentPhase == 'phaseDraw' || event.currentPhase == 'phaseDiscard') {
if (!player.noPhaseDelay) {
// @ts-ignore
if (player == game.me) {
await game.asyncDelay();
// game.delay();
}
else {
await game.asyncDelayx();
// game.delayx();
}
}
}
const next = player[event.currentPhase]();
next.phaseIndex = event.num;
if (phase.length > 1) {
next._extraPhaseReason = phase[1];
}
if (event.currentPhase == 'phaseDraw' || event.currentPhase == 'phaseDiscard') {
if (!player.noPhaseDelay) {
// @ts-ignore
if (player == game.me) {
game.delay();
}
else {
game.delayx();
}
}
}
return await next;
}
},
async (event, _trigger, player) => {
if (event.currentPhase == 'phaseUse') {
if (event.currentPhase === 'phaseUse') {
// @ts-ignore
game.broadcastAll(() => {
// @ts-ignore
@ -244,5 +247,43 @@ export default {
delete _status.currentPhase;
}, player);
}
],
phaseDraw: [
async (event, _trigger, player) => {
game.log(player, '进入了摸牌阶段');
event.trigger("phaseDrawBegin1");
},
async (event) => {
event.trigger("phaseDrawBegin2");
},
async (event, _trigger, player) => {
// @ts-ignore
if (game.modPhaseDraw) {
// @ts-ignore
return game.modPhaseDraw(player, event.num);
}
else {
if (event.num > 0) {
let num = event.num;
if (event.attachDraw) {
for (let i = 0; i < event.attachDraw.length; i++) {
// @ts-ignore
ui.cardPile.insertBefore(event.attachDraw[i], ui.cardPile.firstChild);
}
num += event.attachDraw.length;
}
const next = player.draw(num);
if (event.attachDraw) {
next.minnum = event.attachDraw.length;
}
return next;
}
}
},
async (event, _trigger, _player, { result }) => {
if (Array.isArray(result)) {
event.cards = result;
}
}
]
};

View File

@ -12388,7 +12388,7 @@ export class Library extends Uninstantable {
next.forceDie = true;
next.includeOut = true;
next.skill = skill || _status.event.name;
next.setContents('phase');
next.setContent('phase');
return next;
}
insertEvent(name, content, arg) {
@ -12410,7 +12410,7 @@ export class Library extends Uninstantable {
phase(skill) {
var next = game.createEvent('phase', false);
next.player = this;
next.setContents('phase');
next.setContent('phase');
if (!_status.roundStart) {
_status.roundStart = this;
}
@ -20492,17 +20492,6 @@ export class Library extends Uninstantable {
if (!_status.event) return;
// game.createEvent的时候还没立即push到next里
Promise.resolve().then(() => {
/*
// 事件自行处理skip情况
if (event.player && event.player.skipList.includes(event.name)) {
_status.event.trigger(event.name + 'Skipped');
event.player.skipList.remove(event.name);
if (lib.phaseName.includes(event.name)) event.player.getHistory('skipped').add(event.name);
const eventPromise = _status.event.next.find(e => e.toEvent() == event);
if (eventPromise) _status.event.next.remove(eventPromise);
return;
}
*/
game.executingAsyncEventMap.set(_status.event.toEvent(), (game.executingAsyncEventMap.get(_status.event.toEvent()) || Promise.resolve()).then(() => {
let eventPromise = _status.event.next.find(e => e.toEvent() == event);
// 如果父级事件也是一个异步的话,那应该立即执行这个事件的
@ -20513,6 +20502,17 @@ export class Library extends Uninstantable {
// 再执行game.loop是因为原有的game.loop被await卡住了
// 得新执行一个只执行这个异步事件的game.loop
// 事件自行处理skip情况
if (event.player && event.player.skipList.includes(event.name)) {
_status.event.trigger(event.name + 'Skipped');
event.player.skipList.remove(event.name);
if (lib.phaseName.includes(event.name)) event.player.getHistory('skipped').add(event.name);
_status.event.next.remove(eventPromise);
event.finish();
resolve();
return eventPromise;
}
if (_status.event != eventPromise) {
eventPromise.parent = _status.event;
_status.event = eventPromise;

View File

@ -11,3 +11,12 @@ export class Uninstantable {
throw new TypeError(`${new.target.name} is not a constructor`);
}
}
/**
*
* @param {number} ms
* @returns {Promise<void>}
*/
export function delay(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}