miao-plugin/models/Abyss.js

101 lines
2.6 KiB
JavaScript
Raw Normal View History

2022-09-21 19:28:33 +00:00
/*
* Mys深渊数据处理
* */
import lodash from 'lodash'
import moment from 'moment'
2022-08-18 10:13:42 +00:00
import Base from '../models/Base.js'
2023-03-07 17:52:11 +00:00
import { Data } from '#miao'
moment.locale('zh-cn')
export default class Abyss extends Base {
constructor (data) {
super()
this.floors = {}
let floors = this.floors
lodash.forEach(data.floors, (floor) => {
let levels = {}
let floorData = {
star: floor.star,
index: floor.index,
levels
}
lodash.forEach(floor.levels, (level) => {
let ds = {
star: level.star
}
levels[level.index] = ds
lodash.forEach(level.battles, (battle) => {
let key = battle.index === 1 ? 'up' : 'down'
let tmp = {}
tmp.timestamp = battle.timestamp
let time = moment(new Date(battle.timestamp * 1000))
tmp.time = time.format('MM-DD HH:mm:ss')
let avatars = []
lodash.forEach(battle.avatars, (avatar) => {
avatars.push(avatar.id)
})
tmp.avatars = avatars
ds[key] = tmp
})
})
floorData.display = levels['3'] || levels['2'] || levels['1']
floors[floor.index] = floorData
})
let keys = 'id:avatar_id,value'
this.reveral = lodash.map(data.reveal_rank, (ds) => Data.getData(ds, keys))
let stat = {}
this.stat = stat
lodash.forEach({
defeat: 'defeat_rank',
dmg: 'damage_rank',
takeDmg: 'take_damage_rank',
e: 'normal_skill_rank',
q: 'energy_skill_rank'
}, (key, dst) => {
stat[dst] = Data.getData(data[key] ? data[key][0] : [], keys)
})
let st = moment(new Date(data.start_time * 1000))
2024-08-20 12:32:23 +00:00
this.schedule = st.format('M') + '月'
this.maxFloor = data.max_floor
this.total = data.total_battle_times
this.time = moment().format('MM-DD HH:mm:ss')
}
getData (floor) {
return Data.getData(this, 'reveral,stat,floors,time,schedule,maxFloor,total')
}
getAvatars () {
let ret = {}
lodash.forEach(this.reveral, (ds) => {
2022-08-18 10:13:42 +00:00
if (ds.id) {
ret[ds.id] = true
}
})
lodash.forEach(this.stat, (ds) => {
2022-08-18 10:13:42 +00:00
if (ds.id) {
ret[ds.id] = true
}
})
lodash.forEach(this.floors, (floor) => {
let levels = floor?.levels || {}
lodash.forEach(levels, (level) => {
lodash.forEach(level.up?.avatars || [], (id) => {
2022-08-18 10:13:42 +00:00
if (id) {
ret[id] = true
}
})
lodash.forEach(level.down?.avatars || [], (id) => {
2022-08-18 10:13:42 +00:00
if (id) {
ret[id] = true
}
})
})
})
return lodash.keys(ret)
}
}