修改pvp积分方式
This commit is contained in:
parent
a28752d7c9
commit
b9be3fb159
@ -18,7 +18,7 @@ import { RoomState } from '../../services/RoomState'
|
|||||||
import { retry } from '../../utils/promise.util'
|
import { retry } from '../../utils/promise.util'
|
||||||
import { RoomLockErr } from '../../common/RoomLockErr'
|
import { RoomLockErr } from '../../common/RoomLockErr'
|
||||||
import { Schedule } from '../../clock/Schedule'
|
import { Schedule } from '../../clock/Schedule'
|
||||||
import { startGame, transformRecord } from '../../services/GameLogic'
|
import { calcScore, startGame, transformRecord } from '../../services/GameLogic'
|
||||||
import { ObjectId } from 'bson'
|
import { ObjectId } from 'bson'
|
||||||
|
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ class PuzzleController extends BaseController {
|
|||||||
history.markModified('members')
|
history.markModified('members')
|
||||||
await history.save()
|
await history.save()
|
||||||
if (mode == 1) {
|
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 broadcast(history.room, 'answer', {accountid, result, score})
|
||||||
await updateScore(history.room, [{accountid, score }])
|
await updateScore(history.room, [{accountid, score }])
|
||||||
|
|
||||||
|
@ -53,4 +53,21 @@ export class Schedule {
|
|||||||
scheduleActive(name: string): boolean {
|
scheduleActive(name: string): boolean {
|
||||||
return this.gameClock.has(name) && this.gameClock.get(name).active
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import * as jetpack from 'fs-jetpack'
|
import * as jetpack from 'fs-jetpack'
|
||||||
import { BaseConst } from '../constants/BaseConst'
|
import { BaseConst } from '../constants/BaseConst'
|
||||||
import { error } from './Debug'
|
import { error } from './Debug'
|
||||||
|
import { GameEnv } from '../config/GameEnv'
|
||||||
|
|
||||||
const $cfg = new Map()
|
const $cfg = new Map()
|
||||||
const jsonPath = 'config'
|
const jsonPath = 'config'
|
||||||
@ -47,6 +48,7 @@ export var DataParser = (function () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
new GameEnv().init($cfg.get(BaseConst.COMPOUND))
|
||||||
Object.assign(global, {
|
Object.assign(global, {
|
||||||
$cfg: $cfg
|
$cfg: $cfg
|
||||||
})
|
})
|
||||||
|
21
src/config/GameEnv.ts
Normal file
21
src/config/GameEnv.ts
Normal 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
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,7 @@ import { Schedule } from '../clock/Schedule'
|
|||||||
import { BaseConst } from '../constants/BaseConst'
|
import { BaseConst } from '../constants/BaseConst'
|
||||||
import { QCategoryCache } from './QCategoryCache'
|
import { QCategoryCache } from './QCategoryCache'
|
||||||
import { PuzzleSession } from '../models/match/PuzzleSession'
|
import { PuzzleSession } from '../models/match/PuzzleSession'
|
||||||
|
import { GameEnv } from '../config/GameEnv'
|
||||||
|
|
||||||
|
|
||||||
export function transformRecord(records: any[]) {
|
export function transformRecord(records: any[]) {
|
||||||
@ -88,7 +89,7 @@ export async function sendOneQuestion(history: any) {
|
|||||||
await sendQuestion(roomId, qdata)
|
await sendQuestion(roomId, qdata)
|
||||||
history.current++
|
history.current++
|
||||||
await history.save()
|
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 subHistory = await PuzzleSession.findById(history.id)
|
||||||
let datas = []
|
let datas = []
|
||||||
for (let [accountid, data] of subHistory.members) {
|
for (let [accountid, data] of subHistory.members) {
|
||||||
@ -96,7 +97,7 @@ export async function sendOneQuestion(history: any) {
|
|||||||
data.answer.set(qid, 0)
|
data.answer.set(qid, 0)
|
||||||
data.errorCount++
|
data.errorCount++
|
||||||
data.comboCount = 0
|
data.comboCount = 0
|
||||||
datas.push({ accountid, score: -1 })
|
datas.push({ accountid, score: 0 })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
subHistory.markModified('members')
|
subHistory.markModified('members')
|
||||||
@ -105,3 +106,10 @@ export async function sendOneQuestion(history: any) {
|
|||||||
await sendOneQuestion(subHistory)
|
await sendOneQuestion(subHistory)
|
||||||
}, history.scheduleKey)
|
}, 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
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user