增加关卡配置的处理
This commit is contained in:
parent
5549c8c804
commit
1318b246e2
@ -6,6 +6,8 @@ import {
|
|||||||
PuzzleStatusClass
|
PuzzleStatusClass
|
||||||
} from '../../models/match/PuzzleSession'
|
} from '../../models/match/PuzzleSession'
|
||||||
import { ZError } from '../../common/ZError'
|
import { ZError } from '../../common/ZError'
|
||||||
|
import { BaseConst } from '../../constants/BaseConst'
|
||||||
|
import { mission_vo } from '../../config/parsers/mission_vo'
|
||||||
|
|
||||||
const transformRecord = function (records: any[]) {
|
const transformRecord = function (records: any[]) {
|
||||||
return records.map(o => {
|
return records.map(o => {
|
||||||
@ -29,11 +31,15 @@ class PuzzleController extends BaseController {
|
|||||||
@router('post /api/:accountid/puzzle/list')
|
@router('post /api/:accountid/puzzle/list')
|
||||||
async list(req, res) {
|
async list(req, res) {
|
||||||
let { shop, level, accountid } = req.params
|
let { shop, level, accountid } = req.params
|
||||||
let count = 10
|
level = +level || 1
|
||||||
|
const cfgs: mission_vo[] = Array.from(global.$cfg.get(BaseConst.MISSION).values())
|
||||||
|
const cfg = cfgs.find(o=>o.number == level) || cfgs[cfgs.length - 1]
|
||||||
|
let count = cfg.beforehand_enemy || 10
|
||||||
let records = await Puzzle.randomQuestions({}, count)
|
let records = await Puzzle.randomQuestions({}, count)
|
||||||
let history = new PuzzleSession({ shop, level })
|
let history = new PuzzleSession({ shop, level })
|
||||||
history.members.set(accountid, new PuzzleStatusClass())
|
history.members.set(accountid, new PuzzleStatusClass())
|
||||||
history.questions = records.map(o => o._id)
|
history.questions = records.map(o => o._id)
|
||||||
|
history.expire = Date.now() + (cfg.time || 90) * 1000
|
||||||
await history.save()
|
await history.save()
|
||||||
const results = transformRecord(records)
|
const results = transformRecord(records)
|
||||||
return {
|
return {
|
||||||
@ -53,6 +59,11 @@ class PuzzleController extends BaseController {
|
|||||||
if (!history) {
|
if (!history) {
|
||||||
throw new ZError(13, 'not found match info')
|
throw new ZError(13, 'not found match info')
|
||||||
}
|
}
|
||||||
|
if (history.status == 9 || history.hasExpired()) {
|
||||||
|
history.status = 9
|
||||||
|
await history.save()
|
||||||
|
throw new ZError(17, 'match end')
|
||||||
|
}
|
||||||
if (!history.members.has(accountid)) {
|
if (!history.members.has(accountid)) {
|
||||||
throw new ZError(14, 'not in current match')
|
throw new ZError(14, 'not in current match')
|
||||||
}
|
}
|
||||||
@ -81,6 +92,7 @@ class PuzzleController extends BaseController {
|
|||||||
statMap.errorCount ++
|
statMap.errorCount ++
|
||||||
statMap.comboCount = 0
|
statMap.comboCount = 0
|
||||||
}
|
}
|
||||||
|
history.status = 1
|
||||||
history.markModified('members')
|
history.markModified('members')
|
||||||
await history.save()
|
await history.save()
|
||||||
return { result, stats: history.members }
|
return { result, stats: history.members }
|
||||||
|
@ -2,6 +2,8 @@ import { dbconn } from '../../decorators/dbconn'
|
|||||||
import { getModelForClass, modelOptions, prop } from '@typegoose/typegoose'
|
import { getModelForClass, modelOptions, prop } from '@typegoose/typegoose'
|
||||||
import { BaseModule } from '../Base'
|
import { BaseModule } from '../Base'
|
||||||
import { Severity } from '@typegoose/typegoose/lib/internal/constants'
|
import { Severity } from '@typegoose/typegoose/lib/internal/constants'
|
||||||
|
import { Base, TimeStamps } from '@typegoose/typegoose/lib/defaultClasses'
|
||||||
|
|
||||||
|
|
||||||
@modelOptions({
|
@modelOptions({
|
||||||
options: {allowMixed: Severity.ALLOW}
|
options: {allowMixed: Severity.ALLOW}
|
||||||
@ -38,9 +40,13 @@ export class PuzzleStatusClass {
|
|||||||
@prop({default: 0})
|
@prop({default: 0})
|
||||||
maxCombo: number
|
maxCombo: number
|
||||||
}
|
}
|
||||||
|
// @ts-ignore
|
||||||
|
export interface PuzzleSessionClass extends Base, TimeStamps {
|
||||||
|
}
|
||||||
|
|
||||||
@dbconn()
|
@dbconn()
|
||||||
@modelOptions({ schemaOptions: { collection: 'puzzle_session' } })
|
@modelOptions({ schemaOptions: { collection: 'puzzle_session', timestamps: true } })
|
||||||
class PuzzleSessionClass extends BaseModule {
|
export class PuzzleSessionClass extends BaseModule {
|
||||||
|
|
||||||
@prop({ _id: false, type: PuzzleStatusClass, default: new Map() })
|
@prop({ _id: false, type: PuzzleStatusClass, default: new Map() })
|
||||||
public members: Map<string, PuzzleStatusClass>
|
public members: Map<string, PuzzleStatusClass>
|
||||||
@ -57,9 +63,22 @@ class PuzzleSessionClass extends BaseModule {
|
|||||||
@prop()
|
@prop()
|
||||||
public room: string
|
public room: string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 比赛状态
|
||||||
|
* 0: 未开始答题
|
||||||
|
* 1: 答题进行中
|
||||||
|
* 9: 结束
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
@prop({default: 0})
|
@prop({default: 0})
|
||||||
public status: number
|
public status: number
|
||||||
|
|
||||||
|
@prop()
|
||||||
|
public expire: number
|
||||||
|
|
||||||
|
public hasExpired(): boolean {
|
||||||
|
return this.expire < Date.now()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PuzzleSession = getModelForClass(PuzzleSessionClass, { existingConnection: PuzzleSessionClass.db })
|
export const PuzzleSession = getModelForClass(PuzzleSessionClass, { existingConnection: PuzzleSessionClass.db })
|
||||||
|
Loading…
x
Reference in New Issue
Block a user