2022-08-18 10:13:42 +00:00
|
|
|
|
import lodash from 'lodash'
|
|
|
|
|
import Base from './Base.js'
|
2022-08-20 23:40:32 +00:00
|
|
|
|
import moment from 'moment'
|
2022-11-24 16:31:36 +00:00
|
|
|
|
import { Data, Cfg } from '../components/index.js'
|
2022-08-18 10:13:42 +00:00
|
|
|
|
import { Character, ProfileArtis, ProfileDmg } from './index.js'
|
2022-11-20 20:45:27 +00:00
|
|
|
|
import AttrCalc from './profile-lib/AttrCalc.js'
|
2022-08-18 10:13:42 +00:00
|
|
|
|
|
|
|
|
|
export default class ProfileData extends Base {
|
2022-11-26 08:12:32 +00:00
|
|
|
|
constructor (ds = {}, uid, attrCalc = true) {
|
2022-08-18 10:13:42 +00:00
|
|
|
|
super()
|
2022-09-03 21:08:57 +00:00
|
|
|
|
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
|
2022-11-22 20:25:36 +00:00
|
|
|
|
this.uid = uid || ''
|
2022-08-18 10:13:42 +00:00
|
|
|
|
this.setBasic(ds)
|
|
|
|
|
ds.attr && this.setAttr(ds.attr)
|
|
|
|
|
ds.weapon && this.setWeapon(ds.weapon)
|
2022-09-06 19:28:46 +00:00
|
|
|
|
ds.talent && this.setTalent(ds.talent)
|
2022-11-22 20:25:36 +00:00
|
|
|
|
this.artis = new ProfileArtis(this.id, this.elem)
|
2022-08-18 10:13:42 +00:00
|
|
|
|
ds.artis && this.setArtis(ds.artis)
|
2022-11-26 08:12:32 +00:00
|
|
|
|
if (attrCalc && Cfg.get('attrCalc') && this.hasData) {
|
|
|
|
|
this.calcAttr()
|
2022-11-24 16:31:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static create (ds, uid) {
|
|
|
|
|
let profile = new ProfileData(ds, uid)
|
|
|
|
|
if (!profile) {
|
|
|
|
|
return false
|
2022-11-22 20:25:36 +00:00
|
|
|
|
}
|
2022-11-24 16:31:36 +00:00
|
|
|
|
return profile
|
2022-08-18 10:13:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-26 08:12:32 +00:00
|
|
|
|
calcAttr () {
|
|
|
|
|
this._attr = AttrCalc.create(this)
|
|
|
|
|
this.attr = this._attr.calc()
|
|
|
|
|
this._attrCalc = true
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-18 10:13:42 +00:00
|
|
|
|
setBasic (ds = {}) {
|
|
|
|
|
this.level = ds.lv || ds.level || 1
|
|
|
|
|
this.cons = ds.cons || 0
|
|
|
|
|
this.fetter = ds.fetter || 0
|
2022-09-05 17:05:06 +00:00
|
|
|
|
this._costume = ds.costume || 0
|
2022-11-22 20:25:36 +00:00
|
|
|
|
this.elem = ds.elem || this.char.elem || ''
|
2022-08-18 10:13:42 +00:00
|
|
|
|
this.dataSource = ds.dataSource || 'enka'
|
2022-11-22 20:25:36 +00:00
|
|
|
|
this.promote = lodash.isUndefined(ds.promote) ? AttrCalc.calcPromote(this.level) : (ds.promote || 0)
|
2022-08-20 23:40:32 +00:00
|
|
|
|
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,
|
2022-11-26 09:21:53 +00:00
|
|
|
|
promote: lodash.isUndefined(ds.promote) ? AttrCalc.calcPromote(ds.level || ds.lv || 1) : (ds.promote || 0),
|
2022-08-18 10:13:42 +00:00
|
|
|
|
affix: ds.affix
|
|
|
|
|
}
|
2022-11-22 20:25:36 +00:00
|
|
|
|
let w = this.weapon
|
|
|
|
|
if (w.level < 20) {
|
|
|
|
|
w.promote = 0
|
|
|
|
|
}
|
2022-08-18 10:13:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setArtis (ds = false) {
|
2022-11-24 15:27:03 +00:00
|
|
|
|
this.artis.setProfile(this, ds)
|
2022-08-18 10:13:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-26 08:12:32 +00:00
|
|
|
|
setTalent (ds = {}, mode = 'original') {
|
2022-08-18 10:13:42 +00:00
|
|
|
|
this.talent = this.char.getAvatarTalent(ds, this.cons, mode)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get name () {
|
|
|
|
|
return this.char?.name || ''
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-18 23:08:16 +00:00
|
|
|
|
// 判断当前profileData是否具有有效数据
|
2022-08-18 10:13:42 +00:00
|
|
|
|
get hasData () {
|
2022-08-18 23:08:16 +00:00
|
|
|
|
// 检查数据源
|
2022-11-26 08:12:32 +00:00
|
|
|
|
if (!this.dataSource || !['enka', 'change', 'miao'].includes(this.dataSource)) {
|
2022-08-18 10:13:42 +00:00
|
|
|
|
return false
|
|
|
|
|
}
|
2022-08-18 23:08:16 +00:00
|
|
|
|
// 检查属性
|
2022-11-24 16:44:45 +00:00
|
|
|
|
if (!this.weapon || !this.talent || !this.artis) {
|
2022-08-18 23:08:16 +00:00
|
|
|
|
return false
|
|
|
|
|
}
|
2022-11-24 16:44:45 +00:00
|
|
|
|
// 检查旅行者
|
|
|
|
|
if (['空', '荧'].includes(this.name)) {
|
|
|
|
|
return !!this.elem
|
|
|
|
|
}
|
2022-08-18 10:13:42 +00:00
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-18 23:08:16 +00:00
|
|
|
|
// 判断当前profileData是否具备有效圣遗物信息
|
2022-08-18 10:13:42 +00:00
|
|
|
|
hasArtis () {
|
|
|
|
|
return this.hasData && this.artis.length > 0
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-05 17:05:06 +00:00
|
|
|
|
get costume () {
|
2022-11-20 20:45:27 +00:00
|
|
|
|
let costume = this._costume
|
|
|
|
|
if (lodash.isArray(costume)) {
|
|
|
|
|
costume = costume[0]
|
|
|
|
|
}
|
2022-09-08 20:34:32 +00:00
|
|
|
|
let talent = this.talent ? lodash.map(this.talent, (ds) => ds.original).join('') : ''
|
2022-11-17 16:54:45 +00:00
|
|
|
|
if (this.cons === 6 || ['ACE', 'ACE²'].includes(this.artis?.markClass) || talent === '101010') {
|
2022-11-20 20:45:27 +00:00
|
|
|
|
return [costume, 'super']
|
2022-09-05 17:05:06 +00:00
|
|
|
|
}
|
2022-11-20 20:45:27 +00:00
|
|
|
|
return [costume, 'normal']
|
2022-09-05 17:05:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-26 08:34:11 +00:00
|
|
|
|
get originalTalent () {
|
|
|
|
|
return lodash.mapValues(this.talent, (ds) => ds.original)
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-18 23:08:16 +00:00
|
|
|
|
// toJSON 供保存使用
|
2022-08-18 10:13:42 +00:00
|
|
|
|
toJSON () {
|
2022-11-26 08:12:32 +00:00
|
|
|
|
let ret = {
|
|
|
|
|
...this.getData('id,name,elem,level,promote,fetter,costume,cons,talent,attr,weapon,artis,dataSource,_time')
|
|
|
|
|
}
|
|
|
|
|
ret.talent = lodash.mapValues(this.talent, (ds) => ds.original)
|
|
|
|
|
ret.costume = this.costume[0] || 0
|
|
|
|
|
return ret
|
2022-08-20 23:40:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 20:54:01 +00:00
|
|
|
|
get dataSourceName () {
|
|
|
|
|
return {
|
|
|
|
|
enka: 'Enka.Network',
|
2022-10-21 14:48:19 +00:00
|
|
|
|
miao: '喵喵Api',
|
2022-09-18 20:54:01 +00:00
|
|
|
|
input: 'Input'
|
|
|
|
|
}[this.dataSource] || 'Enka.NetWork'
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-19 19:16:00 +00:00
|
|
|
|
get isProfile () {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-18 23:08:16 +00:00
|
|
|
|
// 获取当前profileData的圣遗物评分,withDetail=false仅返回简略信息
|
2022-08-18 10:13:42 +00:00
|
|
|
|
getArtisMark (withDetail = true) {
|
2022-09-08 20:34:32 +00:00
|
|
|
|
if (this.hasData) {
|
2022-09-08 09:38:15 +00:00
|
|
|
|
return this.artis.getMarkDetail(withDetail)
|
|
|
|
|
}
|
|
|
|
|
return {}
|
2022-08-18 10:13:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-08 22:04:08 +00:00
|
|
|
|
get hasDmg () {
|
|
|
|
|
return this.hasData && !!ProfileDmg.dmgRulePath(this.name)
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-18 23:08:16 +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 })
|
|
|
|
|
}
|
|
|
|
|
}
|