miao-plugin/models/ArtifactSet.js

89 lines
1.9 KiB
JavaScript
Raw Normal View History

/*
* 圣遗物套装
* */
2023-05-21 18:13:38 +00:00
import lodash from 'lodash'
import Base from './Base.js'
2023-10-20 08:59:06 +00:00
import { Meta } from '#miao'
import { Artifact } from './index.js'
class ArtifactSet extends Base {
2023-10-20 08:59:06 +00:00
constructor (data, game = 'gs') {
super()
if (!data) {
2023-10-20 08:59:06 +00:00
return false
}
let name = data.name
let cache = this._getCache(`arti-set:${game}:${name}`)
if (cache) {
return cache
}
this.game = game
this.meta = data
return this._cache()
}
get img () {
2023-11-07 21:01:31 +00:00
let arti = Artifact.get(this.idxs[1] || this.idxs[5], this.game)
return arti ? arti.img : ''
}
static getByArti (name) {
let arti = Artifact.get(name)
if (arti && arti.set) {
return ArtifactSet.get(arti.set)
}
return false
}
2023-10-20 08:59:06 +00:00
static get (name, game = 'gs') {
2023-11-07 21:01:31 +00:00
if (game === 'gs' && /^\d{5}$/.test(name)) {
name = name.toString().slice(0, 2)
}
2023-10-20 08:59:06 +00:00
let data = Meta.matchGame(game, 'artiSet', name)
if (data) {
return new ArtifactSet(data.data, data.game)
}
return false
}
static getArtiNameBySet (set, idx = 1) {
let artiSet = ArtifactSet.get(set)
if (artiSet) {
return artiSet.getArtiName(idx)
}
return ''
}
2023-05-21 18:13:38 +00:00
static getArtisSetBuff (name, num, game = 'gs') {
let { artiBuffs } = Meta.getMeta(game, 'arti')
let ret = (artiBuffs[name] && artiBuffs[name][num]) || artiBuffs[name + num]
2023-05-21 18:13:38 +00:00
if (!ret) return false
if (lodash.isPlainObject(ret)) return [ret]
return ret
}
2023-10-18 13:19:12 +00:00
// 循环圣遗物套装
2023-11-07 21:01:31 +00:00
static eachSet (idxs, fn, game = 'gs') {
lodash.forEach(idxs || [], (v, k) => {
2023-10-18 13:19:12 +00:00
let artisSet = ArtifactSet.get(k, game)
if (artisSet) {
if (v >= 4) {
fn(artisSet, 2)
}
fn(artisSet, v)
}
})
}
2023-10-20 08:59:06 +00:00
getArtiName (idx = 1) {
2023-11-07 21:01:31 +00:00
return this.idxs[idx]
2023-10-20 08:59:06 +00:00
}
getArti (idx = 1) {
return Artifact.get(this.getArtiName(idx), this.game)
}
}
export default ArtifactSet