修改pvp积分方式

This commit is contained in:
zhl 2021-05-08 19:56:03 +08:00
parent a28752d7c9
commit b9be3fb159
5 changed files with 52 additions and 4 deletions

View File

@ -18,7 +18,7 @@ import { RoomState } from '../../services/RoomState'
import { retry } from '../../utils/promise.util'
import { RoomLockErr } from '../../common/RoomLockErr'
import { Schedule } from '../../clock/Schedule'
import { startGame, transformRecord } from '../../services/GameLogic'
import { calcScore, startGame, transformRecord } from '../../services/GameLogic'
import { ObjectId } from 'bson'
@ -93,7 +93,7 @@ class PuzzleController extends BaseController {
history.markModified('members')
await history.save()
if (mode == 1) {
let score = result ? 3 : -1
let score = result ? calcScore(history.scheduleKey, statMap.comboCount) : 0
await broadcast(history.room, 'answer', {accountid, result, score})
await updateScore(history.room, [{accountid, score }])

View File

@ -53,4 +53,21 @@ export class Schedule {
scheduleActive(name: string): boolean {
return this.gameClock.has(name) && this.gameClock.get(name).active
}
/**
*
* @param {string} name
* @return {number}
*/
getLeftTime(name: string) {
if (!this.gameClock.has(name)) {
return 0
}
let clock = this.gameClock.get(name)
if (!clock.active) {
this.gameClock.delete(name)
return 0
}
return clock.time - clock.elapsedTime
}
}

View File

@ -1,6 +1,7 @@
import * as jetpack from 'fs-jetpack'
import { BaseConst } from '../constants/BaseConst'
import { error } from './Debug'
import { GameEnv } from '../config/GameEnv'
const $cfg = new Map()
const jsonPath = 'config'
@ -47,6 +48,7 @@ export var DataParser = (function () {
}
}
}
new GameEnv().init($cfg.get(BaseConst.COMPOUND))
Object.assign(global, {
$cfg: $cfg
})

21
src/config/GameEnv.ts Normal file
View File

@ -0,0 +1,21 @@
import { singleton } from '../decorators/singleton'
import { compound_vo } from './parsers/compound_vo'
@singleton
export class GameEnv {
// PVP每题可用时间
public pvpInterval: number
// PVP当前连击数的分
public pvpComboRate: number
// PVP剩余时间分
public pvpTimeRate: number
// PVP答对基础分
public pvpBaseScore: number
public init(data: Map<number, compound_vo>) {
this.pvpInterval = (+data.get(99018).value) * 1000
this.pvpComboRate = +data.get(99017).value
this.pvpTimeRate = +data.get(99016).value
this.pvpBaseScore = +data.get(99015).value
}
}

View File

@ -11,6 +11,7 @@ import { Schedule } from '../clock/Schedule'
import { BaseConst } from '../constants/BaseConst'
import { QCategoryCache } from './QCategoryCache'
import { PuzzleSession } from '../models/match/PuzzleSession'
import { GameEnv } from '../config/GameEnv'
export function transformRecord(records: any[]) {
@ -88,7 +89,7 @@ export async function sendOneQuestion(history: any) {
await sendQuestion(roomId, qdata)
history.current++
await history.save()
new Schedule().beginSchedule(BaseConst.MATCH_ANSWER_TIME, async function () {
new Schedule().beginSchedule(new GameEnv().pvpInterval, async function () {
let subHistory = await PuzzleSession.findById(history.id)
let datas = []
for (let [accountid, data] of subHistory.members) {
@ -96,7 +97,7 @@ export async function sendOneQuestion(history: any) {
data.answer.set(qid, 0)
data.errorCount++
data.comboCount = 0
datas.push({ accountid, score: -1 })
datas.push({ accountid, score: 0 })
}
}
subHistory.markModified('members')
@ -105,3 +106,10 @@ export async function sendOneQuestion(history: any) {
await sendOneQuestion(subHistory)
}, history.scheduleKey)
}
export function calcScore(timeKey: string, combo: number) {
const time = new Schedule().getLeftTime(timeKey)
const cfg = new GameEnv()
return cfg.pvpBaseScore + time / 100 * cfg.pvpTimeRate + combo * cfg.pvpComboRate
}