fix 修复奇遇本答题逻辑
This commit is contained in:
@@ -3,7 +3,9 @@ import { getGamedata } from '../pubUtils/gamedata';
|
||||
import { EventRecordModel } from '../db/EventRecord';
|
||||
import { RoleModel } from '../db/Role';
|
||||
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';
|
||||
import { EVENT_STATUS, EVENT_RECORD_STATUS, EVENT_TYPE, EVENT_RANDOM_TYPE_ONE_OPEN, EVENT_QUIZ_NUM, EVENT_ANSWER_STATUS } from '../consts/consts';
|
||||
import { STATUS } from '../consts/statusCode';
|
||||
import { stat } from 'fs';
|
||||
|
||||
|
||||
export async function setBattleStatus(app: Application, session: FrontendOrBackendSession, roleId: string, battleId: number , isSuccess: boolean, battleCode: string) {
|
||||
@@ -206,8 +208,8 @@ export function checkEventStatus(type: number, status: number) {
|
||||
}
|
||||
|
||||
|
||||
export function getEventSuccessStatus(type: number, status: number, answer: Array<{id: number, answer: number}>) {
|
||||
let isSuccess: boolean; // 检查状态是否正确
|
||||
export function getEventSuccessStatus(type: number, status: number, question: Array<{id: number, status: number}>) {
|
||||
let isSuccess: boolean, returnResult = 1; // 检查状态是否正确
|
||||
if(type == EVENT_TYPE.BATTLE) {
|
||||
if(status == EVENT_RECORD_STATUS.BATTLE_SUCCESS) {
|
||||
isSuccess = true;
|
||||
@@ -217,17 +219,26 @@ export function getEventSuccessStatus(type: number, status: number, answer: Arra
|
||||
} else if(type == EVENT_TYPE.BOX) {
|
||||
isSuccess = true;
|
||||
} else if (type == EVENT_TYPE.QUIZ) {
|
||||
isSuccess = checkQuiz(answer)
|
||||
isSuccess = true;
|
||||
for(let { status = EVENT_ANSWER_STATUS.WAITING } of question) {
|
||||
console.log(status);
|
||||
if(status == EVENT_ANSWER_STATUS.WRONG) {
|
||||
isSuccess = false;
|
||||
} else if(status == EVENT_ANSWER_STATUS.WAITING) {
|
||||
isSuccess = false;
|
||||
returnResult = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return isSuccess
|
||||
return { isSuccess, status: returnResult }
|
||||
}
|
||||
|
||||
export function checkQuizParam(param: Array<{id: number, answer: number }>, database?: Array<{id: number}>) {
|
||||
export function checkQuizParam(param: Array<number>, database?: Array<{id: number}>) {
|
||||
|
||||
if(database) {
|
||||
let flag = true;
|
||||
for(let {id} of database) {
|
||||
let index = param.findIndex(cur => cur.id == id);
|
||||
let index = param.indexOf(id);
|
||||
if(index == -1) flag = false; break;
|
||||
}
|
||||
return flag
|
||||
@@ -251,14 +262,12 @@ function randomQuestion(num: number) {
|
||||
return result;
|
||||
}
|
||||
|
||||
function checkQuiz(arr: Array<{id: number, answer: number }>) {
|
||||
let flag = true;
|
||||
export function checkQuiz(id: number, answer: number) {
|
||||
let questions = getGamedata('Questions');
|
||||
for(let {id, answer} of arr) {
|
||||
let result = questions[id - 1];
|
||||
if(!result || result.correct != answer) {
|
||||
flag = false;
|
||||
}
|
||||
let result = questions[id - 1];
|
||||
|
||||
return {
|
||||
isCorrect: !!result && result.correct == answer,
|
||||
answerNo: result?result.correct: 0
|
||||
}
|
||||
return flag
|
||||
}
|
||||
|
||||
@@ -35,16 +35,22 @@ export class WarReward {
|
||||
if(this.isSuccess) { // 成功了才给固定奖励
|
||||
let {fixReward = ''} = this.warInfo;
|
||||
let reward = decodeStr('fixReward', fixReward);
|
||||
for(let obj of reward) this.rewards.push({type: BATTLE_REWARD_TYPE.FIX_REWARD, ...obj, count: obj.count * num});
|
||||
for(let i = 0; i < num; i++) {
|
||||
for(let obj of reward) {
|
||||
this.rewards.push({type: BATTLE_REWARD_TYPE.FIX_REWARD, times: i +1, ...obj, count: obj.count });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private handleConditionReward(num: number) {
|
||||
if(this.isSuccess) {
|
||||
let {conditionReward = ''} = this.warInfo;
|
||||
let reward = decodeStr('conditionReward', conditionReward);
|
||||
for(let obj of reward) {
|
||||
if(this.condition.get(obj.condition)) {
|
||||
this.rewards.push({type: BATTLE_REWARD_TYPE.CONDITION_REWARD, ...obj, count: obj.count * num});
|
||||
for(let i = 0; i < num; i++) {
|
||||
for(let obj of reward) {
|
||||
if(this.condition.get(obj.condition)) {
|
||||
this.rewards.push({type: BATTLE_REWARD_TYPE.CONDITION_REWARD, times: i +1, ...obj, count: obj.count});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,7 +79,7 @@ export class WarReward {
|
||||
}
|
||||
if(flag) {
|
||||
getNum ++; getSum++;
|
||||
this.rewards.push({type: BATTLE_REWARD_TYPE.RANDOM_REWARD, ...obj});
|
||||
this.rewards.push({type: BATTLE_REWARD_TYPE.RANDOM_REWARD, times: i +1, ...obj});
|
||||
}
|
||||
}
|
||||
await BattleDropModel.updateByGid(this.roleId, this.battleId, gid, {
|
||||
|
||||
Reference in New Issue
Block a user