支持自定义评分规则、支持动态选用、更新相关文档

This commit is contained in:
UCPr 2025-03-27 01:31:46 +08:00
parent 06ec5152a0
commit 504d2792a8
11 changed files with 217 additions and 114 deletions

View file

@ -1,6 +1,7 @@
import type { Equip } from '../equip.js'
import { baseValueData, scoreData } from '../../lib/score.js'
import type { scoreWeight } from '../../lib/score.js'
import { idToName } from '../../lib/convert/property.js'
import { baseValueData } from '../../lib/score.js'
import { getMapData } from '../../utils/file.js'
enum rarity { S, A, B }
@ -11,15 +12,16 @@ const mainStats = getMapData('EquipMainStats') as { [partition: string]: number[
const subStats = Object.keys(baseValueData).map(Number)
export default class Score {
protected scoreData: typeof scoreData[string]
protected equip: Equip
/** 词条权重 */
protected weight: typeof scoreWeight[string]
/** 驱动盘n号位 */
protected partition: number
/** 用户主词条 */
protected userMainStat: number
constructor(charID: string, equip: Equip) {
this.scoreData = scoreData[charID]
constructor(equip: Equip, weight: Score['weight']) {
this.equip = equip
this.weight = weight
this.partition = this.equip.equipment_type
this.userMainStat = this.equip.main_properties[0].property_id
}
@ -47,12 +49,12 @@ export default class Score {
get_max_count() {
/** 权重最大的4个副词条 */
const subMaxStats = subStats
.filter(p => p !== this.userMainStat && this.scoreData[p])
.sort((a, b) => this.scoreData[b] - this.scoreData[a]).slice(0, 4)
.filter(p => p !== this.userMainStat && this.weight[p])
.sort((a, b) => this.weight[b] - this.weight[a]).slice(0, 4)
if (!subMaxStats.length) return 0
logger.debug(`[${this.partition}号位]理论副词条:` + subMaxStats.map(idToName).reduce((a, p, i) => a + `${p}*${this.scoreData[subMaxStats[i]].toFixed(2)} `, ''))
let count = this.scoreData[subMaxStats[0]] * 6 // 权重最大副词条强化五次
subMaxStats.slice(1).forEach(p => count += this.scoreData[p] || 0) // 其他词条各计入一次
logger.debug(`[${this.partition}号位]理论副词条:` + subMaxStats.map(idToName).reduce((a, p, i) => a + `${p}*${this.weight[subMaxStats[i]].toFixed(2)} `, ''))
let count = this.weight[subMaxStats[0]] * 6 // 权重最大副词条强化五次
subMaxStats.slice(1).forEach(p => count += this.weight[p] || 0) // 其他词条各计入一次
logger.debug(`[${this.partition}号位]理论词条数:${logger.blue(count)}`)
return count
}
@ -62,7 +64,7 @@ export default class Score {
let count = 0
for (const prop of this.equip.properties) {
const propID = prop.property_id
const weight = this.scoreData[propID]
const weight = this.weight[propID]
if (weight) {
logger.debug(`[${this.partition}号位]实际副词条:${idToName(propID)} ${logger.green(prop.count + 1)}*${weight}`)
count += weight * (prop.count + 1)
@ -90,18 +92,18 @@ export default class Score {
}
// 456号位
const mainMaxStat = mainStats[this.partition]
.filter(p => this.scoreData[p])
.sort((a, b) => this.scoreData[b] - this.scoreData[a])[0]
const mainScore = (mainMaxStat ? 12 * (this.scoreData[this.userMainStat] || 0) / this.scoreData[mainMaxStat] : 12) * this.get_level_multiplier()
.filter(p => this.weight[p])
.sort((a, b) => this.weight[b] - this.weight[a])[0]
const mainScore = (mainMaxStat ? 12 * (this.weight[this.userMainStat] || 0) / this.weight[mainMaxStat] : 12) * this.get_level_multiplier()
const subScore = actual_count / max_count * 43
const score = (mainScore + subScore) * rarity_multiplier
logger.debug(`[${this.partition}号位] ${logger.magenta(`(${mainScore} + ${subScore}) * ${rarity_multiplier} = ${score}`)}`)
return score
}
static main(charID: string, equip: Equip) {
static main(equip: Equip, weight: Score['weight']) {
try {
return new Score(charID, equip).get_score()
return new Score(equip, weight).get_score()
} catch (err) {
logger.error('角色驱动盘评分计算错误:', err)
return 0