更新面板Model数据结构

This commit is contained in:
Kokomi 2023-10-19 01:01:11 +08:00
parent da903e4418
commit cde805a146
14 changed files with 195 additions and 192 deletions

View File

@ -3,7 +3,7 @@
*/
import lodash from 'lodash'
import { Data } from '#miao'
import { Character, ArtifactSet, ProfileData, Weapon, Player } from '#miao.models'
import { Character, ArtifactSet, Avatar, Weapon, Player } from '#miao.models'
// 默认武器
let defWeapon = {
@ -188,7 +188,7 @@ const ProfileChange = {
* @param charid
* @param ds
* @param game
* @returns {ProfileData|boolean}
* @returns {Avatar|boolean}
*/
getProfile (uid, charid, ds, game = 'gs') {
if (!charid) {
@ -231,7 +231,7 @@ const ProfileChange = {
return profiles[key]?.id ? profiles[key] : source
}
// 初始化profile
let ret = new ProfileData({
let ret = new Avatar({
uid,
id: char.id,
level,

View File

@ -1,4 +1,4 @@
import { ProfileData, Weapon } from '#miao.models'
import { Avatar, Weapon } from '#miao.models'
export const ProfileWeapon = {
async calc (profile, game = 'gs') {
@ -10,7 +10,7 @@ export const ProfileWeapon = {
if (affix === 5 && w.maxAffix !== 5) {
continue
}
let tempProfile = new ProfileData({
let tempProfile = new Avatar({
...profile.getData('uid,id,level,cons,fetter,elem,promote,talent,artis'),
dataSource: 'change'
}, game, false)

View File

@ -2,12 +2,11 @@
* 圣遗物
* */
import Base from './Base.js'
import { Format } from '#miao'
import { ArtifactSet } from './index.js'
import { artiMap, attrMap, mainIdMap, attrIdMap } from '../resources/meta/artifact/index.js'
import { idMap as idMapSR, artiMap as artiMapSR, metaData as metaDataSR, abbr as abbrSR } from '../resources/meta-sr/artifact/index.js'
import lodash from 'lodash'
import { artiMap, attrMap } from '../resources/meta/artifact/index.js'
import { idMap as idMapSR, artiMap as artiMapSR, abbr as abbrSR } from '../resources/meta-sr/artifact/index.js'
import ArtisMark from './artis/ArtisMark.js'
import ArtisAttr from './artis/ArtisAttr.js'
class Artifact extends Base {
static getAttrs
@ -49,6 +48,11 @@ class Artifact extends Base {
if (!name) {
return false
}
// 传入为artis对象
if (name.game) {
return Artifact.get(name.id || name.name, name.game)
}
if (game === 'sr') {
name = idMapSR[name]?.name || name
}
@ -72,45 +76,6 @@ class Artifact extends Base {
}
}
static getMainById (id, level = 20, star = 5) {
let key = mainIdMap[id]
if (!key) {
return false
}
let attrCfg = attrMap[Format.isElem(key) ? 'dmg' : key]
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 {
key,
value: attrCfg.value * (1.2 + 0.34 * level) * posEff * (starEff[star || 5])
}
}
static getAttrsByIds (ids, star = 5) {
let ret = []
let tmp = {}
lodash.forEach(ids, (id) => {
let cfg = attrIdMap[id]
if (!cfg) {
return true
}
let { key, value } = cfg
if (!tmp[key]) {
tmp[key] = {
key,
upNum: 0,
eff: 0,
value: 0
}
ret.push(tmp[key])
}
tmp[key].value += value * (attrMap[key].format === 'pct' ? 100 : 1)
tmp[key].upNum++
tmp[key].eff += value / attrMap[key].value * (attrMap[key].format === 'pct' ? 100 : 1)
})
return ret
}
getStarById (id) {
return this.meta.ids[id] || ''
}
@ -129,45 +94,9 @@ class Artifact extends Base {
}
// 获取圣遗物属性数据
getAttrData (mainId, attrData, level = 1, star = 5, idx = 1) {
let mainKey = metaDataSR.mainIdx[idx][mainId]
let starCfg = metaDataSR.starData[star]
let mainCfg = starCfg.main[mainKey]
if (!mainId || !mainCfg) {
return false
getAttrData (arti, idx = 1, game = 'gs') {
return ArtisAttr.getData(arti, idx, game)
}
let main = {
id: mainId,
key: mainKey,
value: mainCfg.base + mainCfg.step * level
}
let attrs = []
lodash.forEach(attrData, (ds) => {
let _ds = ds
if (lodash.isString(ds)) {
let [id, count, step] = ds.split(',')
ds = { id, count, step }
}
let attrCfg = starCfg.sub[ds.id]
if (!attrCfg) {
console.log('not found attr', ds, _ds)
return true
}
let value = attrCfg?.base * ds.count + attrCfg.step * ds.step
attrs.push({
...ds,
key: attrCfg?.key,
upNum: ds.count,
eff: value / (attrCfg.base + attrCfg.step * 2),
value
})
})
return {
main,
attrs
}
}
}
export default Artifact

View File

@ -1,13 +1,15 @@
import lodash from 'lodash'
import AvatarData from './AvatarData.js'
import AvatarBase from './avatar/AvatarBase.js'
import { Data, Cfg } from '#miao'
import { ProfileArtis, AvatarArtis, ProfileDmg } from './index.js'
import AttrCalc from './profile/AttrCalc.js'
import { ProfileDmg } from './index.js'
import Attr from './attr/Attr.js'
import CharImg from './character/CharImg.js'
import Artis from './artis/Artis.js'
export default class ProfileData extends AvatarData {
export default class Avatar extends AvatarBase {
constructor (ds = {}, game = 'gs', calc = true) {
super(ds, game)
this._artis = new Artis(this.game, true)
if (calc) {
this.calcAttr()
}
@ -53,39 +55,39 @@ export default class ProfileData extends AvatarData {
return this.hasData && !!ProfileDmg.dmgRulePath(this.name, this.game)
}
get mysArtis(){
return this._mysArtis
}
get artis () {
return this._artis
}
static create (ds, game = 'gs', calc = true) {
let profile = new ProfileData(ds, game, calc)
let profile = new Avatar(ds, game, calc)
if (!profile) {
return false
}
return profile
}
initArtis () {
this._artis = new ProfileArtis(this.id, this.elem, this.game)
this._mysArtis = new AvatarArtis(this.id, this.game)
setAvatar (ds, source = '') {
super.setAvatar(ds, source)
if (ds.artis) {
this._artis.setArtisData(ds.artis)
}
// this.calcAttr()
}
calcAttr () {
this._attr = AttrCalc.create(this)
this._attr = Attr.create(this)
this.attr = this._attr.calc()
this.base = this._attr.getBase()
}
setArtis (ds = false, isMysArtis = false) {
if (isMysArtis) {
this.mysArtis.setArtis(ds.artis?.artis || ds.artis || ds)
} else {
this.artis?.setProfile(this, ds.artis?.artis || ds.artis || ds)
getArtis (isMysArtis = false) {
return isMysArtis ? this._mysArtis : this._artis
}
setArtis (ds = {}, isMysArtis = false) {
let artis = this.getArtis(isMysArtis)
artis.setArtisData(ds)
}
// 获取当前profileData的圣遗物评分withDetail=false仅返回简略信息

View File

@ -7,7 +7,7 @@
import lodash from 'lodash'
import Base from './Base.js'
import { Data } from '#miao'
import { AvatarData, ProfileRank, Character } from './index.js'
import { Avatar, ProfileRank, Character } from './index.js'
import MysAvatar from './player/MysAvatar.js'
import Profile from './player/Profile.js'
@ -183,7 +183,7 @@ export default class Player extends Base {
}
}
if (!avatars[id] && create) {
avatars[id] = AvatarData.create({ id }, this.game)
avatars[id] = Avatar.create({ id }, this.game)
}
return avatars[id] || false
}
@ -232,7 +232,7 @@ export default class Player extends Base {
// 获取指定角色的面板数据
getProfile (id) {
let avatar = this.getAvatar(id)
return avatar ? avatar.getProfile() : false
return avatar
}
// 获取所有面板数据

View File

@ -7,11 +7,11 @@ import { Data, Format } from '#miao'
import ArtisMark from './ArtisMark.js'
import { attrMap as attrMapGS } from '../../resources/meta/artifact/index.js'
import { attrMap as attrMapSR } from '../../resources/meta-sr/artifact/index.js'
import CharArtis from '../profile/CharArtis.js'
import ArtisMarkCfg from './ArtisMarkCfg.js'
import ArtisBase from './ArtisBase.js'
export default class Artis extends ArtisBase {
constructor (isProfile = false, game = 'gs') {
constructor (game = 'gs', isProfile = false) {
super(game)
this.isProfile = !!isProfile
}
@ -31,7 +31,7 @@ export default class Artis extends ArtisBase {
getCharCfg () {
let char = Character.get(this.charid)
let { game, isGs } = char
let { attrWeight, title } = CharArtis.getCharArtisCfg(char, this.profile, this)
let { attrWeight, title } = ArtisMarkCfg.getCharArtisCfg(char, this.profile, this)
let attrs = {}
let baseAttr = char.baseAttr || { hp: 14000, atk: 230, def: 700 }
let attrMap = isGs ? attrMapGS : attrMapSR
@ -122,25 +122,28 @@ export default class Artis extends ArtisBase {
}
setArtis (idx = 1, ds = {}) {
idx = idx.toString().replace('arti', '')
parent.setArtis(idx, ds)
idx = idx.toString().replace('arti', '') * 1 || 1
super.setArtis(idx, ds)
if (!this.isProfile) {
return
}
let arti = this.artis[idx]
if (!ds.attrIds || !ds.mainId) {
return false
}
arti.mainId = ds.mainId
arti.attrIds = ds.attrIds
arti.main = {}
arti.attrs = {}
let artiObj = Artifact.get(ds.id, this.game)
let artiObj = Artifact.get(arti.id || arti.name, this.game)
if (!artiObj) {
return false
}
let attr = artiObj.getAttrData(ds.mainId, attrIds, arti.level, arti.star, idx)
let attr = artiObj.getAttrData(arti, idx, this.game)
if (!attr) {
console.log('attr id error', ds.main, ds.mainId, idx, arti.level, arti.star)
return false
}
arti.main = attr.main
arti.attrs = attr.attrs
}
// 获取保存数据
@ -155,7 +158,7 @@ export default class Artis extends ArtisBase {
if (!this.isProfile) {
return true
}
tmp.mainId = ds.main?.id
tmp.mainId = ds.mainId || ds.main?.id
if (this.isSr) {
tmp.attrIds = []
lodash.forEach(ds.attrs, (as) => {

101
models/artis/ArtisAttr.js Normal file
View File

@ -0,0 +1,101 @@
import { Format } from '#miao'
import lodash from 'lodash'
import { attrIdMap, attrMap, mainIdMap } from '../../resources/meta/artifact/index.js'
import { metaData as metaDataSR } from '../../resources/meta-sr/artifact/index.js'
let AttrGS = {
getMain (id, level, star) {
let key = mainIdMap[id]
if (!key) {
return false
}
let attrCfg = attrMap[Format.isElem(key) ? 'dmg' : key]
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 {
id,
key,
value: attrCfg.value * (1.2 + 0.34 * level) * posEff * (starEff[star || 5])
}
},
getAttr (ids, star = 5) {
let ret = []
let tmp = {}
lodash.forEach(ids, (id) => {
let cfg = attrIdMap[id]
if (!cfg) {
return true
}
let { key, value } = cfg
if (!tmp[key]) {
tmp[key] = {
key,
upNum: 0,
eff: 0,
value: 0
}
ret.push(tmp[key])
}
tmp[key].value += value * (attrMap[key].format === 'pct' ? 100 : 1)
tmp[key].upNum++
tmp[key].eff += value / attrMap[key].value * (attrMap[key].format === 'pct' ? 100 : 1)
})
return ret
},
getData (mainId, attrIds, level, star) {
return {
main: AttrGS.getMain(mainId, level, star),
attrs: AttrGS.getAttr(attrIds, star)
}
}
}
let AttrSR = {
getData (mainId, attrIds, level, star, idx = 1) {
let mainKey = metaDataSR.mainIdx[idx][mainId]
let starCfg = metaDataSR.starData[star]
let mainCfg = starCfg.main[mainKey]
if (!mainId || !mainCfg) {
return false
}
let main = {
id: mainId,
key: mainKey,
value: mainCfg.base + mainCfg.step * level
}
let attrs = []
lodash.forEach(attrIds, (ds) => {
let _ds = ds
if (lodash.isString(ds)) {
let [id, count, step] = ds.split(',')
ds = { id, count, step }
}
let attrCfg = starCfg.sub[ds.id]
if (!attrCfg) {
console.log('not found attr', ds, _ds)
return true
}
let value = attrCfg?.base * ds.count + attrCfg.step * ds.step
attrs.push({
...ds,
key: attrCfg?.key,
upNum: ds.count,
eff: value / (attrCfg.base + attrCfg.step * 2),
value
})
})
return {
main,
attrs
}
}
}
export default {
getData (arti, idx = 1, game = 'gs') {
let tmp = game === 'gs' ? AttrGS : AttrSR
return tmp.getData(arti.mainId, arti.attrIds, arti.level, arti.star, idx)
}
}

View File

@ -2,13 +2,13 @@
* 面板属性计算
* @type {{}}
*/
import { Weapon, ProfileAttr, ArtifactSet } from '../index.js'
import { Format } from '#miao'
import { Weapon, ArtifactSet } from '#miao.models'
import AttrData from './AttrData.js'
import { weaponBuffs } from '../../resources/meta/weapon/index.js'
import lodash from 'lodash'
class AttrCalc {
class Attr {
constructor (profile) {
this.profile = profile
this.char = profile.char
@ -26,10 +26,10 @@ class AttrCalc {
/**
* 静态调用入口
* @param profile
* @returns {AttrCalc}
* @returns {Attr}
*/
static create (profile) {
return new AttrCalc(profile)
return new Attr(profile)
}
// 只有原神才需要
@ -56,7 +56,7 @@ class AttrCalc {
* @returns {{}}
*/
calc () {
this.attr = ProfileAttr.create(this.char, {})
this.attr = AttrData.create(this.char, {})
if (this.isGs) {
this.addAttr('recharge', 100, true)
this.addAttr('cpct', 5, true)
@ -266,4 +266,4 @@ class AttrCalc {
}
}
export default AttrCalc
export default Attr

View File

@ -1,5 +1,5 @@
import lodash from 'lodash'
import Base from './Base.js'
import Base from '../Base.js'
import { Format } from '#miao'
const baseAttr = {
@ -11,7 +11,7 @@ let attrReg = {
sr: new RegExp(`^(${baseAttr.sr.join('|')})(Base|Plus|Pct|Inc)$`)
}
class ProfileAttr extends Base {
class AttrData extends Base {
constructor (char, data = null) {
super()
this.char = char
@ -20,7 +20,7 @@ class ProfileAttr extends Base {
}
static create (char, data = null) {
return new ProfileAttr(char, data)
return new AttrData(char, data)
}
init (data) {
@ -147,4 +147,4 @@ class ProfileAttr extends Base {
}
}
export default ProfileAttr
export default AttrData

View File

@ -1,14 +1,15 @@
import lodash from 'lodash'
import Base from './Base.js'
import Base from '../Base.js'
import moment from 'moment'
import { Character, AvatarArtis, ProfileData, Weapon } from './index.js'
import { Character, Avatar, Weapon } from '#miao.models'
import { Data, Format } from '#miao'
import AttrCalc from './profile/AttrCalc.js'
import Profile from './player/Profile.js'
import Attr from '../attr/Attr.js'
import Profile from '../player/Profile.js'
import Artis from '../artis/Artis.js'
const charKey = 'name,abbr,sName,star,imgs,face,side,gacha,weaponTypeName'.split(',')
export default class AvatarData extends Base {
export default class AvatarBase extends Base {
constructor (ds = {}, game = 'gs') {
super()
let char = Character.get({ id: ds.id, elem: ds.elem })
@ -18,7 +19,7 @@ export default class AvatarData extends Base {
this.id = char.id
this.char = char
this.game = char.game || game
this._mysArtis = new AvatarArtis(this.id, this.game)
this._mysArtis = new Artis(this.game)
this.setAvatar(ds)
}
@ -58,6 +59,14 @@ export default class AvatarData extends Base {
return minTalent >= maxLv
}
get artis () {
return this._mysArtis
}
get mysArtis () {
return this._mysArtis
}
/**
* 获取圣遗物套装属性
* @returns {boolean|*|{imgs: *[], names: *[], sets: {}, abbrs: *[], sName: string, name: (string|*)}|{}}
@ -91,16 +100,8 @@ export default class AvatarData extends Base {
return ''
}
get mysArtis () {
return this._mysArtis
}
get artis () {
return this._mysArtis
}
static create (ds, game = 'gs') {
let avatar = new AvatarData(ds, game)
let avatar = new AvatarBase(ds, game)
if (!avatar) {
return false
}
@ -118,7 +119,7 @@ export default class AvatarData extends Base {
this.setBasic(ds, source)
ds.weapon && this.setWeapon(ds.weapon)
ds.talent && this.setTalent(ds.talent, 'original', source)
this.setArtis(ds)
this._mysArtis.setArtisData(ds.mysArtis || ds.artis)
delete this._now
}
@ -134,7 +135,7 @@ export default class AvatarData extends Base {
this.fetter = ds.fetter || this.fetter || 0
this._costume = ds.costume || this._costume || 0
this.elem = ds.elem || this.elem || this.char.elem || ''
this.promote = lodash.isUndefined(ds.promote) ? (this.promote || AttrCalc.calcPromote(this.level)) : (ds.promote || 0)
this.promote = lodash.isUndefined(ds.promote) ? (this.promote || Attr.calcPromote(this.level)) : (ds.promote || 0)
this.trees = this.trees || []
this._source = ds._source || this._source || '' // 数据源
this._time = ds._time || this._time || now // 面板最后更新时间
@ -191,7 +192,7 @@ export default class AvatarData extends Base {
id: ds.id || w.id,
name: ds.name || w.name,
level: ds.level || ds.lv || 1,
promote: lodash.isUndefined(ds.promote) ? AttrCalc.calcPromote(ds.level || ds.lv || 1) : (ds.promote || 0),
promote: lodash.isUndefined(ds.promote) ? Attr.calcPromote(ds.level || ds.lv || 1) : (ds.promote || 0),
affix: ds.affix,
...w.getData('star,abbr,type,img')
}
@ -246,15 +247,15 @@ export default class AvatarData extends Base {
}
}
setArtis (ds, source) {
this.mysArtis.setArtisData(ds.mysArtis || ds.artis, source)
setArtis (ds) {
this.mysArtis.setArtisData(ds.mysArtis || ds.artis)
}
getProfile () {
if (!this.isProfile) {
return false
}
return ProfileData.create(this, this.game)
return Avatar.create(this, this.game)
}
// 判断当前profileData是否具备有效圣遗物信息

View File

@ -2,13 +2,11 @@ import Base from './Base.js'
import Character from './Character.js'
import Artifact from './Artifact.js'
import ArtifactSet from './ArtifactSet.js'
import AvatarData from './AvatarData.js'
import Abyss from './Abyss.js'
import Player from './Player.js'
import ProfileServ from './ProfileServ.js'
import ProfileReq from './ProfileReq.js'
import ProfileData from './ProfileData.js'
import ProfileAttr from './ProfileAttr.js'
import Avatar from './Avatar.js'
import ProfileDmg from './ProfileDmg.js'
import ProfileRank from './ProfileRank.js'
import Material from './Material.js'
@ -16,17 +14,18 @@ import Weapon from './Weapon.js'
import User from './User.js'
import MysApi from './MysApi.js'
export const ProfileData = Avatar
export const AvatarData = ProfileData
export {
Base,
Abyss,
Character,
Artifact,
ArtifactSet,
AvatarData,
ProfileServ,
ProfileReq,
ProfileData,
ProfileAttr,
Avatar,
ProfileDmg,
ProfileRank,
Material,

View File

@ -1,32 +0,0 @@
/**
* 旧面板数据迁移
* 去除旧格式控制逻辑复杂度
*/
import fs from 'node:fs'
import lodash from 'lodash'
import { Data } from '#miao'
const DataTrans = {
trans () {
const srcPath = './data/UserData'
let uids = fs.readdirSync(srcPath)
uids = uids.filter((uid) => /\.json/i.test(uid))
lodash.forEach(uids, (uid) => {
let data = Data.readJSON(`/data/UserData/${uid}`)
DataTrans.doTrans(data)
})
},
doTrans (data) {
lodash.forEach(data.avatars, (ds, id) => {
data.avatars[id] = DataTrans.getAvatar(ds)
})
},
getAvatar (data) {
let artisSet = {}
lodash.forEach(data.artis, (ds, idx) => {
})
}
}
export default DataTrans

View File

@ -2,7 +2,7 @@
* 伤害计算 - Buff计算
* */
import lodash from 'lodash'
import { ProfileArtis, ArtifactSet, Weapon } from '../index.js'
import { ArtifactSet, Weapon } from '../index.js'
/*
理论参考www.miyoushe.com/ys/article/32359316

View File

@ -4,7 +4,7 @@ import fs from 'node:fs'
let Trans = {
init () {
Data.createDir('temp/UserData_BAK')
Data.createDir('temp/UserDataBAK')
let uids = fs.readdirSync('./data/UserData')
uids = uids.filter((uid) => /\.(json)/i.test(uid))
let success = 0
@ -27,7 +27,7 @@ let Trans = {
try {
let src = `./data/UserData/${uid}.json`
let dst = `./temp/UserData_BAK/${uid}.json`
let dst = `./temp/UserDataBAK/${uid}.json`
fs.existsSync(dst) && fs.unlinkSync(dst)
fs.copyFileSync(src, dst)
fs.unlinkSync(src)