军团:修改定时任务活跃奖励逻辑
This commit is contained in:
@@ -849,6 +849,10 @@ export class GuildHandler {
|
|||||||
|
|
||||||
const myUserGuild = await UserGuildModel.getMyGuild(roleId, 'auth guildCode');
|
const myUserGuild = await UserGuildModel.getMyGuild(roleId, 'auth guildCode');
|
||||||
if(!myUserGuild) return resResult(STATUS.GUILD_NOT_FOUND);
|
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);
|
const hasRank = await existsRank(REDIS_KEY.GUILD_ACTIVE_RANK, serverId);
|
||||||
if(!hasRank) await initSingleRankWithServer(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 { GuildRecType } from "../db/GuildRec";
|
||||||
import { ARMY } from "../pubUtils/dicParam";
|
import { ARMY } from "../pubUtils/dicParam";
|
||||||
import { sendMail } from "./mailService";
|
import { sendMail } from "./mailService";
|
||||||
import { setRank } from "./redisService";
|
import { setRank, getMyRank, initSingleRank } from "./redisService";
|
||||||
import { GuildRankParam, GuildLeader } from "../pubUtils/interface";
|
import { GuildRankParam, GuildLeader } from "../pubUtils/interface";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -166,24 +166,16 @@ export async function getUserGuildWithRefActive(roleId: string, select: string)
|
|||||||
*/
|
*/
|
||||||
export async function settleGuildWeekly() {
|
export async function settleGuildWeekly() {
|
||||||
console.log('————— 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 });
|
const userGuildList = await UserGuildModel.getListByGuild(code, 'roleId auth activeWeekly', { activeWeekly: -1, activeUpdateTime: 1 });
|
||||||
|
|
||||||
let activeMemberCnt = 0; // 活跃度高于1000的成员人数
|
|
||||||
let otherMemberCnt = 0; // 除了大将军以外从活跃高到底成员人数,用户计算活跃排名百分比
|
let otherMemberCnt = 0; // 除了大将军以外从活跃高到底成员人数,用户计算活跃排名百分比
|
||||||
let jobNum = 0; // 职位分配权重加成
|
let members = new Map<string, number>();
|
||||||
let members = new Map<string, {job: number, active: boolean}>();
|
|
||||||
|
|
||||||
for(let {roleId, auth, activeWeekly} of userGuildList) {
|
for(let {roleId, auth, activeWeekly} of userGuildList) {
|
||||||
let active = false;
|
|
||||||
let job = 0;
|
let job = 0;
|
||||||
|
|
||||||
if(activeWeekly > ARMY.ARMY_WEEKHONOUR_LIMIT) {
|
|
||||||
activeMemberCnt ++;
|
|
||||||
active = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(auth == GUILD_AUTH.LEADER) {
|
if(auth == GUILD_AUTH.LEADER) {
|
||||||
job = GUILD_JOB.DAJIANGJUN;
|
job = GUILD_JOB.DAJIANGJUN;
|
||||||
@@ -194,28 +186,25 @@ export async function settleGuildWeekly() {
|
|||||||
for(let [id, {rankProportion}] of gameData.guildPosition) {
|
for(let [id, {rankProportion}] of gameData.guildPosition) {
|
||||||
let rankCnt = Math.ceil(memberCnt * rankProportion / 100);
|
let rankCnt = Math.ceil(memberCnt * rankProportion / 100);
|
||||||
job = id;
|
job = id;
|
||||||
if(otherMemberCnt < rankCnt) break;
|
if(otherMemberCnt <= rankCnt) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await UserGuildModel.updateInfo(roleId, { job, activeWeekly: 0 }, {});
|
await UserGuildModel.updateInfo(roleId, { job,/* activeWeekly: 0*/ }, {});
|
||||||
jobNum += gameData.guildPosition.get(job).activeRatio;
|
|
||||||
|
|
||||||
members.set(roleId, {job, active});
|
if(activeWeekly > ARMY.ARMY_WEEKHONOUR_LIMIT) { // 低于一定不发奖励
|
||||||
|
members.set(roleId, job);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 转换周活跃奖励
|
// 转换周活跃奖励
|
||||||
let allWeeklyReward = getGuildActiveWeekReward(activeWeekly);
|
let rank = await getMyRank(REDIS_KEY.GUILD_ACTIVE_RANK, serverId, code);
|
||||||
let ratio = 1;
|
let allWeeklyReward = getGuildActiveWeekReward(rank);
|
||||||
let averageBase = ratio * ( 1- ARMY.ARMY_POSITION_WEEKREWARD) / 100; // 70% 活跃值高于100均分
|
for(let [roleId, job] of members) {
|
||||||
let positionBase = ratio * ARMY.ARMY_POSITION_WEEKREWARD / 100; // 30% 职位均分
|
let jobActiveRatio = gameData.guildPosition.get(job).activeRatio;
|
||||||
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 reward = allWeeklyReward.map(cur => {
|
let reward = allWeeklyReward.map(cur => {
|
||||||
return {
|
return {
|
||||||
id: cur.id,
|
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);
|
await sendMail(MAIL_TYPE.GUILD_ACTIVE_REWARD, roleId, '系统', [], reward);
|
||||||
@@ -223,7 +212,7 @@ export async function settleGuildWeekly() {
|
|||||||
|
|
||||||
await GuildModel.updateInfo(code, { activeWeekly: 0 }, {});
|
await GuildModel.updateInfo(code, { activeWeekly: 0 }, {});
|
||||||
}
|
}
|
||||||
|
await initSingleRank(REDIS_KEY.GUILD_ACTIVE_RANK);
|
||||||
await SystemConfigModel.updateSystemConfig({settleGuildWeeklyTime: nowSeconds()}); // 记录一下
|
await SystemConfigModel.updateSystemConfig({settleGuildWeeklyTime: nowSeconds()}); // 记录一下
|
||||||
console.log('————— settleGuildWeekly结束 —————');
|
console.log('————— settleGuildWeekly结束 —————');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ export enum GUILD_OPERATE {
|
|||||||
BE_SET_AUTH = 27, // 被授权头衔
|
BE_SET_AUTH = 27, // 被授权头衔
|
||||||
BE_IMPEACH = 28, // 被弹劾
|
BE_IMPEACH = 28, // 被弹劾
|
||||||
RECEIVE_ACTIVE = 29, // 领取每日活跃宝箱
|
RECEIVE_ACTIVE = 29, // 领取每日活跃宝箱
|
||||||
|
GET_ACTIVE_RANK = 30, // 查看活跃排行榜
|
||||||
}
|
}
|
||||||
|
|
||||||
// 军团状态
|
// 军团状态
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ export default class UserGuild extends BaseModel {
|
|||||||
@prop({ required: true, default: 0 })
|
@prop({ required: true, default: 0 })
|
||||||
activeDaily: number;
|
activeDaily: number;
|
||||||
|
|
||||||
@prop({ required: true, default: Date.now() })
|
@prop({ required: true, default: nowSeconds() })
|
||||||
activeUpdateTime: number;
|
activeUpdateTime: number;
|
||||||
|
|
||||||
@prop({ required: true, default: USER_GUILD_STATUS.ON, enum: USER_GUILD_STATUS})
|
@prop({ required: true, default: USER_GUILD_STATUS.ON, enum: USER_GUILD_STATUS})
|
||||||
@@ -128,7 +128,6 @@ export default class UserGuild extends BaseModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static async updateInfo(roleId: string, update: UserGuildUpdateParam, incParam: { activeDaily?: number, activeWeekly?: number, trainCount?: number }, select?: string) {
|
public static async updateInfo(roleId: string, update: UserGuildUpdateParam, incParam: { activeDaily?: number, activeWeekly?: number, trainCount?: number }, select?: string) {
|
||||||
console.log(roleId, JSON.stringify(update))
|
|
||||||
const result: UserGuildType = await UserGuildModel.findOneAndUpdate({ roleId, status: USER_GUILD_STATUS.ON }, { $set: update, $inc: incParam }, { new: true }).select(select).lean();
|
const result: UserGuildType = await UserGuildModel.findOneAndUpdate({ roleId, status: USER_GUILD_STATUS.ON }, { $set: update, $inc: incParam }, { new: true }).select(select).lean();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -355,10 +355,10 @@ export function getTrainBaseByLv(lv: number) {
|
|||||||
return gameData.trainBase.get(lv);
|
return gameData.trainBase.get(lv);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getGuildActiveWeekReward(point: number) {
|
export function getGuildActiveWeekReward(rank: number) {
|
||||||
let result = gameData.guildActiveWeekReward.find(cur => {
|
let result = gameData.guildActiveWeekReward.find(cur => {
|
||||||
let {weekPointMax, weekPointMin} = cur;
|
let {rankMax, rankMin} = cur;
|
||||||
return point >= weekPointMin && point <= (weekPointMax || weekPointMax == -1);
|
return rank >= rankMin && rank <= (rankMax || rankMax == -1);
|
||||||
});
|
});
|
||||||
let reward = new Array<RewardInter>();
|
let reward = new Array<RewardInter>();
|
||||||
if(result) reward = result.reward;
|
if(result) reward = result.reward;
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ export interface DicGuildActiveWeekReward {
|
|||||||
// id
|
// id
|
||||||
readonly id: number;
|
readonly id: number;
|
||||||
// 周最低点数
|
// 周最低点数
|
||||||
readonly weekPointMin: number;
|
readonly rankMin: number;
|
||||||
// 周最高点数
|
// 周最高点数
|
||||||
readonly weekPointMax: number;
|
readonly rankMax: number;
|
||||||
// 奖励
|
// 奖励
|
||||||
readonly reward: RewardInter[];
|
readonly reward: RewardInter[];
|
||||||
|
|
||||||
|
|||||||
@@ -156,12 +156,14 @@ export const dicTrainBase = new Map<number, DicTrainBase>(); // 练兵场
|
|||||||
export const dicDonateBase = new Map<number, DicDonateBase>(); // 捐献所
|
export const dicDonateBase = new Map<number, DicDonateBase>(); // 捐献所
|
||||||
export const dicWishPoolBase = new Map<number, DicWishPoolBase>(); // 许愿池
|
export const dicWishPoolBase = new Map<number, DicWishPoolBase>(); // 许愿池
|
||||||
export const dicStoreBase = new Map<number, DicWishPoolBase>(); // 许愿池
|
export const dicStoreBase = new Map<number, DicWishPoolBase>(); // 许愿池
|
||||||
|
export let maxMemberCnt = 0; // 满配最大人数
|
||||||
|
|
||||||
// 中军大帐
|
// 中军大帐
|
||||||
const strCenter = readJsonFile(FILENAME.DIC_GUILD_STRUCTURE_CENTER);
|
const strCenter = readJsonFile(FILENAME.DIC_GUILD_STRUCTURE_CENTER);
|
||||||
let arrCenter = JSON.parse(strCenter);
|
let arrCenter = JSON.parse(strCenter);
|
||||||
arrCenter.forEach(o => {
|
arrCenter.forEach(o => {
|
||||||
setStructureConsume(o);
|
setStructureConsume(o);
|
||||||
|
if(o.peopleNum > maxMemberCnt) maxMemberCnt = o.peopleNum;
|
||||||
dicCenterBase.set(o.level, _.pick(o, Object.keys(DicCenterKeys)));
|
dicCenterBase.set(o.level, _.pick(o, Object.keys(DicCenterKeys)));
|
||||||
});
|
});
|
||||||
arrCenter = undefined;
|
arrCenter = undefined;
|
||||||
|
|||||||
Executable → Regular
+5
@@ -143,5 +143,10 @@
|
|||||||
"id": 29,
|
"id": 29,
|
||||||
"name": "领取活跃宝箱",
|
"name": "领取活跃宝箱",
|
||||||
"authority": "1&2&3"
|
"authority": "1&2&3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 30,
|
||||||
|
"name": "查看军团活跃排行榜",
|
||||||
|
"authority": "1&2&3&4"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
Reference in New Issue
Block a user