为面板数据增加圣遗物检测,防止错误数据

This commit is contained in:
Kokomi 2023-02-10 01:50:52 +08:00
parent 673d813f6f
commit 782a677322
5 changed files with 75 additions and 55 deletions

View File

@ -137,6 +137,16 @@ export default class AvatarArtis extends Base {
return !lodash.isEmpty(this.artis) return !lodash.isEmpty(this.artis)
} }
get hasAttr () {
for (let idx = 1; idx <= 5; idx++) {
let ds = this.artis[idx]
if (ds && (!ds.name || !ds.main || !ds.attrs)) {
return false
}
}
return true
}
mainAttr (idx = '') { mainAttr (idx = '') {
if (!idx) { if (!idx) {
let ret = {} let ret = {}

View File

@ -4,6 +4,7 @@ import moment from 'moment'
import { Character, AvatarArtis, ProfileData, Weapon } from './index.js' import { Character, AvatarArtis, ProfileData, Weapon } from './index.js'
import { Data } from '../components/index.js' import { Data } from '../components/index.js'
import AttrCalc from './profile-lib/AttrCalc.js' import AttrCalc from './profile-lib/AttrCalc.js'
import Profile from './player-lib/Profile.js'
const charKey = 'name,abbr,sName,star,imgs,face,side,gacha,weaponTypeName'.split(',') const charKey = 'name,abbr,sName,star,imgs,face,side,gacha,weaponTypeName'.split(',')
@ -107,7 +108,7 @@ export default class AvatarData extends Base {
* 当前数据是否需要更新天赋 * 当前数据是否需要更新天赋
* @returns {boolean} * @returns {boolean}
*/ */
needRefreshTalent () { get needRefreshTalent () {
// 不存在天赋数据 // 不存在天赋数据
if (!this.hasTalent) { if (!this.hasTalent) {
return true return true
@ -116,42 +117,6 @@ export default class AvatarData extends Base {
return (new Date() * 1) - this._talent > 3600 * 2 * 1000 return (new Date() * 1) - this._talent > 3600 * 2 * 1000
} }
async refreshTalent (mys) {
if (mys && mys.isSelfCookie) {
let char = this.char
if (!char) {
return false
}
let id = char.id
let talent = {}
let talentRes = await mys.getDetail(id)
// { data: null, message: '请先登录', retcode: -100, api: 'detail' }
if (talentRes && talentRes.skill_list) {
let talentList = lodash.orderBy(talentRes.skill_list, ['id'], ['asc'])
for (let val of talentList) {
let { max_level: maxLv, level_current: lv } = val
if (val.name.includes('普通攻击')) {
talent.a = lv
continue
}
if (maxLv >= 10 && !talent.e) {
talent.e = lv
continue
}
if (maxLv >= 10 && !talent.q) {
talent.q = lv
}
}
}
let ret = char.getAvatarTalent(talent, this.cons, 'original')
if (ret) {
this.setTalent(ret, 'original', 'mys')
}
return true
}
return false
}
setArtis (ds, source) { setArtis (ds, source) {
this.artis.setArtisData(ds.artis, source) this.artis.setArtisData(ds.artis, source)
} }
@ -164,23 +129,9 @@ export default class AvatarData extends Base {
return this.char?.name || '' return this.char?.name || ''
} }
/** // 是否是合法面板数据
*
*/
get isProfile () { get isProfile () {
// 检查数据源 return Profile.isProfile(this)
if (!this._source || !['enka', 'change', 'miao'].includes(this._source)) {
return false
}
// 检查属性
if (!this.weapon || !this.talent || !this.artis) {
return false
}
// 检查旅行者
if (['空', '荧'].includes(this.name)) {
return !!this.elem
}
return true
} }
getProfile () { getProfile () {

View File

@ -78,7 +78,7 @@ const MysAvatar = {
} }
lodash.forEach(ids, (id) => { lodash.forEach(ids, (id) => {
let avatar = player.getAvatar(id) let avatar = player.getAvatar(id)
if (avatar.needRefreshTalent()) { if (avatar.needRefreshTalent) {
ret.push(avatar.id) ret.push(avatar.id)
} }
}) })
@ -110,7 +110,7 @@ const MysAvatar = {
for (let val of avatarArr) { for (let val of avatarArr) {
for (let id of val) { for (let id of val) {
let avatar = player.getAvatar(id) let avatar = player.getAvatar(id)
skillRet.push(await avatar.refreshTalent(mys)) skillRet.push(await MysAvatar.refreshAvatarTalent(avatar, mys))
} }
skillRet = await Promise.all(skillRet) skillRet = await Promise.all(skillRet)
skillRet = skillRet.filter(item => item.id) skillRet = skillRet.filter(item => item.id)
@ -118,6 +118,42 @@ const MysAvatar = {
} }
} }
player.save() player.save()
},
async refreshAvatarTalent (avatar, mys) {
if (mys && mys.isSelfCookie) {
let char = avatar.char
if (!char) {
return false
}
let id = char.id
let talent = {}
let talentRes = await mys.getDetail(id)
// { data: null, message: '请先登录', retcode: -100, api: 'detail' }
if (talentRes && talentRes.skill_list) {
let talentList = lodash.orderBy(talentRes.skill_list, ['id'], ['asc'])
for (let val of talentList) {
let { max_level: maxLv, level_current: lv } = val
if (val.name.includes('普通攻击')) {
talent.a = lv
continue
}
if (maxLv >= 10 && !talent.e) {
talent.e = lv
continue
}
if (maxLv >= 10 && !talent.q) {
talent.q = lv
}
}
}
let ret = char.getAvatarTalent(talent, avatar.cons, 'original')
if (ret) {
avatar.setTalent(ret, 'original', 'mys')
}
return true
}
return false
} }
} }
export default MysAvatar export default MysAvatar

View File

@ -54,6 +54,26 @@ const Profile = {
e.reply(`UID:${uid}更新面板失败,更新服务:${serv.name}`) e.reply(`UID:${uid}更新面板失败,更新服务:${serv.name}`)
return false return false
} }
},
isProfile (avatar) {
// 检查数据源
if (!avatar._source || !['enka', 'change', 'miao'].includes(avatar._source)) {
return false
}
// 检查武器及天赋
if (!avatar.weapon || !avatar.talent) {
return false
}
// 检查圣遗物词条是否完备
if (!avatar.artis || !avatar.artis.hasAttr) {
return false
}
// 检查旅行者
if (['空', '荧'].includes(avatar.name)) {
return !!avatar.elem
}
return true
} }
} }

View File

@ -167,6 +167,9 @@ let ArtisMark = {
let ret = 0 let ret = 0
let { attrs, posMaxMark } = charCfg let { attrs, posMaxMark } = charCfg
let key = mainAttr?.key let key = mainAttr?.key
if (!key) {
return 0
}
let fixPct = 1 let fixPct = 1
posIdx = posIdx * 1 posIdx = posIdx * 1
if (posIdx >= 3) { if (posIdx >= 3) {