优化Enka下对圣遗物词条PropIds的处理逻辑,使属性计算更准确

修复部分情况下自定义面板图不展示的问题
This commit is contained in:
Kokomi 2023-02-12 19:56:47 +08:00
parent 1ee3e9df51
commit 0292db4350
9 changed files with 365 additions and 1252 deletions

View File

@ -43,7 +43,7 @@ export async function profileArtis (e) {
return await Common.render('character/artis-mark', { return await Common.render('character/artis-mark', {
uid, uid,
elem: char.elem, elem: char.elem,
splash: char.getImgs(profile.costume).splash0, splash: profile.costumeSplash,
data: profile, data: profile,
costume: profile.costume ? '2' : '', costume: profile.costume ? '2' : '',
artisDetail, artisDetail,

View File

@ -195,6 +195,7 @@ export async function renderProfile (e, char, mode = 'profile', params = {}) {
let artisDetail = profile.getArtisMark() let artisDetail = profile.getArtisMark()
let artisKeyTitle = ProfileArtis.getArtisKeyTitle() let artisKeyTitle = ProfileArtis.getArtisKeyTitle()
let imgs = char.getImgs(profile.costume) let imgs = char.getImgs(profile.costume)
let costumeSplash = profile.costumeSplash
// 渲染图像 // 渲染图像
let msgRes = await Common.render('character/profile-detail', { let msgRes = await Common.render('character/profile-detail', {
save_id: uid, save_id: uid,
@ -210,6 +211,7 @@ export async function renderProfile (e, char, mode = 'profile', params = {}) {
artisKeyTitle, artisKeyTitle,
enemyLv, enemyLv,
imgs, imgs,
costumeSplash,
enemyName: dmgCalc.enemyName || '小宝', enemyName: dmgCalc.enemyName || '小宝',
talentMap: { a: '普攻', e: '战技', q: '爆发' }, talentMap: { a: '普攻', e: '战技', q: '爆发' },
bodyClass: `char-${char.name}`, bodyClass: `char-${char.name}`,
@ -218,7 +220,7 @@ export async function renderProfile (e, char, mode = 'profile', params = {}) {
}, { e, scale: 1.6, retMsgId: true }) }, { e, scale: 1.6, retMsgId: true })
if (msgRes && msgRes.message_id) { if (msgRes && msgRes.message_id) {
// 如果消息发送成功就将message_id和图片路径存起来3小时过期 // 如果消息发送成功就将message_id和图片路径存起来3小时过期
await redis.set(`miao:original-picture:${msgRes.message_id}`, imgs.splash0, { EX: 3600 * 3 }) await redis.set(`miao:original-picture:${msgRes.message_id}`, costumeSplash, { EX: 3600 * 3 })
} }
return true return true
} }

View File

@ -58,22 +58,24 @@ class Artifact extends Base {
} }
} }
static getMainById (id, level = 20, star) { static getMainById (id, level = 20, star = 5) {
let cfg = mainIdMap[id] let key = mainIdMap[id]
if (!cfg) { if (!key) {
return false return false
} }
let attrCfg = attrMap[Format.isElem(cfg.key) ? 'dmg' : cfg.key] let attrCfg = attrMap[Format.isElem(key) ? 'dmg' : key]
let eff = ['hpPlus', 'atkPlus', 'defPlus'].includes(cfg.key) ? 2 : 1 let posEff = ['hpPlus', 'atkPlus', 'defPlus'].includes(key) ? 2 : 1
let starEff = { 1: 0.21, 2: 0.36, 3: 0.6, 4: 0.9, 5: 1 }
return { return {
key: cfg.key, key,
value: attrCfg.value * (1.2 + 0.34 * level) * eff value: attrCfg.value * (1.2 + 0.34 * level) * posEff * (starEff[star || 5])
} }
} }
static getAttrsByIds (ids) { static getAttrsByIds (ids, star = 5) {
let ret = [] let ret = []
let tmp = {} let tmp = {}
let starEff = { 1: 0.21, 2: 0.36, 3: 0.6, 4: 0.8, 5: 1 }
lodash.forEach(ids, (id) => { lodash.forEach(ids, (id) => {
let cfg = attrIdMap[id] let cfg = attrIdMap[id]
if (!cfg) { if (!cfg) {
@ -93,7 +95,7 @@ class Artifact extends Base {
}) })
lodash.forEach(tmp, (ds, key) => { lodash.forEach(tmp, (ds, key) => {
if (attrMap[key]) { if (attrMap[key]) {
ds.value = attrMap[key].value * ds.eff ds.value = attrMap[key].value * ds.eff * starEff[star]
} }
}) })
return ret return ret

View File

@ -87,7 +87,7 @@ export default class AvatarArtis extends Base {
arti.mainId = ds.mainId arti.mainId = ds.mainId
arti.attrIds = ds.attrIds arti.attrIds = ds.attrIds
arti.main = Artifact.getMainById(ds.mainId, arti._level, arti._star) arti.main = Artifact.getMainById(ds.mainId, arti._level, arti._star)
arti.attrs = Artifact.getAttrsByIds(ds.attrIds) arti.attrs = Artifact.getAttrsByIds(ds.attrIds, arti._star)
} else if (ds.main && ds.attrs) { } else if (ds.main && ds.attrs) {
arti.main = ArtisMark.formatAttr(ds.main || {}) arti.main = ArtisMark.formatAttr(ds.main || {})
arti.attrs = [] arti.attrs = []

View File

@ -20,6 +20,9 @@ let getMeta = function (name) {
} }
class Character extends Base { class Character extends Base {
// 默认获取的数据
_dataKey = 'id,name,abbr,title,star,elem,allegiance,weapon,birthday,astro,cncv,jpcv,ver,desc,talentCons'
constructor ({ id, name = '', elem = '' }) { constructor ({ id, name = '', elem = '' }) {
super() super()
// 检查缓存 // 检查缓存
@ -40,9 +43,6 @@ class Character extends Base {
return this._cache() return this._cache()
} }
// 默认获取的数据
_dataKey = 'id,name,abbr,title,star,elem,allegiance,weapon,birthday,astro,cncv,jpcv,ver,desc,talentCons'
// 是否为官方角色 // 是否为官方角色
get isOfficial () { get isOfficial () {
return /[12]0\d{6}/.test(this._id) return /[12]0\d{6}/.test(this._id)
@ -140,6 +140,59 @@ class Character extends Base {
return this.meta?.talentCons || {} return this.meta?.talentCons || {}
} }
// 获取生日
get birthday () {
let birth = this.birth
if (!birth) {
return ''
}
birth = birth.split('-')
return `${birth[0]}${birth[1]}`
}
// 基于角色名获取Character
static get (val) {
let id = CharId.getId(val, Character.gsCfg)
if (!id) {
return false
}
return new Character(id)
}
static forEach (fn, type = 'all') {
lodash.forEach(idMap, (name, id) => {
let char = Character.get({ id, name })
if (type === 'release' && !char.isRelease) {
return true
}
if (type === 'official' && !char.isOfficial) {
return true
}
return fn(char) !== false
})
}
// 当获取角色为旅行者时会考虑当前uid的账号情况返回对应旅行者
static async getAvatar (name, uid) {
let char = Character.get(name)
return await char.getTraveler(uid)
}
// TODO待废弃
static getAbbr () {
return abbrMap
}
// TODO待废弃
static checkWifeType (charid, type) {
return !!wifeMap[type][charid]
}
// 获取排序ID
static sortIds (arr) {
return arr.sort((a, b) => (idSort[a] || 300) - (idSort[b] || 300))
}
// 获取attr列表 // 获取attr列表
getAttrList () { getAttrList () {
let { meta } = this let { meta } = this
@ -151,16 +204,6 @@ class Character extends Base {
return CharMeta.getMaterials(this, type) return CharMeta.getMaterials(this, type)
} }
// 获取生日
get birthday () {
let birth = this.birth
if (!birth) {
return ''
}
birth = birth.split('-')
return `${birth[0]}${birth[1]}`
}
// 获取角色character-img图片 // 获取角色character-img图片
getCardImg (se = false, def = true) { getCardImg (se = false, def = true) {
if (this.name === '旅行者') { if (this.name === '旅行者') {
@ -169,6 +212,8 @@ class Character extends Base {
return CharImg.getCardImg(this.name, se, def) return CharImg.getCardImg(this.name, se, def)
} }
// 设置旅行者数据
getAvatarTalent (talent = {}, cons = 0, mode = 'original') { getAvatarTalent (talent = {}, cons = 0, mode = 'original') {
return CharTalent.getAvatarTalent(this.id, talent, cons, mode, this.talentCons) return CharTalent.getAvatarTalent(this.id, talent, cons, mode, this.talentCons)
} }
@ -192,34 +237,22 @@ class Character extends Base {
// 获取角色插画 // 获取角色插画
getImgs (costume = '') { getImgs (costume = '') {
if (!lodash.isArray(costume)) { if (lodash.isArray(costume)) {
costume = [costume, false] costume = costume[0]
} }
let costumeCfg = [this.checkCostume(costume[0]) ? '2' : '', costume[1] || 'normal'] let costumeIdx = this.checkCostume(costume) ? '2' : ''
let cacheId = `costume${costumeIdx}`
let cacheId = `costume${costume[0]}`
if (!this._imgs) { if (!this._imgs) {
this._imgs = {} this._imgs = {}
} }
if (!this._imgs[cacheId]) { if (!this._imgs[cacheId]) {
this._imgs[cacheId] = CharImg.getImgs(this.name, costumeCfg, this.isTraveler ? this.elem : '', this.source === 'amber' ? 'png' : 'webp') this._imgs[cacheId] = CharImg.getImgs(this.name, costumeIdx, this.isTraveler ? this.elem : '', this.source === 'amber' ? 'png' : 'webp')
} }
let ret = this._imgs[cacheId] return this._imgs[cacheId]
let nPath = `meta/character/${this.name}`
if (costumeCfg[1] === 'super') {
ret.splash0 = CharImg.getRandomImg(
[`profile/super-character/${this.name}`, `profile/normal-character/${this.name}`],
[`${nPath}/imgs/splash0.webp`, `${nPath}/imgs/splash${costumeCfg[0]}.webp`, `/${nPath}/imgs/splash.webp`]
)
} else {
ret.splash0 = CharImg.getRandomImg(
[`profile/normal-character/${this.name}`],
[`${nPath}/imgs/splash${costumeCfg[0]}.webp`, `/${nPath}/imgs/splash.webp`]
)
}
return ret
} }
// 基于角色名获取Character
// 获取详情数据 // 获取详情数据
getDetail (elem = '') { getDetail (elem = '') {
if (this._detail) { if (this._detail) {
@ -242,7 +275,8 @@ class Character extends Base {
return this._detail return this._detail
} }
// 设置旅行者数据 // 获取别名数据
// TODO迁移至Avatar // TODO迁移至Avatar
setTraveler (uid = '') { setTraveler (uid = '') {
if (this.isTraveler && uid && uid.toString().length === 9) { if (this.isTraveler && uid && uid.toString().length === 9) {
@ -253,6 +287,8 @@ class Character extends Base {
} }
} }
// 检查wife类型
// 获取旅行者数据 // 获取旅行者数据
async getTraveler (uid) { async getTraveler (uid) {
if (this.isTraveler) { if (this.isTraveler) {
@ -285,52 +321,6 @@ class Character extends Base {
return await this.getTraveler(uid) return await this.getTraveler(uid)
} }
// 基于角色名获取Character
static get (val) {
let id = CharId.getId(val, Character.gsCfg)
if (!id) {
return false
}
return new Character(id)
}
static forEach (fn, type = 'all') {
lodash.forEach(idMap, (name, id) => {
let char = Character.get({ id, name })
if (type === 'release' && !char.isRelease) {
return true
}
if (type === 'official' && !char.isOfficial) {
return true
}
return fn(char) !== false
})
}
// 基于角色名获取Character
// 当获取角色为旅行者时会考虑当前uid的账号情况返回对应旅行者
static async getAvatar (name, uid) {
let char = Character.get(name)
return await char.getTraveler(uid)
}
// 获取别名数据
// TODO待废弃
static getAbbr () {
return abbrMap
}
// 检查wife类型
// TODO待废弃
static checkWifeType (charid, type) {
return !!wifeMap[type][charid]
}
// 获取排序ID
static sortIds (arr) {
return arr.sort((a, b) => (idSort[a] || 300) - (idSort[b] || 300))
}
// 获取伤害计算配置 // 获取伤害计算配置
getCalcRule () { getCalcRule () {
if (!this._calcRule && this._calcRule !== false) { if (!this._calcRule && this._calcRule !== false) {

View File

@ -3,6 +3,7 @@ import AvatarData from './AvatarData.js'
import { Data } from '../components/index.js' import { Data } from '../components/index.js'
import { ProfileArtis, ProfileDmg } from './index.js' import { ProfileArtis, ProfileDmg } from './index.js'
import AttrCalc from './profile-lib/AttrCalc.js' import AttrCalc from './profile-lib/AttrCalc.js'
import CharImg from './character-lib/CharImg.js'
export default class ProfileData extends AvatarData { export default class ProfileData extends AvatarData {
constructor (ds = {}, calc = true) { constructor (ds = {}, calc = true) {
@ -17,16 +18,27 @@ export default class ProfileData extends AvatarData {
return this.isProfile return this.isProfile
} }
get splashCostume () { get costumeSplash () {
let costume = this._costume let costume = this._costume
if (lodash.isArray(costume)) { costume = this.char.checkCostume(costume) ? '2' : ''
costume = costume[0]
} let nPath = `meta/character/${this.name}`
let isSuper = false
let talent = this.talent ? lodash.map(this.talent, (ds) => ds.original).join('') : '' let talent = this.talent ? lodash.map(this.talent, (ds) => ds.original).join('') : ''
if (this.cons === 6 || ['ACE', 'ACE²'].includes(this.artis?.markClass) || talent === '101010') { if (this.cons === 6 || ['ACE', 'ACE²'].includes(this.artis?.markClass) || talent === '101010') {
return [costume, 'super'] isSuper = true
}
if (isSuper) {
return CharImg.getRandomImg(
[`profile/super-character/${this.name}`, `profile/normal-character/${this.name}`],
[`${nPath}/imgs/splash0.webp`, `${nPath}/imgs/splash${costume}.webp`, `/${nPath}/imgs/splash.webp`]
)
} else {
return CharImg.getRandomImg(
[`profile/normal-character/${this.name}`],
[`${nPath}/imgs/splash${costume}.webp`, `/${nPath}/imgs/splash.webp`]
)
} }
return [costume, 'normal']
} }
get hasDmg () { get hasDmg () {
@ -61,7 +73,6 @@ export default class ProfileData extends AvatarData {
} }
setArtis (ds = false) { setArtis (ds = false) {
console.log('ds', ds.artis?.artis[1])
this.artis?.setProfile(this, ds.artis?.artis || ds.artis || ds) this.artis?.setProfile(this, ds.artis?.artis || ds.artis || ds)
} }

View File

@ -82,10 +82,8 @@ const CharImg = {
}, },
// 获取角色的图像资源数据 // 获取角色的图像资源数据
getImgs (name, costumeCfg = '', travelerElem = '', fileType = 'webp') { getImgs (name, costumeIdx = '', travelerElem = '', fileType = 'webp') {
if (!lodash.isArray(costumeCfg)) { costumeIdx = costumeIdx === '2' ? '2' : ''
costumeCfg = [costumeCfg, 'normal']
}
let imgs = {} let imgs = {}
if (!['空', '荧', '旅行者'].includes(name)) { if (!['空', '荧', '旅行者'].includes(name)) {
travelerElem = '' travelerElem = ''
@ -102,10 +100,10 @@ const CharImg = {
let tAdd = (key, path) => { let tAdd = (key, path) => {
imgs[key] = `${travelerElem ? tPath : nPath}${path}.${fileType}` imgs[key] = `${travelerElem ? tPath : nPath}${path}.${fileType}`
} }
add('face', 'imgs/face', `imgs/face${costumeCfg[0]}`) add('face', 'imgs/face', `imgs/face${costumeIdx}`)
add('side', 'imgs/side', `imgs/side${costumeCfg[0]}`) add('side', 'imgs/side', `imgs/side${costumeIdx}`)
add('gacha', 'imgs/gacha') add('gacha', 'imgs/gacha')
add('splash', 'imgs/splash', `imgs/splash${costumeCfg[0]}`) add('splash', 'imgs/splash', `imgs/splash${costumeIdx}`)
// 检查彩蛋自定义 // 检查彩蛋自定义
tAdd('card', 'imgs/card') tAdd('card', 'imgs/card')
tAdd('banner', 'imgs/banner') tAdd('banner', 'imgs/banner')

View File

@ -11,7 +11,7 @@
{{block 'main'}} {{block 'main'}}
<div class="basic"> <div class="basic">
<div class="main-pic" <div class="main-pic"
style="background-image:url({{_res_path}}{{imgs.splash0}})"></div> style="background-image:url({{_res_path}}{{costumeSplash || imgs?.splash}})"></div>
<div class="detail"> <div class="detail">
<div class="char-name">{{data.name}}</div> <div class="char-name">{{data.name}}</div>
<div class="char-lv">UID {{uid}} - Lv.{{data.level}} <div class="char-lv">UID {{uid}} - Lv.{{data.level}}

File diff suppressed because it is too large Load Diff