miao-plugin/models/Artifact.js

102 lines
2.1 KiB
JavaScript
Raw Normal View History

/*
* 圣遗物
* */
import Base from './Base.js'
2023-03-07 17:52:11 +00:00
import { Format } from '#miao'
import { ArtifactSet } from './index.js'
import { artiMap, attrMap, mainIdMap, attrIdMap } from '../resources/meta/artifact/index.js'
import lodash from 'lodash'
class Artifact extends Base {
static getAttrs
constructor (name) {
super()
let cache = this._getCache(`arti:${name}`)
if (cache) {
return cache
}
let data = artiMap[name]
if (!data) {
return false
}
this.name = name
this.meta = data
return this._cache()
}
2022-08-18 10:13:42 +00:00
get artiSet () {
return ArtifactSet.get(this.set)
}
2022-08-18 10:13:42 +00:00
get setName () {
return this.set
}
2022-08-18 10:13:42 +00:00
get img () {
return `meta/artifact/imgs/${this.setName}/${this.idx}.webp`
}
static get (name) {
if (artiMap[name]) {
return new Artifact(name)
2022-08-18 10:13:42 +00:00
}
return false
}
2022-08-18 10:13:42 +00:00
static getSetNameByArti (name) {
let arti = Artifact.get(name)
if (arti) {
return arti.setName
}
return ''
}
2022-09-07 19:48:03 +00:00
static getMeta () {
2022-08-18 10:13:42 +00:00
return {
attrMap
}
}
static getMainById (id, level = 20, star = 5) {
let key = mainIdMap[id]
if (!key) {
return false
}
let attrCfg = attrMap[Format.isElem(key) ? 'dmg' : key]
let posEff = ['hpPlus', 'atkPlus', 'defPlus'].includes(key) ? 2 : 1
let starEff = { 1: 0.21, 2: 0.36, 3: 0.6, 4: 0.9, 5: 1 }
return {
key,
value: attrCfg.value * (1.2 + 0.34 * level) * posEff * (starEff[star || 5])
}
}
static getAttrsByIds (ids, star = 5) {
let ret = []
let tmp = {}
lodash.forEach(ids, (id) => {
let cfg = attrIdMap[id]
if (!cfg) {
return true
}
let { key, value } = cfg
if (!tmp[key]) {
tmp[key] = {
key,
upNum: 0,
eff: 0,
value: 0
}
ret.push(tmp[key])
}
2023-02-21 19:49:49 +00:00
tmp[key].value += value * (attrMap[key].format === 'pct' ? 100 : 1)
tmp[key].upNum++
tmp[key].eff += value / attrMap[key].value * (attrMap[key].format === 'pct' ? 100 : 1)
})
return ret
}
2022-08-18 10:13:42 +00:00
}
2022-08-18 10:13:42 +00:00
export default Artifact