全局:加载json方法全部改为最新
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import { FrontendOrBackendSession, pinus } from 'pinus';
|
||||
import { getGamedata } from '../pubUtils/gamedata';
|
||||
import EventRecord, { EventRecordModel } from '../db/EventRecord';
|
||||
import { RoleModel } from '../db/Role';
|
||||
import { genCode, decodeStrSingle, decodeStr, getRandomWithWeight, resResult } from '../pubUtils/util';
|
||||
import { genCode, getRandEelmWithWeight, resResult, getRandSingleEelm } from '../pubUtils/util';
|
||||
import { EVENT_STATUS, EVENT_RECORD_STATUS, EVENT_TYPE, EVENT_RANDOM_TYPE_ONE_OPEN, EVENT_QUIZ_NUM, EVENT_ANSWER_STATUS, FUNCS_ID } from '../consts';
|
||||
import { EVENT_REFRESH_NUM } from '../consts';
|
||||
import { STATUS } from '../consts/statusCode';
|
||||
import { gameData } from '../pubUtils/data';
|
||||
import { DicQuestion } from '../pubUtils/dictionary/DicQuestion';
|
||||
|
||||
/**
|
||||
* 从检查接口调用,检查是否有这么个战斗,顺便保存一下battleCode
|
||||
@@ -235,7 +235,7 @@ export async function refreshEvent(num: number, roleId: string, roleName: string
|
||||
let randomList = dicEvent;
|
||||
let curPoint = new Array<number>();
|
||||
for(let i = 0; i < num; i++) {
|
||||
let {dic} = getRandomWithWeight(randomList);
|
||||
let {dic} = getRandEelmWithWeight(randomList);
|
||||
// 临时处理,不出现相同的关卡id
|
||||
for(let x = 0; x < 1000; x++) {
|
||||
let hasEvent = event.find(cur => {
|
||||
@@ -243,7 +243,7 @@ export async function refreshEvent(num: number, roleId: string, roleName: string
|
||||
let hasPreEvent = preEvents.find(cur => {
|
||||
return cur.type == EVENT_TYPE.BATTLE && cur.battleId == dic.warId});
|
||||
if(!hasEvent && !hasPreEvent) break;
|
||||
dic = getRandomWithWeight(randomList).dic;
|
||||
dic = getRandEelmWithWeight(randomList).dic;
|
||||
}
|
||||
|
||||
// if(!dic) break;
|
||||
@@ -377,14 +377,16 @@ export function checkQuizParam(param: Array<number>, database?: Array<{id: numb
|
||||
* @param num 题目数量
|
||||
*/
|
||||
function randomQuestion(num: number) {
|
||||
let questions = getGamedata('Questions');
|
||||
let questions = new Array<DicQuestion>();
|
||||
gameData.question.forEach(cur => {
|
||||
questions.push(cur);
|
||||
});
|
||||
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];
|
||||
let dicQuestion = getRandSingleEelm(questions);
|
||||
let {id, question, answer, correct} = dicQuestion;
|
||||
if(rid.includes(id)) continue;
|
||||
rid.push(id);
|
||||
let answer = [a1, a2, a3, a4].filter(cur => cur);
|
||||
result.push({id, question, answer, correct});
|
||||
num--;
|
||||
}
|
||||
@@ -398,8 +400,7 @@ function randomQuestion(num: number) {
|
||||
* @param answer
|
||||
*/
|
||||
export function checkQuiz(id: number, answer: number) {
|
||||
let questions = getGamedata('Questions');
|
||||
let result = questions[id - 1];
|
||||
let result = gameData.question.get(id);
|
||||
|
||||
return {
|
||||
isCorrect: !!result && result.correct == answer,
|
||||
|
||||
Reference in New Issue
Block a user