初步增加排名功能

This commit is contained in:
Kokomi 2022-11-08 04:08:24 +08:00
parent a1642ec469
commit 9ba9781701
11 changed files with 174 additions and 8 deletions

1
.gitignore vendored
View File

@ -14,3 +14,4 @@
/config/character.js
/config/profile.js
/config/help.js
/config/cfg.js

View File

@ -1,14 +1,17 @@
import lodash from 'lodash'
import { autoRefresh, getTargetUid } from './ProfileCommon.js'
import { Common, Profile } from '../../components/index.js'
import { ProfileRank } from '../../models/index.js'
import { Common, Profile, Data } from '../../components/index.js'
export async function profileList (e) {
let uid = await getTargetUid(e)
if (!uid) {
return true
}
let profiles = Profile.getAll(uid) || {}
let rank = false
if (e.group_id) {
rank = await ProfileRank.create({ group: e.group_id, uid, qq: e.user_id })
}
let servName = Profile.getServName(uid)
let hasNew = false
let newCount = 0
@ -20,7 +23,9 @@ export async function profileList (e) {
msg = '获取角色面板数据成功'
newChar = e.newChar
}
lodash.forEach(profiles || {}, (profile) => {
const cfg = await Data.importCfg('cfg')
const groupRank = cfg?.diyCfg?.groupRank || false
await Profile.forEach(uid, async function (profile) {
if (!profile.hasData) {
return true
}
@ -31,6 +36,9 @@ export async function profileList (e) {
tmp.level = profile.level || 1
tmp.cons = profile.cons
tmp.isNew = 0
if (rank) {
tmp.groupRank = await rank.getRank(profile)
}
if (newChar[char.name]) {
tmp.isNew = 1
newCount++
@ -62,6 +70,7 @@ export async function profileList (e) {
chars,
servName,
hasNew,
msg
msg,
groupRank
}, { e, scale: 1.6 })
}

View File

@ -108,6 +108,16 @@ let Profile = {
return false
},
async forEach (uid, fn) {
let profiles = Profile.getAll(uid)
for (let id in profiles) {
let ret = await fn(profiles[id], id)
if (ret === false) {
return false
}
}
},
inputProfile (uid, e) {
let { avatar, inputData } = e
let char = Character.get(avatar)

View File

@ -0,0 +1,2 @@
export const groupRank = false
export const isSys = true

42
models/ProfileRank.js Normal file
View File

@ -0,0 +1,42 @@
import { Format } from '../components/index.js'
import lodash from 'lodash'
export default class ProfileRank {
constructor (data) {
this.group = data.group || data.groupId
this.qq = data.qq
this.uid = data.uid + ''
}
static async create (data) {
return new ProfileRank(data)
}
key (profile, type) {
return `miao:rank:${this.group}:${type}:${profile.id}`
}
async getRank (profile, force = false) {
const key = this.key(profile, 'mark')
let rank = await redis.zRank(key, this.uid)
if (!rank || force) {
let mark = profile.getArtisMark(false)
if (mark) {
await redis.zAdd(key, { score: mark._mark, value: this.uid })
rank = await redis.zRank(key, this.uid)
}
}
if (lodash.isNumber(rank)) {
let count = await redis.zCard(key)
let mark = await redis.zScore(key, this.uid)
return {
rank: rank + 1,
count,
value: Format.comma(mark, 1),
_value: mark,
pct: Format.percent(Math.max(0.01, Math.min(0.999, (count - rank) / count)))
}
}
return false
}
}

View File

@ -10,6 +10,7 @@ import ProfileReq from './ProfileReq.js'
import ProfileData from './ProfileData.js'
import ProfileArtis from './ProfileArtis.js'
import ProfileDmg from './ProfileDmg.js'
import ProfileRank from './ProfileRank.js'
import Material from './Material.js'
import Weapon from './Weapon.js'
import User from './User.js'
@ -28,6 +29,7 @@ export {
ProfileData,
ProfileArtis,
ProfileDmg,
ProfileRank,
Material,
Weapon,
User,

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

View File

@ -18,6 +18,7 @@ body,
}
.char-item {
margin: 5px 0;
position: relative;
}
.char-item .name {
margin-top: 5px;
@ -44,6 +45,44 @@ body,
border-radius: 50%;
margin-right: 3px;
}
.char-item .group-rank {
position: absolute;
background: url('./imgs/rank-bg.png') left top no-repeat;
background-size: auto 100%;
left: 0;
top: 0;
margin-top: -5px;
width: 74px;
height: 74px;
}
.char-item .group-rank span {
position: absolute;
font-size: 12px;
width: 16px;
height: 16px;
bottom: 0;
left: 50%;
margin-left: -7px;
text-align: center;
transform: scale(0.8);
display: none;
text-shadow: 0 0 2px #b26f08;
}
.char-item .group-rank.rank-1 {
background-position: 25% 0;
}
.char-item .group-rank.rank-2 {
background-position: 50% 0;
}
.char-item .group-rank.rank-3 {
background-position: 75% 0;
}
.char-item .group-rank.rank-4 {
background-position: 100% 0;
}
.char-item .group-rank.rank-4 span {
display: block;
}
.char-icon {
width: 64px;
height: 64px;
@ -78,4 +117,7 @@ body,
border-radius: 50%;
margin-right: 3px;
}
.no-rank .group-rank {
display: none;
}
/*# sourceMappingURL=profile-list.css.map */

View File

@ -15,7 +15,7 @@
<div class="label">{{msg+", "}}更新角色时请不要出场对应角色,以获取准确面板数据</div>
<div class="label">你可以使用<span>#{{demo}}面板</span><span>#{{demo}}伤害</span><span>#{{demo}}圣遗物</span>命令来查看面板信息了</div>
</div>
<div class="cont">
<div class="cont {{groupRank?'has-rank':'no-rank'}}">
<div class="char-list">
{{each chars char}}
<div class="char-item {{char.isNew&&hasNew ?'new-char':''}}">
@ -24,6 +24,13 @@
style="background-image:url({{_res_path}}{{char.face}})"></span>
</div>
<span class="name">{{char.abbr}}<span class="cons cons-{{char.cons}}">{{char.cons}}</span></span>
{{if char.groupRank}}
{{set gr = char.groupRank}}
{{set rank = gr.rank > 9 ? 10:(gr.rank <=3 ? gr.rank : 4)}}
<div class="group-rank rank-{{rank}}">
<span>{{gr.rank}}</span>
</div>
{{/if}}
</div>
{{/each}}
</div>

View File

@ -22,6 +22,7 @@ body, .container {
.char-item {
margin: 5px 0;
position: relative;
.name {
margin-top: 5px;
@ -52,6 +53,52 @@ body, .container {
margin-right: 3px;
}
}
.group-rank {
position: absolute;
background: url('./imgs/rank-bg.png') left top no-repeat;
background-size: auto 100%;
left: 0;
top: 0;
margin-top: -5px;
width: 74px;
height: 74px;
span {
position: absolute;
font-size: 12px;
width: 16px;
height: 16px;
bottom: 0;
left: 50%;
margin-left: -7px;
text-align: center;
transform: scale(.8);
display: none;
text-shadow: 0 0 2px #b26f08;
}
&.rank-1 {
background-position: 25% 0;
}
&.rank-2 {
background-position: 50% 0;
}
&.rank-3 {
background-position: 75% 0;
}
&.rank-4 {
background-position: 100% 0;
span {
display: block;
}
}
}
}
.char-icon {
@ -93,3 +140,7 @@ body, .container {
margin-right: 3px;
}
}
.no-rank .group-rank {
display: none;
}

View File

@ -265,4 +265,4 @@ let eta = {
流浪者: '2022-12-07 11:00:00',
珐露珊: '2022-12-07 11:00:00'
}
await down('73,74', true)
await down('75,76', true)