增加单人模式游戏结果的分数计算
This commit is contained in:
parent
a2e8c877cd
commit
a8d63eb715
@ -111,6 +111,7 @@ class PuzzleController extends BaseController {
|
||||
}
|
||||
history.status = 1
|
||||
history.markModified('members')
|
||||
let gameResult = 0
|
||||
await history.save()
|
||||
if (mode == 1) {
|
||||
let score = result ? calcPvpScore(history.scheduleKey, statMap.comboCount) : 0
|
||||
@ -121,24 +122,26 @@ class PuzzleController extends BaseController {
|
||||
// await sendOneQuestion(history)
|
||||
// }
|
||||
} else if (mode == 0) {
|
||||
let result = checkSingleFinish(history, accountid)
|
||||
if (result) {
|
||||
gameResult = checkSingleFinish(history, accountid)
|
||||
if (gameResult) {
|
||||
history.status = 9
|
||||
//TODO:: 计算积分, 并更新排行榜
|
||||
let score = calcSingleScore()
|
||||
let rankObj = {
|
||||
shop: history.shop,
|
||||
level: history.level,
|
||||
accountId: accountid,
|
||||
score,
|
||||
mode: 0,
|
||||
session: history.id
|
||||
if (gameResult === 1) {
|
||||
let score = calcSingleScore(history, accountid)
|
||||
let rankObj = {
|
||||
shop: history.shop,
|
||||
level: history.level,
|
||||
accountId: accountid,
|
||||
score,
|
||||
mode: 0,
|
||||
session: history.id
|
||||
}
|
||||
await updateSingleRank(rankObj)
|
||||
}
|
||||
await updateSingleRank(rankObj)
|
||||
history.markModified('members')
|
||||
await history.save()
|
||||
}
|
||||
}
|
||||
return { result, answer: record.a1, stats: history.members }
|
||||
return { result, answer: record.a1, stats: history.members, gameResult }
|
||||
}
|
||||
|
||||
@role('anon')
|
||||
|
@ -15,12 +15,25 @@ export class GameEnv {
|
||||
// 特效播放时间
|
||||
public effectTimeLong: number
|
||||
|
||||
// 单人血量分
|
||||
public singleHpRate: number
|
||||
// 单人最大连击数的分
|
||||
public singleComboRate: number
|
||||
// 单人剩余时间分
|
||||
public singleTimeRate: number
|
||||
// 单人降低难度后的得分折扣
|
||||
public singleLowLvlRate: number
|
||||
|
||||
public init(data: Map<number, compound_vo>) {
|
||||
this.pvpInterval = (+data.get(99018).value)
|
||||
this.pvpComboRate = +data.get(99017).value
|
||||
this.pvpTimeRate = +data.get(99016).value
|
||||
this.pvpBaseScore = +data.get(99015).value
|
||||
this.effectTimeLong = +data.get(99025).value
|
||||
this.singleHpRate = +data.get(99002).value
|
||||
this.singleComboRate = +data.get(99004).value
|
||||
this.singleTimeRate = +data.get(99003).value
|
||||
this.singleLowLvlRate = +data.get(99005).value
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -37,9 +37,25 @@ export class PuzzleStatusClass {
|
||||
*/
|
||||
@prop({default: 0})
|
||||
maxCombo: number
|
||||
|
||||
/**
|
||||
* 多人模式中, 该玩家在房间中的sessionId, 用于重连
|
||||
* @type {string}
|
||||
*/
|
||||
@prop()
|
||||
sessionId: string
|
||||
/**
|
||||
* 游戏胜利后的得分
|
||||
* @type {number}
|
||||
*/
|
||||
@prop({default: 0})
|
||||
score: number
|
||||
|
||||
/**
|
||||
* 游戏结果
|
||||
* @type {number}
|
||||
*/
|
||||
@prop({default: 0})
|
||||
public gameResult: number
|
||||
|
||||
}
|
||||
// @ts-ignore
|
||||
|
@ -150,28 +150,43 @@ export async function updateSingleRank({shop, level, accountId, score, session,
|
||||
* @return {number} 0: 未结束, -1: 失败, 1: 胜利
|
||||
*/
|
||||
export function checkSingleFinish(history: any, accountId: string): number {
|
||||
if (history.hasExpired()) {
|
||||
return -1
|
||||
}
|
||||
let cfg = fetchLevelCfg(history.level)
|
||||
let result = 0
|
||||
let stat = history.members.get(accountId)
|
||||
if (stat.rightCount >= cfg.enemy) {
|
||||
return 1
|
||||
if (history.hasExpired()) {
|
||||
result = -1
|
||||
} else {
|
||||
let cfg = fetchLevelCfg(history.level)
|
||||
if (stat.rightCount >= cfg.enemy) {
|
||||
result = 1
|
||||
} else if (stat.errorCount >= cfg.hp) {
|
||||
result = -1
|
||||
}
|
||||
}
|
||||
if (stat.errorCount >= cfg.hp) {
|
||||
return -1
|
||||
if (result !== 0) {
|
||||
stat.gameResult = result
|
||||
}
|
||||
|
||||
return 0
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO::
|
||||
* 计算单人模式的得分
|
||||
* @return {number}
|
||||
*/
|
||||
export function calcSingleScore() {
|
||||
return 0
|
||||
export function calcSingleScore(history: any, accountId: string) {
|
||||
let cfgLevel = fetchLevelCfg(history.level)
|
||||
let time = (Date.now() - history.createdAt.getTime()) / 1000
|
||||
let stat = history.members.get(accountId)
|
||||
let combo = stat.maxCombo
|
||||
let hp = cfgLevel.hp - stat.errorCount
|
||||
hp = hp < 0 ? 0 : hp
|
||||
time = time < 0 ? 0 : time
|
||||
let cfg = new GameEnv()
|
||||
let score = time * cfg.singleTimeRate + hp * cfg.singleHpRate + combo * cfg.singleComboRate
|
||||
if (history.difficultyMode) {
|
||||
score *= cfg.singleLowLvlRate
|
||||
}
|
||||
stat.score = score
|
||||
return score
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user