2022-11-23 20:26:07 +00:00
|
|
|
/**
|
|
|
|
* 角色别名及角色ID相关
|
|
|
|
* */
|
2022-09-03 21:08:57 +00:00
|
|
|
import lodash from 'lodash'
|
2023-03-07 17:52:11 +00:00
|
|
|
import { Data, Format } from '#miao'
|
2022-11-24 15:27:03 +00:00
|
|
|
import { charPosIdx } from './CharMeta.js'
|
2023-05-20 17:14:07 +00:00
|
|
|
import { aliasMap as aliasMapSR } from '../../resources/meta-sr/character/meta.js'
|
2022-09-03 21:08:57 +00:00
|
|
|
|
|
|
|
// 别名表
|
|
|
|
let aliasMap = {}
|
|
|
|
// ID表
|
|
|
|
let idMap = {}
|
|
|
|
// 简写表
|
|
|
|
let abbrMap = {}
|
|
|
|
// wife
|
|
|
|
let wifeMap = {}
|
|
|
|
// id排序
|
|
|
|
let idSort = {}
|
|
|
|
|
2023-05-14 20:19:33 +00:00
|
|
|
let gameMap = {}
|
|
|
|
|
|
|
|
let srData = Data.readJSON('/resources/meta-sr/character/data.json', 'miao')
|
|
|
|
|
2022-09-03 21:08:57 +00:00
|
|
|
async function init () {
|
|
|
|
let { sysCfg, diyCfg } = await Data.importCfg('character')
|
2023-05-14 20:19:33 +00:00
|
|
|
|
|
|
|
lodash.forEach(srData, (ds) => {
|
|
|
|
let { id, name } = ds
|
|
|
|
aliasMap[id] = id
|
|
|
|
aliasMap[name] = id
|
|
|
|
idMap[id] = name
|
|
|
|
gameMap[id] = 'sr'
|
|
|
|
})
|
|
|
|
|
2023-05-20 17:14:07 +00:00
|
|
|
// 添加别名
|
|
|
|
lodash.forEach(aliasMapSR, (v, k) => {
|
2023-05-20 17:20:39 +00:00
|
|
|
aliasMap[k] = aliasMap[v]
|
2023-05-20 17:14:07 +00:00
|
|
|
})
|
2023-05-14 20:19:33 +00:00
|
|
|
|
2022-09-03 21:08:57 +00:00
|
|
|
lodash.forEach([diyCfg.customCharacters, sysCfg.characters], (roleIds) => {
|
|
|
|
lodash.forEach(roleIds || {}, (aliases, id) => {
|
|
|
|
aliases = aliases || []
|
|
|
|
if (aliases.length === 0) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// 建立别名映射
|
|
|
|
lodash.forEach(aliases || [], (alias) => {
|
|
|
|
alias = alias.toLowerCase()
|
|
|
|
aliasMap[alias] = id
|
|
|
|
})
|
|
|
|
aliasMap[id] = id
|
|
|
|
idMap[id] = aliases[0]
|
2023-05-14 20:19:33 +00:00
|
|
|
gameMap[id] = 'gs'
|
2022-09-03 21:08:57 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
lodash.forEach([sysCfg.wifeData, diyCfg.wifeData], (wifeData) => {
|
|
|
|
lodash.forEach(wifeData || {}, (ids, type) => {
|
|
|
|
type = Data.def({ girlfriend: 0, boyfriend: 1, daughter: 2, son: 3 }[type], type)
|
|
|
|
if (!wifeMap[type]) {
|
|
|
|
wifeMap[type] = {}
|
|
|
|
}
|
|
|
|
Data.eachStr(ids, (id) => {
|
|
|
|
id = aliasMap[id]
|
|
|
|
if (id) {
|
|
|
|
wifeMap[type][id] = true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
abbrMap = sysCfg.abbr
|
|
|
|
}
|
|
|
|
|
|
|
|
await init()
|
|
|
|
|
|
|
|
lodash.forEach(charPosIdx, (chars, pos) => {
|
|
|
|
chars = chars.split(',')
|
|
|
|
lodash.forEach(chars, (name, idx) => {
|
|
|
|
let id = aliasMap[name]
|
|
|
|
if (id) {
|
|
|
|
idSort[id] = pos * 100 + idx
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
const CharId = {
|
|
|
|
aliasMap,
|
|
|
|
idMap,
|
2023-05-14 20:19:33 +00:00
|
|
|
gameMap,
|
2022-09-03 21:08:57 +00:00
|
|
|
abbrMap,
|
|
|
|
wifeMap,
|
|
|
|
idSort,
|
2023-05-14 20:19:33 +00:00
|
|
|
isGs (id) {
|
|
|
|
return gameMap[id] === 'gs'
|
|
|
|
},
|
|
|
|
isSr (id) {
|
|
|
|
return gameMap[id] === 'sr'
|
|
|
|
},
|
2023-10-19 09:48:52 +00:00
|
|
|
getId (ds = '', gsCfg = null, game = '') {
|
2022-09-03 21:08:57 +00:00
|
|
|
if (!ds) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
const ret = (id, elem = '') => {
|
2023-05-14 20:19:33 +00:00
|
|
|
if (CharId.isSr(id)) {
|
|
|
|
return { id, name: idMap[id], game: 'sr' }
|
|
|
|
} else {
|
|
|
|
return { id, elem, name: idMap[id], game: 'gs' }
|
|
|
|
}
|
2022-09-03 21:08:57 +00:00
|
|
|
}
|
|
|
|
if (!lodash.isObject(ds)) {
|
2022-12-27 20:01:22 +00:00
|
|
|
let original = lodash.trim(ds || '')
|
|
|
|
ds = original.toLowerCase()
|
2023-10-19 09:48:52 +00:00
|
|
|
if(game !== 'sr') {
|
|
|
|
// 尝试使用元素起始匹配
|
|
|
|
let em = Format.matchElem(ds, '', true)
|
|
|
|
if (em && aliasMap[em.name] && CharId.isTraveler(aliasMap[em.name])) {
|
|
|
|
return ret(aliasMap[em.name], em.elem)
|
|
|
|
}
|
2022-09-03 21:08:57 +00:00
|
|
|
}
|
|
|
|
// 直接匹配
|
|
|
|
if (aliasMap[ds]) {
|
|
|
|
return ret(aliasMap[ds])
|
|
|
|
}
|
2022-10-02 20:02:18 +00:00
|
|
|
// 调用V3方法匹配
|
|
|
|
if (gsCfg && gsCfg.getRole) {
|
2022-12-27 20:01:22 +00:00
|
|
|
let roleRet = gsCfg.getRole(original)
|
2022-10-02 20:02:18 +00:00
|
|
|
if (roleRet.name && aliasMap[roleRet.name]) {
|
|
|
|
return ret(aliasMap[roleRet.name])
|
|
|
|
}
|
|
|
|
}
|
2022-09-03 21:08:57 +00:00
|
|
|
// 无匹配结果
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
// 获取字段进行匹配
|
2022-09-04 06:15:00 +00:00
|
|
|
let { id = '', name = '' } = ds
|
2022-11-24 15:27:03 +00:00
|
|
|
let elem = Format.elem(ds.elem || ds.element)
|
2022-09-03 21:08:57 +00:00
|
|
|
// 直接匹配
|
|
|
|
if (aliasMap[id || name]) {
|
|
|
|
return ret(aliasMap[id || name], elem)
|
|
|
|
}
|
|
|
|
// 尝试解析名字
|
|
|
|
let nId = CharId.getId(ds.name)
|
|
|
|
if (nId) {
|
2022-09-04 06:15:00 +00:00
|
|
|
return ret(nId.id, elem || nId.elem || '')
|
2022-09-03 21:08:57 +00:00
|
|
|
}
|
|
|
|
// 无匹配结果
|
|
|
|
return false
|
|
|
|
},
|
|
|
|
|
2023-05-14 20:19:33 +00:00
|
|
|
isTraveler (id, game = 'gs') {
|
2022-09-03 21:08:57 +00:00
|
|
|
if (id) {
|
|
|
|
return [10000007, 10000005, 20000000].includes(id * 1)
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
},
|
|
|
|
|
2023-05-14 20:19:33 +00:00
|
|
|
getSrMeta (name) {
|
|
|
|
return srData?.[aliasMap[name]] || {}
|
2022-09-03 21:08:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
export default CharId
|