军团:修改个人功勋→个人活跃
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { gameData } from "../pubUtils/data";
|
||||
import { gameData, getGuildActiveWeekReward } from "../pubUtils/data";
|
||||
import { GuildModel, GuildType } from "../db/Guild";
|
||||
import { resResult, shouldRefreshWeek, shouldRefresh } from "../pubUtils/util";
|
||||
import { STATUS, GUILD_OPERATE, MAIL_TYPE } from "../consts";
|
||||
import { STATUS, GUILD_OPERATE, MAIL_TYPE, GUILD_AUTH, GUILD_JOB } from "../consts";
|
||||
import { RoleModel, RoleType } from "../db/Role";
|
||||
import { UserGuildModel, UserGuildType } from "../db/UserGuild";
|
||||
import { UserGuildApplyModel } from "../db/UserGuildApply";
|
||||
@@ -12,6 +12,8 @@ import { GuildRecType } from "../db/GuildRec";
|
||||
import { MailModel } from "../db/Mail";
|
||||
import { RewardInter } from "../pubUtils/interface";
|
||||
import { getRedis } from "./redisService";
|
||||
import { ARMY } from "../pubUtils/dicParam";
|
||||
import { sendMail } from "./mailService";
|
||||
|
||||
/**
|
||||
* @description 检查该玩家是否有权限做操作
|
||||
@@ -121,14 +123,14 @@ export async function addGuildActive(guildCode: string, serverId: number, active
|
||||
export async function getUserGuildWithRefActive(roleId: string, select: string) {
|
||||
let userGuild = await UserGuildModel.getMyGuild(roleId, select? select + ' +refTimeDaily': '+refTimeDaily');
|
||||
if(!userGuild) return false;
|
||||
let { receivedActive, refTimeDaily } = userGuild;
|
||||
let { receivedActive, refTimeDaily, activeDaily, activeRecord } = userGuild;
|
||||
|
||||
const now = new Date();
|
||||
let isRefDaily = shouldRefresh(refTimeDaily, now, 0);
|
||||
if(isRefDaily) {
|
||||
receivedActive = 0; refTimeDaily = now;
|
||||
receivedActive = 0; refTimeDaily = now; activeDaily = 0; activeRecord = [];
|
||||
|
||||
userGuild = await UserGuildModel.updateInfo(roleId, { receivedActive, refTimeDaily }, select);
|
||||
userGuild = await UserGuildModel.updateInfo(roleId, { receivedActive, refTimeDaily, activeDaily, activeRecord }, select);
|
||||
if(!userGuild) return false;
|
||||
}
|
||||
|
||||
@@ -141,15 +143,68 @@ export async function getUserGuildWithRefActive(roleId: string, select: string)
|
||||
*/
|
||||
export async function settleGuildWeekly() {
|
||||
console.log('————— settleGuildWeekly —————');
|
||||
const guildList = await GuildModel.findAllGuild('code activeWeekly');
|
||||
const guildList = await GuildModel.findAllGuild('code activeWeekly memberCnt');
|
||||
|
||||
for(let { code, activeWeekly, memberCnt } of guildList) {
|
||||
const userGuildList = await UserGuildModel.getListByGuild(code, 'roleId auth activeWeekly', { activeWeekly: -1, activeUpdateTime: 1 });
|
||||
|
||||
let activeMemberCnt = 0; // 活跃度高于100的成员人数
|
||||
let otherMemberNum = 0; // 除了大将军以外从活跃高到底成员人数,用户计算活跃排名百分比
|
||||
let jobCnt = new Map<number, number>();
|
||||
let members = new Map<string, {job: number, active: boolean}>();
|
||||
|
||||
for(let {roleId, auth, activeWeekly} of userGuildList) {
|
||||
let active = false;
|
||||
let job = 0;
|
||||
|
||||
if(activeWeekly > 100) {
|
||||
activeMemberCnt ++;
|
||||
active = true;
|
||||
}
|
||||
|
||||
if(auth == GUILD_AUTH.LEADER) {
|
||||
job = GUILD_JOB.DAJIANGJUN;
|
||||
} else if (activeWeekly <= 100) {
|
||||
job = GUILD_JOB.SHIBING;
|
||||
} else {
|
||||
otherMemberNum++;
|
||||
for(let [id, {rankProportion}] of gameData.guildPosition) {
|
||||
let rankCnt = Math.ceil(memberCnt * rankProportion / 100);
|
||||
console.log('*', id, memberCnt, rankProportion, otherMemberNum, rankCnt)
|
||||
job = id;
|
||||
if(otherMemberNum < rankCnt) break;
|
||||
}
|
||||
}
|
||||
await UserGuildModel.updateInfo(roleId, { job, activeWeekly: 0 });
|
||||
if(!jobCnt.has(job)) jobCnt.set(job, 0);
|
||||
jobCnt.set(job, jobCnt.get(job) + 1);
|
||||
|
||||
members.set(roleId, {job, active});
|
||||
}
|
||||
|
||||
for(let { code, activeWeekly } of guildList) {
|
||||
// 转换周活跃奖励
|
||||
const userGuildList = await UserGuildModel.getListByGuild(code, 'honourWeekly', { honourWeekly: -1, honourUpdateTime: 1 });
|
||||
|
||||
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 / 100;
|
||||
let myJobRewardRatio = positionBase * jobActiveRatio / jobCnt.get(job);
|
||||
let reward = allWeeklyReward.map(cur => {
|
||||
return {
|
||||
id: cur.id,
|
||||
count: Math.ceil(cur.count * (myAverageRatio + myJobRewardRatio))
|
||||
}
|
||||
});
|
||||
await sendMail(MAIL_TYPE.GUILD_ACTIVE_REWARD, roleId, '系统', [], reward);
|
||||
}
|
||||
|
||||
await GuildModel.updateInfo(code, { activeWeekly: 0 }, {});
|
||||
}
|
||||
|
||||
await SystemConfigModel.updateSystemConfig({settleGuildWeeklyTime: nowSeconds()}); // 记录一下
|
||||
console.log('————— settleGuildWeekly结束 —————');
|
||||
}
|
||||
|
||||
export const message = {
|
||||
|
||||
Reference in New Issue
Block a user