修正服务端机器人有时报delayRun无法找到的问题

This commit is contained in:
zhl 2020-12-22 15:02:05 +08:00
parent 2213505af4
commit b9378cec7e

View File

@ -2,7 +2,11 @@ import {singleton} from "../common/Singleton";
import {GameEnv} from "../cfg/GameEnv";
const baseCfg = new GameEnv();
const delayRun = function (max: number, min?: number) {
min = min || 0;
let milliseconds = (Math.random() * (max - min) + min) * 1000 | 0;
return new Promise(resolve => setTimeout(resolve, milliseconds));
}
/**
*
* @param type GameEnv中的字段名
@ -12,11 +16,7 @@ export function wait(type: string) {
propertyKey: string,
descriptor: PropertyDescriptor) => {
const method = descriptor.value;
let delayRun = function (max: number, min?: number) {
min = min || 0;
let milliseconds = (Math.random() * (max - min) + min) * 1000 | 0;
return new Promise(resolve => setTimeout(resolve, milliseconds));
}
descriptor.value = function (...args: any[]) {
// @ts-ignore
let time = baseCfg[type] as number;
@ -26,8 +26,9 @@ export function wait(type: string) {
let minTime = minDelay / 100 * time;
delayRun(maxTime, minTime)
.then(() => {
return method!.apply(this, args);
})
.finally(() => {
.catch(err => {
return method!.apply(this, args);
})
@ -44,11 +45,6 @@ export function delay(num: number) {
propertyKey: string,
descriptor: PropertyDescriptor) => {
const method = descriptor.value;
let delayRun = function (max: number, min?: number) {
min = min || 0;
let milliseconds = (Math.random() * (max - min) + min) * 1000 | 0;
return new Promise(resolve => setTimeout(resolve, milliseconds));
}
descriptor.value = function (...args: any[]) {
delayRun(num, 0)
.then(() => {