fix 修复奇遇本答题逻辑
This commit is contained in:
@@ -2,8 +2,8 @@ import { Application, BackendSession } from 'pinus';
|
||||
import { getGamedata } from '../../../pubUtils/gamedata';
|
||||
import EventRecord, { EventRecordModel } from '../../../db/EventRecord';
|
||||
import { RoleModel } from '../../../db/Role';
|
||||
import { EVENT_STATUS, EVENT_RECORD_STATUS } from '../../../consts/consts';
|
||||
import { checkEvent, getEventTime, refreshEvent, checkEventStatus, getEventSuccessStatus, checkQuizParam } from '../../../services/eventSercive';
|
||||
import { EVENT_STATUS, EVENT_RECORD_STATUS, EVENT_ANSWER_STATUS } from '../../../consts/consts';
|
||||
import { checkEvent, getEventTime, refreshEvent, checkEventStatus, getEventSuccessStatus, checkQuizParam, checkQuiz } from '../../../services/eventSercive';
|
||||
import { handleFixedReward } from '../../../services/rewardService';
|
||||
import { STATUS } from '../../../consts/statusCode';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
@@ -39,9 +39,38 @@ export class EventBattleHandler {
|
||||
return resResult(STATUS.SUCCESS, { list: event });
|
||||
}
|
||||
|
||||
// 回答问题
|
||||
async checkAnswer(msg: { eventId: number, eventCode: string, questionId: number, answer: number }, session: BackendSession) {
|
||||
const {eventId, eventCode, questionId, answer} = msg;
|
||||
let roleId = session.get('roleId');
|
||||
// let roleName = session.get('roleName');
|
||||
// let eventStatus = session.get('eventStatus');
|
||||
|
||||
let event = await EventRecordModel.getEventRecordByCode(roleId, eventCode);
|
||||
if(!event) {
|
||||
return resResult(STATUS.EVENT_RECORD_NOT_FOUND);
|
||||
}
|
||||
let { status, type, eventId: dataEventId, question } = event;
|
||||
|
||||
let flag = checkEventStatus(type, status);
|
||||
if(!flag) {
|
||||
return resResult(STATUS.EVENT_STATUS_ERROR);
|
||||
}
|
||||
if(dataEventId != eventId) {
|
||||
return resResult(STATUS.EVENT_WRONG_ID);
|
||||
}
|
||||
let curQuestion = question.find(cur => cur.id == questionId);
|
||||
if(!curQuestion) return resResult(STATUS.EVENT_QUESTION_NOT_FOUND);
|
||||
|
||||
let {isCorrect, answerNo} = checkQuiz(questionId, answer);
|
||||
await EventRecordModel.saveEventAnswer(eventCode, questionId, isCorrect?EVENT_ANSWER_STATUS.CORRECT:EVENT_ANSWER_STATUS.WRONG);
|
||||
|
||||
return resResult(STATUS.SUCCESS, { eventCode, eventId, questionId, isCorrect, answerNo });
|
||||
}
|
||||
|
||||
// 获取关卡列表
|
||||
async receiveEventReward(msg: { eventId: number, eventCode: string, answer: Array<{id: number, answer: number}> }, session: BackendSession) {
|
||||
const {eventId, eventCode, answer = []} = msg;
|
||||
async receiveEventReward(msg: { eventId: number, eventCode: string }, session: BackendSession) {
|
||||
const {eventId, eventCode} = msg;
|
||||
let roleId = session.get('roleId');
|
||||
let roleName = session.get('roleName');
|
||||
let eventStatus = session.get('eventStatus');
|
||||
@@ -56,11 +85,12 @@ export class EventBattleHandler {
|
||||
if(!flag) {
|
||||
return resResult(STATUS.EVENT_STATUS_ERROR);
|
||||
}
|
||||
if(!checkQuizParam(answer, question)) {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
let isSuccess = getEventSuccessStatus(type, status, answer);
|
||||
|
||||
let checkResult = getEventSuccessStatus(type, status, question);
|
||||
if(checkResult.status == -1) {
|
||||
return resResult(STATUS.EVENT_QUESTION_NO_ANSWER);
|
||||
}
|
||||
let isSuccess = checkResult.isSuccess;
|
||||
|
||||
if(dataEventId != eventId) {
|
||||
return resResult(STATUS.EVENT_WRONG_ID);
|
||||
|
||||
Reference in New Issue
Block a user