变更Enka服务的圣遗物储存格式,圣遗物词条改为记录propIds

This commit is contained in:
Kokomi 2023-02-12 03:51:50 +08:00
parent 72c6356656
commit 1ee3e9df51
8 changed files with 1333 additions and 95 deletions

View File

@ -2,10 +2,14 @@
* 圣遗物
* */
import Base from './Base.js'
import { Format } from '../components/index.js'
import { ArtifactSet } from './index.js'
import { artiMap, attrMap } from '../resources/meta/artifact/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}`)
@ -29,6 +33,10 @@ class Artifact extends Base {
return this.set
}
get img () {
return `meta/artifact/imgs/${this.setName}/${this.idx}.webp`
}
static get (name) {
if (artiMap[name]) {
return new Artifact(name)
@ -36,10 +44,6 @@ class Artifact extends Base {
return false
}
get img () {
return `meta/artifact/imgs/${this.setName}/${this.idx}.webp`
}
static getSetNameByArti (name) {
let arti = Artifact.get(name)
if (arti) {
@ -53,6 +57,47 @@ class Artifact extends Base {
attrMap
}
}
static getMainById (id, level = 20, star) {
let cfg = mainIdMap[id]
if (!cfg) {
return false
}
let attrCfg = attrMap[Format.isElem(cfg.key) ? 'dmg' : cfg.key]
let eff = ['hpPlus', 'atkPlus', 'defPlus'].includes(cfg.key) ? 2 : 1
return {
key: cfg.key,
value: attrCfg.value * (1.2 + 0.34 * level) * eff
}
}
static getAttrsByIds (ids) {
let ret = []
let tmp = {}
lodash.forEach(ids, (id) => {
let cfg = attrIdMap[id]
if (!cfg) {
return true
}
let { key, eff } = cfg
if (!tmp[key]) {
tmp[key] = {
key,
eff: 0,
upNum: 0
}
ret.push(tmp[key])
}
tmp[key].eff += eff
tmp[key].upNum++
})
lodash.forEach(tmp, (ds, key) => {
if (attrMap[key]) {
ds.value = attrMap[key].value * ds.eff
}
})
return ret
}
}
export default Artifact

View File

@ -14,6 +14,38 @@ export default class AvatarArtis extends Base {
this.artis = {}
}
get sets () {
return this.getSetData().sets || {}
}
get names () {
return this.getSetData().names || []
}
get hasArtis () {
return !lodash.isEmpty(this.artis)
}
get hasAttr () {
return ArtisMark.hasAttr(this.artis)
}
static _eachArtisSet (sets, fn) {
lodash.forEach(sets || [], (v, k) => {
let artisSet = ArtifactSet.get(k)
if (artisSet) {
if (v >= 4) {
fn(artisSet, 2)
}
fn(artisSet, v)
}
})
}
static getArtisKeyTitle () {
return ArtisMark.getKeyTitleMap()
}
setArtisData (ds = {}, profile = false) {
// let force = !this.hasArtis || ArtisMark.hasAttr(ds) || !ArtisMark.hasAttr(this.artis)
if (!profile || (profile && ArtisMark.hasAttr(ds))) {
@ -33,16 +65,30 @@ export default class AvatarArtis extends Base {
arti.name = ds._name || ds.name || arti.name || ''
arti.set = ds._set || Artifact.getSetNameByArti(arti._name) || ds.set || ''
arti.level = ds._level || ds.level || 1
} else {
arti.name = ds.name || arti.name || ''
arti.set = ds.set || Artifact.getSetNameByArti(arti.name) || ''
arti.level = ds.level || 1
arti.star = ds._star || ds.star || 5
arti.main = ds.main
arti.attrs = ds.attrs
return true
}
// 存在面板数据,更新面板数据
if (ds.main && ds.attrs) {
arti.name = ds.name || arti.name || ''
arti.set = ds.set || Artifact.getSetNameByArti(arti.name) || ''
arti.level = ds.level || 1
arti.star = ds.star || 5
if (ds.mainId || ds.main) {
arti._name = ds.name || arti.name
arti._set = ds.set || Artifact.getSetNameByArti(arti.name) || arti.set || ''
arti._level = ds.level || arti.level
arti._star = ds.star || arti.star || 5
}
// 存在面板数据,更新面板数据
if (ds.mainId && ds.attrIds) {
arti.mainId = ds.mainId
arti.attrIds = ds.attrIds
arti.main = Artifact.getMainById(ds.mainId, arti._level, arti._star)
arti.attrs = Artifact.getAttrsByIds(ds.attrIds)
} else if (ds.main && ds.attrs) {
arti.main = ArtisMark.formatAttr(ds.main || {})
arti.attrs = []
for (let attrIdx in ds.attrs || []) {
@ -79,11 +125,20 @@ export default class AvatarArtis extends Base {
if (ds) {
let tmp = {
name: ds.name || '',
level: ds.level || 1
level: ds.level || 1,
star: ds.star || 5
}
if (ds.main && ds.attrs) {
tmp._name = ds._name || null
tmp._level = ds._level || null
if ((ds.mainId && ds.attrIds) || (ds.main && ds.attrs)) {
if ((ds._name && ds._name !== ds.name) || (ds._level && ds._level !== ds.level) || (ds._star && ds._star !== ds.star)) {
tmp._name = ds._name || null
tmp._level = ds._level || null
tmp._star = ds._star || null
}
}
if (ds.mainId && ds.attrIds) {
tmp.mainId = ds.mainId || null
tmp.attrIds = ds.attrIds
} else if (ds.main && ds.attrs) {
tmp.main = ds.main || null
tmp.attrs = []
for (let attrIdx in ds.attrs || []) {
@ -123,22 +178,6 @@ export default class AvatarArtis extends Base {
return ret
}
get sets () {
return this.getSetData().sets || {}
}
get names () {
return this.getSetData().names || []
}
get hasArtis () {
return !lodash.isEmpty(this.artis)
}
get hasAttr () {
return ArtisMark.hasAttr(this.artis)
}
mainAttr (idx = '') {
if (!idx) {
let ret = {}
@ -223,23 +262,7 @@ export default class AvatarArtis extends Base {
}
}
static _eachArtisSet (sets, fn) {
lodash.forEach(sets || [], (v, k) => {
let artisSet = ArtifactSet.get(k)
if (artisSet) {
if (v >= 4) {
fn(artisSet, 2)
}
fn(artisSet, v)
}
})
}
eachArtisSet (fn) {
AvatarArtis._eachArtisSet(this.sets, fn)
}
static getArtisKeyTitle () {
return ArtisMark.getKeyTitleMap()
}
}

View File

@ -12,37 +12,6 @@ export default class ProfileData extends AvatarData {
}
}
initArtis () {
this.artis = new ProfileArtis(this.id, this.elem)
}
static create (ds) {
let profile = new ProfileData(ds)
if (!profile) {
return false
}
return profile
}
setAttr (ds) {
this.attr = lodash.extend(Data.getData(ds, 'atk,atkBase,def,defBase,hp,hpBase,mastery,recharge'), {
heal: ds.heal || ds.hInc || 0,
cpct: ds.cpct || ds.cRate,
cdmg: ds.cdmg || ds.cDmg,
dmg: ds.dmg || ds.dmgBonus || 0,
phy: ds.phy || ds.phyBonus || 0
})
}
calcAttr () {
this._attr = AttrCalc.create(this)
this.attr = this._attr.calc()
}
setArtis (ds = false) {
this.artis?.setProfile(this, ds.artis?.artis || ds.artis || ds)
}
// 判断当前profileData是否具有有效数据
get hasData () {
return this.isProfile
@ -60,6 +29,42 @@ export default class ProfileData extends AvatarData {
return [costume, 'normal']
}
get hasDmg () {
return this.hasData && !!ProfileDmg.dmgRulePath(this.name)
}
static create (ds) {
let profile = new ProfileData(ds)
if (!profile) {
return false
}
return profile
}
initArtis () {
this.artis = new ProfileArtis(this.id, this.elem)
}
setAttr (ds) {
this.attr = lodash.extend(Data.getData(ds, 'atk,atkBase,def,defBase,hp,hpBase,mastery,recharge'), {
heal: ds.heal || ds.hInc || 0,
cpct: ds.cpct || ds.cRate,
cdmg: ds.cdmg || ds.cDmg,
dmg: ds.dmg || ds.dmgBonus || 0,
phy: ds.phy || ds.phyBonus || 0
})
}
calcAttr () {
this._attr = AttrCalc.create(this)
this.attr = this._attr.calc()
}
setArtis (ds = false) {
console.log('ds', ds.artis?.artis[1])
this.artis?.setProfile(this, ds.artis?.artis || ds.artis || ds)
}
// 获取当前profileData的圣遗物评分withDetail=false仅返回简略信息
getArtisMark (withDetail = true) {
if (this.hasData) {
@ -68,10 +73,6 @@ export default class ProfileData extends AvatarData {
return {}
}
get hasDmg () {
return this.hasData && !!ProfileDmg.dmgRulePath(this.name)
}
// 计算当前profileData的伤害信息
async calcDmg ({ enemyLv = 91, mode = 'profile', dmgIdx = 0 }) {
if (!this.dmg) {

View File

@ -66,6 +66,27 @@ let EnkaData = {
},
getArtifact (data) {
let ret = {}
lodash.forEach(data, (ds) => {
let flat = ds.flat || {}
let re = ds.reliquary
let idx = artisIdxMap[flat.equipType]
if (!idx) {
return
}
let setName = idsMap[flat.setNameTextMapHash] || ''
ret[idx] = {
name: ArtifactSet.getArtiNameBySet(setName, idx),
level: Math.min(20, ((re.level) || 1) - 1),
star: flat.rankLevel || 5,
mainId: re.mainPropId,
attrIds: re.appendPropIdList
}
})
return ret
},
getArtifactBak (data) {
let ret = {}
let get = function (d) {
if (!d) {

View File

@ -84,6 +84,7 @@ let MiaoData = {
ret[idx] = {
name: ds.name,
level: ds.level,
star: ds.rank,
main: get(ds.mainAffix),
attrs: [
get(sub[0]),

View File

@ -1,3 +1,4 @@
// Enka IdsMap
export const idsMap = {
20848859: '黑岩斩刀',
33330467: '元素熟练',
@ -509,4 +510,4 @@ export const artisIdxMap = {
时之沙: 3,
空之杯: 4,
理之冠: 5
}
}

View File

@ -67,23 +67,31 @@ let ArtisMark = {
let ret = []
let totalUpNum = 0
let ltArr = []
let isIdAttr = false
lodash.forEach(ds, (d) => {
isIdAttr = !!d.eff
let arti = ArtisMark.formatArti(d, charAttrCfg)
ret.push(arti)
if (isIdAttr) {
return true
}
totalUpNum += arti.upNum
if (arti.hasLt) {
ltArr.push(arti)
}
ret.push(arti)
delete arti.hasLt
delete arti.hasGt
})
ltArr = lodash.sortBy(ltArr, 'upNum').reverse()
for (let arti of ltArr) {
if (totalUpNum > 9) {
arti.upNum = arti.upNum - 1
totalUpNum--
} else {
break
if (!isIdAttr) {
ltArr = lodash.sortBy(ltArr, 'upNum').reverse()
for (let arti of ltArr) {
if (totalUpNum > 9) {
arti.upNum = arti.upNum - 1
totalUpNum--
} else {
break
}
}
}
return ret
@ -103,16 +111,13 @@ let ArtisMark = {
if (!key || key === 'undefined') {
return {}
}
let arrCfg = attrMap[isDmg ? 'dmg' : key]
val = Format[arrCfg.format](val, 1)
let ret = {
key,
value: val
}
if (!isMain) {
if (!isMain && !ret.eff) {
let incRet = ArtisMark.getIncNum(key, value)
ret.upNum = incRet.num
ret.hasGt = incRet.hasGt

File diff suppressed because it is too large Load Diff