fix:修改奇遇本逻辑
This commit is contained in:
@@ -2,8 +2,8 @@ import { Application, FrontendOrBackendSession } from 'pinus';
|
||||
import { getGamedata } from '../pubUtils/gamedata';
|
||||
import { EventRecordModel } from '../db/EventRecord';
|
||||
import { RoleModel } from '../db/Role';
|
||||
import { genCode, decodeStrSingle, decodeStr } from '../pubUtils/util';
|
||||
import { EVENT_STATUS, EVENT_RECORD_STATUS, EVENT_TYPE } from '../consts/consts';
|
||||
import { genCode, decodeStrSingle, decodeStr, getRandomWithWeight } from '../pubUtils/util';
|
||||
import { EVENT_STATUS, EVENT_RECORD_STATUS, EVENT_TYPE, EVENT_RANDOM_TYPE_ONE_OPEN, EVENT_QUIZ_NUM } from '../consts/consts';
|
||||
|
||||
|
||||
export async function setBattleStatus(app: Application, session: FrontendOrBackendSession, roleId: string, battleId: number , isSuccess: boolean, battleCode: string) {
|
||||
@@ -108,35 +108,56 @@ export async function refreshEvent(num: number, roleId: string, roleName: string
|
||||
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;
|
||||
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) { // 一轮刷新过,开始新的一轮,保证所有事件都能刷新一遍
|
||||
turn ++;
|
||||
randomList = [...dicEvent];
|
||||
console.log(JSON.stringify(randomList));
|
||||
|
||||
for(let i = 0; i < num; i++) {
|
||||
if(randomList.length == 0) { // 一轮刷新过,开始新的一轮,保证所有事件都能刷新一遍
|
||||
turn ++;
|
||||
randomList = [...dicEvent];
|
||||
}
|
||||
if(randomList.length == 0) break; // 如果还是为0,pass
|
||||
|
||||
let index = Math.floor(Math.random() * randomList.length);
|
||||
let dic = randomList[index];
|
||||
let position = randomPosition(dic.position);
|
||||
let question = dic.eventType == EVENT_TYPE.QUIZ?randomQuestion(EVENT_QUIZ_NUM): undefined;
|
||||
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,
|
||||
position, question
|
||||
});
|
||||
event.push(data);
|
||||
randomList.splice(index, 1);
|
||||
}
|
||||
} else {
|
||||
let randomList = dicEvent;
|
||||
console.log('*********', randomList.length, num);
|
||||
for(let i = 0; i < num; i++) {
|
||||
let {dic} = getRandomWithWeight(randomList);
|
||||
console.log(JSON.stringify(dic))
|
||||
// if(!dic) break;
|
||||
let position = randomPosition(dic.position);
|
||||
let eventCode = genCode(8);
|
||||
let question = dic.eventType == EVENT_TYPE.QUIZ?randomQuestion(EVENT_QUIZ_NUM): [];
|
||||
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,
|
||||
position, question
|
||||
});
|
||||
event.push(data)
|
||||
}
|
||||
if(randomList.length == 0) break; // 如果还是为0,pass
|
||||
|
||||
let index = Math.floor(Math.random() * randomList.length);
|
||||
let dic = randomList[index];
|
||||
let position = randomPosition(dic.position);
|
||||
let question = dic.eventType == EVENT_TYPE.QUIZ?randomQuestion(): undefined;
|
||||
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,
|
||||
position, question
|
||||
});
|
||||
event.push(data);
|
||||
randomList.splice(index, 1);
|
||||
}
|
||||
return event;
|
||||
}
|
||||
@@ -185,7 +206,7 @@ export function checkEventStatus(type: number, status: number) {
|
||||
}
|
||||
|
||||
|
||||
export function getEventSuccessStatus(type: number, status: number, question: {id: number, answer: number}) {
|
||||
export function getEventSuccessStatus(type: number, status: number, answer: Array<{id: number, answer: number}>) {
|
||||
let isSuccess: boolean; // 检查状态是否正确
|
||||
if(type == EVENT_TYPE.BATTLE) {
|
||||
if(status == EVENT_RECORD_STATUS.BATTLE_SUCCESS) {
|
||||
@@ -196,22 +217,47 @@ export function getEventSuccessStatus(type: number, status: number, question: {i
|
||||
} else if(type == EVENT_TYPE.BOX) {
|
||||
isSuccess = true;
|
||||
} else if (type == EVENT_TYPE.QUIZ) {
|
||||
isSuccess = checkQuiz(question)
|
||||
isSuccess = checkQuiz(answer)
|
||||
}
|
||||
return isSuccess
|
||||
}
|
||||
|
||||
function randomQuestion() {
|
||||
let questions = getGamedata('Questions');
|
||||
let index = Math.floor(Math.random() * questions.length);
|
||||
let result = questions[index];
|
||||
let {id, question, a1, a2, a3, a4, correct} = result;
|
||||
return {id, question, answer: [a1, a2, a3, a4], correct};
|
||||
export function checkQuizParam(param: Array<{id: number, answer: number }>, database?: Array<{id: number}>) {
|
||||
|
||||
if(database) {
|
||||
let flag = true;
|
||||
for(let {id} of database) {
|
||||
let index = param.findIndex(cur => cur.id == id);
|
||||
if(index == -1) flag = false; break;
|
||||
}
|
||||
return flag
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
function checkQuiz(obj: {id: number, answer: number }) {
|
||||
let {id, answer} = obj;
|
||||
function randomQuestion(num: number) {
|
||||
let questions = getGamedata('Questions');
|
||||
let result = questions[id - 1];
|
||||
return !!result && result.correct == answer;
|
||||
}
|
||||
let rid:Array<number> = [], result = [];
|
||||
while(num > 0) {
|
||||
let index = Math.floor(Math.random() * questions.length);
|
||||
let {id, question, a1, a2, a3, a4, correct} = questions[index];
|
||||
if(rid.includes(id)) continue;
|
||||
rid.push(id);
|
||||
result.push({id, question, answer: [a1, a2, a3, a4], correct});
|
||||
num--;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function checkQuiz(arr: Array<{id: number, answer: number }>) {
|
||||
let flag = true;
|
||||
let questions = getGamedata('Questions');
|
||||
for(let {id, answer} of arr) {
|
||||
let result = questions[id - 1];
|
||||
if(!result || result.correct != answer) {
|
||||
flag = false;
|
||||
}
|
||||
}
|
||||
return flag
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user