初步增加排名功能

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

3
.gitignore vendored
View File

@ -13,4 +13,5 @@
!/resources/help/theme/default !/resources/help/theme/default
/config/character.js /config/character.js
/config/profile.js /config/profile.js
/config/help.js /config/help.js
/config/cfg.js

View File

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

View File

@ -108,6 +108,16 @@ let Profile = {
return false 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) { inputProfile (uid, e) {
let { avatar, inputData } = e let { avatar, inputData } = e
let char = Character.get(avatar) 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 ProfileData from './ProfileData.js'
import ProfileArtis from './ProfileArtis.js' import ProfileArtis from './ProfileArtis.js'
import ProfileDmg from './ProfileDmg.js' import ProfileDmg from './ProfileDmg.js'
import ProfileRank from './ProfileRank.js'
import Material from './Material.js' import Material from './Material.js'
import Weapon from './Weapon.js' import Weapon from './Weapon.js'
import User from './User.js' import User from './User.js'
@ -28,6 +29,7 @@ export {
ProfileData, ProfileData,
ProfileArtis, ProfileArtis,
ProfileDmg, ProfileDmg,
ProfileRank,
Material, Material,
Weapon, Weapon,
User, User,

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

View File

@ -18,6 +18,7 @@ body,
} }
.char-item { .char-item {
margin: 5px 0; margin: 5px 0;
position: relative;
} }
.char-item .name { .char-item .name {
margin-top: 5px; margin-top: 5px;
@ -44,6 +45,44 @@ body,
border-radius: 50%; border-radius: 50%;
margin-right: 3px; 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 { .char-icon {
width: 64px; width: 64px;
height: 64px; height: 64px;
@ -78,4 +117,7 @@ body,
border-radius: 50%; border-radius: 50%;
margin-right: 3px; margin-right: 3px;
} }
.no-rank .group-rank {
display: none;
}
/*# sourceMappingURL=profile-list.css.map */ /*# sourceMappingURL=profile-list.css.map */

View File

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

View File

@ -22,6 +22,7 @@ body, .container {
.char-item { .char-item {
margin: 5px 0; margin: 5px 0;
position: relative;
.name { .name {
margin-top: 5px; margin-top: 5px;
@ -52,6 +53,52 @@ body, .container {
margin-right: 3px; 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 { .char-icon {
@ -92,4 +139,8 @@ body, .container {
border-radius: 50%; border-radius: 50%;
margin-right: 3px; 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',
珐露珊: '2022-12-07 11:00:00' 珐露珊: '2022-12-07 11:00:00'
} }
await down('73,74', true) await down('75,76', true)