军团:添加活跃排行榜
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { gameData, getGuildActiveWeekReward } from "../pubUtils/data";
|
||||
import { gameData, getGuildActiveWeekReward, getGuildActiveByIdAndType } from "../pubUtils/data";
|
||||
import { GuildModel, GuildType } from "../db/Guild";
|
||||
import { resResult, shouldRefreshWeek, shouldRefresh } from "../pubUtils/util";
|
||||
import { STATUS, GUILD_OPERATE, MAIL_TYPE, GUILD_AUTH, GUILD_JOB } from "../consts";
|
||||
import { STATUS, GUILD_OPERATE, MAIL_TYPE, GUILD_AUTH, GUILD_JOB, REDIS_KEY, } from "../consts";
|
||||
import { RoleModel, RoleType } from "../db/Role";
|
||||
import { UserGuildModel, UserGuildType } from "../db/UserGuild";
|
||||
import { UserGuildApplyModel } from "../db/UserGuildApply";
|
||||
@@ -11,6 +11,8 @@ import { pinus } from "pinus";
|
||||
import { GuildRecType } from "../db/GuildRec";
|
||||
import { ARMY } from "../pubUtils/dicParam";
|
||||
import { sendMail } from "./mailService";
|
||||
import { setRank } from "./redisService";
|
||||
import { GuildRankParam, GuildLeader } from "../pubUtils/interface";
|
||||
|
||||
/**
|
||||
* @description 检查该玩家是否有权限做操作
|
||||
@@ -90,16 +92,26 @@ export async function getGuildWithRefActive(guildCode: string, serverId: number)
|
||||
* 增加活跃
|
||||
* @param guildCode 军团唯一code
|
||||
* @param serverId 区
|
||||
* @param active 增加的活跃
|
||||
* @param id 增加活跃的操作
|
||||
* @param type 类型 activePoint内配的type
|
||||
* @param active debug直接增加的活跃
|
||||
*/
|
||||
export async function addActive(roleId: string, serverId: number, id: number, active: number) {
|
||||
export async function addActive(roleId: string, serverId: number, id: number, type: number, active?: number) {
|
||||
|
||||
let dicActiveWay = gameData.guildActiveWays.get(id);
|
||||
if(id && !dicActiveWay) {
|
||||
return { status: 0, resResult: resResult(STATUS.DIC_DATA_NOT_FOUND) };
|
||||
}
|
||||
if(!active) {
|
||||
active = getGuildActiveByIdAndType(id, type);
|
||||
}
|
||||
|
||||
let userGuild = await getUserGuildWithRefActive(roleId, 'activeRecord receivedActive activeDaily activeWeekly guildCode');
|
||||
if(!userGuild) return false;
|
||||
if(!userGuild) return { status: 0, resResult: resResult(STATUS.GUILD_NOT_FOUND) };
|
||||
|
||||
let guildCode = userGuild.guildCode;
|
||||
let guild = await getGuildWithRefActive(guildCode, serverId);
|
||||
if(!guild) return false;
|
||||
if(!guild) return { status: 0, resResult: resResult(STATUS.GUILD_NOT_FOUND) };
|
||||
|
||||
let {activeRecord} = userGuild;
|
||||
if(id != 0) { // 用于debug,传0时直接增加活跃
|
||||
@@ -107,13 +119,22 @@ export async function addActive(roleId: string, serverId: number, id: number, ac
|
||||
if( curActiveRecord ) {
|
||||
curActiveRecord.count ++;
|
||||
} else {
|
||||
activeRecord.push({id, count: 1});
|
||||
curActiveRecord = {id, count: 1};
|
||||
activeRecord.push(curActiveRecord);
|
||||
}
|
||||
if(curActiveRecord.count > dicActiveWay.count) { // 次数超过时,不增加活跃
|
||||
active = 0;
|
||||
}
|
||||
}
|
||||
userGuild = await UserGuildModel.updateInfo(roleId, { activeRecord }, { activeDaily: active, activeWeekly: active });
|
||||
userGuild = await UserGuildModel.updateInfo(roleId, { activeRecord, activeUpdateTime: nowSeconds() }, { activeDaily: active, activeWeekly: active });
|
||||
|
||||
guild = await GuildModel.updateInfo(guildCode, { }, { activeDaily: active, activeWeekly: active });
|
||||
return { guild, userGuild };
|
||||
guild = await GuildModel.updateInfo(guildCode, { activeUpdateTime: nowSeconds() }, { activeDaily: active, activeWeekly: active });
|
||||
|
||||
// 排行榜更新
|
||||
let leader = await RoleModel.findById(guild.leader);
|
||||
let guildRankParam = new GuildRankParam(guild.icon, guild.name, guild.lv, new GuildLeader(leader));
|
||||
await setRank(REDIS_KEY.GUILD_ACTIVE_RANK, serverId, guild.code, guild.activeWeekly, guild.activeUpdateTime * 1000, guildRankParam);
|
||||
return { status: 1, guild, userGuild };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -176,7 +197,7 @@ export async function settleGuildWeekly() {
|
||||
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});
|
||||
|
||||
Reference in New Issue
Block a user