练兵场结算
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);
|
||||
|
||||
Reference in New Issue
Block a user