🐞 fix(guild): 试炼挑战奖励领取过的不允许再领
This commit is contained in:
@@ -4,7 +4,7 @@ import { DEBUG_MAGIC_WORD, ITEM_CHANGE_REASON, STATUS, TASK_TYPE, TRAIN_REWARD_T
|
||||
import { GuildTrainModel } from '../../../db/GuildTrain';
|
||||
import { BattleRecordModel } from '../../../db/BattleRecord';
|
||||
import { nowSeconds, getTimeFun, getZeroPoint } from '../../../pubUtils/timeUtil';
|
||||
import { refreshTrain, getGuildTrainInfo, unlockTrain, getGuildTrainRewards, getGuildTrainInstance, getTrainBoxRewardsResult, resetTrain } from '../../../services/guildTrainService';
|
||||
import { refreshTrain, getGuildTrainInfo, unlockTrain, getGuildTrainRewards, getGuildTrainInstance, getTrainBoxRewardsResult, resetTrain, getTrainBoxRewardsResultWithoutAlreadyGeted } from '../../../services/guildTrainService';
|
||||
import { findIndex, findWhere } from 'underscore'
|
||||
import { lockData } from '../../../services/redLockService';
|
||||
import { GUILD_REPORT_NUM, GUILD_POINT_WAYS } from '../../../consts/constModules/guildConst';
|
||||
@@ -79,8 +79,8 @@ export class GuildTrainHandler {
|
||||
let userGuild = await refreshTrain(myUserGuild, roleId, serverId);
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code } = userGuild;
|
||||
let resTrainBoxs = await getTrainBoxRewardsResult(code);
|
||||
const { guildCode: code, trainBoxRewards} = userGuild;
|
||||
let resTrainBoxs = await getTrainBoxRewardsResultWithoutAlreadyGeted(code, trainBoxRewards);
|
||||
return resResult(STATUS.SUCCESS, { trainBoxRewards: resTrainBoxs });
|
||||
}
|
||||
/**
|
||||
@@ -309,9 +309,10 @@ export class GuildTrainHandler {
|
||||
let goods = await addItems(roleId, roleName, sid, [good], ITEM_CHANGE_REASON.TRAIN_BOX_REWARD);
|
||||
|
||||
let resGuildTrain = await GuildTrainModel.receiveBoxByIndex(code, roleId, trainId, hid, index, good);
|
||||
let resUserGuild = await UserGuildModel.receiveTrainBoxRewards(roleId, trainId);
|
||||
res.releaseCallback();//解锁
|
||||
|
||||
if (!resGuildTrain) {
|
||||
if (!resGuildTrain || !resUserGuild) {
|
||||
return resResult(STATUS.GUILD_GET_TRAIN_BOX_FAIL);
|
||||
}
|
||||
let result: any = getGuildTrainRewards(resGuildTrain);
|
||||
|
||||
@@ -60,6 +60,39 @@ export async function getTrainBoxRewardsResult(guildCode: string) {
|
||||
return resTrainBoxs
|
||||
}
|
||||
|
||||
/**
|
||||
* 领过的试炼宝箱不允许再领
|
||||
*
|
||||
* @export
|
||||
* @param {string} guildCode
|
||||
* @param {number[]} receivedTrainBox
|
||||
* @return {*}
|
||||
*/
|
||||
export async function getTrainBoxRewardsResultWithoutAlreadyGeted(guildCode: string, receivedTrainBox:number[]) {
|
||||
|
||||
let guildTrains = await GuildTrainModel.findGuildTrain(guildCode);//获得未失效的宝箱奖励
|
||||
let resTrainBoxs = [];
|
||||
guildTrains.forEach(({ trainInstances, trainId }) => {
|
||||
let { trainInstances: instances } = getArmyTrainJuDian(trainId);
|
||||
let flag = false;
|
||||
let boxRewards = [];
|
||||
trainInstances.map(({ hid, progress, endTime, trainBoxs }) => {
|
||||
let isComplete = false;
|
||||
let instance = findWhere(instances, { hid });
|
||||
if (progress >= instance.progress) {
|
||||
isComplete = true;
|
||||
if (endTime > nowSeconds())
|
||||
flag = true;
|
||||
}
|
||||
boxRewards.push({ hid, recordBoxs: trainBoxs, trainId, endTime, isComplete });
|
||||
});
|
||||
if (flag && (receivedTrainBox.indexOf(trainId) == -1)) {
|
||||
resTrainBoxs.push({ trainId, boxRewards });
|
||||
}
|
||||
})
|
||||
return resTrainBoxs
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得未失效的试炼宝箱奖励
|
||||
* @param guildTrain
|
||||
|
||||
@@ -85,6 +85,10 @@ export default class UserGuild extends BaseModel {
|
||||
|
||||
@prop({ required: true, default: [] })
|
||||
trainRewards: Array<number>;//领取过的进阶等级
|
||||
|
||||
@prop({ required: true, default: [] })
|
||||
trainBoxRewards: Array<number>;//领取过的挑战奖励
|
||||
|
||||
//捐献所
|
||||
@prop({ required: true, default: [], type: Number })
|
||||
receiveBoxs: Array<number>; //今天捐献所领取宝箱id记录,
|
||||
@@ -145,12 +149,12 @@ 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 = [], wishGoods = [], wishDntCnt = 0, refTimeDaily, refBossTime, trainCount, buyTrainCount, trainTime, trainRewards = [], refineCnt = [], refRefineTime } = lastGuild||{};
|
||||
let { receiveBoxs = [], donateCnt = 0, receivedActive = [], encourageCnt = 0, bossChallengeCnt = 0, receivedWishPool = [], wishGoods = [], wishDntCnt = 0, refTimeDaily, refBossTime, trainCount, buyTrainCount, trainTime, trainRewards = [], refineCnt = [], refRefineTime, trainBoxRewards = [] } = 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, wishGoods, wishDntCnt, refTimeDaily, refBossTime, trainCount, buyTrainCount, trainTime, trainRewards, refineCnt, refRefineTime });
|
||||
const 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, trainRewards, refineCnt, refRefineTime, trainBoxRewards });
|
||||
|
||||
// trainRewards: 试炼奖励, 无论在任何情况下都不能被清空(次数可以重置,奖励领过就不能再领了,无论在哪个军团)
|
||||
// 【退出军团】 和 【再加入军团】不在同一天; 此处包含: 首次加入军团(lastGuild == null)
|
||||
@@ -220,6 +224,22 @@ export default class UserGuild extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录玩家领取过的试炼宝箱奖励(每个boss都有一个抽卡奖励)
|
||||
*
|
||||
* @static
|
||||
* @param {string} roleId
|
||||
* @param {number} trainId
|
||||
* @param {boolean} [lean=true]
|
||||
* @return {*}
|
||||
* @memberof UserGuild
|
||||
*/
|
||||
public static async receiveTrainBoxRewards(roleId: string, trainId: number, lean = true) {
|
||||
const result = await UserGuildModel.findOneAndUpdate({ roleId, status: USER_GUILD_STATUS.ON},
|
||||
{ $push:{trainBoxRewards: trainId} },{new: true}).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async addTrainCount(roleId: string, trainCount: number, lean = true) {
|
||||
const result = await UserGuildModel.findOneAndUpdate({ roleId, status: USER_GUILD_STATUS.ON},
|
||||
{ $inc: { trainCount, buyTrainCount: trainCount } }, {new: true}).lean(lean);
|
||||
|
||||
Reference in New Issue
Block a user