2022-09-04 21:03:23 +00:00
|
|
|
import Base from './Base.js'
|
|
|
|
import { Data } from '../components/index.js'
|
2022-11-26 21:51:36 +00:00
|
|
|
import { weaponData, weaponAbbr, weaponAlias, weaponType, weaponSet } from '../resources/meta/weapon/index.js'
|
|
|
|
import lodash from 'lodash'
|
2022-09-04 21:03:23 +00:00
|
|
|
|
|
|
|
class Weapon extends Base {
|
|
|
|
constructor (name) {
|
|
|
|
super(name)
|
2022-11-22 20:25:36 +00:00
|
|
|
let meta = weaponData[name]
|
2022-09-04 21:03:23 +00:00
|
|
|
if (!meta) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
let cache = this._getCache(`weapon:${name}`)
|
|
|
|
if (cache) {
|
|
|
|
return cache
|
|
|
|
}
|
2023-02-26 15:42:56 +00:00
|
|
|
this.id = meta.id
|
2022-09-04 21:03:23 +00:00
|
|
|
this.name = meta.name
|
|
|
|
this.meta = meta
|
|
|
|
this.type = meta.type
|
|
|
|
this.star = meta.star
|
2022-09-08 20:34:32 +00:00
|
|
|
return this._cache()
|
2022-09-04 21:03:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get abbr () {
|
2022-11-26 21:51:36 +00:00
|
|
|
return weaponAbbr[this.name] || this.name
|
2022-09-04 21:03:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get title () {
|
|
|
|
return this.name
|
|
|
|
}
|
|
|
|
|
|
|
|
get img () {
|
2022-09-24 12:19:59 +00:00
|
|
|
return `meta/weapon/${this.type}/${this.name}/icon.webp`
|
2022-09-04 21:03:23 +00:00
|
|
|
}
|
|
|
|
|
2023-02-21 19:49:49 +00:00
|
|
|
get imgs () {
|
|
|
|
return {
|
|
|
|
icon: `meta/weapon/${this.type}/${this.name}/icon.webp`,
|
|
|
|
icon2: `meta/weapon/${this.type}/${this.name}/awaken.webp`,
|
|
|
|
gacha: `meta/weapon/${this.type}/${this.name}/gacha.webp`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-04 21:03:23 +00:00
|
|
|
get icon () {
|
|
|
|
return this.img
|
|
|
|
}
|
|
|
|
|
2022-11-20 20:45:27 +00:00
|
|
|
get detail () {
|
|
|
|
return this.getDetail()
|
|
|
|
}
|
|
|
|
|
2022-12-27 20:01:22 +00:00
|
|
|
get maxLv () {
|
|
|
|
return this.star <= 2 ? 70 : 90
|
|
|
|
}
|
|
|
|
|
|
|
|
get maxAffix () {
|
|
|
|
let datas = this.detail?.affixData?.datas || {}
|
|
|
|
return (datas['0'] && datas['0'][4]) ? 5 : 1
|
|
|
|
}
|
|
|
|
|
2022-11-26 21:51:36 +00:00
|
|
|
static isWeaponSet (name) {
|
|
|
|
return weaponSet.includes(name)
|
|
|
|
}
|
|
|
|
|
|
|
|
static get (name, type = '') {
|
|
|
|
name = lodash.trim(name)
|
|
|
|
if (weaponAlias[name]) {
|
|
|
|
return new Weapon(weaponAlias[name])
|
|
|
|
}
|
|
|
|
if (type) {
|
|
|
|
let name2 = name + (weaponType[type] || type)
|
|
|
|
if (weaponAlias[name2]) {
|
|
|
|
return new Weapon(weaponAlias[name2])
|
|
|
|
}
|
2022-11-20 20:45:27 +00:00
|
|
|
}
|
|
|
|
return false
|
2022-09-04 21:03:23 +00:00
|
|
|
}
|
2023-02-21 19:49:49 +00:00
|
|
|
|
|
|
|
getDetail () {
|
|
|
|
if (this._detail) {
|
|
|
|
return this._detail
|
|
|
|
}
|
|
|
|
const path = 'resources/meta/weapon'
|
|
|
|
try {
|
|
|
|
this._detail = Data.readJSON(`${path}/${this.type}/${this.name}/data.json`)
|
|
|
|
} catch (e) {
|
|
|
|
console.log(e)
|
|
|
|
}
|
|
|
|
return this._detail
|
|
|
|
}
|
|
|
|
|
|
|
|
calcAttr (level, promote = -1) {
|
|
|
|
let lvLeft = 1
|
|
|
|
let lvRight = 20
|
|
|
|
let lvStep = [1, 20, 40, 50, 60, 70, 80, 90]
|
|
|
|
let currPromote = 0
|
|
|
|
for (let idx = 0; idx < lvStep.length - 1; idx++) {
|
|
|
|
if (promote === -1 || (currPromote === promote)) {
|
|
|
|
if (level >= lvStep[idx] && level <= lvStep[idx + 1]) {
|
|
|
|
lvLeft = lvStep[idx]
|
|
|
|
lvRight = lvStep[idx + 1]
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
currPromote++
|
|
|
|
}
|
|
|
|
let wAttr = this?.detail?.attr || {}
|
|
|
|
let wAtk = wAttr.atk || {}
|
|
|
|
let valueLeft = wAtk[lvLeft + '+'] || wAtk[lvLeft] || {}
|
|
|
|
let valueRight = wAtk[lvRight] || {}
|
|
|
|
let atkBase = valueLeft * 1 + ((valueRight - valueLeft) * (level - lvLeft) / (lvRight - lvLeft))
|
|
|
|
let wBonus = wAttr.bonusData || {}
|
|
|
|
valueLeft = wBonus[lvLeft + '+'] || wBonus[lvLeft]
|
|
|
|
valueRight = wBonus[lvRight]
|
|
|
|
let stepCount = Math.ceil((lvRight - lvLeft) / 5)
|
|
|
|
let valueStep = (valueRight - valueLeft) / stepCount
|
|
|
|
let value = valueLeft + (stepCount - Math.ceil((lvRight - level) / 5)) * valueStep
|
|
|
|
return {
|
|
|
|
atkBase,
|
|
|
|
attr: {
|
|
|
|
key: wAttr.bonusKey,
|
|
|
|
value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getAffixInfo (affix) {
|
|
|
|
let d = this.getDetail()
|
|
|
|
let ad = this.detail.affixData
|
|
|
|
let txt = ad.text
|
|
|
|
lodash.forEach(ad.datas, (ds, idx) => {
|
|
|
|
txt = txt.replace(`$[${idx}]`, ds[affix - 1])
|
|
|
|
})
|
|
|
|
return {
|
|
|
|
name: d.name,
|
|
|
|
star: d.star,
|
|
|
|
desc: d.desc,
|
|
|
|
imgs: this.imgs,
|
|
|
|
affix,
|
|
|
|
affixTitle: d.affixTitle,
|
|
|
|
affixDetail: txt
|
|
|
|
}
|
|
|
|
}
|
2022-09-04 21:03:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Weapon
|