奇遇随机添加权重

This commit is contained in:
luying
2020-10-14 17:19:09 +08:00
parent c06f422297
commit 57d60be3a2
5 changed files with 784 additions and 64 deletions

View File

@@ -2,8 +2,8 @@ import { Application, BackendSession, FrontendOrBackendSession } from 'pinus';
import { getGamedata } from '../../../util/gamedata';
import { EventRecordModel } from '../../../db/EventRecord';
import { RoleModel } from '../../../db/Role';
import { genCode, decodeStr, decodeStrSingle, Reward } from '../../../util/util';
import { EVENT_STATUS, EVENT_RECORD_STATUS, EVENT_TYPE } from '../../../consts/consts';
import { genCode, decodeStr, decodeStrSingle, Reward, getRandomWithWeight } from '../../../util/util';
import { EVENT_STATUS, EVENT_RECORD_STATUS, EVENT_TYPE, EVENT_RANDOM_TYPE_ONE_OPEN } from '../../../consts/consts';
export default function(app: Application) {
return new EventBattleHandler(app);
@@ -177,35 +177,55 @@ async function refreshEvent(num: number, roleId: string, roleName: string, t) {
suitLevel = decodeStrSingle('eventSuitLevel', suitLevel);
return suitLevel.min <= role.lv && suitLevel.max >= role.lv
});
let historyRecord = await EventRecordModel.getHostoryEventRecord(roleId);
let {history, turn} = historyRecord;
let randomList = dicEvent.filter(cur => {
return history.find(ccur => {
return ccur.eventId != cur.eventID;
});
});
console.log(JSON.stringify(randomList));
for(let i = 0; i < num; i++) {
if(randomList.length == 0) { // 一轮刷新过,开始新的一轮,保证所有事件都能刷新一遍
turn ++;
randomList = [...dicEvent];
if(EVENT_RANDOM_TYPE_ONE_OPEN) { // 每轮进行记录,保证每次随机出的不重复
let historyRecord = await EventRecordModel.getHostoryEventRecord(roleId);
let {history, turn} = historyRecord;
let randomList = dicEvent.filter(cur => {
return history.find(ccur => {
return ccur.eventId != cur.eventID;
});
});
console.log(JSON.stringify(randomList));
for(let i = 0; i < num; i++) {
if(randomList.length == 0) { // 刷新的3个事件不重复
turn ++;
randomList = [...dicEvent];
}
let {dic, index} = getRandomWithWeight(randomList);
if(!dic) break;
let eventCode = genCode(8);
let data = await EventRecordModel.saveEventRecord(eventCode, {
roleId, refTime: t, eventId: dic.eventID,
roleName, turn, type: dic.eventType, battleId: dic.warId||0, quality: dic.quality,
status: EVENT_RECORD_STATUS.WAITING
});
event.push(data)
randomList.splice(index, 1);
}
} else {
let randomList = dicEvent;
for(let i = 0; i < num; i++) {
let {dic} = getRandomWithWeight(randomList);
console.log('****', JSON.stringify(randomList))
if(!dic) break;
let eventCode = genCode(8);
let data = await EventRecordModel.saveEventRecord(eventCode, {
roleId, refTime: t, eventId: dic.eventID,
roleName, type: dic.eventType, battleId: dic.warId||0, quality: dic.quality,
status: EVENT_RECORD_STATUS.WAITING
});
event.push(data)
}
let index = Math.floor(Math.random() * randomList.length);
let dic = randomList[index];
let eventCode = genCode(8);
let data = await EventRecordModel.saveEventRecord(eventCode, {
roleId, refTime: t, eventId: dic.eventID,
roleName, turn, type: dic.eventType, battleId: dic.warId||0, quality: dic.quality,
status: EVENT_RECORD_STATUS.WAITING
});
event.push(data)
randomList.splice(index, 1);
}
return event;
}
function pushEventMsg(app, roleId, channelName, msg ) {
console.log('***pushEventMsg', channelName)
let channelService = app.get('channelService');