miao-plugin/components/profile-data/enka-data.js

219 lines
5.3 KiB
JavaScript
Raw Normal View History

2022-07-27 18:36:49 +00:00
import lodash from 'lodash'
2022-08-18 10:13:42 +00:00
import enkaMeta from './enka-meta.js'
import { Character, ArtifactSet, ProfileData } from '../../models/index.js'
const artiIdx = {
EQUIP_BRACER: 1,
EQUIP_NECKLACE: 2,
EQUIP_SHOES: 3,
EQUIP_RING: 4,
EQUIP_DRESS: 5
2022-07-27 18:36:49 +00:00
}
const attrMap = {
2022-07-27 18:36:49 +00:00
HP: '小生命',
HP_PERCENT: '大生命',
ATTACK: '小攻击',
ATTACK_PERCENT: '大攻击',
DEFENSE: '小防御',
DEFENSE_PERCENT: '大防御',
FIRE_ADD_HURT: '火元素伤害加成',
ICE_ADD_HURT: '冰元素伤害加成',
ROCK_ADD_HURT: '岩元素伤害加成',
ELEC_ADD_HURT: '雷元素伤害加成',
WIND_ADD_HURT: '风元素伤害加成',
WATER_ADD_HURT: '水元素伤害加成',
PHYSICAL_ADD_HURT: '物理伤害加成',
GRASS_ADD_HURT: '草元素伤害加成',
2022-07-27 18:36:49 +00:00
HEAL_ADD: '治疗加成',
ELEMENT_MASTERY: '元素精通',
CRITICAL: '暴击率',
CRITICAL_HURT: '暴击伤害',
CHARGE_EFFICIENCY: '充能效率'
}
2022-08-18 10:13:42 +00:00
let EnkaData = {
2022-09-10 19:59:45 +00:00
getProfile (data) {
2022-07-27 18:36:49 +00:00
let char = Character.get(data.avatarId)
2022-08-18 10:13:42 +00:00
let profile = new ProfileData({ id: char.id })
profile.setBasic({
level: data.propMap['4001'].val * 1,
cons: data.talentIdList ? data.talentIdList.length : 0,
2022-08-18 10:13:42 +00:00
fetter: data.fetterInfo.expLevel,
costume: char.checkCostume(data.costumeId) ? data.costumeId : 0,
2022-08-18 10:13:42 +00:00
dataSource: 'enka'
})
profile.setAttr(EnkaData.getAttr(data.fightPropMap))
profile.setWeapon(EnkaData.getWeapon(data.equipList))
profile.setArtis(EnkaData.getArtifact(data.equipList))
let talentRet = EnkaData.getTalent(char.id, data.skillLevelMap)
profile.setTalent(talentRet.talent, 'original')
// 为旅行者增加elem
if (talentRet.elem) {
profile.elem = talentRet.elem
}
2022-08-18 10:13:42 +00:00
return EnkaData.dataFix(profile)
},
2022-09-10 19:59:45 +00:00
getAttr (data) {
2022-07-27 18:36:49 +00:00
let ret = {}
let attrKey = {
// atk: 2001,
atkBase: 4,
def: 2002,
defBase: 7,
hp: 2000,
hpBase: 1,
mastery: 28,
2022-08-18 10:13:42 +00:00
cpct: {
src: 20,
pct: true
},
2022-08-18 10:13:42 +00:00
cdmg: {
src: 22,
pct: true
},
2022-08-18 10:13:42 +00:00
heal: {
src: 26,
pct: true
},
recharge: {
src: 23,
pct: true
}
2022-07-27 18:36:49 +00:00
}
lodash.forEach(attrKey, (cfg, key) => {
if (!lodash.isObject(cfg)) {
2022-07-27 18:36:49 +00:00
cfg = { src: cfg }
}
2022-07-27 18:36:49 +00:00
let val = data[cfg.src] || 0
if (cfg.pct) {
val = val * 100
}
2022-07-27 18:36:49 +00:00
ret[key] = val
})
ret.atk = data['4'] * (1 + (data['6'] || 0)) + (data['5'] || 0)
let maxDmg = 0
// 火40 水42 风44 岩45 冰46 雷46
// 41 雷
2022-07-27 18:36:49 +00:00
lodash.forEach('40,41,42,43,44,45,45,46'.split(','), (key) => {
maxDmg = Math.max(data[key] * 1, maxDmg)
})
// phy 30
2022-08-18 10:13:42 +00:00
ret.dmg = maxDmg * 100
ret.phy = data['30'] * 100
2022-07-27 18:36:49 +00:00
return ret
},
2022-09-10 19:59:45 +00:00
getArtifact (data) {
2022-07-27 18:36:49 +00:00
let ret = {}
let get = function (d) {
if (!d) {
2022-07-27 18:36:49 +00:00
return []
}
2022-07-27 18:36:49 +00:00
let id = d.appendPropId || d.mainPropId || ''
id = id.replace('FIGHT_PROP_', '')
if (!attrMap[id]) {
2022-07-27 18:36:49 +00:00
return []
}
2022-07-27 18:36:49 +00:00
return [attrMap[id], d.statValue]
}
lodash.forEach(data, (ds) => {
2022-08-18 10:13:42 +00:00
let flat = ds.flat || {}
let sub = flat.reliquarySubstats || []
2022-07-27 18:36:49 +00:00
let idx = artiIdx[flat.equipType]
if (!idx) {
2022-07-27 18:36:49 +00:00
return
}
2022-08-18 10:13:42 +00:00
let setName = enkaMeta[flat.setNameTextMapHash] || ''
ret[idx] = {
name: ArtifactSet.getArtiNameBySet(setName, idx),
2022-08-18 10:13:42 +00:00
set: setName,
level: Math.min(20, ((ds.reliquary && ds.reliquary.level) || 1) - 1),
main: get(flat.reliquaryMainstat),
attrs: [
get(sub[0]),
get(sub[1]),
get(sub[2]),
get(sub[3])
]
}
})
2022-07-27 18:36:49 +00:00
return ret
},
2022-09-10 19:59:45 +00:00
getWeapon (data) {
let ds = {}
lodash.forEach(data, (temp) => {
2022-07-27 18:36:49 +00:00
if (temp.flat && temp.flat.itemType === 'ITEM_WEAPON') {
ds = temp
return false
}
})
2022-07-27 18:36:49 +00:00
let { weapon, flat } = ds
return {
2022-08-18 10:13:42 +00:00
name: enkaMeta[flat.nameTextMapHash],
star: flat.rankLevel,
level: weapon.level,
promote: weapon.promoteLevel,
2022-06-03 09:20:23 +00:00
affix: (lodash.values(weapon.affixMap)[0] || 0) + 1
}
},
2022-09-10 19:59:45 +00:00
getTalent (charid, ds = {}) {
let char = Character.get(charid)
let { talentId = {}, talentElem = {}, talentKey = {} } = char.meta
let elem = ''
let idx = 0
2022-07-27 18:36:49 +00:00
let ret = {}
lodash.forEach(ds, (lv, id) => {
let key
if (talentId[id]) {
let tid = talentId[id]
key = talentKey[tid]
elem = elem || talentElem[tid]
} else {
key = ['a', 'e', 'q'][idx++]
}
ret[key] = {
2022-08-18 10:13:42 +00:00
original: lv
}
})
return {
elem: elem,
talent: ret
}
},
2022-09-10 19:59:45 +00:00
dataFix (ret) {
if (ret._fix) {
2022-07-27 18:36:49 +00:00
return ret
}
let { attr, id, weapon } = ret
2022-07-27 18:36:49 +00:00
id = id * 1
switch (id) {
case 10000052:
// 雷神被动加成fix
2022-08-18 10:13:42 +00:00
attr.dmg = Math.max(0, attr.dmg - (attr.recharge - 100) * 0.4)
2022-07-27 18:36:49 +00:00
break
case 10000041:
// 莫娜被动fix
2022-08-18 10:13:42 +00:00
attr.dmg = Math.max(0, attr.dmg - attr.recharge * 0.2)
2022-07-27 18:36:49 +00:00
break
}
let wDmg = {
息灾: 12,
波乱月白经津: 12,
雾切之回光: 12,
猎人之径: 12
}
let { name, affix } = weapon
// 修正武器的加伤
if (wDmg[name]) {
attr.dmg = Math.max(0, attr.dmg - wDmg[name] - wDmg[name] * (affix - 1) / 4)
}
2022-07-27 18:36:49 +00:00
ret._fix = true
return ret
}
2022-07-27 18:36:49 +00:00
}
2022-08-18 10:13:42 +00:00
export default EnkaData