}
+ */
+ async refreshTalent (player, ids, force) {
+ let e = player?.e
+ let mys = e?._mys
+ if (!e || !mys) {
+ return false
+ }
+ let needReqIds = MysAvatar.getNeedRefreshIds(player, ids)
+ if (needReqIds.length > 0) {
+ if (needReqIds.length > 8) {
+ e && e.reply('正在获取角色信息,请稍候...')
+ }
+ let num = 10
+ let ms = 100
+ let skillRet = []
+ let avatarArr = lodash.chunk(needReqIds, num)
+ for (let val of avatarArr) {
+ for (let id of val) {
+ let avatar = player.getAvatar(id)
+ skillRet.push(await avatar.refreshTalent(mys))
+ }
+ skillRet = await Promise.all(skillRet)
+ skillRet = skillRet.filter(item => item.id)
+ await Common.sleep(ms)
+ }
+ }
+ player.save()
+ }
+}
+export default MysAvatar
diff --git a/components/profile-data/enka-data.js b/models/player-lib/enka-data.js
similarity index 98%
rename from components/profile-data/enka-data.js
rename to models/player-lib/enka-data.js
index 2f9be073..6944ee75 100644
--- a/components/profile-data/enka-data.js
+++ b/models/player-lib/enka-data.js
@@ -1,6 +1,6 @@
import lodash from 'lodash'
import enkaMeta from './enka-meta.js'
-import { Character, ArtifactSet, ProfileData } from '../../models/index.js'
+import { Character, ArtifactSet, ProfileData } from '../index.js'
const artiIdx = {
EQUIP_BRACER: 1,
diff --git a/components/profile-data/enka-meta.js b/models/player-lib/enka-meta.js
similarity index 100%
rename from components/profile-data/enka-meta.js
rename to models/player-lib/enka-meta.js
diff --git a/components/profile-data/enka.js b/models/player-lib/enka.js
similarity index 94%
rename from components/profile-data/enka.js
rename to models/player-lib/enka.js
index bab155b0..adda6986 100644
--- a/components/profile-data/enka.js
+++ b/models/player-lib/enka.js
@@ -1,6 +1,6 @@
import lodash from 'lodash'
-import { Data } from '../index.js'
-import { ProfileServ } from '../../models/index.js'
+import { Data } from '../../components/index.js'
+import { ProfileServ } from '../index.js'
import EnkaData from './enka-data.js'
let HttpsProxyAgent = ''
diff --git a/components/profile-data/miao-data.js b/models/player-lib/miao-data.js
similarity index 58%
rename from components/profile-data/miao-data.js
rename to models/player-lib/miao-data.js
index 4784a9d7..282c49b8 100644
--- a/components/profile-data/miao-data.js
+++ b/models/player-lib/miao-data.js
@@ -1,6 +1,28 @@
-import { Character, ProfileData } from '../../models/index.js'
+import { Character, Artifact } from '../index.js'
import lodash from 'lodash'
-import { artiIdx, artiSetMap, attrMap } from './miao-meta.js'
+
+const attrMap = {
+ HP: 'hpPlus',
+ HP_PERCENT: 'hp',
+ ATTACK: 'atkPlus',
+ ATTACK_PERCENT: 'atk',
+ DEFENSE: 'defPlus',
+ DEFENSE_PERCENT: 'def',
+ FIRE_ADD_HURT: '',
+ ICE_ADD_HURT: 'cryo',
+ ROCK_ADD_HURT: 'geo',
+ ELEC_ADD_HURT: 'electro',
+ WIND_ADD_HURT: 'anemo',
+ WATER_ADD_HURT: 'hydro',
+ PHYSICAL_ADD_HURT: 'phy',
+ GRASS_ADD_HURT: 'dendro',
+ HEAL_ADD: 'heal',
+ ELEMENT_MASTERY: 'mastery',
+ CRITICAL: 'cpct',
+ CRITICAL_HURT: 'cdmg',
+ CHARGE_EFFICIENCY: 'recharge'
+}
+
let MiaoData = {
key: 'miao',
@@ -27,70 +49,21 @@ let MiaoData = {
level: ds.level
}
},
- getProfile (ds) {
+ setAvatar (player, ds) {
let char = Character.get(ds.id)
- let profile = new ProfileData({ id: char.id })
- profile.setBasic({
+ let avatar = player.getAvatar(ds.id)
+ let talentRet = MiaoData.getTalent(char.id, ds.skill)
+ avatar.setAvatar({
level: ds.level,
cons: ds.constellationNum || 0,
fetter: ds.fetterLevel,
costume: char.checkCostume(ds.costumeID) ? ds.costumeID : 0,
- dataSource: 'miao'
- })
- profile.setAttr(MiaoData.getAttr(ds.combatValue))
- profile.setWeapon(MiaoData.getWeapon(ds.weapon))
- profile.setArtis(MiaoData.getArtifact(ds.reliquary))
- let talentRet = MiaoData.getTalent(char.id, ds.skill)
- profile.setTalent(talentRet.talent, 'level')
- if (talentRet.elem) {
- profile.elem = talentRet.elem
- }
- return profile
- },
- getAttr (data) {
- let ret = {}
- lodash.forEach({
- atk: 'attack',
- atkBase: 'baseATK',
- hp: 'health',
- hpBase: 'baseHP',
- def: 'defense',
- defBase: 'baseDEF',
- mastery: 'elementMastery',
- cpct: {
- src: 'critRate',
- pct: true
- },
- cdmg: {
- src: 'critDamage',
- pct: true
- },
- heal: {
- src: 'heal',
- pct: true
- },
- recharge: {
- src: 'recharge',
- pct: true
- }
- }, (cfg, key) => {
- if (!lodash.isObject(cfg)) {
- cfg = { src: cfg }
- }
- let val = data[cfg.src] || 0
- if (cfg.pct) {
- val = val * 100
- }
- ret[key] = val
- })
- let maxDmg = 0
- let hurt = data.addHurt || {}
- lodash.forEach('fire,elec,water,grass,wind,rock,ice'.split(','), (key) => {
- maxDmg = Math.max(hurt[key] * 100, maxDmg)
- })
- ret.dmg = maxDmg
- ret.phy = hurt.physical * 100
- return ret
+ elem: talentRet.elem,
+ weapon: MiaoData.getWeapon(ds.weapon),
+ talent: talentRet.talent,
+ artis: MiaoData.getArtifact(ds.reliquary)
+ }, 'miao')
+ return avatar
},
getWeapon (weapon) {
return {
@@ -116,18 +89,23 @@ let MiaoData = {
if (value && value < 1) {
value = value * 100
}
- return [attrMap[name], value]
+ return { key: attrMap[name], value }
}
-
lodash.forEach(data, (ds) => {
let sub = ds.appendAffix || []
- let idx = artiIdx[ds.type]
+ let idx = {
+ 生之花: 1,
+ 死之羽: 2,
+ 时之沙: 3,
+ 空之杯: 4,
+ 理之冠: 5
+ }[ds.type]
if (!idx) {
return
}
- ret[`arti${idx}`] = {
+ ret[idx] = {
name: ds.name,
- set: artiSetMap[ds.name] || '',
+ set: Artifact.getSetNameByArti(ds.name) || '',
level: ds.level,
main: get(ds.mainAffix),
attrs: [
@@ -162,7 +140,6 @@ let MiaoData = {
}
}
})
-
return {
talent: ret,
elem
diff --git a/components/profile-data/miao.js b/models/player-lib/miao.js
similarity index 66%
rename from components/profile-data/miao.js
rename to models/player-lib/miao.js
index 1160a74b..f60ad8c7 100644
--- a/components/profile-data/miao.js
+++ b/models/player-lib/miao.js
@@ -1,6 +1,6 @@
import lodash from 'lodash'
-import { Data } from '../index.js'
-import { ProfileServ } from '../../models/index.js'
+import { Data } from '../../components/index.js'
+import { ProfileServ } from '../index.js'
import MiaoData from './miao-data.js'
export default new ProfileServ({
@@ -18,19 +18,14 @@ export default new ProfileServ({
return data
},
- userData (data) {
- return Data.getData(data, 'name:nickname,avatar:profilePicture.avatarID,level,signature')
- },
-
- profileData (data) {
- let ret = {}
+ updatePlayer (player, data) {
+ player.setBasicData(Data.getData(data, 'name:nickname,face:profilePicture.avatarID,card:nameCardID,level,word:worldLevel,sign:signature'))
lodash.forEach(data.showAvatarInfoList, (ds) => {
- let profile = MiaoData.getProfile(ds)
- if (profile && profile.id) {
- ret[profile.id] = profile
+ let ret = MiaoData.setAvatar(player, ds)
+ if (ret) {
+ player._update.push(ret.id)
}
})
- return ret
},
// 获取冷却时间
diff --git a/models/profile-lib/AttrCalc.js b/models/profile-lib/AttrCalc.js
index 7c3df43f..f831b7a0 100644
--- a/models/profile-lib/AttrCalc.js
+++ b/models/profile-lib/AttrCalc.js
@@ -103,7 +103,7 @@ class AttrCalc {
* 计算武器属性
*/
setWeaponAttr () {
- let wData = this.profile?.weapon
+ let wData = this.profile?.weapon || {}
let weapon = Weapon.get(wData?.name)
let level = wData.level
let promote = lodash.isUndefined(wData.promote) ? -1 : wData.promote
diff --git a/models/profile-lib/ProfileFile.js b/models/profile-lib/ProfileFile.js
deleted file mode 100644
index 1f158009..00000000
--- a/models/profile-lib/ProfileFile.js
+++ /dev/null
@@ -1,38 +0,0 @@
-import fs from 'node:fs'
-import { Data } from '../../components/index.js'
-import lodash from 'lodash'
-
-const _path = process.cwd()
-const userPath = `${_path}/data/UserData/`
-if (!fs.existsSync(userPath)) {
- fs.mkdirSync(userPath)
-}
-
-let ProfileFile = {
- getData (uid) {
- let data = Data.readJSON('/data/UserData', 'root')
- if (data && data.chars) {
- return data
- } else {
- return {
- uid,
- chars: {}
- }
- }
- },
- saveData (profile) {
- let userData = {}
- const userFile = `${userPath}/${uid}.json`
- if (fs.existsSync(userFile)) {
- userData = JSON.parse(fs.readFileSync(userFile, 'utf8')) || {}
- }
- lodash.assignIn(userData, lodash.pick(data, 'uid,name,lv,avatar'.split(',')))
- userData.chars = userData.chars || {}
- lodash.forEach(data.chars, (char, charId) => {
- userData.chars[charId] = char
- })
- fs.writeFileSync(userFile, JSON.stringify(userData), '', ' ')
- return data
- }
-}
-export default ProfileFile
\ No newline at end of file
diff --git a/resources/character/character-card.html b/resources/character/character-card.html
index 722ee765..7f2b59d3 100644
--- a/resources/character/character-card.html
+++ b/resources/character/character-card.html
@@ -78,7 +78,7 @@
- 数据源:{{data.dataSourceName}} {{data.updateTime}}
+ 数据源:{{ {miao:'喵喵API', 'enka':'Enka.Network', mys:'米游社'}[data.source]||data.source }} {{data.updateTime}}
{{else}}
{{if custom}}
diff --git a/tools/profile-calc-test.js b/tools/profile-calc-test.js
deleted file mode 100644
index 5e54c08f..00000000
--- a/tools/profile-calc-test.js
+++ /dev/null
@@ -1,117 +0,0 @@
-import fs from 'fs'
-import { Profile } from '../components/index.js'
-import AttrCalc from '../models/profile-lib/AttrCalc.js'
-import lodash from 'lodash'
-
-let _path = process.cwd()
-
-function testCalcAttr (profile) {
- if (profile.hasData) {
- let attrCalc = AttrCalc.create(profile)
- let attr2 = attrCalc.calc()
- let char = profile.char
- let ret = {}
- lodash.forEach(profile.attr, (val, key) => {
- let diff = val - (attr2[key] || 0)
- if (Math.abs(diff / val) > 0.005 && Math.abs(diff) > 0.99) {
- ret[key] = [val, attr2[key]]
- }
- })
- if (!lodash.isEmpty(ret)) {
- let retKeys = lodash.keys(ret)
- let retKeyStr = lodash.keys(ret).join(',')
- let ret2 = lodash.extend({}, ret)
- if (retKeyStr === 'hp') {
- let [s, d] = ret.hp
- let hpBase = profile.attr?.hpBase
- let pct = Math.round((s - d) / hpBase * 100)
- if ([6, 12, 18, 30, 25, 31, 37, 43, 55].includes(pct)) {
- delete ret.hp
- }
- }
- if ((ret.atkBase) || (retKeys.length === 2 && ret.atkBase && ret.atk)) {
-
- if ([1, 20, 40, 50, 60, 70, 80, 90].includes(profile.weapon.level)) {
- delete ret.atkBase
- delete ret.atk
- }
- }
- if (ret.def && ret.defBase && ret.hp && ret.hpBase) {
- let [s, d] = ret.defBase
- if (s > d && [1, 20, 40, 50, 60, 70, 80, 90].includes(profile.level)) {
- delete ret.def
- delete ret.defBase
- delete ret.hp
- delete ret.hpBase
- delete ret[char.detail?.attr?.keys[3]]
- }
- }
- if (retKeyStr === 'recharge') {
- if (char.isTraveler && char.isElem('风')) {
- delete ret.recharge
- }
- }
- if (retKeyStr === 'dmg') {
- let [s, d] = ret.dmg
- let dmg = Math.round(Math.abs(s - d - 46.6))
- console.log(dmg)
- if ([0, 15].includes(dmg) || char.name === '莫娜') {
- delete ret.dmg
- }
- }
- let cmd = `#${profile.name}面板${profile.uid}`
- if (lodash.isEmpty(ret)) {
- console.log(`Calc IGNORE: ${cmd}`)
- return true
- } else {
- console.log(`Calc Diff: ${cmd}`, ret2)
- }
- return false
- } else {
- console.log(`Calc OK:${profile.uid}:${profile.id}`)
- return true
- }
- } else {
- console.log('!has data')
- return true
- }
-}
-
-async function test (ignore) {
- let files = fs.readdirSync(`${_path}/data/UserData`)
- let count = 0
- let total = 0
- for (let file of files) {
- if (count > 0) {
- break
- }
- let testRet = /(\d{9}).json/.exec(file)
- if (testRet && testRet[1]) {
- let uid = testRet[1]
- if (ignore.includes(uid * 1)) {
- continue
- }
- Profile.forEach(uid, (profile) => {
- if (count > 0) {
- return false
- }
- let cmd = `#${profile.name}面板${profile.uid}`
- if (ignore.includes(cmd)) {
- return true
- }
- console.log(profile.id)
- let ret = testCalcAttr(profile)
- if (ret === false) {
- count++
- }
- total++
- })
- }
- }
- console.log(`calc test done total:${total}`)
- return true
-}
-
-const ignore = ['#荧面板100000023', '#班尼特面板100009630', '#荧面板100147429', '#八重神子面板100160080', '#纳西妲面板100181800', '#荧面板100211780',
- '#九条裟罗面板100248492', '#砂糖面板100270260']
-await test(ignore)