2023-03-04 14:30:13 +08:00
|
|
|
|
import base from './base.js'
|
|
|
|
|
import MysInfo from './mys/mysInfo.js'
|
|
|
|
|
import MysApi from './mys/mysApi.js'
|
|
|
|
|
import lodash from 'lodash'
|
|
|
|
|
import gsCfg from './gsCfg.js'
|
|
|
|
|
|
|
|
|
|
export default class Calculator extends base {
|
2023-07-26 05:08:48 +08:00
|
|
|
|
constructor(e) {
|
2023-03-04 14:30:13 +08:00
|
|
|
|
super(e)
|
|
|
|
|
this.model = 'calculator'
|
2023-07-26 05:08:48 +08:00
|
|
|
|
this.checkMsg = `设置角色、武器、技能等级有误\n指令:${e.isSr ? '*克拉拉养成\n示例:*克拉拉养成75 80 6 9 9 9\n参数为角色、武器、普攻、战技、终结技、天赋' : '#刻晴养成\n示例:#刻晴养成81 90 9 9 9\n参数为角色、武器、技能等级'}`
|
2023-03-04 14:30:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-26 05:08:48 +08:00
|
|
|
|
async get(role) {
|
2023-03-04 14:30:13 +08:00
|
|
|
|
this.role = role
|
|
|
|
|
/** 获取绑定uid */
|
|
|
|
|
let uid = await MysInfo.getUid(this.e)
|
|
|
|
|
if (!uid) return false
|
|
|
|
|
|
|
|
|
|
/** 判断是否绑定了ck */
|
2023-05-09 11:03:38 +08:00
|
|
|
|
let ck = await MysInfo.checkUidBing(uid, this.e)
|
2023-03-04 14:30:13 +08:00
|
|
|
|
if (!ck) {
|
|
|
|
|
await this.e.reply(MysInfo.tips)
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.mysApi = new MysApi(uid, ck.ck, { log: true })
|
|
|
|
|
|
2023-07-26 05:08:48 +08:00
|
|
|
|
let seed_id = lodash.sample('abcdefghijklmnopqrstuvwxyz0123456789', 16).replace(/,/g, '')
|
|
|
|
|
let device_fp = await MysInfo.get(this.e, 'getFp', {
|
|
|
|
|
seed_id
|
|
|
|
|
})
|
|
|
|
|
this.headers = {
|
|
|
|
|
'x-rpc-device_fp': device_fp?.data?.device_fp
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-04 14:30:13 +08:00
|
|
|
|
/** 获取角色数据 */
|
2023-07-26 05:08:48 +08:00
|
|
|
|
let character = await MysInfo.get(this.e, this.e.isSr ? 'avatarInfo' : 'character', {
|
|
|
|
|
headers: this.headers,
|
|
|
|
|
})
|
2023-03-04 14:30:13 +08:00
|
|
|
|
if (!character || character.retcode !== 0) return false
|
|
|
|
|
character = character.data
|
|
|
|
|
|
|
|
|
|
/** 获取设置参数 */
|
|
|
|
|
await this.getSet()
|
|
|
|
|
|
|
|
|
|
/** 获取计算角色 */
|
2023-07-26 05:08:48 +08:00
|
|
|
|
this.dataCharacter = character[this.e.isSr ? 'avatar_list' : 'avatars'].find((item) => item.id == role.roleId)
|
2023-03-04 14:30:13 +08:00
|
|
|
|
|
|
|
|
|
/** 获取计算参数 */
|
|
|
|
|
let body = await this.getBody()
|
|
|
|
|
if (!body) return false
|
|
|
|
|
|
|
|
|
|
/** 计算 */
|
|
|
|
|
let computes = await this.computes(body)
|
|
|
|
|
if (!computes) return false
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
saveId: uid,
|
|
|
|
|
uid,
|
|
|
|
|
dataCharacter: this.dataCharacter,
|
|
|
|
|
setSkill: this.setSkill,
|
|
|
|
|
skillList: this.skillList,
|
|
|
|
|
computes,
|
|
|
|
|
...this.screenData
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-26 05:08:48 +08:00
|
|
|
|
async getSet() {
|
|
|
|
|
let defSetSkill = this.e.isSr ? '80,80,6,10,10,10'.split(',') : '90,90,10,10,10'.split(',')
|
2023-03-04 14:30:13 +08:00
|
|
|
|
|
2023-07-26 05:08:48 +08:00
|
|
|
|
let set = this.e.msg.replace(/#|#|星铁|养成|计算/g, '').trim()
|
2023-03-04 14:30:13 +08:00
|
|
|
|
|
|
|
|
|
set = set.replace(/,| /g, ',')
|
|
|
|
|
|
|
|
|
|
set = set.replace(this.role.alias, '')
|
|
|
|
|
|
|
|
|
|
let setSkill = []
|
2023-07-26 05:08:48 +08:00
|
|
|
|
let length = this.e.isSr ? 6 : 5
|
2023-03-04 14:30:13 +08:00
|
|
|
|
if (set) {
|
|
|
|
|
setSkill = set.split(',')
|
|
|
|
|
setSkill = lodash.compact(setSkill)
|
2023-07-26 05:08:48 +08:00
|
|
|
|
for (let i = 0; i < length; i++) {
|
2023-03-04 14:30:13 +08:00
|
|
|
|
if (!setSkill[i]) setSkill[i] = defSetSkill[i]
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
setSkill = defSetSkill
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-26 05:08:48 +08:00
|
|
|
|
if (setSkill.length != length) {
|
|
|
|
|
let reMsg = this.checkMsg.replace(/刻晴|克拉拉/g, this.role.alias)
|
2023-03-04 14:30:13 +08:00
|
|
|
|
await this.e.reply(reMsg)
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 检查参数 */
|
2023-07-26 05:08:48 +08:00
|
|
|
|
let check = this.e.isSr ? [80, 80, 6, 10, 10, 10] : [90, 90, 10, 10, 10]
|
2023-03-04 14:30:13 +08:00
|
|
|
|
for (const key in check) {
|
|
|
|
|
if (check[key] < Number(setSkill[key])) {
|
|
|
|
|
setSkill[key] = check[key]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.setSkill = setSkill
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-26 05:08:48 +08:00
|
|
|
|
async getBody() {
|
2023-03-04 14:30:13 +08:00
|
|
|
|
// 技能
|
|
|
|
|
let skillList = []
|
|
|
|
|
if (this.dataCharacter) {
|
|
|
|
|
/** 角色存在获取技能数据 */
|
2023-07-26 05:08:48 +08:00
|
|
|
|
let data = this.e.isSr ? { avatar_id: this.role.roleId, tab_from: 'TabOwned' } : { avatar_id: this.role.roleId }
|
|
|
|
|
let detail = await MysInfo.get(this.e, 'detail', {
|
|
|
|
|
headers: this.headers,
|
|
|
|
|
...data
|
|
|
|
|
})
|
2023-03-04 14:30:13 +08:00
|
|
|
|
if (!detail || detail.retcode !== 0) return false
|
|
|
|
|
|
2023-07-26 05:08:48 +08:00
|
|
|
|
skillList = detail.data.skill_list || detail.data.skills
|
2023-03-04 14:30:13 +08:00
|
|
|
|
} else {
|
|
|
|
|
/** 尚未拥有的角色 */
|
2023-07-26 05:08:48 +08:00
|
|
|
|
if (this.e.isSr) {
|
|
|
|
|
let detail = await MysInfo.get(this.e, 'detail', {
|
|
|
|
|
headers: this.headers,
|
|
|
|
|
avatar_id: this.role.roleId,
|
|
|
|
|
tab_from: 'TabAll'
|
|
|
|
|
})
|
|
|
|
|
if (!detail || detail.retcode !== 0) return false
|
|
|
|
|
|
|
|
|
|
this.avatar = detail.data.avatar
|
|
|
|
|
skillList = detail.data.skills
|
|
|
|
|
} else {
|
|
|
|
|
skillList = await this.getSkillId(this.role.roleId)
|
|
|
|
|
}
|
2023-03-04 14:30:13 +08:00
|
|
|
|
|
|
|
|
|
if (!skillList) {
|
2023-07-26 05:08:48 +08:00
|
|
|
|
this.e.reply('暂无角色数据,请稍后再试\n星铁角色养成请使用*开头')
|
2023-03-04 14:30:13 +08:00
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let four = gsCfg.getdefSet('role', 'other').four
|
|
|
|
|
|
|
|
|
|
this.dataCharacter = {
|
|
|
|
|
level: 1,
|
|
|
|
|
name: this.role.name,
|
2023-07-26 05:08:48 +08:00
|
|
|
|
icon: this.e.isSr ? this.avatar.icon_url : `${this.screenData.pluResPath}img/role/${this.role.name}.png`,
|
|
|
|
|
rarity: this.e.isSr ? this.avatar.rarity : four.includes(Number(this.role.roleId)) ? 4 : 5
|
2023-03-04 14:30:13 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 拼接计算参数 */
|
2023-07-26 05:08:48 +08:00
|
|
|
|
let body
|
|
|
|
|
if (this.e.isSr) {
|
|
|
|
|
body = {
|
|
|
|
|
game: 'hkrpg',
|
|
|
|
|
avatar: {
|
|
|
|
|
item_id: Number(this.role.roleId),
|
|
|
|
|
cur_level: Number(this.dataCharacter.level),
|
|
|
|
|
target_level: Number(this.setSkill[0]),
|
2023-03-04 14:30:13 +08:00
|
|
|
|
},
|
2023-07-26 05:08:48 +08:00
|
|
|
|
skill_list: []
|
|
|
|
|
}
|
|
|
|
|
for (let data of skillList) {
|
|
|
|
|
let skill = {
|
|
|
|
|
item_id: data.point_id,
|
|
|
|
|
cur_level: data.cur_level,
|
|
|
|
|
target_level: data.target_level
|
2023-03-04 14:30:13 +08:00
|
|
|
|
}
|
2023-07-26 05:08:48 +08:00
|
|
|
|
if (Number(this.setSkill[0]) >= data.min_level_limit) body.skill_list.push(skill)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
skillList = skillList.filter((item) => item.max_level != 1)
|
|
|
|
|
|
|
|
|
|
body = {
|
|
|
|
|
avatar_id: Number(this.role.roleId),
|
|
|
|
|
avatar_level_current: Number(this.dataCharacter.level),
|
|
|
|
|
avatar_level_target: Number(this.setSkill[0]),
|
|
|
|
|
skill_list: [
|
|
|
|
|
{
|
|
|
|
|
id: Number(skillList[0].group_id),
|
|
|
|
|
level_current: Number(skillList[0].level_current),
|
|
|
|
|
level_target: Number(this.setSkill[2])
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: Number(skillList[1].group_id),
|
|
|
|
|
level_current: Number(skillList[1].level_current),
|
|
|
|
|
level_target: Number(this.setSkill[3])
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: Number(skillList[2].group_id),
|
|
|
|
|
level_current: Number(skillList[2].level_current),
|
|
|
|
|
level_target: Number(this.setSkill[4])
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
2023-03-04 14:30:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.mysApi.getServer().startsWith('os')) {
|
|
|
|
|
body.lang = "zh-cn"
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-26 05:08:48 +08:00
|
|
|
|
if (this.e.isSr) {
|
|
|
|
|
if (this.dataCharacter.equip) {
|
|
|
|
|
body.equipment = {
|
|
|
|
|
item_id: Number(this.dataCharacter.equip.id),
|
|
|
|
|
cur_level: Number(this.dataCharacter.equip.level),
|
|
|
|
|
target_level: Number(this.setSkill[1])
|
|
|
|
|
}
|
2023-03-04 14:30:13 +08:00
|
|
|
|
}
|
2023-07-26 05:08:48 +08:00
|
|
|
|
} else {
|
|
|
|
|
if (this.dataCharacter.weapon) {
|
|
|
|
|
if (Number(this.dataCharacter.weapon.rarity) < 3) {
|
|
|
|
|
this.setSkill[1] = 70
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
body.weapon = {
|
|
|
|
|
id: Number(this.dataCharacter.weapon.id),
|
|
|
|
|
level_current: Number(this.dataCharacter.weapon.level),
|
|
|
|
|
level_target: Number(this.setSkill[1])
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-04 14:30:13 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-26 05:08:48 +08:00
|
|
|
|
|
|
|
|
|
skillList = skillList.filter((item) => item.max_level != 1)
|
2023-03-04 14:30:13 +08:00
|
|
|
|
this.skillList = skillList
|
|
|
|
|
return body
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-26 05:08:48 +08:00
|
|
|
|
async getSkillId(roleId) {
|
|
|
|
|
let avatarSkill = await MysInfo.get(this.e, 'avatarSkill', {
|
|
|
|
|
headers: this.headers,
|
|
|
|
|
avatar_id: roleId
|
|
|
|
|
})
|
2023-03-04 14:30:13 +08:00
|
|
|
|
if (!avatarSkill || avatarSkill.retcode !== 0) return false
|
|
|
|
|
avatarSkill = avatarSkill.data
|
|
|
|
|
avatarSkill.list.forEach((item) => {
|
|
|
|
|
item.level_current = 1
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return avatarSkill.list
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-26 05:08:48 +08:00
|
|
|
|
async computes(body) {
|
|
|
|
|
let computes = await MysInfo.get(this.e, 'compute', body)
|
2023-03-04 14:30:13 +08:00
|
|
|
|
if (!computes || computes.retcode !== 0) return false
|
|
|
|
|
computes = computes.data
|
|
|
|
|
|
|
|
|
|
let formart = (num) => {
|
|
|
|
|
return num > 10000 ? (num / 10000).toFixed(1) + ' w' : num
|
|
|
|
|
}
|
2023-07-26 05:08:48 +08:00
|
|
|
|
if (this.e.isSr) delete computes.coin_id
|
2023-03-04 14:30:13 +08:00
|
|
|
|
for (let i in computes) {
|
|
|
|
|
for (let j in computes[i]) {
|
|
|
|
|
computes[i][j].num = formart(computes[i][j].num)
|
|
|
|
|
|
2023-07-26 05:08:48 +08:00
|
|
|
|
if (computes[i][j][this.e.isSr ? 'item_name' : 'name'].includes('「')) {
|
2023-03-04 14:30:13 +08:00
|
|
|
|
computes[i][j].isTalent = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return computes
|
|
|
|
|
}
|
|
|
|
|
}
|