diff --git a/game-server/app/servers/guild/handler/wishPoolHandler.ts b/game-server/app/servers/guild/handler/wishPoolHandler.ts index 86668ad99..5029be3ca 100644 --- a/game-server/app/servers/guild/handler/wishPoolHandler.ts +++ b/game-server/app/servers/guild/handler/wishPoolHandler.ts @@ -8,13 +8,13 @@ import { gameData, getGoodById, getWishPoolReward } from '../../../pubUtils/data import { addItems, checkGoods, checkHeroEquips, checkHeroes, getHonourObject, handleCost } from '../../../services/role/rewardService'; import { ITID, CONSUME_TYPE } from '../../../consts/constModules/itemConst'; import { GUILD_POINT_WAYS, GUILD_STRUCTURE, WISH_POOL_TYPE } from '../../../consts/constModules/guildConst'; -import { getWishPool, getUserGuildWithRefActive, addActive } from '../../../services/guildService'; +import { getWishPool, getUserGuildWithRefActive, addActive, canWishToday } from '../../../services/guildService'; import { findIndex, findWhere } from 'underscore'; import { RoleModel } from '../../../db/Role'; import { getRoleOnlineInfo } from '../../../services/redisService'; import { ARMY } from '../../../pubUtils/dicParam'; import { guildInter } from '../../../pubUtils/interface'; -import { getSeconds, getZeroPoint, nowSeconds } from '../../../pubUtils/timeUtil'; +import { getSeconds, getZeroPoint, nowSeconds, isToday } from '../../../pubUtils/timeUtil'; import { sendMessageToUserWithSuc } from '../../../services/pushService'; import { isGoodsHidden } from '../../../services/dataService'; export default function(app: Application) { @@ -51,6 +51,11 @@ export class WishPoolHandler { let userGuild = await getUserGuildWithRefActive(roleId); if (!userGuild) return resResult(STATUS.WRONG_PARMS); + // 退出A军团 和 新入B军团 在同一天, 且在A军团已经许过愿,那么此时不允许许愿 + if (!await canWishToday(roleId)) { + return resResult(STATUS.HAS_REACH_WISH_COUNT_LIMIT); + } + const { guildCode: code, wishGoods, receivedWishPool } = userGuild; let { lv } = await GuildModel.findGuild(code, serverId, 'lv'); diff --git a/game-server/app/services/guildService.ts b/game-server/app/services/guildService.ts index 5db467599..2c091d812 100644 --- a/game-server/app/services/guildService.ts +++ b/game-server/app/services/guildService.ts @@ -29,6 +29,7 @@ import { BattleRecordModel } from "../db/BattleRecord"; import { BossInstanceModel } from "../db/BossInstance"; import { pick } from "underscore"; import { memberJoinGuildToLeague } from "./gvg/gvgTeamService"; +import { isToday } from '../pubUtils/timeUtil'; export async function getMyGuildInfo(roleId: string, sid: string, userGuild: UserGuildType, guild: GuildType, serverId: number, session: FrontendOrBackendSession) { @@ -141,7 +142,10 @@ export async function joinGuild(code: string, guildName: string, lv: number, rol } //成长任务-加入军团 - await checkTask(serverId, roleId, sid, TASK_TYPE.GUILD_JOIN); + if (!isToday(role.quitGuildTime)) { + // 离开军团 和 加入进团 不是同一天,才新建初始化任务(包含首次加入) + await checkTask(serverId, roleId, sid, TASK_TYPE.GUILD_JOIN); + } return { status: 0, guild, userGuild, roleName: role.roleName, memberCnt: guild.memberCnt, guildCe: guild.guildCe } } @@ -234,6 +238,32 @@ export async function getUserGuildWithRefActive(roleId: string, select?: string) return userGuild; } +/** + * 今天在军团中是否能许愿 + * + * @export + * @param {string} roleId + */ +export async function canWishToday(roleId: string): Promise { + let role = await RoleModel.findByRoleId(roleId); + if (!role) { + return false; + } + + let userGuild = await UserGuildModel.findMyLastGuild(roleId, ' wishGoods'); + if (!userGuild) { + return true; + } + + // 今天退出过军团 & 在退出的军团许过愿 + if (isToday(role.quitGuildTime) && (userGuild.wishGoods && userGuild.wishGoods.length > 0)) { + // 新加入的军团不允许许愿 + return false; + } + + return true; +} + async function sendUnreceivedWishPool(wishGoods: WishGood[], roleId: string) { wishGoods.map(async function ({ donateNames, goodId, drawCnt }) { let goodInfo = getGoodById(goodId) diff --git a/shared/db/UserGuild.ts b/shared/db/UserGuild.ts index ae844bece..98f06d26f 100644 --- a/shared/db/UserGuild.ts +++ b/shared/db/UserGuild.ts @@ -2,7 +2,7 @@ import BaseModel from './BaseModel'; import { index, getModelForClass, prop, DocumentType, Ref } from '@typegoose/typegoose'; import Role, { RoleType } from './Role'; import { GUILD_AUTH, USER_GUILD_STATUS, GUILD_JOB } from '../consts'; -import { getZeroPointD, nowSeconds } from '../pubUtils/timeUtil'; +import { getZeroPointD, nowSeconds, isToday } from '../pubUtils/timeUtil'; import { ARMY } from '../pubUtils/dicParam'; class ActiveRecord { @prop({ required: true }) @@ -145,12 +145,42 @@ export default class UserGuild extends BaseModel { public static async createUserGuild(guildCode: string, role: RoleType, isLeader: boolean) { const lastGuild = await UserGuildModel.findMyLastGuild(role.roleId, '+refTimeDaily'); - let { receiveBoxs = [], donateCnt = 0, receivedActive = [], encourageCnt = 0, bossChallengeCnt = 0, receivedWishPool = [], refTimeDaily, refBossTime, trainCount, buyTrainCount, trainTime } = lastGuild||{}; + let { receiveBoxs = [], donateCnt = 0, receivedActive = [], encourageCnt = 0, bossChallengeCnt = 0, receivedWishPool = [], wishGoods = [], wishDntCnt = 0, refTimeDaily, refBossTime, trainCount, buyTrainCount, trainTime } = lastGuild||{}; const doc = new UserGuildModel(); let job = isLeader? GUILD_JOB.DAJIANGJUN: GUILD_JOB.SHIBING; let auth = isLeader? GUILD_AUTH.LEADER: GUILD_AUTH.MEMBER; - const update = Object.assign(doc.toJSON(), { guildCode, roleId: role.roleId, role: role._id, job, auth, receiveBoxs, donateCnt, receivedActive, encourageCnt, bossChallengeCnt, receivedWishPool, refTimeDaily, refBossTime, trainCount, buyTrainCount, trainTime }); + let update = Object.assign(doc.toJSON(), { guildCode, roleId: role.roleId, role: role._id, job, auth, receiveBoxs, donateCnt, receivedActive, encourageCnt, bossChallengeCnt, receivedWishPool, wishGoods, wishDntCnt, refTimeDaily, refBossTime, trainCount, buyTrainCount, trainTime }); + + // 【退出军团】 和 【再加入军团】在同一天 + if (isToday(role.quitGuildTime)) { + // 同一个军团: 所有数据保留; 不同军团: 许愿池数据清空,当天不允许许愿,其他数据保留 + if (guildCode !== lastGuild?.guildCode) { + update.wishGoods = []; + update.receivedWishPool = []; + update.wishDntCnt = 0; + } + + + } else { + // 【退出军团】 和 【再加入军团】不在同一天; 此处包含: 首次加入军团(lastGuild == null) + if (lastGuild) { + // 之前加入过军团 - 清空之前的数据 + update.receiveBoxs = []; + update.donateCnt = 0; + update.receivedActive = []; + update.encourageCnt = 0; + update.bossChallengeCnt = 0; + update.receivedWishPool = []; + update.wishGoods = []; + update.wishDntCnt = 0; + update.refTimeDaily = null; + update.refBossTime = null; + update.trainCount = 0; + update.buyTrainCount = 0; + update.trainTime = 0; + } + } delete update._id; const result: UserGuildType = await UserGuildModel.findOneAndUpdate({ roleId: role.roleId, guildCode, status: USER_GUILD_STATUS.ON }, { $set: update }, { upsert: true, new: true }) diff --git a/shared/pubUtils/timeUtil.ts b/shared/pubUtils/timeUtil.ts index 0fce21cfc..5c835b715 100644 --- a/shared/pubUtils/timeUtil.ts +++ b/shared/pubUtils/timeUtil.ts @@ -568,4 +568,8 @@ export function getPastTime() { export function getFutureTime() { return moment('2100-01-01').unix(); +} + +export function isToday(time: number): Boolean { + return moment().format('YYYYMMDD') === moment(time * 1000).format('YYYYMMDD'); } \ No newline at end of file