军团:修改定时任务活跃奖励逻辑
This commit is contained in:
@@ -849,6 +849,10 @@ export class GuildHandler {
|
||||
|
||||
const myUserGuild = await UserGuildModel.getMyGuild(roleId, 'auth guildCode');
|
||||
if(!myUserGuild) return resResult(STATUS.GUILD_NOT_FOUND);
|
||||
|
||||
// 检查权限
|
||||
const checkResult = await checkAuth(GUILD_OPERATE.GET_ACTIVE_RANK, roleId);
|
||||
if(!checkResult) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
|
||||
|
||||
const hasRank = await existsRank(REDIS_KEY.GUILD_ACTIVE_RANK, serverId);
|
||||
if(!hasRank) await initSingleRankWithServer(REDIS_KEY.GUILD_ACTIVE_RANK, serverId);
|
||||
|
||||
@@ -11,7 +11,7 @@ import { pinus } from "pinus";
|
||||
import { GuildRecType } from "../db/GuildRec";
|
||||
import { ARMY } from "../pubUtils/dicParam";
|
||||
import { sendMail } from "./mailService";
|
||||
import { setRank } from "./redisService";
|
||||
import { setRank, getMyRank, initSingleRank } from "./redisService";
|
||||
import { GuildRankParam, GuildLeader } from "../pubUtils/interface";
|
||||
|
||||
/**
|
||||
@@ -166,24 +166,16 @@ export async function getUserGuildWithRefActive(roleId: string, select: string)
|
||||
*/
|
||||
export async function settleGuildWeekly() {
|
||||
console.log('————— settleGuildWeekly —————');
|
||||
const guildList = await GuildModel.findAllGuild('code activeWeekly memberCnt');
|
||||
const guildList = await GuildModel.findAllGuild('code activeWeekly memberCnt serverId');
|
||||
|
||||
for(let { code, activeWeekly, memberCnt } of guildList) {
|
||||
for(let { code, memberCnt, serverId } of guildList) {
|
||||
const userGuildList = await UserGuildModel.getListByGuild(code, 'roleId auth activeWeekly', { activeWeekly: -1, activeUpdateTime: 1 });
|
||||
|
||||
let activeMemberCnt = 0; // 活跃度高于1000的成员人数
|
||||
let otherMemberCnt = 0; // 除了大将军以外从活跃高到底成员人数,用户计算活跃排名百分比
|
||||
let jobNum = 0; // 职位分配权重加成
|
||||
let members = new Map<string, {job: number, active: boolean}>();
|
||||
let members = new Map<string, number>();
|
||||
|
||||
for(let {roleId, auth, activeWeekly} of userGuildList) {
|
||||
let active = false;
|
||||
let job = 0;
|
||||
|
||||
if(activeWeekly > ARMY.ARMY_WEEKHONOUR_LIMIT) {
|
||||
activeMemberCnt ++;
|
||||
active = true;
|
||||
}
|
||||
|
||||
if(auth == GUILD_AUTH.LEADER) {
|
||||
job = GUILD_JOB.DAJIANGJUN;
|
||||
@@ -194,28 +186,25 @@ export async function settleGuildWeekly() {
|
||||
for(let [id, {rankProportion}] of gameData.guildPosition) {
|
||||
let rankCnt = Math.ceil(memberCnt * rankProportion / 100);
|
||||
job = id;
|
||||
if(otherMemberCnt < rankCnt) break;
|
||||
if(otherMemberCnt <= rankCnt) break;
|
||||
}
|
||||
}
|
||||
await UserGuildModel.updateInfo(roleId, { job, activeWeekly: 0 }, {});
|
||||
jobNum += gameData.guildPosition.get(job).activeRatio;
|
||||
await UserGuildModel.updateInfo(roleId, { job,/* activeWeekly: 0*/ }, {});
|
||||
|
||||
members.set(roleId, {job, active});
|
||||
if(activeWeekly > ARMY.ARMY_WEEKHONOUR_LIMIT) { // 低于一定不发奖励
|
||||
members.set(roleId, job);
|
||||
}
|
||||
}
|
||||
|
||||
// 转换周活跃奖励
|
||||
let allWeeklyReward = getGuildActiveWeekReward(activeWeekly);
|
||||
let ratio = 1;
|
||||
let averageBase = ratio * ( 1- ARMY.ARMY_POSITION_WEEKREWARD) / 100; // 70% 活跃值高于100均分
|
||||
let positionBase = ratio * ARMY.ARMY_POSITION_WEEKREWARD / 100; // 30% 职位均分
|
||||
for(let [roleId, {job, active}] of members) {
|
||||
let myAverageRatio = active? (averageBase / activeMemberCnt): 0;
|
||||
let jobActiveRatio = gameData.guildPosition.get(job).activeRatio / jobNum;
|
||||
let myJobRewardRatio = positionBase * jobActiveRatio;
|
||||
let rank = await getMyRank(REDIS_KEY.GUILD_ACTIVE_RANK, serverId, code);
|
||||
let allWeeklyReward = getGuildActiveWeekReward(rank);
|
||||
for(let [roleId, job] of members) {
|
||||
let jobActiveRatio = gameData.guildPosition.get(job).activeRatio;
|
||||
let reward = allWeeklyReward.map(cur => {
|
||||
return {
|
||||
id: cur.id,
|
||||
count: Math.ceil(cur.count * (myAverageRatio + myJobRewardRatio))
|
||||
count: Math.ceil(cur.count * jobActiveRatio)
|
||||
}
|
||||
});
|
||||
await sendMail(MAIL_TYPE.GUILD_ACTIVE_REWARD, roleId, '系统', [], reward);
|
||||
@@ -223,7 +212,7 @@ export async function settleGuildWeekly() {
|
||||
|
||||
await GuildModel.updateInfo(code, { activeWeekly: 0 }, {});
|
||||
}
|
||||
|
||||
await initSingleRank(REDIS_KEY.GUILD_ACTIVE_RANK);
|
||||
await SystemConfigModel.updateSystemConfig({settleGuildWeeklyTime: nowSeconds()}); // 记录一下
|
||||
console.log('————— settleGuildWeekly结束 —————');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user