练兵场结算
This commit is contained in:
@@ -23,7 +23,7 @@ export class GuildHandler {
|
||||
|
||||
// 获得boss关卡
|
||||
async getBossInstance(msg: {}, session: BackendSession) {
|
||||
const roleId = session.get('roleId');
|
||||
const roleId: string = session.get('roleId');
|
||||
let userGuild = await UserGuildModel.getMyGuild(roleId, 'guildCode');
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
@@ -39,8 +39,8 @@ export class GuildHandler {
|
||||
|
||||
//开启演武场
|
||||
async openBossInstance(msg: {}, session: BackendSession) {
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
const roleId: string = session.get('roleId');
|
||||
const serverId: number = parseInt(session.get('serverId'));
|
||||
let userGuild = await UserGuildModel.getMyGuild(roleId, 'auth guildCode');
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
@@ -74,8 +74,8 @@ export class GuildHandler {
|
||||
}
|
||||
|
||||
async battleBoss(msg: {}, session: BackendSession) {
|
||||
const roleId = session.get('roleId');
|
||||
const roleName = session.get('roleName');
|
||||
const roleId: string = session.get('roleId');
|
||||
const roleName: string = session.get('roleName');
|
||||
let userGuild = await UserGuildModel.getMyGuild(roleId, 'guildCode');
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
@@ -101,7 +101,7 @@ export class GuildHandler {
|
||||
record: { heroes:[],recordNum: bossInstance.num, bossHp: bossInstance.bossHp},
|
||||
}
|
||||
}, true);
|
||||
const serverId = session.get('serverId');
|
||||
const serverId:number = parseInt(session.get('serverId'));
|
||||
await addBossInstance(code, serverId, roleId);
|
||||
if (!findWhere(ranks, {roleId})) {
|
||||
await BossInstanceModel.pushRanks(code, {roleId, score: 0, time: nowSeconds()});
|
||||
@@ -113,8 +113,8 @@ export class GuildHandler {
|
||||
|
||||
async action (msg: { damage: number, battleCode: string }, session: BackendSession ) {
|
||||
const { battleCode, damage } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
const roleId: string = session.get('roleId');
|
||||
const serverId: number = parseInt(session.get('serverId'));
|
||||
let userGuild = await UserGuildModel.getMyGuild(roleId, 'guildCode');
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import { Application, BackendSession, pinus } from 'pinus';
|
||||
import { UserGuildModel } from '../../../db/UserGuild';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { STATUS } from '../../../consts';
|
||||
|
||||
export default function (app: Application) {
|
||||
return new GuildRefinerHandler(app);
|
||||
}
|
||||
|
||||
export class GuildRefinerHandler {
|
||||
constructor(private app: Application) {
|
||||
|
||||
}
|
||||
|
||||
async refineEquip(msg: {eId: number}, session: BackendSession) {
|
||||
const roleId = session.get('roleId');
|
||||
let userGuild = await UserGuildModel.getMyGuild(roleId, 'guildCode');
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,17 +3,17 @@ import { resResult, genCode, getRandomByLen } from '../../../pubUtils/util';
|
||||
import { STATUS, GUILD_OPERATE, GUILD_AUTH, GUILD_JOB } from '../../../consts';
|
||||
import { GuildTrainModel } from '../../../db/GuildTrain';
|
||||
import { BattleRecordModel } from '../../../db/BattleRecord';
|
||||
import { nowSeconds, getTodayZeroPoint } from '../../../pubUtils/timeUtil';
|
||||
import { getUserGuild, getGuildTrainInfo, lockTrain, getGuildTrain, getGuildTrainRewards} from '../../../services/guildTrainService';
|
||||
import { nowSeconds, getHourPoint, getCurHourPoint } from '../../../pubUtils/timeUtil';
|
||||
import { getUserGuild, getGuildTrainInfo, lockTrain, resetTrain, getGuildTrainRewards} from '../../../services/guildTrainService';
|
||||
import { findIndex, findWhere, indexBy } from 'underscore'
|
||||
import { lockData } from '../../../services/redLockService';
|
||||
import { GUILD_DATA_NAME } from '../../../consts/constModules/guildConst';
|
||||
import { GUILD_DATA_NAME, REFRESH_HOUR } from '../../../consts/constModules/guildConst';
|
||||
import { UserGuildModel } from '../../../db/UserGuild';
|
||||
import { GuildModel } from '../../../db/Guild';
|
||||
import { getArmyTrainJuDian, getTrainSoloReward, getTrainBaseByLv } from '../../../pubUtils/data';
|
||||
import { CURRENCY_BY_TYPE, CURRENCY_TYPE } from '../../../consts/constModules/itemConst';
|
||||
import { handleCost, addItems } from '../../../services/rewardService';
|
||||
|
||||
import { ARMY } from '../../../pubUtils/dicParam';
|
||||
export default function (app: Application) {
|
||||
return new GuildTrainHandler(app);
|
||||
}
|
||||
@@ -25,9 +25,9 @@ export class GuildTrainHandler {
|
||||
|
||||
//获得试炼的详情
|
||||
async getTrainInstance(msg: {}, session: BackendSession) {
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
let userGuild = await getUserGuild(roleId);
|
||||
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;
|
||||
@@ -43,8 +43,9 @@ export class GuildTrainHandler {
|
||||
guildTrains.push(guildTrain);
|
||||
}
|
||||
}
|
||||
let { trainCount, trainRewards } = userGuild;
|
||||
let result = getGuildTrainInfo(guildTrains, roleId, trainCount, trainRewards, [trainId]);
|
||||
let { trainCount, trainRewards, buyTrainCount } = userGuild;
|
||||
let result:any = getGuildTrainInfo(guildTrains, roleId, trainCount, trainRewards, [trainId]);
|
||||
result.buyTrainCount = buyTrainCount;
|
||||
return resResult(STATUS.SUCCESS, result);
|
||||
}
|
||||
|
||||
@@ -52,8 +53,8 @@ export class GuildTrainHandler {
|
||||
const { hid, difficulty, trainId } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
const roleName = session.get('roleName');
|
||||
const serverId = session.get('serverId');
|
||||
let userGuild = await getUserGuild(roleId);
|
||||
const serverId = parseInt(session.get('serverId'));
|
||||
let userGuild = await getUserGuild(roleId, serverId);
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code } = userGuild;
|
||||
@@ -88,11 +89,11 @@ export class GuildTrainHandler {
|
||||
|
||||
async trainBattleEnd(msg: { battleCode: string, isSuccess: boolean}, session: BackendSession) {
|
||||
const { battleCode, isSuccess } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
const roleName = session.get('roleName');
|
||||
const sid = session.get('sid');
|
||||
let userGuild = await getUserGuild(roleId);
|
||||
const roleId: string = session.get('roleId');
|
||||
const serverId: number = parseInt(session.get('serverId'));
|
||||
const roleName: string = session.get('roleName');
|
||||
const sid: string = session.get('sid');
|
||||
let userGuild = await getUserGuild(roleId, serverId);
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code } = userGuild;
|
||||
@@ -104,7 +105,10 @@ export class GuildTrainHandler {
|
||||
// if (userGuild.trainCount - 1 < 0) {
|
||||
// return resResult(STATUS.WRONG_PARMS);
|
||||
// }
|
||||
if (time > getTodayZeroPoint()) {
|
||||
if (time < getCurHourPoint(REFRESH_HOUR) && nowSeconds() > getCurHourPoint(REFRESH_HOUR)) {
|
||||
return resResult(STATUS.GUILD_TRAIN_IS_RESETED);//关卡已经重置
|
||||
}
|
||||
if (time > getHourPoint(REFRESH_HOUR)) {
|
||||
userGuild = await UserGuildModel.updateInfo(roleId, {}, { trainCount: -1 });
|
||||
}
|
||||
await BattleRecordModel.updateBattleRecordByCode(battleCode, {
|
||||
@@ -195,11 +199,11 @@ export class GuildTrainHandler {
|
||||
|
||||
async getTrainInstanceBox(msg: { trainId: number , hid: number, index: number}, session: BackendSession) {
|
||||
let { trainId, hid, index } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
const roleName = session.get('roleName');
|
||||
const roleId: string = session.get('roleId');
|
||||
const serverId: number = parseInt(session.get('serverId'));
|
||||
const roleName: string = session.get('roleName');
|
||||
const sid = session.get('sid');
|
||||
let userGuild = await getUserGuild(roleId);
|
||||
let userGuild = await getUserGuild(roleId, serverId);
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code } = userGuild;
|
||||
@@ -232,11 +236,11 @@ export class GuildTrainHandler {
|
||||
|
||||
async getTrainLvUpRewards(msg: {trainId: number }, session: BackendSession) {
|
||||
let { trainId } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
const roleName = session.get('roleName');
|
||||
const sid = session.get('sid');
|
||||
const roleId: string = session.get('roleId');
|
||||
const roleName: string = session.get('roleName');
|
||||
const sid: string = session.get('sid');
|
||||
|
||||
let { jinjieReward } = getTrainBaseByLv(trainId);
|
||||
let { jinjieReward } = getArmyTrainJuDian(trainId);
|
||||
let userGuild = await UserGuildModel.receiveTrainRewards(roleId, trainId);
|
||||
if (!userGuild) {
|
||||
return resResult(STATUS.GUILD_GET_TRAIN_REWARD_FAIL);
|
||||
@@ -245,10 +249,22 @@ export class GuildTrainHandler {
|
||||
let { trainRewards } = userGuild;
|
||||
return resResult(STATUS.SUCCESS, { trainRewards, goods });
|
||||
}
|
||||
|
||||
//购买挑战次数
|
||||
async purchaseTrainCount(msg: {code: string, trainId: number }, session: BackendSession) {
|
||||
let { code, trainId } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
|
||||
async purchaseTrainCount(msg: {count: number}, session: BackendSession) {
|
||||
let { count } = msg;
|
||||
const roleId:string = session.get('roleId');
|
||||
const serverId: number = parseInt(session.get('serverId'));
|
||||
const sid:string = session.get('sid');
|
||||
let userGuild = await getUserGuild(roleId, serverId);
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
if (userGuild.buyTrainCount >= ARMY.ARMY_TRAIN_BUYTIMES)
|
||||
return resResult(STATUS.GUILD_BUY_TRAIN_COUNT_REACH_MAX)
|
||||
let result = await handleCost(roleId, sid, [{id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD), count: ARMY.ARMY_TRAIN_TIMESCOST}]);
|
||||
if(!result)
|
||||
return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
let { trainCount, buyTrainCount } = await UserGuildModel.addTrainCount(roleId, count);
|
||||
return resResult(STATUS.SUCCESS, { trainCount, buyTrainCount });
|
||||
}
|
||||
}
|
||||
@@ -91,7 +91,7 @@ export async function getBossInstanceWhenEnd(bossInstance: BossInstanceType, rol
|
||||
* @param damage
|
||||
* @param roleId
|
||||
*/
|
||||
export async function bossResult(code: string, serverId: string, dataName: string, roleId: string, damage: number) {
|
||||
export async function bossResult(code: string, serverId: number, dataName: string, roleId: string, damage: number) {
|
||||
let res:any = await lockData(serverId, dataName, code);//加锁
|
||||
if (!!res.err)
|
||||
return true;
|
||||
@@ -138,7 +138,7 @@ export async function bossResult(code: string, serverId: string, dataName: strin
|
||||
return true;
|
||||
}
|
||||
|
||||
export async function addBossInstance(code: string, serverId:string, roleId: string) {
|
||||
export async function addBossInstance(code: string, serverId:number, roleId: string) {
|
||||
let loginKey = 'login_roleId_' + roleId;
|
||||
let sid = await getRedis(loginKey);
|
||||
let key = 'serverId_' + serverId + 'guildCode_' + code;
|
||||
@@ -146,7 +146,7 @@ export async function addBossInstance(code: string, serverId:string, roleId: str
|
||||
saddAsync(key, [value]);
|
||||
}
|
||||
|
||||
export async function pushBossHpMessage(code: string, serverId:string, bossHp:number, isDelKey?: boolean ) {
|
||||
export async function pushBossHpMessage(code: string, serverId:number, bossHp:number, isDelKey?: boolean ) {
|
||||
let key = 'serverId_' + serverId + 'guildCode_' + code;
|
||||
let members = await smembersAsync(key);
|
||||
let uids = members.map(member=>{
|
||||
@@ -161,7 +161,7 @@ export async function pushBossHpMessage(code: string, serverId:string, bossHp:nu
|
||||
}
|
||||
}
|
||||
|
||||
export async function checkMemberExists(code: string, serverId:string, roleId: string, battleCode:string ) {
|
||||
export async function checkMemberExists(code: string, serverId:number, roleId: string, battleCode:string ) {
|
||||
let loginKey = 'login_roleId_' + roleId;
|
||||
let sid = await getRedis(loginKey);
|
||||
let key = 'serverId_' + serverId + 'guildCode_' + code ;
|
||||
|
||||
@@ -1,19 +1,28 @@
|
||||
import { UserGuildModel } from '../db/UserGuild';
|
||||
import { getArmyTrainJuDian } from '../pubUtils/data';
|
||||
import { getTodayZeroPoint, nowSeconds } from '../pubUtils/timeUtil';
|
||||
import { GUILD_REPORT_NUM } from '../consts/constModules/guildConst';
|
||||
import { nowSeconds, getHourPoint } from '../pubUtils/timeUtil';
|
||||
import { GUILD_REPORT_NUM, GUILD_DATA_NAME, REFRESH_HOUR } from '../consts/constModules/guildConst';
|
||||
import { GuildTrainType, GuildTrainModel, TrainInstance } from '../db/GuildTrain';
|
||||
import { GuildModel } from '../db/Guild';
|
||||
import { findWhere } from 'underscore';
|
||||
export async function getUserGuild(roleId: string) {
|
||||
import { ARMY } from '../pubUtils/dicParam';
|
||||
import { lockData } from '../services/redLockService';
|
||||
import { pinus } from 'pinus';
|
||||
import { MailModel, MailType } from '../db/Mail';
|
||||
import { getRandomByLen, resResult } from '../pubUtils/util';
|
||||
import { getRedis } from '../services/redisService';
|
||||
import { STATUS } from '../consts/statusCode';
|
||||
export async function getUserGuild(roleId: string, serverId: number) {
|
||||
let userGuild = await UserGuildModel.getMyGuild(roleId,'trainCount trainTime trainRewards');
|
||||
if (!userGuild)
|
||||
return;
|
||||
let { trainCount, trainTime} = userGuild;
|
||||
if (trainTime < getTodayZeroPoint()) {
|
||||
trainCount = 2;
|
||||
let { trainCount, trainTime, buyTrainCount, guildCode} = userGuild;
|
||||
await resetTrain(guildCode, serverId);
|
||||
if (trainTime < getHourPoint(REFRESH_HOUR)) {
|
||||
trainCount = ARMY.ARMY_TRAIN_BUYTIMES;
|
||||
buyTrainCount = 0;
|
||||
userGuild = await UserGuildModel.updateInfo(roleId, {trainCount, trainTime: nowSeconds(), buyTrainCount});
|
||||
}
|
||||
userGuild = await UserGuildModel.updateInfo(roleId, {trainCount, trainTime: nowSeconds()});
|
||||
return userGuild;
|
||||
}
|
||||
|
||||
@@ -22,7 +31,7 @@ export async function recordUserGuild(roleId: string, code: string) {
|
||||
if (!userGuild||userGuild.guildCode != code)
|
||||
return;
|
||||
let { trainCount, trainTime} = userGuild;
|
||||
if (trainTime < getTodayZeroPoint()) {
|
||||
if (trainTime < getHourPoint(REFRESH_HOUR)) {
|
||||
trainCount = 0;
|
||||
}
|
||||
userGuild = await UserGuildModel.updateInfo(roleId, {trainCount, trainTime: nowSeconds()});
|
||||
@@ -119,4 +128,57 @@ export async function lockTrain(code: string, trainId: number) {
|
||||
await GuildModel.updateInfo(code, {trainId}, {});
|
||||
|
||||
return guildTrain;
|
||||
}
|
||||
|
||||
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);
|
||||
if (!guild) {
|
||||
res.releaseCallback();//解锁
|
||||
return;
|
||||
}
|
||||
res.releaseCallback();//解锁
|
||||
const userGuildList = await UserGuildModel.getListByGuild(code, 'trainRewards', {});
|
||||
const guildTrains = await GuildTrainModel.getGuildTrainBoxs(code);
|
||||
let mails = new Array<MailType>();
|
||||
let pushMessage = [];
|
||||
let uids = [];
|
||||
userGuildList.forEach(async function ({roleId, trainRewards}) {
|
||||
let goods = [];
|
||||
guildTrains.forEach(guildTrain=>{
|
||||
guildTrain.trainInstances.forEach(({ trainBoxs })=>{
|
||||
if (!findWhere(trainBoxs, {roleId})) {
|
||||
let { heroRewards } = getArmyTrainJuDian(guildTrain.trainId);
|
||||
let good = getRandomByLen(heroRewards);
|
||||
goods.push(good);
|
||||
}
|
||||
})
|
||||
});
|
||||
for (let trainId = 1; trainId < guild.trainId; trainId++) {
|
||||
let { jinjieReward } = getArmyTrainJuDian(trainId);
|
||||
if (trainRewards.indexOf(trainId)) {
|
||||
goods.push(...jinjieReward);
|
||||
}
|
||||
}
|
||||
let key = 'login_roleId_' + roleId;
|
||||
let sid = await getRedis(key);
|
||||
if (!!goods.length) {
|
||||
const doc = new MailModel();
|
||||
const mail = Object.assign(doc.toJSON(), {roleId, goods, sendName: '系统', mailId: 1, sendTime: nowSeconds(), content:'练兵场未领取宝箱奖励和进阶奖励:'});
|
||||
mails.push(mail);
|
||||
if (!!sid) {
|
||||
pushMessage.push({route: 'onMailsAdd', data:[mail], uid: roleId, sid});
|
||||
}
|
||||
}
|
||||
if (!!sid) {
|
||||
uids.push({ uid: roleId, sid});
|
||||
}
|
||||
});
|
||||
pinus.app.channelService.pushMessageByUids('onGuildTainReset', resResult(STATUS.SUCCESS, {}), uids);
|
||||
await MailModel.addMails(mails);
|
||||
await GuildTrainModel.resetGuildTrain(code);
|
||||
await lockTrain(code, 1);
|
||||
await UserGuildModel.resetTrainUserGuild(code);
|
||||
}
|
||||
@@ -45,7 +45,7 @@ export class RedlockService {
|
||||
|
||||
}
|
||||
|
||||
export async function lockData(serverId: string, dataName: string, id: string ) {
|
||||
export async function lockData(serverId: number, dataName: string, id: string ) {
|
||||
let key = 'serverId_'+serverId+'_'+dataName+'_'+id;
|
||||
let lockKey = 'locks:' + key;
|
||||
console.log(' lockKey = '+ lockKey);
|
||||
|
||||
@@ -17,7 +17,6 @@ export async function initAllRank() {
|
||||
const client: Redis.RedisClient = pinus.app.get('redis');
|
||||
const serverList = await GameModel.getAllServerList();
|
||||
await client.delAsync(REDIS_KEY.USER_INFO);
|
||||
await client.delAsync(REDIS_KEY.PVP_RANK);
|
||||
for(let {id} of serverList) {
|
||||
await client.delAsync(getKeyName(REDIS_KEY.TOWER_RANK, id));
|
||||
await initRank(id);
|
||||
|
||||
@@ -120,6 +120,8 @@ export enum GUILD_DATA_NAME {
|
||||
BOSS_SCRIPT = 'BossInstance',
|
||||
TRAIN = 'BossInstance',
|
||||
TRAIN_BOX = 'BossInstanceBox',
|
||||
GUILD = 'Guild'
|
||||
}
|
||||
|
||||
export const GUILD_REPORT_NUM = 40;
|
||||
export const REFRESH_HOUR = 5;
|
||||
|
||||
@@ -225,6 +225,8 @@ export const STATUS = {
|
||||
GUILD_TRAIN_REWARD_IS_RECEIVED: {code: 30913, simStr: '试炼进阶奖励已领取'},
|
||||
GUILD_GET_TRAIN_REWARD_FAIL: {code: 30913, simStr: '宝箱领取失败'},
|
||||
GUILD_TRAIN_LEVEL_IS_COMPLETE: {code: 30913, simStr: '试炼已经进阶'},
|
||||
GUILD_BUY_TRAIN_COUNT_REACH_MAX: { code: 30913, simStr: '训练场购买挑战次数以达到上线' },
|
||||
GUILD_TRAIN_IS_RESETED: { code: 30913, simStr: '训练场购买挑战次数以达到上线' },
|
||||
|
||||
// 社交相关状态 40000 - 49999
|
||||
// 运营模块相关状态 50000 - 59999
|
||||
|
||||
@@ -3,6 +3,7 @@ import { index, getModelForClass, prop, DocumentType, Ref } from '@typegoose/typ
|
||||
import Role, { RoleType } from './Role';
|
||||
import { genCode } from '../pubUtils/util';
|
||||
import { GUILD_STRUCTURE, GUILD_STATUS, GUILD_PER_PAGE } from '../consts';
|
||||
import { getCurWeekTime } from '../pubUtils/timeUtil';
|
||||
|
||||
class Structure {
|
||||
@prop({ required: true })
|
||||
@@ -79,6 +80,10 @@ export default class Guild extends BaseModel {
|
||||
|
||||
@prop({ required: true, default: 1 })
|
||||
trainId: number; // 试炼id
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
resetTrainTime: number;//上次刷新挑战训练场次数的时间
|
||||
|
||||
public static async createGuild(params: { name: string, icon: number, notice: string }, role: RoleType, serverId: number) {
|
||||
const doc = new GuildModel();
|
||||
const update = Object.assign(doc.toJSON(), params, { leader: role._id, members: [role.roleId], guildCe: role.ce, serverId });
|
||||
@@ -174,6 +179,12 @@ export default class Guild extends BaseModel {
|
||||
const result = await GuildModel.findOneAndUpdate({ $elemMatch: {members: roleId}, status: GUILD_STATUS.RUNNING}, {$inc: {guildCe: inc}}, {new: true}).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async resetGuildTrain(code: string, serverId: 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}}).lean(lean);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const GuildModel = getModelForClass(Guild);
|
||||
|
||||
32
shared/db/GuildRefine.ts
Normal file
32
shared/db/GuildRefine.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
|
||||
class ScienceTree {
|
||||
@prop({ required: true })
|
||||
id: number;
|
||||
@prop({ required: true })
|
||||
time: number;
|
||||
@prop({ required: true })
|
||||
assistCount: number;
|
||||
}
|
||||
|
||||
@index({ guildCode: 1 })
|
||||
|
||||
export default class GuildRefiner extends BaseModel {
|
||||
@prop({ required: true })
|
||||
guildCode: string;
|
||||
|
||||
@prop({ required: true, type: ScienceTree, default:[] })
|
||||
scienceTrees: ScienceTree[];
|
||||
|
||||
public static async createScienceTree(guildCode: string, scienceTrees: ScienceTree[], lean = true) {
|
||||
const result = await GuildRefinerModel.findOneAndUpdate({ guildCode }, {$set: {scienceTrees}}, {new: true, upsert: true}).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
export const GuildRefinerModel = getModelForClass(GuildRefiner);
|
||||
|
||||
export interface GuildRefinerType extends Pick<DocumentType<GuildRefiner>, keyof GuildRefiner>{}
|
||||
@@ -110,6 +110,16 @@ export default class GuildTrain extends BaseModel {
|
||||
{ $push:{ 'trainInstances.$.trainBoxs': {roleId, index, good} }}, {new: true}).lean(lean);
|
||||
return guildTrain;
|
||||
}
|
||||
|
||||
public static async resetGuildTrain(guildCode: string) {
|
||||
const result = await GuildTrainModel.updateMany({guildCode}, {$set:{locked: false}});
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async getGuildTrainBoxs(guildCode: string) {
|
||||
const result: GuildTrainType[] = await GuildTrainModel.find({guildCode, 'trainInstances.endTime':{$gte: nowSeconds()}, locked: false});
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,8 @@ 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 { nowSeconds } from '../pubUtils/timeUtil';
|
||||
import { ARMY } from '../pubUtils/dicParam';
|
||||
class ActiveRecord {
|
||||
@prop({ required: true })
|
||||
id: number;
|
||||
@@ -51,12 +52,16 @@ export default class UserGuild extends BaseModel {
|
||||
@prop({ required: true, default: 0 })
|
||||
trainCount: number;//每日挑战训练场的次数
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
buyTrainCount: number;//每日挑战训练场购买次数
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
trainTime: number;//上次刷新挑战训练场次数的时间
|
||||
|
||||
@prop({ required: true, default: [] })
|
||||
trainRewards: Array<number>;//领取过的进阶等级
|
||||
|
||||
|
||||
public static async getMyAuth(roleId: string, guildCode?: string, userGuild?: UserGuildType) {
|
||||
let myGuild: UserGuildType;
|
||||
if(!userGuild) {
|
||||
@@ -133,6 +138,17 @@ export default class UserGuild extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static async addTrainCount(roleId: string, trainCount: number, lean = true) {
|
||||
const result = await UserGuildModel.findOneAndUpdate({ roleId, status: USER_GUILD_STATUS.ON, $gte:{buyTrainCount: trainCount}},
|
||||
{$inc: {trainCount, buyTrainCount: -1 * trainCount}}, {new: true}).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async resetTrainUserGuild(guildCode: string) {
|
||||
const result = await UserGuildModel.updateMany({ guildCode }, {$set: { trainCount: ARMY.ARMY_TRAIN_BUYTIMES, buyTrainCount: 0, trainTime: nowSeconds(), trainRewards: [] }});
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const UserGuildModel = getModelForClass(UserGuild);
|
||||
|
||||
@@ -344,14 +344,15 @@ export function getBossByLv(lv: number) {
|
||||
export function getArmyTrainJuDian(trainId: number) {
|
||||
return gameData.armyTrainJuDian.get(trainId);
|
||||
}
|
||||
|
||||
export function getTrainSoloReward(id: number) {
|
||||
return gameData.trainSoloReward.get(id);
|
||||
}
|
||||
|
||||
export function getTrainBaseByLv(lv: number) {
|
||||
return gameData.trainBase.get(lv);
|
||||
}
|
||||
|
||||
|
||||
export function getGuildActiveWeekReward(point: number) {
|
||||
let result = gameData.guildActiveWeekReward.find(cur => {
|
||||
let {weekPointMax, weekPointMin} = cur;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { readJsonFile, parseGoodStr } from '../util'
|
||||
import { FILENAME } from '../../consts'
|
||||
type KeysEnum<T> = { [P in keyof Required<T>]: true };
|
||||
import { RewardInter } from '../interface';
|
||||
const _ = require('lodash');
|
||||
|
||||
export interface DicArmyTrainJuDian {
|
||||
@@ -9,12 +10,15 @@ export interface DicArmyTrainJuDian {
|
||||
// 目标品质
|
||||
readonly trainInstances: Array<{hid: number, warId: number, progress: number}>;
|
||||
readonly heroRewards: Array<{id: number, count: number}>;
|
||||
// 进阶奖励
|
||||
readonly jinjieReward: RewardInter[];
|
||||
}
|
||||
|
||||
const DicArmyTrainJuDianKeys: KeysEnum<DicArmyTrainJuDian> = {
|
||||
id: true,
|
||||
trainInstances: true,
|
||||
heroRewards: true
|
||||
heroRewards: true,
|
||||
jinjieReward: true
|
||||
};
|
||||
|
||||
const str = readJsonFile(FILENAME.DIC_ARMY_TRAIN_JU_DIAN);
|
||||
@@ -26,7 +30,8 @@ arr.forEach(o => {
|
||||
let arr = element.split('&');
|
||||
return {hid: parseInt(arr[0]), warId: parseInt(arr[1]), progress: parseInt(arr[2])};
|
||||
});
|
||||
|
||||
o.jinjieReward = parseGoodStr(o.jinjieReward);
|
||||
|
||||
o.heroRewards = parseGoodStr(o.shilianReward);
|
||||
|
||||
dicArmyTrainJuDian.set(o.id,_.pick(o, Object.keys(DicArmyTrainJuDianKeys)));
|
||||
|
||||
@@ -80,8 +80,7 @@ export interface DicTrainBase {
|
||||
readonly difficultyRatio: number;
|
||||
// 据点奖励增长系数
|
||||
readonly judianRewardRatio: number;
|
||||
// 进阶奖励
|
||||
readonly jinjieReward: RewardInter[];
|
||||
|
||||
}
|
||||
|
||||
const DicTrainKeys: KeysEnum<DicTrainBase> = {
|
||||
@@ -90,7 +89,6 @@ const DicTrainKeys: KeysEnum<DicTrainBase> = {
|
||||
trainLevel: true,
|
||||
difficultyRatio: true,
|
||||
judianRewardRatio: true,
|
||||
jinjieReward: true
|
||||
};
|
||||
|
||||
// 捐献所
|
||||
@@ -200,7 +198,6 @@ const strTrain = readJsonFile(FILENAME.DIC_GUILD_TRAIN_BASE);
|
||||
let arrTrain = JSON.parse(strTrain);
|
||||
arrTrain.forEach(o => {
|
||||
setStructureConsume(o);
|
||||
o.jinjieReward = parseGoodStr(o.jinjieReward);
|
||||
dicTrainBase.set(o.level, _.pick(o, Object.keys(DicTrainKeys)));
|
||||
});
|
||||
arrTrain = undefined;
|
||||
|
||||
@@ -54,4 +54,30 @@ export function getWeekDate(now: Date, day: number, hour: number){ //获得本
|
||||
let nowYear = now.getFullYear(); //当前年
|
||||
let nowMonth = now.getMonth(); //月
|
||||
return new Date(nowYear, nowMonth, nowDay - nowDayOfWeek + day, hour);
|
||||
};
|
||||
};
|
||||
|
||||
export function getCurWeekTime(day: number, hour: number) {
|
||||
let data = getWeekDate(new Date(), day, hour);
|
||||
return data.getTime();
|
||||
}
|
||||
|
||||
export function getHourPoint(hour: number) {
|
||||
var date = new Date();
|
||||
date.setHours(hour);
|
||||
date.setMinutes(0);
|
||||
date.setSeconds(0);
|
||||
var time = Math.floor(date.getTime() / PER_SECOND);
|
||||
if (nowSeconds() < time) {
|
||||
return time - PER_DAY;
|
||||
}
|
||||
return time;
|
||||
}
|
||||
|
||||
export function getCurHourPoint(hour: number) {
|
||||
var date = new Date();
|
||||
date.setHours(hour);
|
||||
date.setMinutes(0);
|
||||
date.setSeconds(0);
|
||||
var time = Math.floor(date.getTime() / PER_SECOND);
|
||||
return time;
|
||||
}
|
||||
@@ -1,56 +1,38 @@
|
||||
[
|
||||
{
|
||||
"id": 1,
|
||||
"weekPointMin": 24000,
|
||||
"weekPointMax": -1,
|
||||
"Reward": "31002&8000"
|
||||
"rankMin": 1,
|
||||
"rankMax": 1,
|
||||
"Reward": "31002&550|40005&3000"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"weekPointMin": 20000,
|
||||
"weekPointMax": 23999,
|
||||
"Reward": "31002&6666"
|
||||
"rankMin": 2,
|
||||
"rankMax": 2,
|
||||
"Reward": "31002&500|40005&2800"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"weekPointMin": 15000,
|
||||
"weekPointMax": 19999,
|
||||
"Reward": "31002&5000"
|
||||
"rankMin": 3,
|
||||
"rankMax": 3,
|
||||
"Reward": "31002&480|40005&2600"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"weekPointMin": 10000,
|
||||
"weekPointMax": 14999,
|
||||
"Reward": "31002&3166"
|
||||
"rankMin": 4,
|
||||
"rankMax": 5,
|
||||
"Reward": "31002&420|40005&2400"
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"weekPointMin": 6000,
|
||||
"weekPointMax": 9999,
|
||||
"Reward": "31002&2000"
|
||||
"rankMin": 6,
|
||||
"rankMax": 10,
|
||||
"Reward": "31002&380|40005&2200"
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"weekPointMin": 3000,
|
||||
"weekPointMax": 5999,
|
||||
"Reward": "31002&999"
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"weekPointMin": 2000,
|
||||
"weekPointMax": 2999,
|
||||
"Reward": "31002&666"
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"weekPointMin": 1000,
|
||||
"weekPointMax": 1999,
|
||||
"Reward": "31002&333"
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"weekPointMin": 0,
|
||||
"weekPointMax": 999,
|
||||
"Reward": "31002&111"
|
||||
"rankMin": 11,
|
||||
"rankMax": -1,
|
||||
"Reward": "31002&300|40005&1800"
|
||||
}
|
||||
]
|
||||
27
shared/resource/jsons/dic_army_joinCondition.json
Normal file
27
shared/resource/jsons/dic_army_joinCondition.json
Normal file
@@ -0,0 +1,27 @@
|
||||
[
|
||||
{
|
||||
"id": 1,
|
||||
"lvLimit": 0,
|
||||
"describe": "不限"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"lvLimit": 10000,
|
||||
"describe": "10000+"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"lvLimit": 50000,
|
||||
"describe": "50000+"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"lvLimit": 100000,
|
||||
"describe": "10万+"
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"lvLimit": 200000,
|
||||
"describe": "20万+"
|
||||
}
|
||||
]
|
||||
@@ -3,42 +3,42 @@
|
||||
"id": 1,
|
||||
"name": "大将军",
|
||||
"rankProportion": 0,
|
||||
"sellRatio": 5,
|
||||
"activeRatio": 5
|
||||
"sellRatio": 3,
|
||||
"activeRatio": 3
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "将军",
|
||||
"rankProportion": 5,
|
||||
"sellRatio": 20,
|
||||
"activeRatio": 20
|
||||
"sellRatio": 2.5,
|
||||
"activeRatio": 2.5
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"name": "校尉",
|
||||
"rankProportion": 15,
|
||||
"sellRatio": 30,
|
||||
"activeRatio": 30
|
||||
"sellRatio": 2,
|
||||
"activeRatio": 2
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"name": "什长",
|
||||
"rankProportion": 30,
|
||||
"sellRatio": 25,
|
||||
"activeRatio": 25
|
||||
"sellRatio": 1.5,
|
||||
"activeRatio": 1.5
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"name": "伍长",
|
||||
"rankProportion": 50,
|
||||
"sellRatio": 20,
|
||||
"activeRatio": 20
|
||||
"sellRatio": 1.2,
|
||||
"activeRatio": 1.2
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"name": "士兵",
|
||||
"rankProportion": 100,
|
||||
"sellRatio": 0,
|
||||
"activeRatio": 0
|
||||
"sellRatio": 1,
|
||||
"activeRatio": 1
|
||||
}
|
||||
]
|
||||
@@ -8,8 +8,7 @@
|
||||
"difficultyRatio": 1,
|
||||
"shilianRewardRatio": 1,
|
||||
"consume": 5000,
|
||||
"buildWords": "&",
|
||||
"jinjieReward": "40005&2000|31002&3000"
|
||||
"buildWords": "&"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
@@ -20,8 +19,7 @@
|
||||
"difficultyRatio": 1.1,
|
||||
"shilianRewardRatio": 1.1,
|
||||
"consume": 6000,
|
||||
"buildWords": "&",
|
||||
"jinjieReward": "40005&3000|31002&3000"
|
||||
"buildWords": "&"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
@@ -32,8 +30,7 @@
|
||||
"difficultyRatio": 1.2,
|
||||
"shilianRewardRatio": 1.2,
|
||||
"consume": 7000,
|
||||
"buildWords": "&",
|
||||
"jinjieReward": "40005&2000|31002&3001"
|
||||
"buildWords": "&"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
@@ -44,8 +41,7 @@
|
||||
"difficultyRatio": 1.3,
|
||||
"shilianRewardRatio": 1.3,
|
||||
"consume": 8000,
|
||||
"buildWords": "&",
|
||||
"jinjieReward": "40005&3000|31002&3001"
|
||||
"buildWords": "&"
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
@@ -56,8 +52,7 @@
|
||||
"difficultyRatio": 1.4,
|
||||
"shilianRewardRatio": 1.4,
|
||||
"consume": 9000,
|
||||
"buildWords": "&",
|
||||
"jinjieReward": "40005&2000|31002&3002"
|
||||
"buildWords": "&"
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
@@ -68,8 +63,7 @@
|
||||
"difficultyRatio": 1.5,
|
||||
"shilianRewardRatio": 1.5,
|
||||
"consume": 10000,
|
||||
"buildWords": "&",
|
||||
"jinjieReward": "40005&3000|31002&3002"
|
||||
"buildWords": "&"
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
@@ -80,8 +74,7 @@
|
||||
"difficultyRatio": 1.6,
|
||||
"shilianRewardRatio": 1.6,
|
||||
"consume": 11000,
|
||||
"buildWords": "&",
|
||||
"jinjieReward": "40005&2000|31002&3003"
|
||||
"buildWords": "&"
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
@@ -92,8 +85,7 @@
|
||||
"difficultyRatio": 1.7,
|
||||
"shilianRewardRatio": 1.7,
|
||||
"consume": 12000,
|
||||
"buildWords": "&",
|
||||
"jinjieReward": "40005&3000|31002&3003"
|
||||
"buildWords": "&"
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
@@ -104,8 +96,7 @@
|
||||
"difficultyRatio": 1.8,
|
||||
"shilianRewardRatio": 1.8,
|
||||
"consume": 13000,
|
||||
"buildWords": "&",
|
||||
"jinjieReward": "40005&2000|31002&3004"
|
||||
"buildWords": "&"
|
||||
},
|
||||
{
|
||||
"id": 10,
|
||||
@@ -116,7 +107,6 @@
|
||||
"difficultyRatio": 2,
|
||||
"shilianRewardRatio": 2,
|
||||
"consume": 15000,
|
||||
"buildWords": "&",
|
||||
"jinjieReward": "40005&3000|31002&3004"
|
||||
"buildWords": "&"
|
||||
}
|
||||
]
|
||||
@@ -6,7 +6,8 @@
|
||||
"heroid": "1&3&5&4",
|
||||
"gkid": "1&8501&800|3&8502&800|5&8503&800|7&8504&800",
|
||||
"shilianReward": "40005&6000|20001&60|21008&30|42008&10",
|
||||
"soloRewardRatio": 1
|
||||
"soloRewardRatio": 1,
|
||||
"jinjieReward": "40005&2000|31002&3000"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
@@ -15,7 +16,8 @@
|
||||
"heroid": "2&3&5&7",
|
||||
"gkid": "2&8505&800|3&8506&800|5&8507&800|7&8508&800",
|
||||
"shilianReward": "40005&4000|20001&60|21008&30|42008&11",
|
||||
"soloRewardRatio": 1.1
|
||||
"soloRewardRatio": 1.1,
|
||||
"jinjieReward": "40005&3000|31002&3000"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
@@ -24,7 +26,8 @@
|
||||
"heroid": "7&8&9&10",
|
||||
"gkid": "7&8509&800|8&8510&800|9&8511&800|10&8512&800",
|
||||
"shilianReward": "40005&3000|20001&60|21008&30|42008&12",
|
||||
"soloRewardRatio": 1.2
|
||||
"soloRewardRatio": 1.2,
|
||||
"jinjieReward": "40005&2000|31002&3001"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
@@ -33,7 +36,8 @@
|
||||
"heroid": "11&12&13&14",
|
||||
"gkid": "11&8513&800|12&8514&800|13&8515&800|14&8516&800",
|
||||
"shilianReward": "40005&2000|20001&60|21008&30|42008&13",
|
||||
"soloRewardRatio": 1.3
|
||||
"soloRewardRatio": 1.3,
|
||||
"jinjieReward": "40005&3000|31002&3001"
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
@@ -42,7 +46,8 @@
|
||||
"heroid": "7&8&9&11",
|
||||
"gkid": "7&8517&800|8&8518&800|9&8519&800|11&8520&800",
|
||||
"shilianReward": "40005&1000|20001&60|21008&30|42008&14",
|
||||
"soloRewardRatio": 1.4
|
||||
"soloRewardRatio": 1.4,
|
||||
"jinjieReward": "40005&2000|31002&3002"
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
@@ -51,7 +56,8 @@
|
||||
"heroid": "11&12&13&15",
|
||||
"gkid": "11&8521&800|12&8522&800|13&8523&800|15&8524&800",
|
||||
"shilianReward": "40005&500|20001&60|21008&30|42008&15",
|
||||
"soloRewardRatio": 1.5
|
||||
"soloRewardRatio": 1.5,
|
||||
"jinjieReward": "40005&3000|31002&3002"
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
@@ -60,7 +66,8 @@
|
||||
"heroid": "7&8&9&12",
|
||||
"gkid": "7&8525&800|8&8526&800|9&8527&800|12&8528&800",
|
||||
"shilianReward": "40005&6000|20001&60|21008&30|42008&16",
|
||||
"soloRewardRatio": 1.6
|
||||
"soloRewardRatio": 1.6,
|
||||
"jinjieReward": "40005&2000|31002&3003"
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
@@ -69,7 +76,8 @@
|
||||
"heroid": "11&12&13&16",
|
||||
"gkid": "11&8529&800|12&8530&800|13&8531&800|16&8532&800",
|
||||
"shilianReward": "40005&4000|20001&60|21008&30|42008&17",
|
||||
"soloRewardRatio": 1.7
|
||||
"soloRewardRatio": 1.7,
|
||||
"jinjieReward": "40005&3000|31002&3003"
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
@@ -78,7 +86,8 @@
|
||||
"heroid": "7&8&9&13",
|
||||
"gkid": "7&8533&800|8&8534&800|9&8535&800|13&8536&800",
|
||||
"shilianReward": "40005&3000|20001&60|21008&30|42008&18",
|
||||
"soloRewardRatio": 1.8
|
||||
"soloRewardRatio": 1.8,
|
||||
"jinjieReward": "40005&2000|31002&3004"
|
||||
},
|
||||
{
|
||||
"id": 10,
|
||||
@@ -87,6 +96,7 @@
|
||||
"heroid": "11&12&13&17",
|
||||
"gkid": "11&8537&800|12&8538&800|13&8539&800|17&8540&800",
|
||||
"shilianReward": "40005&2000|20001&60|21008&30|42008&19",
|
||||
"soloRewardRatio": 2
|
||||
"soloRewardRatio": 2,
|
||||
"jinjieReward": "40005&3000|31002&3004"
|
||||
}
|
||||
]
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user