miao-plugin/models/ProfileData.js

164 lines
4.1 KiB
JavaScript
Raw Normal View History

2022-08-18 10:13:42 +00:00
import lodash from 'lodash'
import Base from './Base.js'
import moment from 'moment'
2022-08-18 10:13:42 +00:00
import { Data } from '../components/index.js'
import { Character, ProfileArtis, ProfileDmg } from './index.js'
export default class ProfileData extends Base {
constructor (ds = {}) {
super()
let char = Character.get({ id: ds.id, elem: ds.elem })
2022-08-18 10:13:42 +00:00
if (!char) {
return false
}
this.id = char.id
this.char = char
this.setBasic(ds)
ds.attr && this.setAttr(ds.attr)
ds.weapon && this.setWeapon(ds.weapon)
ds.talent && this.setTalent(ds.talent)
2022-08-18 10:13:42 +00:00
this.artis = new ProfileArtis(this.id)
ds.artis && this.setArtis(ds.artis)
}
setBasic (ds = {}) {
this.level = ds.lv || ds.level || 1
this.cons = ds.cons || 0
this.fetter = ds.fetter || 0
this._costume = ds.costume || 0
this.elem = ds.elem || ''
2022-08-18 10:13:42 +00:00
this.dataSource = ds.dataSource || 'enka'
this._time = ds._time || ds.updateTime || new Date() * 1
2022-08-18 10:13:42 +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
})
}
setWeapon (ds = {}) {
this.weapon = {
name: ds.name,
star: ds.rank || ds.star || 1,
level: ds.level || ds.lv || 1,
promote: ds.promote || 1,
affix: ds.affix
}
}
setArtis (ds = false) {
if (ds) {
this.artis.setProfile(this, ds)
2022-08-18 10:13:42 +00:00
}
}
setTalent (ds = {}, mode = 'level') {
this.talent = this.char.getAvatarTalent(ds, this.cons, mode)
}
get name () {
return this.char?.name || ''
}
// 判断当前profileData是否具有有效数据
2022-08-18 10:13:42 +00:00
get hasData () {
// 检查数据源
if (!this.dataSource || !['enka', 'input2', 'miao', 'miao-pre'].includes(this.dataSource)) {
2022-08-18 10:13:42 +00:00
return false
}
// 检查旅行者
2022-08-18 10:13:42 +00:00
if (['空', '荧'].includes(this.name)) {
return !!this.elem
2022-08-18 10:13:42 +00:00
}
// 检查属性
if (!this.weapon || !this.attr || !this.talent || !this.artis) {
return false
}
if (this.dataSource === 'miao-pre') {
this.dataSource = 'miao'
}
2022-08-18 10:13:42 +00:00
return true
}
// 判断当前profileData是否具备有效圣遗物信息
2022-08-18 10:13:42 +00:00
hasArtis () {
return this.hasData && this.artis.length > 0
}
get costume () {
2022-09-10 19:59:45 +00:00
let cMap = [
10000022, // 温迪
10000030, // 钟离
2022-10-18 18:13:23 +00:00
10000052, // 雷神
10000073 // 纳西妲
2022-09-10 19:59:45 +00:00
]
let talent = this.talent ? lodash.map(this.talent, (ds) => ds.original).join('') : ''
2022-09-10 19:59:45 +00:00
if (cMap.includes(this.id)) {
if (this.cons === 6 || ['ACE', 'ACE²'].includes(this.artis?.markClass) || talent === '101010') {
2022-09-10 19:59:45 +00:00
return 'super'
}
}
return this._costume
}
// toJSON 供保存使用
2022-08-18 10:13:42 +00:00
toJSON () {
2022-09-10 19:59:45 +00:00
return this.getData('id,name,level,cons,fetter,attr,weapon,talent,artis,dataSource,costume,elem,_time')
}
get updateTime () {
let time = this._time
if (!time) {
return ''
}
if (lodash.isString(time)) {
return moment(time).format('MM-DD HH:mm')
}
if (lodash.isNumber(time)) {
return moment(new Date(time)).format('MM-DD HH:mm')
}
return ''
2022-08-18 10:13:42 +00:00
}
get dataSourceName () {
return {
enka: 'Enka.Network',
miao: '喵喵Api',
input: 'Input'
}[this.dataSource] || 'Enka.NetWork'
}
2022-09-19 19:16:00 +00:00
get isProfile () {
return true
}
// 获取当前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
}
get hasDmg () {
return this.hasData && !!ProfileDmg.dmgRulePath(this.name)
}
// 计算当前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 })
}
}