diff --git a/apps/profile/ProfileArtis.js b/apps/profile/ProfileArtis.js index a2642881..e5b89b9a 100644 --- a/apps/profile/ProfileArtis.js +++ b/apps/profile/ProfileArtis.js @@ -5,7 +5,7 @@ import lodash from 'lodash' import { Cfg, Common } from '#miao' import { getTargetUid, profileHelp, getProfileRefresh } from './ProfileCommon.js' -import { Artifact, Character, ProfileArtis, Player } from '#miao.models' +import { Artifact, Character, Player } from '#miao.models' /* * 角色圣遗物面板 diff --git a/apps/profile/ProfileDetail.js b/apps/profile/ProfileDetail.js index 35a9c074..892438f5 100644 --- a/apps/profile/ProfileDetail.js +++ b/apps/profile/ProfileDetail.js @@ -2,7 +2,7 @@ import lodash from 'lodash' import { getTargetUid, getProfileRefresh } from './ProfileCommon.js' import ProfileList from './ProfileList.js' import { Cfg, Common, Data, Format } from '#miao' -import { MysApi, ProfileRank, ProfileArtis, Character, Weapon } from '#miao.models' +import { MysApi, ProfileRank, Character, Weapon, Artifact } from '#miao.models' import ProfileChange from './ProfileChange.js' import { profileArtis } from './ProfileArtis.js' import { ProfileWeapon } from './ProfileWeapon.js' diff --git a/models/Avatar.js b/models/Avatar.js index 79d8f812..86c55c09 100644 --- a/models/Avatar.js +++ b/models/Avatar.js @@ -77,7 +77,7 @@ export default class Avatar extends AvatarBase { calcAttr () { this._attr = Attr.create(this) - this.attr = this._attr.calc() + this.attr = this._attr.calc(this) this.base = this._attr.getBase() } @@ -93,7 +93,7 @@ export default class Avatar extends AvatarBase { // 获取当前profileData的圣遗物评分,withDetail=false仅返回简略信息 getArtisMark (withDetail = true) { if (this.hasData) { - return this.artis.getMarkDetail(withDetail) + return this.artis.getMarkDetail(this, withDetail) } return {} } @@ -108,4 +108,23 @@ export default class Avatar extends AvatarBase { } return await this.dmg.calcData({ enemyLv, mode, dmgIdx, idxIsInput }) } + + // toJSON 供保存使用 + toJSON () { + let keys = this.isGs ? + 'name,id,elem,level,promote,fetter,costume,cons,talent:originalTalent' : + 'name,id,elem,level,promote,cons,talent:originalTalent,trees' + let ret = { + ...this.getData(keys), + weapon: Data.getData(this.weapon, this.isGs ? 'name,level,promote,affix' : 'id,level,promote,affix'), + artis: this.artis.toJSON() + } + if (!this.mysArtis.isSameArtis(this.artis)) { + ret.mysArtis = this.mysArtis.toJSON() + } + return { + ...ret, + ...this.getData('_source,_time,_update,_talent') + } + } } diff --git a/models/artis/Artis.js b/models/artis/Artis.js index bf8d0107..5d158401 100644 --- a/models/artis/Artis.js +++ b/models/artis/Artis.js @@ -28,10 +28,10 @@ export default class Artis extends ArtisBase { * 获取角色配置 * @returns {{classTitle: *, weight: *, posMaxMark: {}, mark: {}, attrs: {}}} */ - getCharCfg () { - let char = Character.get(this.charid) + getCharCfg (profile) { + let char = profile.char let { game, isGs } = char - let { attrWeight, title } = ArtisMarkCfg.getCharArtisCfg(char, this.profile, this) + let { attrWeight, title } = ArtisMarkCfg.getCharArtisCfg(char, profile, this) let attrs = {} let baseAttr = char.baseAttr || { hp: 14000, atk: 230, def: 700 } let attrMap = isGs ? attrMapGS : attrMapSR @@ -60,8 +60,8 @@ export default class Artis extends ArtisBase { } } - getMarkDetail (withDetail = true) { - let charCfg = this.getCharCfg() + getMarkDetail (profile, withDetail = true) { + let charCfg = this.getCharCfg(profile) let artis = {} let setCount = {} let totalMark = 0 @@ -216,4 +216,15 @@ export default class Artis extends ArtisBase { }) return check } + + isSameArtis (target) { + let k = (ds) => [ds?.name || '', ds?.level || '', ds?.star || ''].join('|') + let ret = true + this.eachIdx((ds, idx) => { + if (k[ds] !== k(target[idx])) { + return ret = false + } + }) + return ret + } } diff --git a/models/artis/ArtisBase.js b/models/artis/ArtisBase.js index ac29e257..62f142a7 100644 --- a/models/artis/ArtisBase.js +++ b/models/artis/ArtisBase.js @@ -54,7 +54,10 @@ export default class ArtisBase extends Base { eachIdx (fn) { for (let idx = 1; idx <= (this.isGs ? 5 : 6); idx++) { this.artis[idx] = this.artis[idx] || {} - fn(this.artis[idx], idx) + let ret = fn(this.artis[idx], idx) + if (ret === false) { + break + } } } @@ -80,9 +83,9 @@ export default class ArtisBase extends Base { arti.star = artiObj.getStarById(ds.id) || arti.star || 5 } else { arti.name = ds.name || arti.name || '' - arti.set = ds.set || Artifact.getSetNameByArti(arti.name) || '' + arti.set = ds.set || Artifact.getSetNameByArti(arti.name) || '' arti.level = ds.level || 1 - arti.star = ds.star || 5 + arti.star = ds.star || 5 } } diff --git a/models/artis/ArtisMarkCfg.js b/models/artis/ArtisMarkCfg.js index dde4845c..552cda23 100644 --- a/models/artis/ArtisMarkCfg.js +++ b/models/artis/ArtisMarkCfg.js @@ -2,6 +2,28 @@ import { usefulAttr as usefulAttrGS } from '../../resources/meta/artifact/artis- import { usefulAttr as usefulAttrSR } from '../../resources/meta-sr/artifact/artis-mark.js' import lodash from 'lodash' +const weaponCfg = { + 磐岩结绿: { + attr: 'hp', + abbr: '绿剑' + }, + 赤角石溃杵: { + attr: 'def', + abbr: '赤角' + }, + 猎人之径: { + attr: 'mastery' + }, + 薙草之稻光: { + attr: 'recharge', + abbr: '薙刀' + }, + 护摩之杖: { + attr: 'hp', + abbr: '护摩' + } +} + const ArtisMarkCfg = { getCharArtisCfg (char, profile, artis) { @@ -36,28 +58,6 @@ const ArtisMarkCfg = { // 对原神一些特殊情况做适配与判定 // 增加攻击力或直接伤害类武器判定 - const weaponCfg = { - 磐岩结绿: { - attr: 'hp', - abbr: '绿剑' - }, - 赤角石溃杵: { - attr: 'def', - abbr: '赤角' - }, - 猎人之径: { - attr: 'mastery' - }, - 薙草之稻光: { - attr: 'recharge', - abbr: '薙刀' - }, - 护摩之杖: { - attr: 'hp', - abbr: '护摩' - } - } - if (weight.atk > 0 && weaponCfg[wn]) { let wCfg = weaponCfg[wn] if (check(wCfg.attr, wCfg.max || 75, wCfg.plus || 75)) { @@ -85,7 +85,7 @@ const ArtisMarkCfg = { } let charRule = char.getArtisCfg() || function ({ def }) { - return def(usefulAttr[char.name] || { atk: 75, cpct: 100, cdmg: 100 }) + return def(usefulAttr[char.name] || { }) } if (charRule) { diff --git a/models/attr/Attr.js b/models/attr/Attr.js index 29faebbe..aa6de9d3 100644 --- a/models/attr/Attr.js +++ b/models/attr/Attr.js @@ -11,7 +11,6 @@ import lodash from 'lodash' class Attr { constructor (profile) { this.profile = profile - this.char = profile.char this.game = this.char.game } @@ -23,6 +22,10 @@ class Attr { return this.game === 'sr' } + get char () { + return this.profile?.char + } + /** * 静态调用入口 * @param profile @@ -75,6 +78,10 @@ class Attr { addAttr (key, val, isBase = false) { + console.log(key, val, isBase) + if (isNaN(val)) { + cs.log(val) + } this.attr.addAttr(key, val, isBase) } diff --git a/models/avatar/AvatarBase.js b/models/avatar/AvatarBase.js index f4c64b3c..585fb5e2 100644 --- a/models/avatar/AvatarBase.js +++ b/models/avatar/AvatarBase.js @@ -20,7 +20,6 @@ export default class AvatarBase extends Base { this.char = char this.game = char.game || game this._mysArtis = new Artis(this.game) - this.setAvatar(ds) } get hasTalent () { @@ -263,18 +262,7 @@ export default class AvatarBase extends Base { return this.isProfile && this.artis.length > 0 } - // toJSON 供保存使用 - toJSON () { - let keys = this.isGs ? - 'name,id,elem,level,promote,fetter,costume,cons,talent:originalTalent' : - 'name,id,elem,level,promote,cons,talent:originalTalent,trees' - return { - ...this.getData(keys), - weapon: Data.getData(this.weapon, this.isGs ? 'name,level,promote,affix' : 'id,level,promote,affix'), - ...this.getData('artis,_source,_time,_update,_talent') - } - } - + // 获取数据详情 getDetail (keys = '') { let imgs = this.char.getImgs(this.costume) if (this.isGs) {