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