练兵场结算
This commit is contained in:
@@ -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