2023-02-08 20:55:54 +00:00
|
|
|
|
import lodash from 'lodash'
|
2023-02-11 07:24:44 +00:00
|
|
|
|
import moment from 'moment'
|
2023-03-07 17:52:11 +00:00
|
|
|
|
import { Data } from '#miao'
|
2023-10-24 19:34:36 +00:00
|
|
|
|
import { chestInfo } from '../../resources/meta-gs/info/index.js'
|
2023-10-19 09:48:52 +00:00
|
|
|
|
import AvatarUtil from './AvatarUtil.js'
|
2023-03-07 17:52:11 +00:00
|
|
|
|
|
2023-02-08 20:55:54 +00:00
|
|
|
|
const MysAvatar = {
|
2023-10-19 16:31:35 +00:00
|
|
|
|
// 检查更新force值
|
2023-03-03 22:01:11 +00:00
|
|
|
|
checkForce (player, force) {
|
|
|
|
|
let e = player?.e
|
|
|
|
|
let mys = e?._mys
|
|
|
|
|
if (!e || !mys || !mys.isSelfCookie) {
|
|
|
|
|
return force
|
|
|
|
|
}
|
|
|
|
|
let ck = mys?.ckInfo?.ck
|
|
|
|
|
if (!ck || player._ck === ck) {
|
|
|
|
|
return force
|
|
|
|
|
}
|
2023-10-19 16:31:35 +00:00
|
|
|
|
return force
|
2023-03-03 22:01:11 +00:00
|
|
|
|
},
|
2023-02-08 20:55:54 +00:00
|
|
|
|
/**
|
|
|
|
|
* 更新米游社角色信息
|
|
|
|
|
* @param player
|
|
|
|
|
* @param force
|
|
|
|
|
* @returns {Promise<boolean>}
|
|
|
|
|
*/
|
2023-02-11 13:22:09 +00:00
|
|
|
|
async refreshMysDetail (player, force = 0) {
|
2023-02-19 21:24:17 +00:00
|
|
|
|
let e = player.e || {}
|
|
|
|
|
let mys = e?._mys
|
2023-02-08 20:55:54 +00:00
|
|
|
|
if (!mys) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
2023-10-19 09:48:52 +00:00
|
|
|
|
if (!AvatarUtil.needRefresh(player._mys, force, { 0: 60, 1: 2, 2: 0 })) {
|
2023-02-08 20:55:54 +00:00
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
let charData = await mys.getCharacter()
|
|
|
|
|
MysAvatar.setMysCharData(player, charData)
|
|
|
|
|
},
|
|
|
|
|
|
2023-02-10 19:40:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* 更新米游社统计信息
|
|
|
|
|
* @param player
|
|
|
|
|
* @param force
|
|
|
|
|
* @returns {Promise<boolean>}
|
|
|
|
|
*/
|
2023-02-11 13:22:09 +00:00
|
|
|
|
async refreshMysInfo (player, force = 0) {
|
2023-02-10 19:40:55 +00:00
|
|
|
|
let mys = player?.e?._mys
|
|
|
|
|
if (!mys) {
|
|
|
|
|
return false
|
|
|
|
|
} // 不必要更新
|
2023-10-19 09:48:52 +00:00
|
|
|
|
if (!AvatarUtil.needRefresh(player._info, force, { 0: 60, 1: 2, 2: 0 })) {
|
2023-02-10 19:40:55 +00:00
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
let infoData = await mys.getIndex()
|
2023-02-11 07:24:44 +00:00
|
|
|
|
if (!infoData || !infoData.role) {
|
2023-02-10 19:40:55 +00:00
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
MysAvatar.setMysInfo(player, infoData)
|
|
|
|
|
},
|
|
|
|
|
|
2023-02-08 20:55:54 +00:00
|
|
|
|
/**
|
|
|
|
|
* 根据已有Mys CharData更新player
|
|
|
|
|
* @param player
|
|
|
|
|
* @param charData
|
|
|
|
|
*/
|
|
|
|
|
setMysCharData (player, charData) {
|
2023-03-03 22:01:11 +00:00
|
|
|
|
if (charData && charData.avatars) {
|
|
|
|
|
let role = charData.role || {}
|
|
|
|
|
player.setBasicData({
|
|
|
|
|
level: role.level,
|
|
|
|
|
name: role.nickname
|
2023-02-08 20:55:54 +00:00
|
|
|
|
})
|
2023-03-03 22:01:11 +00:00
|
|
|
|
let charIds = {}
|
|
|
|
|
lodash.forEach(charData.avatars, (ds) => {
|
|
|
|
|
let avatar = Data.getData(ds, 'id,level,cons:actived_constellation_num,fetter')
|
|
|
|
|
avatar.elem = ds.element.toLowerCase()
|
|
|
|
|
// 处理时装数据
|
|
|
|
|
let costume = (ds?.costumes || [])[0]
|
|
|
|
|
if (costume && costume.id) {
|
|
|
|
|
avatar.costume = costume.id
|
2023-02-12 21:18:06 +00:00
|
|
|
|
}
|
2023-03-03 22:01:11 +00:00
|
|
|
|
avatar.weapon = Data.getData(ds.weapon, 'name,star:rarity,level,promote:promote_level,affix:affix_level')
|
|
|
|
|
// 处理圣遗物数据
|
|
|
|
|
let artis = {}
|
|
|
|
|
lodash.forEach(ds.reliquaries, (re) => {
|
|
|
|
|
const posIdx = { 生之花: 1, 死之羽: 2, 时之沙: 3, 空之杯: 4, 理之冠: 5 }
|
|
|
|
|
if (re && re.name && posIdx[re.pos_name]) {
|
|
|
|
|
artis[posIdx[re.pos_name]] = {
|
|
|
|
|
name: re.name,
|
|
|
|
|
level: re.level
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
avatar.artis = artis
|
|
|
|
|
player.setAvatar(avatar, 'mys')
|
|
|
|
|
charIds[avatar.id] = true
|
2023-02-12 21:18:06 +00:00
|
|
|
|
})
|
2023-10-19 09:48:52 +00:00
|
|
|
|
// 若角色数据>8,则说明为带ck更新
|
|
|
|
|
// 检查缓存,删除错误缓存的数据
|
2023-03-03 22:01:11 +00:00
|
|
|
|
if (lodash.keys(charIds).length > 8) {
|
|
|
|
|
player.forEachAvatar((avatar) => {
|
|
|
|
|
if (!charIds[avatar.id] && !avatar.isProfile) {
|
2023-10-19 11:24:42 +00:00
|
|
|
|
player.delAvatar(avatar.id)
|
2023-03-03 22:01:11 +00:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-19 11:24:42 +00:00
|
|
|
|
if (player.hasAvatar()) {
|
2023-03-03 22:01:11 +00:00
|
|
|
|
player._mys = new Date() * 1
|
|
|
|
|
player.save()
|
2023-02-12 21:18:06 +00:00
|
|
|
|
}
|
2023-02-08 20:55:54 +00:00
|
|
|
|
},
|
|
|
|
|
|
2023-02-10 19:40:55 +00:00
|
|
|
|
setMysInfo (player, infoData) {
|
|
|
|
|
let role = infoData.role
|
|
|
|
|
// 设置角色信息
|
|
|
|
|
let homeLevel = ((infoData?.homes || [])[0])?.level
|
2023-02-11 07:24:44 +00:00
|
|
|
|
if (role) {
|
2023-02-10 21:44:56 +00:00
|
|
|
|
player.setBasicData({
|
|
|
|
|
level: role.level,
|
|
|
|
|
name: role.nickname
|
|
|
|
|
})
|
|
|
|
|
}
|
2023-02-10 19:40:55 +00:00
|
|
|
|
// 设置角色数据
|
2023-02-10 21:44:56 +00:00
|
|
|
|
lodash.forEach(infoData?.avatars || [], (ds) => {
|
2023-02-10 19:40:55 +00:00
|
|
|
|
let avatar = Data.getData(ds, 'id,level,cons:actived_constellation_num,fetter')
|
|
|
|
|
avatar.elem = ds.element.toLowerCase()
|
|
|
|
|
player.setAvatar(avatar, 'mys')
|
|
|
|
|
})
|
|
|
|
|
let stats = {}
|
2023-02-10 21:44:56 +00:00
|
|
|
|
lodash.forEach(infoData?.stats || [], (num, key) => {
|
2023-02-10 19:40:55 +00:00
|
|
|
|
key = key.replace('_number', '')
|
|
|
|
|
if (key !== 'spiral_abyss') {
|
|
|
|
|
stats[lodash.camelCase(key)] = num
|
|
|
|
|
}
|
|
|
|
|
})
|
2023-10-18 13:19:12 +00:00
|
|
|
|
if (stats?.fieldExtMap) {
|
|
|
|
|
delete stats.fieldExtMap
|
|
|
|
|
}
|
2023-02-10 19:40:55 +00:00
|
|
|
|
let exploration = {}
|
2023-02-10 21:44:56 +00:00
|
|
|
|
lodash.forEach(infoData?.world_explorations || [], (ds) => {
|
2023-02-10 19:40:55 +00:00
|
|
|
|
let { name } = ds
|
|
|
|
|
if (name === '层岩巨渊') {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
exploration[name === '层岩巨渊·地下矿区' ? '层岩巨渊' : name] = ds.exploration_percentage
|
|
|
|
|
})
|
|
|
|
|
player.info = {
|
|
|
|
|
homeLevel,
|
|
|
|
|
stats,
|
|
|
|
|
exploration
|
|
|
|
|
}
|
2023-10-18 13:19:12 +00:00
|
|
|
|
|
2023-02-10 19:40:55 +00:00
|
|
|
|
player._info = new Date() * 1
|
|
|
|
|
player.save()
|
|
|
|
|
},
|
|
|
|
|
|
2023-02-08 20:55:54 +00:00
|
|
|
|
/**
|
|
|
|
|
* 获取当前角色需要更新天赋的角色ID
|
|
|
|
|
* @param player
|
|
|
|
|
* @param ids 角色列表,若传入则查询指定角色列表,不传入查询全部
|
2023-02-11 13:22:09 +00:00
|
|
|
|
* @param force
|
2023-02-08 20:55:54 +00:00
|
|
|
|
* @returns {*[]}
|
|
|
|
|
*/
|
2023-02-11 13:22:09 +00:00
|
|
|
|
getNeedRefreshIds (player, ids, force = 0) {
|
2023-02-08 20:55:54 +00:00
|
|
|
|
let ret = []
|
|
|
|
|
if (!ids) {
|
2023-10-19 11:24:42 +00:00
|
|
|
|
ids = player.getAvatarIds()
|
2023-02-08 20:55:54 +00:00
|
|
|
|
} else if (!lodash.isArray(ids)) {
|
|
|
|
|
ids = [ids]
|
|
|
|
|
}
|
|
|
|
|
lodash.forEach(ids, (id) => {
|
|
|
|
|
let avatar = player.getAvatar(id)
|
2023-02-12 21:18:06 +00:00
|
|
|
|
if (!avatar) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
2023-02-19 04:05:42 +00:00
|
|
|
|
let needMap = { 0: avatar.hasTalent ? 60 * 48 : 60 * 3, 1: 60, 2: 0 }
|
2023-10-19 09:48:52 +00:00
|
|
|
|
if (AvatarUtil.needRefresh(avatar._talent, force, needMap)) {
|
2023-02-08 20:55:54 +00:00
|
|
|
|
ret.push(avatar.id)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
return ret
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 使用MysApi刷新指定角色的天赋信息
|
|
|
|
|
* @param player
|
|
|
|
|
* @param ids
|
|
|
|
|
* @param force
|
2023-11-05 19:18:49 +00:00
|
|
|
|
* @returns {Promise<number|boolean>}
|
2023-02-08 20:55:54 +00:00
|
|
|
|
*/
|
2023-02-11 13:22:09 +00:00
|
|
|
|
async refreshTalent (player, ids, force = 0) {
|
2023-02-08 20:55:54 +00:00
|
|
|
|
let e = player?.e
|
|
|
|
|
let mys = e?._mys
|
2023-02-19 12:57:26 +00:00
|
|
|
|
if (!e || !mys || !mys.isSelfCookie) {
|
2023-02-08 20:55:54 +00:00
|
|
|
|
return false
|
|
|
|
|
}
|
2023-03-03 22:01:11 +00:00
|
|
|
|
force = MysAvatar.checkForce(player, force)
|
2023-02-11 13:22:09 +00:00
|
|
|
|
let needReqIds = MysAvatar.getNeedRefreshIds(player, ids, force)
|
2023-11-05 19:18:49 +00:00
|
|
|
|
let refreshCount = 0
|
|
|
|
|
let failCount = 0
|
2023-02-08 20:55:54 +00:00
|
|
|
|
if (needReqIds.length > 0) {
|
|
|
|
|
if (needReqIds.length > 8) {
|
|
|
|
|
e && e.reply('正在获取角色信息,请稍候...')
|
|
|
|
|
}
|
2023-02-18 10:29:09 +00:00
|
|
|
|
// 并发5,请求天赋数据
|
|
|
|
|
await Data.asyncPool(5, needReqIds, async (id) => {
|
|
|
|
|
let avatar = player.getAvatar(id)
|
2023-11-05 19:18:49 +00:00
|
|
|
|
if (!avatar) {
|
2023-02-19 04:05:42 +00:00
|
|
|
|
return false
|
|
|
|
|
}
|
2023-10-19 16:31:35 +00:00
|
|
|
|
if (avatar.isMaxTalent || failCount > 5) {
|
2023-02-19 04:05:42 +00:00
|
|
|
|
avatar.setTalent(false, 'original', true)
|
2023-02-18 10:29:09 +00:00
|
|
|
|
return false
|
2023-02-08 20:55:54 +00:00
|
|
|
|
}
|
2023-02-18 10:29:09 +00:00
|
|
|
|
let ret = await MysAvatar.refreshAvatarTalent(avatar, mys)
|
|
|
|
|
if (ret === false) {
|
|
|
|
|
failCount++
|
2023-11-05 19:18:49 +00:00
|
|
|
|
} else {
|
|
|
|
|
refreshCount++
|
2023-02-18 10:29:09 +00:00
|
|
|
|
}
|
|
|
|
|
})
|
2023-02-08 20:55:54 +00:00
|
|
|
|
}
|
|
|
|
|
player.save()
|
2023-11-05 19:18:49 +00:00
|
|
|
|
return refreshCount
|
2023-02-09 17:50:52 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
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)
|
2024-04-05 03:28:51 +00:00
|
|
|
|
let game = avatar.game
|
|
|
|
|
if (game === 'gs' && talentRes && talentRes.skill_list) {
|
2023-02-09 17:50:52 +00:00
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-05 03:28:51 +00:00
|
|
|
|
} else if (game === 'sr' && talentRes && talentRes.skills) {
|
|
|
|
|
let talentList = lodash.orderBy(talentRes.skills, ['point_id'], ['asc'])
|
|
|
|
|
for (let val of talentList) {
|
|
|
|
|
let { cur_level: lv, anchor } = val
|
|
|
|
|
if (anchor.includes('Point01')) {
|
|
|
|
|
talent.a = lv
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
if (anchor.includes('Point02')) {
|
|
|
|
|
talent.e = lv
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
if (anchor.includes('Point03')) {
|
|
|
|
|
talent.q = lv
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
if (anchor.includes('Point04')) {
|
|
|
|
|
talent.t = lv
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-02-09 17:50:52 +00:00
|
|
|
|
}
|
|
|
|
|
let ret = char.getAvatarTalent(talent, avatar.cons, 'original')
|
2023-02-18 10:29:09 +00:00
|
|
|
|
avatar.setTalent(ret, 'original', true)
|
|
|
|
|
return !!ret
|
2023-02-09 17:50:52 +00:00
|
|
|
|
}
|
|
|
|
|
return false
|
2023-02-11 07:24:44 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getDate (time) {
|
|
|
|
|
return time ? moment(new Date(time)).format('MM-DD HH:mm') : ''
|
2023-02-11 13:22:09 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getInfo (player) {
|
2023-02-13 19:47:22 +00:00
|
|
|
|
let chestMap = []
|
|
|
|
|
Data.eachStr('common,exquisite,precious,luxurious,magic', (key) => {
|
|
|
|
|
chestMap.push({
|
|
|
|
|
key: `${key}Chest`,
|
|
|
|
|
...chestInfo[key]
|
|
|
|
|
})
|
|
|
|
|
})
|
2023-02-11 13:22:09 +00:00
|
|
|
|
let ret = {
|
|
|
|
|
...(player.info || {}),
|
2023-02-13 19:47:22 +00:00
|
|
|
|
chestMap
|
2023-02-11 13:22:09 +00:00
|
|
|
|
}
|
|
|
|
|
let stats = ret.stats || {}
|
|
|
|
|
if (stats?.activeDay) {
|
|
|
|
|
let num = stats?.activeDay
|
|
|
|
|
let year = Math.floor(num / 365)
|
|
|
|
|
let month = Math.floor((num % 365) / 30.41)
|
|
|
|
|
let day = Math.floor((num % 365) % 30.41)
|
|
|
|
|
let msg = ''
|
|
|
|
|
if (year > 0) {
|
|
|
|
|
msg += year + '年'
|
|
|
|
|
}
|
|
|
|
|
if (month > 0) {
|
|
|
|
|
msg += month + '个月'
|
|
|
|
|
}
|
|
|
|
|
if (day > 0) {
|
|
|
|
|
msg += day + '天'
|
|
|
|
|
}
|
|
|
|
|
ret.activeDay = msg
|
|
|
|
|
}
|
|
|
|
|
let avatarCount = 0
|
|
|
|
|
let avatar5Count = 0
|
|
|
|
|
let goldCount = 0
|
|
|
|
|
player.forEachAvatar((avatar) => {
|
|
|
|
|
avatarCount++
|
|
|
|
|
if (avatar.star === 5) {
|
|
|
|
|
avatar5Count++
|
2023-02-19 04:05:42 +00:00
|
|
|
|
if (!avatar.char?.isTraveler) {
|
|
|
|
|
goldCount += (avatar.cons || 0) + 1
|
|
|
|
|
}
|
2023-02-11 13:22:09 +00:00
|
|
|
|
}
|
|
|
|
|
let w = avatar.weapon
|
|
|
|
|
if (w && w.star === 5) {
|
|
|
|
|
goldCount += w.affix * 1
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
stats.avatar = Math.max(stats.avatar, avatarCount)
|
|
|
|
|
stats.goldCount = goldCount
|
|
|
|
|
stats.avatar5 = avatar5Count
|
|
|
|
|
ret.stats = stats
|
|
|
|
|
return ret
|
2023-11-02 13:20:16 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getMaterials (avatar) {
|
|
|
|
|
let ret = {}
|
|
|
|
|
let { char } = avatar
|
|
|
|
|
ret.talent = char.getMaterials('talent')
|
|
|
|
|
ret.weekly = char.getMaterials('weekly')
|
|
|
|
|
return ret
|
2023-02-08 20:55:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
export default MysAvatar
|