miao-plugin/models/ProfileData.js

98 lines
2.8 KiB
JavaScript
Raw Normal View History

2022-08-18 10:13:42 +00:00
import lodash from 'lodash'
2023-02-09 16:57:25 +00:00
import AvatarData from './AvatarData.js'
import { Data } from '../components/index.js'
2023-02-09 16:57:25 +00:00
import { ProfileArtis, ProfileDmg } from './index.js'
2022-11-20 20:45:27 +00:00
import AttrCalc from './profile-lib/AttrCalc.js'
import CharImg from './character-lib/CharImg.js'
2022-08-18 10:13:42 +00:00
2023-02-09 16:57:25 +00:00
export default class ProfileData extends AvatarData {
2023-02-10 14:01:18 +00:00
constructor (ds = {}, calc = true) {
2023-02-09 16:57:25 +00:00
super(ds)
2023-02-10 14:01:18 +00:00
if (calc) {
this.calcAttr()
}
}
// 判断当前profileData是否具有有效数据
get hasData () {
return this.isProfile
}
get costumeSplash () {
let costume = this._costume
costume = this.char.checkCostume(costume) ? '2' : ''
let nPath = `meta/character/${this.name}`
let isSuper = false
let talent = this.talent ? lodash.map(this.talent, (ds) => ds.original).join('') : ''
if (this.cons === 6 || ['ACE', 'ACE²'].includes(this.artis?.markClass) || talent === '101010') {
isSuper = true
}
if (isSuper) {
return CharImg.getRandomImg(
[`profile/super-character/${this.name}`, `profile/normal-character/${this.name}`],
[`${nPath}/imgs/splash0.webp`, `${nPath}/imgs/splash${costume}.webp`, `/${nPath}/imgs/splash.webp`]
)
} else {
return CharImg.getRandomImg(
[`profile/normal-character/${this.name}`],
[`${nPath}/imgs/splash${costume}.webp`, `/${nPath}/imgs/splash.webp`]
)
}
}
get hasDmg () {
return this.hasData && !!ProfileDmg.dmgRulePath(this.name)
2023-02-09 16:57:25 +00:00
}
2023-02-08 20:55:54 +00:00
static create (ds) {
let profile = new ProfileData(ds)
if (!profile) {
return false
}
return profile
2022-08-18 10:13:42 +00:00
}
initArtis () {
this.artis = new ProfileArtis(this.id, this.elem)
}
2023-02-09 16:57:25 +00:00
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()
}
2022-08-18 10:13:42 +00:00
setArtis (ds = false) {
2023-02-09 16:57:25 +00:00
this.artis?.setProfile(this, ds.artis?.artis || ds.artis || ds)
2022-08-18 10:13:42 +00:00
}
// 获取当前profileData的圣遗物评分withDetail=false仅返回简略信息
2022-08-18 10:13:42 +00:00
getArtisMark (withDetail = true) {
if (this.hasData) {
return this.artis.getMarkDetail(withDetail)
}
return {}
2022-08-18 10:13:42 +00:00
}
// 计算当前profileData的伤害信息
2022-08-18 10:13:42 +00:00
async calcDmg ({ enemyLv = 91, mode = 'profile', dmgIdx = 0 }) {
if (!this.dmg) {
2022-08-22 20:53:31 +00:00
let ds = this.getData('id,level,attr,cons,artis:artis.sets')
ds.talent = lodash.mapValues(this.talent, 'level')
ds.weapon = Data.getData(this.weapon, 'name,affix')
this.dmg = new ProfileDmg(ds)
2022-08-18 10:13:42 +00:00
}
return await this.dmg.calcData({ enemyLv, mode, dmgIdx })
}
}