事件:修复有时候刷不到事件的问题
This commit is contained in:
@@ -178,6 +178,7 @@ export async function refreshEvent(num: number, roleId: string, roleName: string
|
||||
let index = Math.floor(Math.random() * randomList.length);
|
||||
let dic = randomList[index];
|
||||
let point = randomPosition(dic.movePointArray, prePoint, curPoint);
|
||||
if(!point) break;
|
||||
let question = dic.eventType == EVENT_TYPE.QUIZ?randomQuestion(EVENT_QUIZ_NUM): undefined;
|
||||
let eventCode = genCode(8);
|
||||
let data = await EventRecordModel.saveEventRecord(eventCode, {
|
||||
@@ -191,21 +192,28 @@ export async function refreshEvent(num: number, roleId: string, roleName: string
|
||||
}
|
||||
} else {
|
||||
let randomList = dicEvent;
|
||||
if(randomList.length == 0) return []
|
||||
let curPoint = new Array<number>();
|
||||
for(let i = 0; i < num; i++) {
|
||||
let {dic} = getRandEelmWithWeight(randomList);
|
||||
// 临时处理,不出现相同的关卡id
|
||||
for(let x = 0; x < 1000; x++) {
|
||||
for(let x = 0; x < 1000; x++) { // 防死循环
|
||||
let hasEvent = event.find(cur => {
|
||||
return cur.type == EVENT_TYPE.BATTLE && cur.battleId == dic.warId});
|
||||
let hasPreEvent = preEvents.find(cur => {
|
||||
return cur.type == EVENT_TYPE.BATTLE && cur.battleId == dic.warId});
|
||||
if(!hasEvent && !hasPreEvent) break;
|
||||
|
||||
if(x < 500) { // 基本不希望本轮和上轮出现过的关卡再次出现
|
||||
if(!hasEvent && !hasPreEvent) break;
|
||||
} else { // 但是实在找不到,只要本轮没出现过就好
|
||||
if(!hasEvent) break;
|
||||
}
|
||||
dic = getRandEelmWithWeight(randomList).dic;
|
||||
}
|
||||
|
||||
// if(!dic) break;
|
||||
if(!dic) break;
|
||||
let point = randomPosition(dic.movePointArray, prePoint, curPoint);
|
||||
if(!point) break;
|
||||
let eventCode = genCode(8);
|
||||
let question = dic.eventType == EVENT_TYPE.QUIZ?randomQuestion(EVENT_QUIZ_NUM): [];
|
||||
let data = await EventRecordModel.saveEventRecord(eventCode, {
|
||||
@@ -232,7 +240,7 @@ function randomPosition(positionArr: number[], prePoint: Array<number>, curPoint
|
||||
range = positionArr.filter(point => {return !curPoint.includes(point)});
|
||||
}
|
||||
if(range.length == 0) { // 还是不够,那是配表的问题,直接报错
|
||||
throw new Error('event position not enough');
|
||||
return false;
|
||||
}
|
||||
let index = Math.floor(Math.random() * range.length);
|
||||
let point = range[index];
|
||||
|
||||
Reference in New Issue
Block a user