一些Bugfix

This commit is contained in:
Kokomi 2023-02-10 21:53:57 +08:00
parent a56e1cd81d
commit 7272da906d
4 changed files with 91 additions and 88 deletions

View File

@ -177,10 +177,10 @@ const ProfileChange = {
return source
}
let cuid = cfg.uid || uid
let cPlayer = Player.create(uid)
let id = cfg.char || source.id
let key = cuid + ':' + id
if (!profiles[key]) {
let cPlayer = Player.create(cuid)
profiles[key] = cPlayer.getProfile(id) || {}
}
return profiles[key]?.id ? profiles[key] : source

View File

@ -199,7 +199,7 @@ export async function renderProfile (e, char, mode = 'profile', params = {}) {
let msgRes = await Common.render('character/profile-detail', {
save_id: uid,
uid,
data: avatar.getData('name,abbr,cons,level,weapon,talent,dataSource,updateTime'),
data: profile.getData('name,abbr,cons,level,weapon,talent,dataSource,updateTime'),
attr,
elem: char.elem,
dmgData,

View File

@ -21,8 +21,72 @@ export default class AvatarData extends Base {
this.setAvatar(ds, source)
}
initArtis () {
this.artis = new AvatarArtis(this.id)
/**
* 当前数据是否需要更新天赋
* @returns {boolean}
*/
get needRefreshTalent() {
// 不存在天赋数据
if (!this.hasTalent) {
return true
}
// 超过2个小时的天赋数据进行请求
return (new Date() * 1) - this._talent > 3600 * 2 * 1000
}
get hasTalent() {
return this.talent && !lodash.isEmpty(this.talent) && !!this._talent
}
get name() {
return this.char?.name || ''
}
// 是否是合法面板数据
get isProfile() {
return Profile.isProfile(this)
}
get costume() {
let costume = this._costume
if (lodash.isArray(costume)) {
costume = costume[0]
}
return costume
}
get originalTalent() {
return lodash.mapValues(this.talent, (ds) => ds.original)
}
/**
* 获取圣遗物套装属性
* @returns {boolean|*|{imgs: *[], names: *[], sets: {}, abbrs: *[], sName: string, name: (string|*)}|{}}
*/
get artisSet() {
return this.artis.getSetData()
}
get dataSource() {
return {
enka: 'Enka.Network',
miao: '喵喵Api',
mys: '米游社'
}[this._source] || this._source
}
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 ''
}
static create(ds, source) {
@ -33,6 +97,10 @@ export default class AvatarData extends Base {
return avatar
}
initArtis() {
this.artis = new AvatarArtis(this.id)
}
_get(key) {
if (charKey.includes(key)) {
return this.char[key]
@ -80,13 +148,16 @@ export default class AvatarData extends Base {
}
setWeapon(ds = {}) {
let w = Weapon.get(ds.name) || {}
let w = Weapon.get(ds.name)
if (!w) {
return false
}
this.weapon = {
name: ds.name,
level: ds.level || ds.lv || 1,
promote: lodash.isUndefined(ds.promote) ? AttrCalc.calcPromote(ds.level || ds.lv || 1) : (ds.promote || 0),
affix: ds.affix,
...w?.getData('star,abbr,type,img')
...w.getData('star,abbr,type,img')
}
if (this.weapon.level < 20) {
this.weapon.promote = 0
@ -104,36 +175,10 @@ export default class AvatarData extends Base {
}
}
/**
* 当前数据是否需要更新天赋
* @returns {boolean}
*/
get needRefreshTalent () {
// 不存在天赋数据
if (!this.hasTalent) {
return true
}
// 超过2个小时的天赋数据进行请求
return (new Date() * 1) - this._talent > 3600 * 2 * 1000
}
setArtis(ds, source) {
this.artis.setArtisData(ds.artis, source)
}
get hasTalent () {
return this.talent && !lodash.isEmpty(this.talent) && !!this._talent
}
get name () {
return this.char?.name || ''
}
// 是否是合法面板数据
get isProfile () {
return Profile.isProfile(this)
}
getProfile() {
if (!this.isProfile) {
return false
@ -146,18 +191,6 @@ export default class AvatarData extends Base {
return this.isProfile && this.artis.length > 0
}
get costume () {
let costume = this._costume
if (lodash.isArray(costume)) {
costume = costume[0]
}
return costume
}
get originalTalent () {
return lodash.mapValues(this.talent, (ds) => ds.original)
}
// toJSON 供保存使用
toJSON() {
return {
@ -171,37 +204,7 @@ export default class AvatarData extends Base {
return this.getData(keys || 'id,name,level,star,cons,fetter,elem,face,side,gacha,abbr,weapon,talent,artisSet') || {}
}
/**
* 获取圣遗物套装属性
* @returns {boolean|*|{imgs: *[], names: *[], sets: {}, abbrs: *[], sName: string, name: (string|*)}|{}}
*/
get artisSet () {
return this.artis.getSetData()
}
getArtisDetail() {
return this.artis.getDetail()
}
get dataSource () {
return {
enka: 'Enka.Network',
miao: '喵喵Api',
mys: '米游社'
}[this._source] || this._source
}
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 ''
}
}

View File

@ -482,7 +482,7 @@ export const attrMap = {
ATTACK_PERCENT: 'atk',
DEFENSE: 'defPlus',
DEFENSE_PERCENT: 'def',
FIRE_ADD_HURT: '',
FIRE_ADD_HURT: 'pyro',
ICE_ADD_HURT: 'cryo',
ROCK_ADD_HURT: 'geo',
ELEC_ADD_HURT: 'electro',