练兵接口调整,新增获得宝箱和战报
This commit is contained in:
59
game-server/app/servers/battle/handler/donateHandler.ts
Normal file
59
game-server/app/servers/battle/handler/donateHandler.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { Application, BackendSession } from 'pinus';
|
||||
import { UserGuildModel } from '../../../db/UserGuild';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { STATUS } from '../../../consts';
|
||||
import { DonationModel } from '../../../db/Donation';
|
||||
import { nowSeconds } from '../../../pubUtils/timeUtil';
|
||||
export default function(app: Application) {
|
||||
return new DonationHandler(app);
|
||||
}
|
||||
|
||||
export class DonationHandler {
|
||||
constructor(private app: Application) {
|
||||
|
||||
}
|
||||
|
||||
async getDonation(msg: {}, session: BackendSession) {
|
||||
const roleId: string = session.get('roleId');
|
||||
let userGuild = await UserGuildModel.getMyGuild(roleId,'donateCnt receiveBoxs guildCode');
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code, donateCnt, receiveBoxs } = userGuild;
|
||||
let { donateFund, reports } = await DonationModel.getDonation(code);
|
||||
return resResult(STATUS.SUCCESS, { receiveBoxs, donateFund, reports, donateCnt });
|
||||
}
|
||||
|
||||
async donate(msg: {id: number}, session: BackendSession) {
|
||||
const { id } = msg;
|
||||
const roleId: string = session.get('roleId');
|
||||
const roleName: string = session.get('roleName');
|
||||
let userGuild = await UserGuildModel.getMyGuild(roleId,'donateCnt receiveBoxs guildCode');
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code, donateCnt: resdonateCnt } = userGuild;
|
||||
if (resdonateCnt <= 0)
|
||||
return resResult(STATUS.SUCCESS);
|
||||
let { donateCnt } = await UserGuildModel.donateFund(roleId, 1);
|
||||
let fund;//捐献TODO
|
||||
let report = {id, roleName, time: nowSeconds()};
|
||||
let { donateFund, reports } = await DonationModel.donation(code, fund, report);
|
||||
return resResult(STATUS.SUCCESS, { donateFund, reports, donateCnt });
|
||||
}
|
||||
|
||||
async receiveBox(msg: {id: number}, session: BackendSession) {
|
||||
const { id } = msg;
|
||||
const roleId: string = session.get('roleId');
|
||||
let userGuild = await UserGuildModel.getMyGuild(roleId,'donateCnt receiveBoxs guildCode');
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code, donateCnt: resdonateCnt, receiveBoxs: resReceiveBoxs } = userGuild;
|
||||
if (resReceiveBoxs.indexOf(id) != -1)
|
||||
return resResult(STATUS.SUCCESS);
|
||||
|
||||
if (resdonateCnt <= 0)
|
||||
return resResult(STATUS.SUCCESS);
|
||||
resReceiveBoxs.push(id);
|
||||
let { receiveBoxs } = await UserGuildModel.updateInfo(roleId, {receiveBoxs: resReceiveBoxs}, {}, 'receiveBoxs');
|
||||
return resResult(STATUS.SUCCESS, { receiveBoxs });
|
||||
}
|
||||
}
|
||||
@@ -83,6 +83,7 @@ export class GuildHandler {
|
||||
return resResult(STATUS.GUILD_STRUCTURE_NOT_FOUND);
|
||||
}
|
||||
let bossBase = getBossByLv(curStructure.lv);
|
||||
//消耗TODO
|
||||
let {bossHp, warId, bossLevel } = getRandomByLen(bossBase.wars);
|
||||
let resGuild = await GuildModel.costFund(code, bossBase.consume)
|
||||
if (!resGuild)
|
||||
|
||||
@@ -15,6 +15,7 @@ import { checkAuth } from '../../../services/guildService';
|
||||
import { ARMY } from '../../../pubUtils/dicParam';
|
||||
import { CURRENCY_BY_TYPE, CURRENCY_TYPE } from '../../../consts/constModules/itemConst';
|
||||
import { openGuildRefine } from '../../../services/guildRefineService';
|
||||
import { now } from 'moment';
|
||||
export default function (app: Application) {
|
||||
return new GuildRefineHandler(app);
|
||||
}
|
||||
@@ -85,17 +86,23 @@ export class GuildRefineHandler {
|
||||
if (!!res.err)
|
||||
return resResult(STATUS.REDLOCK_ERR);
|
||||
let guildRefine = await GuildRefineModel.getRefine(code);
|
||||
for (let scienceTree of guildRefine.scienceTrees) {
|
||||
let nowTime = nowSeconds();
|
||||
for (let scienceTree of guildRefine.scienceTrees) {
|
||||
if (scienceTree.id == id)
|
||||
return resResult(STATUS.GUILD_LIGHT_UP_THE_SCIENCETREE);
|
||||
|
||||
if (scienceTree.endTime > nowSeconds())
|
||||
if (scienceTree.endTime > nowTime)
|
||||
return resResult(STATUS.GUILD_SCIENCETREE_IS_RUNNING);
|
||||
}
|
||||
for (let prePosition of developConsume.prePositions) {
|
||||
let scienceTree = findWhere(guildRefine.scienceTrees, {id: prePosition});
|
||||
if (!scienceTree||scienceTree.endTime > nowTime)
|
||||
return resResult(STATUS.GUILD_PERSITION_TREE_NOT_LIGHT);
|
||||
}
|
||||
const costResult = await GuildModel.costFund(code, developConsume.fundConsume);
|
||||
if(!costResult)
|
||||
return resResult(STATUS.GUILD_FUND_NOT_ENOUGH);
|
||||
let scienceTree = { id, endTime: nowSeconds() + developConsume.timeConsume, assistRoleIds: []}
|
||||
let scienceTree = { id, endTime: nowTime + developConsume.timeConsume, assistRoleIds: []}
|
||||
let { scienceTrees } = await GuildRefineModel.pushRefine(code, scienceTree);
|
||||
res.releaseCallback();
|
||||
return resResult(STATUS.SUCCESS, { scienceTrees });
|
||||
|
||||
@@ -7,7 +7,7 @@ import { nowSeconds, getHourPoint, getCurHourPoint } from '../../../pubUtils/tim
|
||||
import { getUserGuild, getGuildTrainInfo, unlockTrain, resetTrain, getGuildTrainRewards} from '../../../services/guildTrainService';
|
||||
import { findIndex, findWhere, indexBy } from 'underscore'
|
||||
import { lockData } from '../../../services/redLockService';
|
||||
import { GUILD_DATA_NAME, REFRESH_HOUR } from '../../../consts/constModules/guildConst';
|
||||
import { GUILD_DATA_NAME, REFRESH_HOUR, GUILD_REPORT_NUM } from '../../../consts/constModules/guildConst';
|
||||
import { UserGuildModel } from '../../../db/UserGuild';
|
||||
import { GuildModel } from '../../../db/Guild';
|
||||
import { getArmyTrainJuDian, getTrainSoloReward, getTrainBaseByLv } from '../../../pubUtils/data';
|
||||
@@ -15,7 +15,7 @@ import { CURRENCY_BY_TYPE, CURRENCY_TYPE } from '../../../consts/constModules/it
|
||||
import { handleCost, addItems } from '../../../services/rewardService';
|
||||
import { ARMY } from '../../../pubUtils/dicParam';
|
||||
import { addActive } from '../../../services/guildService';
|
||||
import { GUILD_STRUCTURE } from '../../../consts/constModules/guildConst';
|
||||
import { GuildTrainReportModel } from '../../../db/GuildTrainReport';
|
||||
export default function (app: Application) {
|
||||
return new GuildTrainHandler(app);
|
||||
}
|
||||
@@ -34,22 +34,70 @@ export class GuildTrainHandler {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code } = userGuild;
|
||||
let { trainId } = await GuildModel.findGuild(code, serverId, 'trainId');
|
||||
let trainIds = [trainId];
|
||||
if (trainId - 1 > 0) {
|
||||
trainIds.push(trainId - 1);
|
||||
}
|
||||
let guildTrains = await GuildTrainModel.findGuildTrainByTrainIds(code, trainIds);
|
||||
if (!guildTrains || !findWhere(guildTrains, {trainId})) {
|
||||
let guildTrain = await unlockTrain(code, trainId);
|
||||
if (!guildTrains) {
|
||||
guildTrains.push(guildTrain);
|
||||
}
|
||||
let guildTrain = await GuildTrainModel.findTrainByTrainIdNotLock(code, trainId);
|
||||
if (!guildTrain ) {
|
||||
guildTrain = await unlockTrain(code, trainId);
|
||||
}
|
||||
let { trainCount, trainRewards, buyTrainCount } = userGuild;
|
||||
let result:any = getGuildTrainInfo(guildTrains, roleId, trainCount, trainRewards, [trainId]);
|
||||
let result:any = getGuildTrainInfo(guildTrain, roleId, trainCount, trainRewards);
|
||||
result.buyTrainCount = buyTrainCount;
|
||||
return resResult(STATUS.SUCCESS, result);
|
||||
}
|
||||
//获得试炼战报
|
||||
async getTrainReports(msg: {}, session: BackendSession) {
|
||||
const roleId: string = session.get('roleId');
|
||||
const serverId: number = parseInt(session.get('serverId'));
|
||||
let userGuild = await getUserGuild(roleId, serverId);
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code } = userGuild;
|
||||
let trainIds = [];
|
||||
let { trainId } = await GuildModel.findGuild(code, serverId, 'trainId');
|
||||
trainIds.push(trainId);
|
||||
if (trainId > 1)
|
||||
trainIds.push(trainId - 1);
|
||||
let trainReports = await GuildTrainReportModel.findGuildTrainByTrainIds(code, trainIds);
|
||||
let reports = [];
|
||||
trainReports.map(({ reports: resReports, trainId: resTrainId})=>{
|
||||
if (resTrainId != trainId) {
|
||||
let lenNum = resReports.length;
|
||||
resReports = resReports.splice(lenNum - GUILD_REPORT_NUM - 1, GUILD_REPORT_NUM);
|
||||
}
|
||||
reports.push(...resReports);
|
||||
});
|
||||
return resResult(STATUS.SUCCESS, {reports});
|
||||
}
|
||||
|
||||
//获得试炼宝箱
|
||||
async getTrainBoxs(msg: {}, session: BackendSession) {
|
||||
const roleId: string = session.get('roleId');
|
||||
const serverId: number = parseInt(session.get('serverId'));
|
||||
let userGuild = await getUserGuild(roleId, serverId);
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code } = userGuild;
|
||||
let guildTrains = await GuildTrainModel.findGuildTrain(code);
|
||||
let resTrainBoxs = [];
|
||||
let { trainId: curTrainId } = await GuildModel.findGuild(code, serverId, 'trainId');
|
||||
guildTrains.forEach(({trainInstances, trainId}) =>{
|
||||
let { trainInstances: instances } = getArmyTrainJuDian(trainId);
|
||||
let flag = false;
|
||||
let boxRewards = []
|
||||
trainInstances.map(({hid, progress, endTime, trainBoxs})=>{
|
||||
let instance = findWhere(instances, { hid });
|
||||
let isComplete = false;
|
||||
if ( progress >= instance.progress)
|
||||
isComplete = true;
|
||||
if (endTime > nowSeconds())
|
||||
flag = true;
|
||||
boxRewards.push({hid, recordBoxs: trainBoxs, trainId, endTime, isComplete});
|
||||
});
|
||||
if (flag || trainId == curTrainId) {
|
||||
resTrainBoxs.push(...boxRewards);
|
||||
}
|
||||
})
|
||||
return resResult(STATUS.SUCCESS, {trainBoxs: resTrainBoxs});
|
||||
}
|
||||
|
||||
async trainBattleStart(msg: { hid: number, trainId: number, difficulty: number }, session: BackendSession) {
|
||||
const { hid, difficulty, trainId } = msg;
|
||||
@@ -141,10 +189,9 @@ export class GuildTrainHandler {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let addScore = Math.floor((isSuccess?trainSoloReward.winScore:trainSoloReward.failScore) * (soloRewardRatio + 100 ) / 100);
|
||||
let goods = await addItems(roleId, roleName, sid, [{id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.HONOUR), count: isSuccess?trainSoloReward.failHonour:trainSoloReward.failHonour}]);
|
||||
let guildTrains = [];
|
||||
let trainIds = [];
|
||||
//是否压制
|
||||
let { isComplete, reports, ranks } = guildTrain;
|
||||
let { isComplete, ranks } = guildTrain;
|
||||
let reports = [];
|
||||
let index = findIndex(ranks, {roleId});
|
||||
if (index !== -1) {
|
||||
ranks[index].score += addScore;
|
||||
@@ -152,11 +199,10 @@ export class GuildTrainHandler {
|
||||
ranks.push({score: addScore, roleId});
|
||||
}
|
||||
let needLockNext = false;
|
||||
let resGuildTrain;
|
||||
let report = {roleId, trainId, hid, score: addScore, time: nowSeconds(), isSuccessed: isSuccess, type: 1};//1表示普通战报, 2表示系统战报即:被成功压制
|
||||
let report = {roleName, trainId, hid, score: addScore, time: nowSeconds(), isSuccessed: isSuccess, type: 1};//1表示普通战报, 2表示系统战报即:被成功压制
|
||||
reports.push(report);
|
||||
if (trainInstance.progress < instance.progress ) {
|
||||
if (trainInstance.progress + addScore >= instance.progress) {
|
||||
reports.push(...[{isSuccessed: true, type: 2, time:nowSeconds(), score: addScore, roleId, trainId, hid},report]);
|
||||
if (!isComplete) {
|
||||
isComplete = true;
|
||||
guildTrain.trainInstances.forEach(({hid: otherHid, progress})=>{
|
||||
@@ -169,33 +215,24 @@ export class GuildTrainHandler {
|
||||
}
|
||||
}
|
||||
let progress = instance.progress;
|
||||
resGuildTrain = await GuildTrainModel.updateGuildTrainProgress(code, trainId, hid, progress, ranks, reports, isComplete);
|
||||
guildTrain = await GuildTrainModel.updateGuildTrainProgress(code, trainId, hid, progress, ranks, isComplete);
|
||||
if (needLockNext) { //
|
||||
let nextResGuildTrain = await unlockTrain(code, trainId + 1);
|
||||
trainIds.push(nextResGuildTrain.trainId);
|
||||
guildTrains.push(nextResGuildTrain);
|
||||
reports.push({ isSuccessed: true, type: 2, time:nowSeconds(), score: addScore, roleName, trainId, hid });
|
||||
guildTrain = await unlockTrain(code, trainId + 1);
|
||||
}
|
||||
res.releaseCallback();//解锁
|
||||
} else {
|
||||
let progress = trainInstance.progress + addScore;
|
||||
resGuildTrain = await GuildTrainModel.updateGuildTrainProgress(code, trainId, hid, progress, ranks, reports, isComplete);
|
||||
guildTrain = await GuildTrainModel.updateGuildTrainProgress(code, trainId, hid, progress, ranks, isComplete);
|
||||
res.releaseCallback();//解锁
|
||||
}
|
||||
} else {
|
||||
reports.push(report);
|
||||
resGuildTrain = await GuildTrainModel.updateGuildTrain(code, trainId, {reports, ranks});
|
||||
guildTrain = await GuildTrainModel.updateGuildTrain(code, trainId, { ranks});
|
||||
res.releaseCallback();//解锁
|
||||
}
|
||||
if (!needLockNext) {
|
||||
if (trainId - 1 > 0 ) {
|
||||
let lastGuildTrain = await GuildTrainModel.findTrainByTrainIdNotLock(code, trainId - 1);
|
||||
guildTrains.push(lastGuildTrain);
|
||||
}
|
||||
trainIds.push(resGuildTrain.trainId);
|
||||
}
|
||||
guildTrains.push(resGuildTrain);
|
||||
await GuildTrainReportModel.pushGuildTrainReports(code, trainId, reports);
|
||||
let { trainCount, trainRewards } = userGuild;
|
||||
let result:any = getGuildTrainInfo(guildTrains, roleId, trainCount, trainRewards, trainIds);
|
||||
let result:any = getGuildTrainInfo(guildTrain, roleId, trainCount, trainRewards);
|
||||
result.battleGoods = goods;
|
||||
await addActive(roleId, serverId, 2, 1);
|
||||
return resResult(STATUS.SUCCESS, result);
|
||||
@@ -211,13 +248,12 @@ export class GuildTrainHandler {
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code } = userGuild;
|
||||
let { structure } = await GuildModel.findGuild(code, serverId, 'structure');
|
||||
let stru = findWhere(structure, {id: 4});
|
||||
let { trainLv } = await GuildModel.findGuild(code, serverId, 'structure');
|
||||
let res:any = await lockData(serverId, GUILD_DATA_NAME.TRAIN_BOX, code + '_' + trainId);//加锁
|
||||
if (!!res.err)
|
||||
return resResult(STATUS.REDLOCK_ERR);
|
||||
|
||||
let { shilianRewardRatio } = getTrainBaseByLv(GUILD_STRUCTURE.TRAIN);
|
||||
let { shilianRewardRatio } = getTrainBaseByLv(trainLv);
|
||||
let { heroRewards, trainInstances } = getArmyTrainJuDian(trainId);
|
||||
let { progress } = findWhere(trainInstances, {hid});
|
||||
let guildTrain = await GuildTrainModel.findTrainInstanceBoxByIndex(code, roleId, trainId, hid, index, progress, nowSeconds());
|
||||
|
||||
@@ -12,7 +12,7 @@ import { MailModel, MailType } from '../db/Mail';
|
||||
import { getRandomByLen, resResult } from '../pubUtils/util';
|
||||
import { getRedis } from './redisService';
|
||||
import { STATUS } from '../consts/statusCode';
|
||||
|
||||
import { GuildTrainReportModel } from '../db/GuildTrainReport'
|
||||
export async function getUserGuild(roleId: string, serverId: number) {
|
||||
let userGuild = await UserGuildModel.getMyGuild(roleId,'trainCount trainTime trainRewards guildCode');
|
||||
if (!userGuild)
|
||||
@@ -57,57 +57,32 @@ export function getGuildTrainRewards (guildTrain) {
|
||||
isComplete = true;
|
||||
return {hid, recordBoxs: trainBoxs, trainId: guildTrain.trainId, endTime, isComplete};
|
||||
})
|
||||
return { trainBoxs};
|
||||
return { trainBoxs };
|
||||
}
|
||||
|
||||
export function getGuildTrainInfo (guildTrains: Array<GuildTrainType>, roleId: string, trainCount:number, trainRewards: Array<number>, trainIds:Array<number>) {
|
||||
let guildTrain;
|
||||
guildTrains.map(({trainId, isComplete, trainInstances, ranks, reports})=>{
|
||||
if (trainIds.indexOf(trainId) == -1) {
|
||||
return;
|
||||
}
|
||||
ranks.sort(function(a, b) {
|
||||
return b.score - a.score;
|
||||
});
|
||||
let myRank = {};
|
||||
let resRanks = ranks.map(({roleId: rankRoleId, score}, index)=>{
|
||||
if (roleId == rankRoleId)
|
||||
myRank = {roleId: rankRoleId, score, rankLv: index+1};
|
||||
return {roleId: rankRoleId, score, rankLv: index+1};
|
||||
});
|
||||
let { trainInstances: instances } = getArmyTrainJuDian(trainId);
|
||||
let resTrainBoxs = [];
|
||||
let resTrainInstances = trainInstances.map(({hid, progress, endTime, trainBoxs})=>{
|
||||
let instance = findWhere(instances, { hid });
|
||||
let isComplete = false;
|
||||
if ( progress >= instance.progress)
|
||||
isComplete = true;
|
||||
resTrainBoxs.push({hid, recordBoxs: trainBoxs, trainId, endTime, isComplete});
|
||||
return {hid, progress, endTime, isComplete};
|
||||
})
|
||||
let lastGuildTrain = findWhere(guildTrains, { trainId: trainId - 1});
|
||||
if (!!lastGuildTrain) {
|
||||
let lenNum = lastGuildTrain.reports.length;
|
||||
if (lenNum < GUILD_REPORT_NUM)
|
||||
reports = [...lastGuildTrain.reports, ...reports];
|
||||
else {
|
||||
let trainReports = lastGuildTrain.reports.splice(lenNum - GUILD_REPORT_NUM - 1, GUILD_REPORT_NUM);
|
||||
reports = [...trainReports, ...reports];
|
||||
}
|
||||
let flag = false;
|
||||
let lastTrainBoxs = lastGuildTrain.trainInstances.map(({hid, endTime, trainBoxs}) => {
|
||||
if (endTime < nowSeconds()) {
|
||||
flag = true;
|
||||
}
|
||||
return {hid, recordBoxs: trainBoxs, trainId: lastGuildTrain.trainId, endTime, isComplete: true};
|
||||
});
|
||||
if (flag) {
|
||||
resTrainBoxs.push(...lastTrainBoxs);
|
||||
}
|
||||
}
|
||||
guildTrain = {trainId, isComplete, trainInstances: resTrainInstances, trainBoxs: resTrainBoxs, reports, myRank, ranks: resRanks};
|
||||
export function getGuildTrainInfo (guildTrain: GuildTrainType, roleId: string, trainCount:number, trainRewards: Array<number>) {
|
||||
let { trainId, isComplete, trainInstances, ranks } = guildTrain;
|
||||
|
||||
ranks.sort(function(a, b) {
|
||||
return b.score - a.score;
|
||||
});
|
||||
return { guildTrain, trainCount, trainRewards};
|
||||
let myRank = {};
|
||||
let resRanks = ranks.map(({roleId: rankRoleId, score}, index)=>{
|
||||
if (roleId == rankRoleId)
|
||||
myRank = {roleId: rankRoleId, score, rankLv: index+1};
|
||||
return {roleId: rankRoleId, score, rankLv: index+1};
|
||||
});
|
||||
let { trainInstances: instances } = getArmyTrainJuDian(trainId);
|
||||
let resTrainInstances = trainInstances.map(({hid, progress, endTime})=>{
|
||||
let instance = findWhere(instances, { hid });
|
||||
let isComplete = false;
|
||||
if ( progress >= instance.progress)
|
||||
isComplete = true;
|
||||
return {hid, progress, endTime, isComplete};
|
||||
});
|
||||
let resGuildTrain = {trainId, isComplete, trainInstances: resTrainInstances, myRank, ranks: resRanks};
|
||||
|
||||
return { guildTrain: resGuildTrain, trainCount, trainRewards};
|
||||
}
|
||||
|
||||
export async function unlockTrain(code: string, trainId: number) {
|
||||
@@ -127,6 +102,7 @@ export async function unlockTrain(code: string, trainId: number) {
|
||||
return t;
|
||||
});
|
||||
guildTrain = await GuildTrainModel.openGuildTrain(code, trainId, instances);
|
||||
await GuildTrainReportModel.resetGuildTrainReport(code, trainId);
|
||||
await GuildModel.updateInfo(code, {trainId}, {});
|
||||
|
||||
return guildTrain;
|
||||
@@ -136,7 +112,9 @@ export async function resetTrain(code: string, serverId: number) {
|
||||
let res:any = await lockData(serverId, GUILD_DATA_NAME.GUILD, code);//加锁
|
||||
if (!!res.err)
|
||||
return;
|
||||
let guild = await GuildModel.resetGuildTrain(code, serverId);
|
||||
let { structure } = await GuildModel.findGuild(code, serverId, 'structure');
|
||||
let { lv } = findWhere(structure, {id: GUILD_STRUCTURE.TRAIN});
|
||||
let guild = await GuildModel.resetGuildTrain(code, serverId, lv);
|
||||
if (!guild) {
|
||||
res.releaseCallback();//解锁
|
||||
return;
|
||||
@@ -161,6 +139,7 @@ export async function resetTrain(code: string, serverId: number) {
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
for (let trainId = 1; trainId < guild.trainId; trainId++) {
|
||||
let { jinjieReward } = getArmyTrainJuDian(trainId);
|
||||
if (trainRewards.indexOf(trainId)) {
|
||||
|
||||
@@ -170,7 +170,7 @@ export const STATUS = {
|
||||
GUILD_REACH_MAX_ASSIST_COUNT: { code: 20967, simStr: '已经达到协助的最大次数' },
|
||||
GUILD_TRAIN_IS_NOT_COMPLETE: { code: 20968, simStr: '军团该训练场没有完成' },
|
||||
GUILD_TRAIN_QUALITY_REWARD_IS_GOT: { code: 20969, simStr: '军团训练进阶奖励已经领取' },
|
||||
|
||||
GUILD_PERSITION_TREE_NOT_LIGHT: { code: 20970, simStr: '军团前置科技树未研发' },
|
||||
// 通用 30000 - 30099
|
||||
DIC_DATA_NOT_FOUND: { code: 30000, simStr: '数据表未找到' },
|
||||
ROLE_MATERIAL_NOT_ENOUGH: { code: 30001, simStr: '材料数量不足' },
|
||||
|
||||
55
shared/db/Donation.ts
Normal file
55
shared/db/Donation.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
import { COUNTER } from './../consts';
|
||||
import { CounterModel } from './Counter';
|
||||
|
||||
class Report {
|
||||
@prop({ required: true })
|
||||
roleName: string;
|
||||
|
||||
@prop({ required: true })
|
||||
time: number;
|
||||
|
||||
@prop({ required: true })
|
||||
id: number;//捐献类型id
|
||||
}
|
||||
|
||||
export default class Donation extends BaseModel {
|
||||
|
||||
@prop({ required: true })
|
||||
guildCode: string;
|
||||
|
||||
@prop({ required: true, default: 0})
|
||||
donateFund: number;
|
||||
|
||||
@prop({ required: true, default: 0})
|
||||
hisDonateFund: number; //历史捐赠最高
|
||||
|
||||
@prop({ required: true, type: Report, default:[] })
|
||||
reports: Array<Report>;
|
||||
|
||||
@prop({ required: true, default: 0})
|
||||
refTime: number;
|
||||
|
||||
public static async createDonation(guildCode: string, lean = true) {
|
||||
const doc = new Donation();
|
||||
const result: DonationType = await DonationModel.findOneAndUpdate({ guildCode }, {$set:doc}, {upsert: true, new: true}).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async getDonation(guildCode: string, select?: string, lean = true) {
|
||||
const result: DonationType = await DonationModel.findOne({ guildCode }).select(select).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async donation(guildCode: string, donateFund: number, report: Report, lean = true) {
|
||||
const result: DonationType = await DonationModel.findOneAndUpdate({ guildCode }, {$inc:{ donateFund, hisDonateFund: donateFund }, $push:{ reports: report}}, {upsert: true, new: true}).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const DonationModel = getModelForClass(Donation);
|
||||
|
||||
export interface DonationType extends Pick<DocumentType<Donation>, keyof Donation>{}
|
||||
export type DonationUpdateParam = Partial<DonationType>; // 将所有字段变成可选项
|
||||
@@ -84,6 +84,9 @@ export default class Guild extends BaseModel {
|
||||
@prop({ required: true, default: 1 })
|
||||
trainId: number; // 试炼id
|
||||
|
||||
@prop({ required: true, default: 1 })
|
||||
trainLv: number; // 试炼等级
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
resetTrainTime: number;//上次刷新挑战训练场次数的时间
|
||||
|
||||
@@ -196,9 +199,9 @@ export default class Guild extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async resetGuildTrain(code: string, serverId: number, lean = true) {
|
||||
public static async resetGuildTrain(code: string, serverId: number, trainLv: number, lean = true) {
|
||||
const time = getCurWeekTime(1, 5);//每周一,5点刷新
|
||||
const result = await GuildModel.findOneAndUpdate({ code, status: GUILD_STATUS.RUNNING, serverId, resetTrainTime:{$ne:time}},{$set: {trainId: 1, resetTrainTime: time}}).lean(lean);
|
||||
const result = await GuildModel.findOneAndUpdate({ code, status: GUILD_STATUS.RUNNING, serverId, resetTrainTime:{$ne:time}},{$set: {trainId: 1, resetTrainTime: time, trainLv}}).lean(lean);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,22 +35,7 @@ class Rank {
|
||||
score: number;
|
||||
}
|
||||
|
||||
class Report {
|
||||
@prop({ required: true })
|
||||
roleId: string;
|
||||
@prop({ required: true })
|
||||
trainId: number;//挑战的试炼关
|
||||
@prop({ required: true })
|
||||
hid: number;//据点
|
||||
@prop({ required: true })
|
||||
score: number;
|
||||
@prop({ required: true })
|
||||
time: number;
|
||||
@prop({ required: true })
|
||||
isSuccessed: boolean;
|
||||
@prop({ required: true })
|
||||
type: number;//1表示普通战报, 2表示系统战报即:被成功压制
|
||||
}
|
||||
|
||||
@index({guildCode:1, trainId:1})
|
||||
export default class GuildTrain extends BaseModel {
|
||||
@prop({ required: true })
|
||||
@@ -63,8 +48,6 @@ export default class GuildTrain extends BaseModel {
|
||||
trainInstances: TrainInstance[];
|
||||
@prop({ required: true, default: [], type: Rank, _id: false })
|
||||
ranks: Rank[];
|
||||
@prop({ required: true, default: [], type: Report, _id: false })
|
||||
reports: Report[];
|
||||
@prop({ required: true, default: false})
|
||||
locked: boolean;
|
||||
|
||||
@@ -88,14 +71,15 @@ export default class GuildTrain extends BaseModel {
|
||||
return guildTrain;
|
||||
}
|
||||
|
||||
public static async updateGuildTrainProgress(guildCode: string, trainId: number, hid:number, progress: number, ranks:Array<Rank>, reports: Array<Report>, isComplete: boolean,lean = true) {
|
||||
public static async updateGuildTrainProgress(guildCode: string, trainId: number, hid:number, progress: number, ranks:Array<Rank>, isComplete: boolean,lean = true) {
|
||||
const guildTrain: GuildTrainType = await GuildTrainModel.findOneAndUpdate({ guildCode, trainId, 'trainInstances.hid':hid},
|
||||
{ $set: {'trainInstances.$.progress': progress, ranks, reports, isComplete,'trainInstances.$.endTime': nowSeconds() + 24*60*60} },{new: true}).lean(lean);
|
||||
{ $set: {'trainInstances.$.progress': progress, ranks, isComplete,'trainInstances.$.endTime': nowSeconds() + 24*60*60} },{new: true}).lean(lean);
|
||||
|
||||
return guildTrain;
|
||||
}
|
||||
|
||||
public static async openGuildTrain(guildCode: string, trainId: number, trainInstances: Array<TrainInstance>, lean = true) {
|
||||
const guildTrain: GuildTrainType = await GuildTrainModel.findOneAndUpdate({ guildCode, trainId },{ trainId, reports: [], locked: false, ranks: [], trainInstances, isComplete: false, guildCode}, {new: true, upsert: true}).lean(lean);
|
||||
const guildTrain: GuildTrainType = await GuildTrainModel.findOneAndUpdate({ guildCode, trainId },{ trainId, locked: false, ranks: [], trainInstances, isComplete: false, guildCode}, {new: true, upsert: true}).lean(lean);
|
||||
return guildTrain;
|
||||
}
|
||||
|
||||
|
||||
51
shared/db/GuildTrainReport.ts
Normal file
51
shared/db/GuildTrainReport.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
|
||||
class Report {
|
||||
@prop({ required: true })
|
||||
roleName: string;
|
||||
@prop({ required: true })
|
||||
trainId: number;//挑战的试炼关
|
||||
@prop({ required: true })
|
||||
hid: number;//据点
|
||||
@prop({ required: true })
|
||||
score: number;
|
||||
@prop({ required: true })
|
||||
time: number;
|
||||
@prop({ required: true })
|
||||
isSuccessed: boolean;
|
||||
@prop({ required: true })
|
||||
type: number;//1表示普通战报, 2表示系统战报即:被成功压制
|
||||
}
|
||||
@index({guildCode: 1, trainId: 1})
|
||||
|
||||
export default class GuildTrainReport extends BaseModel {
|
||||
@prop({ required: true })
|
||||
guildCode: string;
|
||||
@prop({ required: true })
|
||||
trainId: number;
|
||||
@prop({ required: true, default: [], type: Report, _id: false })
|
||||
reports: Report[];
|
||||
|
||||
public static async pushGuildTrainReports(guildCode: string, trainId: number, reports: Array<Report>, lean = true) {
|
||||
const guildTrainReport: GuildTrainReportType = await GuildTrainReportModel.findOneAndUpdate({ guildCode, trainId },
|
||||
{ $push: {reports:{ $each:reports } } },{new: true}).lean(lean);
|
||||
return guildTrainReport;
|
||||
}
|
||||
|
||||
public static async resetGuildTrainReport(guildCode: string, trainId: number, lean = true) {
|
||||
const guildTrainReport: GuildTrainReportType = await GuildTrainReportModel.findOneAndUpdate({ guildCode, trainId },
|
||||
{ $set: {reports:[], guildCode, trainId } }, {new: true, upsert: true}).lean(lean);
|
||||
return guildTrainReport;
|
||||
}
|
||||
|
||||
public static async findGuildTrainByTrainIds(guildCode: string, trainIds:Array<number>, lean = true) {
|
||||
const guildTrains: GuildTrainReportType[] = await GuildTrainReportModel.find({ trainId:{ $in:trainIds}, guildCode }).lean(lean);
|
||||
return guildTrains;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const GuildTrainReportModel = getModelForClass(GuildTrainReport);
|
||||
|
||||
export interface GuildTrainReportType extends Pick<DocumentType<GuildTrainReport>, keyof GuildTrainReport> { };
|
||||
@@ -11,6 +11,22 @@ class ActiveRecord {
|
||||
count: number;
|
||||
}
|
||||
|
||||
class WishGood {
|
||||
@prop({ required: true })
|
||||
id: number;
|
||||
@prop({ required: true })
|
||||
type: number;
|
||||
@prop({ required: true })
|
||||
goodId: number;
|
||||
@prop({ required: true })
|
||||
count: number;
|
||||
@prop({ required: true, default:0 })
|
||||
receiveCnt: number;
|
||||
@prop({ required: true, default:0 })
|
||||
drawCnt: number;
|
||||
}
|
||||
|
||||
|
||||
@index({ roleId: 1 })
|
||||
export default class UserGuild extends BaseModel {
|
||||
@prop({ required: true })
|
||||
@@ -56,11 +72,22 @@ export default class UserGuild extends BaseModel {
|
||||
buyTrainCount: number;//每日挑战训练场购买次数
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
trainTime: number;//上次刷新挑战训练场次数的时间
|
||||
trainTime: number;//上次刷新挑战训练场次数的时间每天5点
|
||||
|
||||
@prop({ required: true, default: [] })
|
||||
trainRewards: Array<number>;//领取过的进阶等级
|
||||
|
||||
@prop({ required: true, default: [], type: WishGood })
|
||||
wishGoods:Array<WishGood>;
|
||||
|
||||
@prop({ required: true, default: [], type: Number })
|
||||
receiveBoxs:Array<number>;
|
||||
|
||||
@prop({ required: true })
|
||||
wishDntCnt:number;//今天许愿池捐献次数
|
||||
|
||||
@prop({ required: true })
|
||||
donateCnt:number;//今天捐献所次数
|
||||
|
||||
public static async getMyAuth(roleId: string, guildCode?: string, userGuild?: UserGuildType) {
|
||||
let myGuild: UserGuildType;
|
||||
@@ -148,6 +175,15 @@ export default class UserGuild extends BaseModel {
|
||||
const result = await UserGuildModel.updateMany({ guildCode }, {$set: { trainCount: ARMY.ARMY_TRAIN_BUYTIMES, buyTrainCount: 0, trainTime: nowSeconds(), trainRewards: [] }});
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async donateFund(roleId: string, donateCnt: number, lean = true) {
|
||||
const result = await UserGuildModel.findOneAndUpdate({ roleId, status: USER_GUILD_STATUS.ON},
|
||||
{$inc: {donateCnt :-1*donateCnt}}, {new: true}).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
export const UserGuildModel = getModelForClass(UserGuild);
|
||||
|
||||
Reference in New Issue
Block a user