Avatar增加获取材料相关方法

This commit is contained in:
Kokomi 2023-11-02 21:20:16 +08:00
parent b2253078f8
commit f19c1fa7c1
4 changed files with 63 additions and 42 deletions

View File

@ -11,7 +11,7 @@ const ProfileStat = {
},
// 渲染
// isAvatarList true:练度统计 false角色列表
// isAvatarList true:角色列表 false练度统计
async render (e, isAvatarList = false) {
// 缓存时间,单位小时
let msg = e.msg.replace('#', '').trim()
@ -20,6 +20,8 @@ const ProfileStat = {
return false
}
let isTalent = !isAvatarList && /天赋|技能/.test(msg)
let mys = await MysApi.init(e)
if (!mys || !mys.uid) return false
@ -32,6 +34,7 @@ const ProfileStat = {
detail: 1,
talent: isAvatarList ? 0 : 1,
rank: true,
materials: isTalent,
retType: 'array',
sort: true
})

View File

@ -8,6 +8,7 @@ import Artis from './artis/Artis.js'
import ProfileAvatar from './avatar/ProfileAvatar.js'
import ArtisMark from './artis/ArtisMark.js'
import moment from 'moment'
import MysAvatar from './avatar/MysAvatar.js'
const charKey = 'name,abbr,sName,star,imgs,face,side,gacha,weaponTypeName'.split(',')
@ -26,7 +27,6 @@ export default class Avatar extends Base {
this.setAvatar(ds)
}
get hasTalent () {
return this.talent && !lodash.isEmpty(this.talent) && !!this._talent
}
@ -91,13 +91,50 @@ export default class Avatar extends Base {
return ''
}
get isAvatar () {
return true
}
// 是否是合法面板数据
get isProfile () {
return ProfileAvatar.isProfile(this)
}
// profile.hasData 别名
get hasData () {
return !!(this.level > 1 || this?.weapon?.name)
}
get imgs () {
return this.char.getImgs(this.costume) || {}
}
get costumeSplash () {
return ProfileAvatar.getCostumeSplash(this)
}
get hasDmg () {
return this.isProfile && !!ProfileDmg.dmgRulePath(this.name, this.game)
}
get artis () {
return this._artis
}
static create (ds, game = 'gs') {
let profile = new Avatar(ds, game)
if (!profile) {
return false
}
return profile
}
_get (key) {
if (charKey.includes(key)) {
return this.char[key]
}
}
/**
* 设置角色基础数据
* @param ds
@ -253,44 +290,6 @@ export default class Avatar extends Base {
}
}
get isAvatar () {
return true
}
// 是否是合法面板数据
get isProfile () {
return ProfileAvatar.isProfile(this)
}
// profile.hasData 别名
get hasData () {
return !!(this.level > 1 || this?.weapon?.name)
}
get imgs () {
return this.char.getImgs(this.costume) || {}
}
get costumeSplash () {
return ProfileAvatar.getCostumeSplash(this)
}
get hasDmg () {
return this.isProfile && !!ProfileDmg.dmgRulePath(this.name, this.game)
}
get artis () {
return this._artis
}
static create (ds, game = 'gs') {
let profile = new Avatar(ds, game)
if (!profile) {
return false
}
return profile
}
setAvatarBase (ds, source = '') {
this._now = new Date() * 1
this.setBasic(ds, source)
@ -373,4 +372,8 @@ export default class Avatar extends Base {
getArtisDetail (mysArtis = false) {
return (mysArtis ? this.mysArtis : this.artis).getDetail()
}
getMaterials () {
return MysAvatar.getMaterials(this)
}
}

View File

@ -360,8 +360,10 @@ export default class Player extends Base {
* @param cfg.detail mys-detail数据更新级别角色列表与详情
* @param cfg.talent mys-talent数据更新级别角色天赋数据
* @param cfg.index mys-index数据更新级别游戏统计数据
* @param cfg.materials 是否返回角色的材料默认false
* @param cfg.retType 返回类型默认id为key对象设置为array时返回数组
* @param cfg.rank 返回为数组时数据是否排序排序规则等级星级天赋命座武器好感的顺序排序
* @param cfg.rank 面板数据是否参与群排序
* @param cfg.sort 返回为数组时数据是否排序排序规则等级星级天赋命座武器好感的顺序排序
* @returns {Promise<any[]|{}>}
*/
@ -390,6 +392,9 @@ export default class Player extends Base {
rank.getRank(profile)
}
}
if (cfg.materials) {
ds.materials = avatar.getMaterials()
}
})
if (cfg.retType !== 'array') {
return avatarRet
@ -402,4 +407,6 @@ export default class Player extends Base {
}
return avatarRet
}
}

View File

@ -317,6 +317,14 @@ const MysAvatar = {
stats.avatar5 = avatar5Count
ret.stats = stats
return ret
},
getMaterials (avatar) {
let ret = {}
let { char } = avatar
ret.talent = char.getMaterials('talent')
ret.weekly = char.getMaterials('weekly')
return ret
}
}
export default MysAvatar