活动:成长活动统计任务,领取奖励接口
This commit is contained in:
@@ -2,6 +2,12 @@ import { Application, BackendSession } from 'pinus';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { STATUS, } from '../../../consts';
|
||||
import { getPlayerGrowthData } from '../../../services/growthService';
|
||||
import { GrowthItem } from '../../../domain/activityField/growthField';
|
||||
import { addItems, createHero } from '../../../services/rewardService';
|
||||
import { HeroModel } from '../../../db/Hero';
|
||||
import { gameData } from '../../../pubUtils/data';
|
||||
import { ActivityModelType } from '../../../db/Activity';
|
||||
import { ActivityGrowthModel } from '../../../db/ActivityGrowth';
|
||||
|
||||
|
||||
export default function (app: Application) {
|
||||
@@ -22,10 +28,8 @@ export class SevenDaysHandler {
|
||||
const { activityId } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
// const funcs: number[] = session.get('funcs');
|
||||
// const sid = session.get('sid');
|
||||
|
||||
let playerData = getPlayerGrowthData(activityId, serverId, roleId)
|
||||
let playerData = await getPlayerGrowthData(activityId, serverId, roleId)
|
||||
|
||||
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
|
||||
@@ -39,17 +43,54 @@ export class SevenDaysHandler {
|
||||
* @memberof SevenDaysHandler
|
||||
*/
|
||||
async getGrowthCellReward(msg: { activityId: number, dayIndex: number, cellIndex: number, type: number }, session: BackendSession) {
|
||||
const { activityId } = msg;
|
||||
const { activityId, dayIndex, cellIndex, type } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
// const funcs: number[] = session.get('funcs');
|
||||
// const sid = session.get('sid');
|
||||
|
||||
let playerData = getPlayerGrowthData(activityId, serverId, roleId)
|
||||
const sid = session.get('sid');
|
||||
const roleName = session.get('roleName');
|
||||
|
||||
let playerData = await getPlayerGrowthData(activityId, serverId, roleId)
|
||||
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
|
||||
return resResult(STATUS.SUCCESS, playerData);
|
||||
let growthItemData: GrowthItem = playerData.findGrowthItem(dayIndex, cellIndex, type);
|
||||
if (!growthItemData) {
|
||||
return resResult(STATUS.ACTIVITY_DATA_ERROR);
|
||||
}
|
||||
if (!growthItemData.isComplete()) {//未完成任务
|
||||
return resResult(STATUS.ACTIVITY_TASK_UNCOMPLETED);
|
||||
}
|
||||
if (!growthItemData.canReceive()) {//已经领取过
|
||||
return resResult(STATUS.ACTIVITY_REWARDED);
|
||||
}
|
||||
|
||||
await ActivityGrowthModel.addCellRecord(activityId, roleId, dayIndex, cellIndex, type, 1);
|
||||
let reward = growthItemData.goodReward();
|
||||
let goods = await addItems(roleId, roleName, sid, reward);
|
||||
let heroReward = growthItemData.heroReward();
|
||||
let addHeros = [];
|
||||
if (heroReward.length > 0) {
|
||||
for (let heroParam of heroReward) {
|
||||
// 检查是否存在武将
|
||||
let hid = heroParam.id;
|
||||
let count = heroParam.count;
|
||||
let hasHero = await HeroModel.findByHidAndRole(hid, roleId);
|
||||
if (hasHero && count > 1) {//已经有武将
|
||||
|
||||
continue;
|
||||
}
|
||||
// 根据dic_hero 获得 1. 碎片id 2. 碎片数量 3. 初始武将星级 4. 初始品质
|
||||
let dicHero = gameData.hero.get(hid);
|
||||
if (!dicHero) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
let { pieceId, quality, initialStars: star, pieceCount, jobid: job, name: hName, initialSkin } = dicHero;
|
||||
// createHero
|
||||
let hero = await createHero(roleId, sid, serverId, {
|
||||
roleId, serverId, roleName, hid, hName, star, quality, job, skins: [{ id: initialSkin, enable: true }]
|
||||
});
|
||||
addHeros.push(hero);
|
||||
}
|
||||
}
|
||||
|
||||
return resResult(STATUS.SUCCESS, { playerData, goods, addHeros });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,17 +100,55 @@ export class SevenDaysHandler {
|
||||
* @memberof SevenDaysHandler
|
||||
*/
|
||||
async getGrowthDayReward(msg: { activityId: number, dayIndex: number }, session: BackendSession) {
|
||||
const { activityId } = msg;
|
||||
const { activityId, dayIndex } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
// const funcs: number[] = session.get('funcs');
|
||||
// const sid = session.get('sid');
|
||||
|
||||
let playerData = getPlayerGrowthData(activityId, serverId, roleId)
|
||||
const sid = session.get('sid');
|
||||
const roleName = session.get('roleName');
|
||||
|
||||
let playerData = await getPlayerGrowthData(activityId, serverId, roleId)
|
||||
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
|
||||
return resResult(STATUS.SUCCESS, playerData);
|
||||
let dayItemData: GrowthItem = playerData.findDayItem(dayIndex);
|
||||
if (!dayItemData) {
|
||||
return resResult(STATUS.ACTIVITY_DATA_ERROR);
|
||||
}
|
||||
if (playerData.totalPoint - playerData.totalConsumePoint < dayItemData.consumePoint) {
|
||||
return resResult(STATUS.ACTIVITY_NO_POINT);
|
||||
}
|
||||
if (dayItemData.getPointReward) {//已经领取过
|
||||
return resResult(STATUS.ACTIVITY_REWARDED);
|
||||
}
|
||||
|
||||
await ActivityGrowthModel.addDayRecord(activityId, roleId, dayIndex, 1);
|
||||
|
||||
let reward = dayItemData.goodReward();
|
||||
let goods = await addItems(roleId, roleName, sid, reward);
|
||||
let heroReward = dayItemData.heroReward();
|
||||
let addHeros = [];
|
||||
if (heroReward.length > 0) {
|
||||
for (let heroParam of heroReward) {
|
||||
// 检查是否存在武将
|
||||
let hid = heroParam.id;
|
||||
let count = heroParam.count;
|
||||
let hasHero = await HeroModel.findByHidAndRole(hid, roleId);
|
||||
if (hasHero && count > 1) {//已经有武将
|
||||
|
||||
continue;
|
||||
}
|
||||
// 根据dic_hero 获得 1. 碎片id 2. 碎片数量 3. 初始武将星级 4. 初始品质
|
||||
let dicHero = gameData.hero.get(hid);
|
||||
if (!dicHero) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
let { pieceId, quality, initialStars: star, pieceCount, jobid: job, name: hName, initialSkin } = dicHero;
|
||||
// createHero
|
||||
let hero = await createHero(roleId, sid, serverId, {
|
||||
roleId, serverId, roleName, hid, hName, star, quality, job, skins: [{ id: initialSkin, enable: true }]
|
||||
});
|
||||
addHeros.push(hero);
|
||||
}
|
||||
}
|
||||
|
||||
return resResult(STATUS.SUCCESS, { playerData, goods, addHeros });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,12 +4,12 @@ import { STATUS, TASK_TYPE } from '../../../consts';
|
||||
import { GuildTrainModel } from '../../../db/GuildTrain';
|
||||
import { BattleRecordModel } from '../../../db/BattleRecord';
|
||||
import { nowSeconds, getHourPoint, getCurHourPoint } from '../../../pubUtils/timeUtil';
|
||||
import { getUserGuild, getGuildTrainInfo, unlockTrain, resetTrain, getGuildTrainRewards} from '../../../services/guildTrainService';
|
||||
import { getUserGuild, getGuildTrainInfo, unlockTrain, resetTrain, getGuildTrainRewards } from '../../../services/guildTrainService';
|
||||
import { findIndex, findWhere, indexBy } from 'underscore'
|
||||
import { lockData } from '../../../services/redLockService';
|
||||
import { lockData } from '../../../services/redLockService';
|
||||
import { REFRESH_HOUR, GUILD_REPORT_NUM, GUILD_POINT_WAYS } from '../../../consts/constModules/guildConst';
|
||||
import { UserGuildModel } from '../../../db/UserGuild';
|
||||
import { GuildModel } from '../../../db/Guild';
|
||||
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';
|
||||
@@ -19,6 +19,7 @@ import { GuildTrainReportModel } from '../../../db/GuildTrainReport';
|
||||
import { DATA_NAME } from '../../../consts/dataName';
|
||||
import { pushGuildTrainSucMsg } from '../../../services/chatService';
|
||||
import { checkTask } from '../../../services/taskService';
|
||||
import { accomplishTask } from '../../../pubUtils/taskUtil';
|
||||
|
||||
export default function (app: Application) {
|
||||
return new GuildTrainHandler(app);
|
||||
@@ -34,17 +35,17 @@ export class GuildTrainHandler {
|
||||
const roleId: string = session.get('roleId');
|
||||
const serverId: number = parseInt(session.get('serverId'));
|
||||
let userGuild = await getUserGuild(roleId, serverId);
|
||||
if (!userGuild)
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code } = userGuild;
|
||||
let { trainId, trainLv } = await GuildModel.findGuild(code, serverId, 'trainId trainLv');
|
||||
let guildTrain = await GuildTrainModel.findTrainByTrainIdNotLock(code, trainId);
|
||||
if (!guildTrain ) {
|
||||
if (!guildTrain) {
|
||||
guildTrain = await unlockTrain(code, trainId);
|
||||
}
|
||||
let { trainCount, trainRewards, buyTrainCount } = userGuild;
|
||||
let result:any = getGuildTrainInfo(guildTrain, roleId, trainCount, trainRewards);
|
||||
result.buyTrainCount = buyTrainCount||0;
|
||||
let result: any = getGuildTrainInfo(guildTrain, roleId, trainCount, trainRewards);
|
||||
result.buyTrainCount = buyTrainCount || 0;
|
||||
result.trainLv = trainLv;
|
||||
return resResult(STATUS.SUCCESS, result);
|
||||
}
|
||||
@@ -53,7 +54,7 @@ export class GuildTrainHandler {
|
||||
const roleId: string = session.get('roleId');
|
||||
const serverId: number = parseInt(session.get('serverId'));
|
||||
let userGuild = await getUserGuild(roleId, serverId);
|
||||
if (!userGuild)
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code } = userGuild;
|
||||
let trainIds = [];
|
||||
@@ -63,11 +64,11 @@ export class GuildTrainHandler {
|
||||
trainIds.push(trainId - 1);
|
||||
let trainReports = await GuildTrainReportModel.findGuildTrainByTrainIds(code, trainIds);
|
||||
let reports = [];
|
||||
trainReports.map(({ reports: resReports, trainId: resTrainId})=>{
|
||||
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 });
|
||||
@@ -78,30 +79,30 @@ export class GuildTrainHandler {
|
||||
const roleId: string = session.get('roleId');
|
||||
const serverId: number = parseInt(session.get('serverId'));
|
||||
let userGuild = await getUserGuild(roleId, serverId);
|
||||
if (!userGuild)
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code } = userGuild;
|
||||
let guildTrains = await GuildTrainModel.findGuildTrain(code);//获得未失效的宝箱奖励
|
||||
let resTrainBoxs = [];
|
||||
guildTrains.forEach(({trainInstances, trainId}) =>{
|
||||
guildTrains.forEach(({ trainInstances, trainId }) => {
|
||||
let { trainInstances: instances } = getArmyTrainJuDian(trainId);
|
||||
let flag = false;
|
||||
let boxRewards = [];
|
||||
trainInstances.map(({hid, progress, endTime, trainBoxs})=>{
|
||||
trainInstances.map(({ hid, progress, endTime, trainBoxs }) => {
|
||||
let isComplete = false;
|
||||
let instance = findWhere(instances, { hid });
|
||||
if ( progress >= instance.progress) {
|
||||
if (progress >= instance.progress) {
|
||||
isComplete = true;
|
||||
if (endTime > nowSeconds())
|
||||
if (endTime > nowSeconds())
|
||||
flag = true;
|
||||
}
|
||||
boxRewards.push({hid, recordBoxs: trainBoxs, trainId, endTime, isComplete});
|
||||
boxRewards.push({ hid, recordBoxs: trainBoxs, trainId, endTime, isComplete });
|
||||
});
|
||||
if (flag) {
|
||||
resTrainBoxs.push({ trainId, boxRewards });
|
||||
}
|
||||
})
|
||||
return resResult(STATUS.SUCCESS, {trainBoxRewards: resTrainBoxs});
|
||||
return resResult(STATUS.SUCCESS, { trainBoxRewards: resTrainBoxs });
|
||||
}
|
||||
/**
|
||||
* 挑战练兵副本
|
||||
@@ -114,35 +115,35 @@ export class GuildTrainHandler {
|
||||
const roleName = session.get('roleName');
|
||||
const serverId = parseInt(session.get('serverId'));
|
||||
let userGuild = await getUserGuild(roleId, serverId);
|
||||
if (!userGuild)
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code } = userGuild;
|
||||
if (userGuild.trainCount <= 0)
|
||||
if (userGuild.trainCount <= 0)
|
||||
return resResult(STATUS.GUILD_TRAIN_BATTLE_COUNT_NOT_ENOUGH);
|
||||
let { trainId: curTeainId } = await GuildModel.findGuild(code, serverId, 'trainId');
|
||||
if (curTeainId !== trainId)
|
||||
if (curTeainId !== trainId)
|
||||
return resResult(STATUS.GUILD_TRAIN_LEVEL_IS_COMPLETE);
|
||||
let guildTrain = await GuildTrainModel.findTrainByTrainIdNotLock(code, trainId, 'trainId isComplete trainInstances');
|
||||
if (!guildTrain && guildTrain.isComplete)
|
||||
if (!guildTrain && guildTrain.isComplete)
|
||||
return resResult(STATUS.GUILD_TRAIN_SCRIPT_NOT_OPENED);
|
||||
let { trainInstances } = getArmyTrainJuDian(trainId);
|
||||
let instance = findWhere(trainInstances, { hid });
|
||||
if (!instance)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let trainInstance = findWhere(guildTrain.trainInstances, { hid });
|
||||
if (!trainInstance)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
if (!trainInstance)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
if (trainInstance.progress >= instance.progress) {
|
||||
return resResult(STATUS.GUILD_TRAIN_IS_COMPLETE);
|
||||
}
|
||||
return resResult(STATUS.GUILD_TRAIN_IS_COMPLETE);
|
||||
}
|
||||
const battleCode = genCode(8); // 关卡唯一值
|
||||
await BattleRecordModel.updateBattleRecordByCode(battleCode, {
|
||||
$set: {
|
||||
roleId, roleName, battleId: instance.warId,
|
||||
status: 0,
|
||||
record: { heroes:[], trainId, hid, guildCode: code, difficulty},
|
||||
record: { heroes: [], trainId, hid, guildCode: code, difficulty },
|
||||
}
|
||||
}, true);
|
||||
}, true);
|
||||
return resResult(STATUS.SUCCESS, { battleCode });
|
||||
}
|
||||
/**
|
||||
@@ -150,7 +151,7 @@ export class GuildTrainHandler {
|
||||
* @param msg
|
||||
* @param session
|
||||
*/
|
||||
async trainBattleEnd(msg: { battleCode: string, isSuccess: boolean}, session: BackendSession) {
|
||||
async trainBattleEnd(msg: { battleCode: string, isSuccess: boolean }, session: BackendSession) {
|
||||
const { battleCode, isSuccess } = msg;
|
||||
const roleId: string = session.get('roleId');
|
||||
const serverId: number = parseInt(session.get('serverId'));
|
||||
@@ -158,33 +159,33 @@ export class GuildTrainHandler {
|
||||
const sid: string = session.get('sid');
|
||||
const funcs: number[] = session.get('funcs');
|
||||
let userGuild = await getUserGuild(roleId, serverId);
|
||||
if (!userGuild)
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code } = userGuild;
|
||||
const battleRecord = await BattleRecordModel.getBattleRecordByCode(battleCode, true);
|
||||
if (!battleRecord || battleRecord.status != 0 || roleId != battleRecord.roleId || battleRecord.record.guildCode != code) {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
let time = Math.floor(battleRecord.createdAt.getTime()/1000);
|
||||
}
|
||||
let time = Math.floor(battleRecord.createdAt.getTime() / 1000);
|
||||
if (userGuild.trainCount - 1 < 0) {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
|
||||
if (time < getCurHourPoint(REFRESH_HOUR) && nowSeconds() > getCurHourPoint(REFRESH_HOUR)) {
|
||||
}
|
||||
|
||||
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, {
|
||||
$set: { status: isSuccess?1:2 }
|
||||
$set: { status: isSuccess ? 1 : 2 }
|
||||
}, true);//设置战斗状态
|
||||
|
||||
|
||||
let trainId = battleRecord.record.trainId;
|
||||
let hid = battleRecord.record.hid;
|
||||
let res:any = await lockData(serverId, DATA_NAME.TRAIN, code + '_' + trainId);//加锁
|
||||
if (!!res.err)
|
||||
return resResult(STATUS.REDLOCK_ERR);
|
||||
let res: any = await lockData(serverId, DATA_NAME.TRAIN, code + '_' + trainId);//加锁
|
||||
if (!!res.err)
|
||||
return resResult(STATUS.REDLOCK_ERR);
|
||||
let guildTrain = await GuildTrainModel.findTrainByTrainIdNotLock(code, trainId);
|
||||
if (!guildTrain) {
|
||||
res.releaseCallback();//解锁
|
||||
@@ -193,7 +194,7 @@ export class GuildTrainHandler {
|
||||
let trainInstance = findWhere(guildTrain.trainInstances, { hid });
|
||||
if (!trainInstance) {
|
||||
res.releaseCallback();//解锁
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
|
||||
let { trainInstances, soloRewardRatio } = getArmyTrainJuDian(trainId);
|
||||
@@ -205,28 +206,28 @@ export class GuildTrainHandler {
|
||||
let trainSoloReward = getTrainSoloReward(battleRecord.record.difficulty);
|
||||
if (!trainSoloReward) {//获得个人奖励信息
|
||||
res.releaseCallback();//解锁
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
let addScore = Math.floor((isSuccess?trainSoloReward.winScore:trainSoloReward.failScore));//个人获得积分,也是压制进度
|
||||
let addScore = Math.floor((isSuccess ? trainSoloReward.winScore : trainSoloReward.failScore));//个人获得积分,也是压制进度
|
||||
//个人功勋奖励
|
||||
let goods = await addItems(roleId, roleName, sid, [{id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.HONOUR), count: Math.floor((isSuccess?trainSoloReward.winHonour:trainSoloReward.failHonour) * (soloRewardRatio + 100 ) / 100)}]);
|
||||
let goods = await addItems(roleId, roleName, sid, [{ id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.HONOUR), count: Math.floor((isSuccess ? trainSoloReward.winHonour : trainSoloReward.failHonour) * (soloRewardRatio + 100) / 100) }]);
|
||||
let { isComplete, ranks } = guildTrain;
|
||||
let reports = [];
|
||||
let index = findIndex(ranks, {roleId});
|
||||
let index = findIndex(ranks, { roleId });
|
||||
if (index !== -1) {
|
||||
ranks[index].score += addScore;//更新原有的排名信息
|
||||
} else {
|
||||
ranks.push({score: addScore, roleId});//新增排名
|
||||
ranks.push({ score: addScore, roleId });//新增排名
|
||||
}
|
||||
let needLockNext = false;
|
||||
let report = {roleName, trainId, hid, score: addScore, time: nowSeconds(), type: isSuccess?2:1, difficulty: battleRecord.record.difficulty};//type 1:失败, 2:成功,3:表示系统战报即:被成功压制
|
||||
let report = { roleName, trainId, hid, score: addScore, time: nowSeconds(), type: isSuccess ? 2 : 1, difficulty: battleRecord.record.difficulty };//type 1:失败, 2:成功,3:表示系统战报即:被成功压制
|
||||
reports.push(report);
|
||||
if (trainInstance.progress < instance.progress ) {
|
||||
if (trainInstance.progress < instance.progress) {
|
||||
if (trainInstance.progress + addScore >= instance.progress) {
|
||||
//压制成功
|
||||
if (!isComplete) {
|
||||
isComplete = true;
|
||||
guildTrain.trainInstances.forEach(({hid: otherHid, progress})=>{
|
||||
guildTrain.trainInstances.forEach(({ hid: otherHid, progress }) => {
|
||||
if (hid != otherHid && progress != instance.progress) {
|
||||
isComplete = false;
|
||||
}
|
||||
@@ -237,12 +238,12 @@ export class GuildTrainHandler {
|
||||
}
|
||||
let progress = instance.progress;
|
||||
guildTrain = await GuildTrainModel.updateGuildTrainProgress(code, trainId, hid, progress, ranks, isComplete);
|
||||
|
||||
|
||||
//type 1:失败, 2:成功,3:表示系统战报即:被成功压制
|
||||
reports.push({ type: 3, time:nowSeconds(), score: addScore, roleName, trainId, hid, difficulty: battleRecord.record.difficulty });
|
||||
reports.push({ type: 3, time: nowSeconds(), score: addScore, roleName, trainId, hid, difficulty: battleRecord.record.difficulty });
|
||||
pushGuildTrainSucMsg(roleId, roleName, code, hid);
|
||||
|
||||
if (needLockNext) {
|
||||
|
||||
if (needLockNext) {
|
||||
guildTrain = await unlockTrain(code, trainId + 1);
|
||||
}
|
||||
res.releaseCallback();//解锁
|
||||
@@ -254,20 +255,22 @@ export class GuildTrainHandler {
|
||||
}
|
||||
} else {
|
||||
//玩家结算前已经完成进度,修改玩家的排名
|
||||
guildTrain = await GuildTrainModel.updateGuildTrain(code, trainId, { ranks});
|
||||
guildTrain = await GuildTrainModel.updateGuildTrain(code, trainId, { ranks });
|
||||
res.releaseCallback();//解锁
|
||||
}
|
||||
await GuildTrainReportModel.pushGuildTrainReports(code, trainId, reports);//增加战报
|
||||
let { trainCount, trainRewards } = userGuild;
|
||||
let result:any = getGuildTrainInfo(guildTrain, roleId, trainCount, trainRewards);//战斗后更新练兵场信息
|
||||
let result: any = getGuildTrainInfo(guildTrain, roleId, trainCount, trainRewards);//战斗后更新练兵场信息
|
||||
result.battleGoods = goods;
|
||||
await addActive(roleId, serverId, GUILD_POINT_WAYS.TRAIN);
|
||||
|
||||
// 任务
|
||||
if(isSuccess) {
|
||||
if (isSuccess) {
|
||||
await checkTask(roleId, sid, funcs, TASK_TYPE.GUILD_TRAIN_SUCESS, 1, true, {});
|
||||
}
|
||||
await checkTask(roleId, sid, funcs, TASK_TYPE.GUILD_TRAIN, 1, true, {});
|
||||
//成长任务
|
||||
await accomplishTask(roleId, TASK_TYPE.GUILD_TRAIN, 1)
|
||||
|
||||
return resResult(STATUS.SUCCESS, result);
|
||||
}
|
||||
@@ -276,19 +279,19 @@ export class GuildTrainHandler {
|
||||
* @param msg
|
||||
* @param session
|
||||
*/
|
||||
async getTrainInstanceBox(msg: { trainId: number , hid: number, index: number}, session: BackendSession) {
|
||||
async getTrainInstanceBox(msg: { trainId: number, hid: number, index: number }, session: BackendSession) {
|
||||
let { trainId, hid, index } = msg;
|
||||
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, serverId);
|
||||
if (!userGuild)
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code } = userGuild;
|
||||
let { trainLv } = await GuildModel.findGuild(code, serverId, 'trainLv');
|
||||
let res:any = await lockData(serverId, DATA_NAME.TRAIN_BOX, code + '_' + trainId + '_' + index);//加锁
|
||||
if (!!res.err)
|
||||
let res: any = await lockData(serverId, DATA_NAME.TRAIN_BOX, code + '_' + trainId + '_' + index);//加锁
|
||||
if (!!res.err)
|
||||
return resResult(STATUS.REDLOCK_ERR);
|
||||
|
||||
let { shilianRewardRatio } = getTrainBaseByLv(trainLv);
|
||||
@@ -317,16 +320,16 @@ export class GuildTrainHandler {
|
||||
return resResult(STATUS.GUILD_TRAIN_BOX_IS_GOT);
|
||||
}
|
||||
let good = getRandomByLen(heroRewards);
|
||||
good.count = Math.floor((100 + shilianRewardRatio) * good.count/100);
|
||||
good.count = Math.floor((100 + shilianRewardRatio) * good.count / 100);
|
||||
let goods = await addItems(roleId, roleName, sid, [good]);
|
||||
|
||||
let resGuildTrain = await GuildTrainModel.receiveBoxByIndex(code, roleId, trainId, hid, index, good);
|
||||
res.releaseCallback();//解锁
|
||||
|
||||
|
||||
if (!resGuildTrain) {
|
||||
return resResult(STATUS.GUILD_GET_TRAIN_BOX_FAIL);
|
||||
}
|
||||
let result:any = getGuildTrainRewards(resGuildTrain);
|
||||
let result: any = getGuildTrainRewards(resGuildTrain);
|
||||
|
||||
result.goods = goods;
|
||||
return resResult(STATUS.SUCCESS, result);
|
||||
@@ -336,22 +339,22 @@ export class GuildTrainHandler {
|
||||
* @param msg
|
||||
* @param session
|
||||
*/
|
||||
async getTrainLvUpRewards(msg: {trainId: number }, session: BackendSession) {
|
||||
async getTrainLvUpRewards(msg: { trainId: number }, session: BackendSession) {
|
||||
let { trainId } = msg;
|
||||
const roleId: string = session.get('roleId');
|
||||
const roleName: string = session.get('roleName');
|
||||
const sid: string = session.get('sid');
|
||||
const serverId: number = parseInt(session.get('serverId'));
|
||||
let userGuild = await getUserGuild(roleId, serverId);
|
||||
if (!userGuild)
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code } = userGuild;
|
||||
let guildTrain = await GuildTrainModel.findTrainByTrainIdNotLock(code, trainId);
|
||||
if (!guildTrain||!guildTrain.isComplete)
|
||||
if (!guildTrain || !guildTrain.isComplete)
|
||||
return resResult(STATUS.GUILD_TRAIN_IS_NOT_COMPLETE);
|
||||
let { jinjieReward } = getArmyTrainJuDian(trainId);
|
||||
if (userGuild.trainRewards.indexOf(trainId) != -1)
|
||||
return resResult(STATUS.GUILD_TRAIN_QUALITY_REWARD_IS_GOT);
|
||||
return resResult(STATUS.GUILD_TRAIN_QUALITY_REWARD_IS_GOT);
|
||||
userGuild = await UserGuildModel.receiveTrainRewards(roleId, trainId);
|
||||
if (!userGuild) {
|
||||
return resResult(STATUS.INTERNAL_ERR);
|
||||
@@ -360,20 +363,20 @@ export class GuildTrainHandler {
|
||||
let { trainRewards } = userGuild;
|
||||
return resResult(STATUS.SUCCESS, { trainRewards, goods });
|
||||
}
|
||||
|
||||
|
||||
//购买挑战次数
|
||||
async purchaseTrainCount(msg: {count: number}, session: BackendSession) {
|
||||
async purchaseTrainCount(msg: { count: number }, session: BackendSession) {
|
||||
let { count } = msg;
|
||||
const roleId:string = session.get('roleId');
|
||||
const roleId: string = session.get('roleId');
|
||||
const serverId: number = parseInt(session.get('serverId'));
|
||||
const sid:string = session.get('sid');
|
||||
const sid: string = session.get('sid');
|
||||
let userGuild = await getUserGuild(roleId, serverId);
|
||||
if (!userGuild)
|
||||
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)
|
||||
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 });
|
||||
|
||||
@@ -2,9 +2,9 @@ import { STATUS } from './../../../consts/statusCode';
|
||||
import { EquipModel } from './../../../db/Equip';
|
||||
import { RoleModel } from './../../../db/Role';
|
||||
import { UserModel } from '../../../db/User';
|
||||
import { GMUserModel } from '../../../db/GMUser';
|
||||
import { GMUserModel } from '../../../db/GMUser';
|
||||
import { Application } from 'pinus';
|
||||
import {FrontendSession} from 'pinus';
|
||||
import { FrontendSession } from 'pinus';
|
||||
import { HeroModel } from './../../../db/Hero';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { COM_BTL_QUALITY, ROLE_SELECT, HERO_SELECT, GUILD_SELECT, USER_GUILD_SELECT, DEBUG_MAGIC_WORD, REDIS_KEY, TASK_TYPE } from '../../../consts';
|
||||
@@ -57,27 +57,27 @@ export class EntryHandler {
|
||||
if (connect.isOnline) { // 多地登陆踢下线
|
||||
await self.app.rpc.connector.connectorRemote.remoteLogin.toServer(connect.sid, role.roleId);
|
||||
}
|
||||
let serverName = this.app.getServerId();
|
||||
await roleLogin(role.roleId, user.userCode, serverName, user.pkgName, role.funcs||[]); // 保存在线用户
|
||||
let serverName = this.app.getServerId();
|
||||
await roleLogin(role.roleId, user.userCode, serverName, user.pkgName, role.funcs || []); // 保存在线用户
|
||||
await session.abind(role.roleId);
|
||||
session.set('uid', role.roleId);
|
||||
session.set('roleId', role.roleId);
|
||||
let updatedMailAt = role.updatedMailAt?role.updatedMailAt:0;
|
||||
let updatedMailAt = role.updatedMailAt ? role.updatedMailAt : 0;
|
||||
session.set('updatedMailAt', updatedMailAt);
|
||||
session.set('roleName', role.roleName);
|
||||
session.set('eventStatus', role.eventStatus);
|
||||
session.set('sid', self.app.get('serverId'));
|
||||
session.set('serverId', role.serverId);
|
||||
session.set('funcs', role.funcs||[]);
|
||||
session.set('funcs', role.funcs || []);
|
||||
session.set('guildCode', role.guildCode);
|
||||
session.push('sid', () => {});
|
||||
session.push('roleId', () => {});
|
||||
session.push('roleName', () => {});
|
||||
session.push('eventStatus', () => {});
|
||||
session.push('serverId', () => {});
|
||||
session.push('funcs', () => {});
|
||||
session.push('updatedMailAt', () => {});
|
||||
session.push('guildCode', () => {});
|
||||
session.push('sid', () => { });
|
||||
session.push('roleId', () => { });
|
||||
session.push('roleName', () => { });
|
||||
session.push('eventStatus', () => { });
|
||||
session.push('serverId', () => { });
|
||||
session.push('funcs', () => { });
|
||||
session.push('updatedMailAt', () => { });
|
||||
session.push('guildCode', () => { });
|
||||
console.log(role.guildCode)
|
||||
// session.push('rid', function (err) {
|
||||
// if (err) {
|
||||
@@ -101,7 +101,7 @@ export class EntryHandler {
|
||||
let heros = await HeroModel.findByRole(role.roleId, [], HERO_SELECT.ENTRY, true);
|
||||
let equips = await EquipModel.findbyRole(role.roleId);
|
||||
let items = await ItemModel.findbyRole(role.roleId);
|
||||
let mails = await getMails(role.roleId, serverId)
|
||||
let mails = await getMails(role.roleId, serverId)
|
||||
await chackFunOpenWhenLogin(role, session);
|
||||
await loginRefresh(role.roleId);
|
||||
reportOneOnline(role.roleId, user.userCode, self.app.get('serverId'), user.pkgName);
|
||||
@@ -121,7 +121,7 @@ export class EntryHandler {
|
||||
let apJson = await getAp(Date.now(), role.roleId);
|
||||
role['apJson'] = apJson;
|
||||
role['mails'] = mails;
|
||||
if(!role.showLineup) role.showLineup = role.topLineup.map(cur => cur.hid);
|
||||
if (!role.showLineup) role.showLineup = role.topLineup.map(cur => cur.hid);
|
||||
role.heads = role.heads.filter(cur => cur.status);
|
||||
role.frames = role.frames.filter(cur => cur.status);
|
||||
role.spines = role.spines.filter(cur => cur.status);
|
||||
@@ -133,18 +133,18 @@ export class EntryHandler {
|
||||
role['worldMsgs'] = await recentWorldMsgs(role.serverId);
|
||||
role['sysMsgs'] = await recentSysMsgs(role.serverId);
|
||||
|
||||
if(role.hasGuild) {
|
||||
let userGuild = await UserGuildModel.getMyGuild(role.roleId, USER_GUILD_SELECT.ENTRY );
|
||||
if(userGuild) {
|
||||
if (role.hasGuild) {
|
||||
let userGuild = await UserGuildModel.getMyGuild(role.roleId, USER_GUILD_SELECT.ENTRY);
|
||||
if (userGuild) {
|
||||
let guild = await GuildModel.findGuild(userGuild.guildCode, role.serverId, GUILD_SELECT.ENTRY);
|
||||
if(guild) {
|
||||
if (guild) {
|
||||
addRoleToGuildChannel(role.roleId, self.app.get('serverId'), userGuild.guildCode);
|
||||
role['guildMsgs'] = await recentGuildMsgs(userGuild.guildCode);
|
||||
role['guildAuth'] = userGuild.auth;
|
||||
role['guildCode'] = userGuild.guildCode;
|
||||
let {lv: guildLv, memberCnt} = guild;
|
||||
let { lv: guildLv, memberCnt } = guild;
|
||||
let dicGuild = gameData.centerBase.get(guildLv);
|
||||
if(dicGuild && memberCnt >= dicGuild.peopleNum) {
|
||||
if (dicGuild && memberCnt >= dicGuild.peopleNum) {
|
||||
role['guildMemberMax'] = true;
|
||||
} else {
|
||||
role['guildMemberMax'] = false;
|
||||
@@ -176,8 +176,8 @@ export class EntryHandler {
|
||||
let roleId = session.get('roleId');
|
||||
let sid = session.get('sid');
|
||||
let serverId = session.get('serverId');
|
||||
roleLeave(roleId).then(function(roleInfo) {
|
||||
if(roleInfo.isOnline) {
|
||||
roleLeave(roleId).then(function (roleInfo) {
|
||||
if (roleInfo.isOnline) {
|
||||
reportOneOnline(roleId, roleInfo.userCode, sid, roleInfo.pkgName);
|
||||
}
|
||||
});
|
||||
@@ -201,7 +201,7 @@ export class EntryHandler {
|
||||
* @param {Object} session current session object
|
||||
*/
|
||||
async gmEnter(msg: { token: string, serverId: number }, session: FrontendSession) {
|
||||
|
||||
|
||||
let self = this;
|
||||
|
||||
let user = await GMUserModel.getGmAccountByToken(msg.token);
|
||||
@@ -217,10 +217,10 @@ export class EntryHandler {
|
||||
session.set('roleName', user.name);
|
||||
session.set('eventStatus', 0);
|
||||
session.set('sid', self.app.get('serverId'));
|
||||
session.push('sid', () => {});
|
||||
session.push('roleId', () => {});
|
||||
session.push('roleName', () => {});
|
||||
session.push('eventStatus', () => {});
|
||||
session.push('sid', () => { });
|
||||
session.push('roleId', () => { });
|
||||
session.push('roleName', () => { });
|
||||
session.push('eventStatus', () => { });
|
||||
// session.push('rid', function (err) {
|
||||
// if (err) {
|
||||
// console.error('set rid for session service failed! error is : %j', err.stack);
|
||||
|
||||
@@ -15,6 +15,7 @@ import { handleCost } from "../../../services/rewardService";
|
||||
import { addActive } from "../../../services/guildService";
|
||||
import { Rank } from "../../../services/rankService";
|
||||
import { checkTask } from "../../../services/taskService";
|
||||
import { accomplishTask } from "../../../pubUtils/taskUtil";
|
||||
|
||||
export default function (app: Application) {
|
||||
return new CityActivityHandler(app);
|
||||
@@ -37,10 +38,10 @@ export class CityActivityHandler {
|
||||
const guildCode = session.get('guildCode');
|
||||
|
||||
let statusResult = getGuildActivityStatus(this.aid);
|
||||
if(!statusResult) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if (!statusResult) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
|
||||
const dbCities = await GuildActivityCityModel.getAllCities(serverId);
|
||||
let cities = getCities(guildCode, dbCities);
|
||||
let cities = getCities(guildCode, dbCities);
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
...statusResult,
|
||||
@@ -60,33 +61,33 @@ export class CityActivityHandler {
|
||||
const { cityId } = msg;
|
||||
|
||||
let statusResult = getGuildActivityStatus(this.aid);
|
||||
if(!statusResult) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if (!statusResult) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
|
||||
let dicCity = gameData.cityActivity.get(cityId);
|
||||
if(!dicCity) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if (!dicCity) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
let obj = getCityActivityObj();
|
||||
let gateHp = obj.getGateHpAndInc(serverId, cityId, dicCity.hp);
|
||||
|
||||
let myGuildActivityRec = await UserGuildActivityRecModel.findByRoleId(roleId, this.aid);
|
||||
let challengeTime = 0;
|
||||
if(myGuildActivityRec) {
|
||||
if (myGuildActivityRec) {
|
||||
challengeTime = myGuildActivityRec.challengeTime;
|
||||
}
|
||||
|
||||
const dbCities = await GuildActivityCityModel.getAllCities(serverId);
|
||||
let cityStatus = pubGetCityStatus(guildCode, cityId, dicCity, dbCities);
|
||||
if(cityStatus == CITY_STATUS.DECLARED) {
|
||||
if (cityStatus == CITY_STATUS.DECLARED) {
|
||||
obj.pushGuild(guildCode, serverId, cityId);
|
||||
}
|
||||
|
||||
let historyCity = obj.getHistoryCity(roleId);
|
||||
if(historyCity) {
|
||||
if (historyCity) {
|
||||
await leaveCityChannel(roleId, sid, historyCity);
|
||||
}
|
||||
await addRoleToCityChannel(roleId, sid, cityId);
|
||||
obj.setHistoryCity(roleId, cityId);
|
||||
|
||||
|
||||
|
||||
let ranks = await getCityActivityRank(guildCode, serverId, cityId, roleId, roleName);
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
@@ -110,12 +111,12 @@ export class CityActivityHandler {
|
||||
|
||||
let { cityId } = msg;
|
||||
let dicCity = gameData.cityActivity.get(cityId);
|
||||
if(dicCity.preCity.length > 0) return resResult(STATUS.CAN_NOT_DECLARE);
|
||||
if (dicCity.preCity.length > 0) return resResult(STATUS.CAN_NOT_DECLARE);
|
||||
|
||||
let checkResult = await GuildActivityCityModel.checkDeclartion(serverId, guildCode);
|
||||
if(!!checkResult) return resResult(STATUS.HAS_DECLARED);
|
||||
if (!!checkResult) return resResult(STATUS.HAS_DECLARED);
|
||||
let curCity = await GuildActivityCityModel.getCity(serverId, cityId);
|
||||
if(curCity && curCity.guardGuildCode) {
|
||||
if (curCity && curCity.guardGuildCode) {
|
||||
return resResult(STATUS.CITY_IS_GUARD);
|
||||
}
|
||||
|
||||
@@ -128,67 +129,67 @@ export class CityActivityHandler {
|
||||
obj.pushGuild(guildCode, serverId, cityId);
|
||||
|
||||
const dbCities = await GuildActivityCityModel.getAllCities(serverId);
|
||||
let cities = getCities(guildCode, dbCities);
|
||||
let cities = getCities(guildCode, dbCities);
|
||||
return resResult(STATUS.SUCCESS, { cities });
|
||||
}
|
||||
|
||||
// 开始挑战
|
||||
async checkBattle(msg: {cityId: number, costGold: boolean, heroes: number[]}, session: BackendSession) {
|
||||
async checkBattle(msg: { cityId: number, costGold: boolean, heroes: number[] }, session: BackendSession) {
|
||||
let { cityId, costGold, heroes } = msg;
|
||||
if(!heroes || heroes.length <= 0) return resResult(STATUS.WRONG_PARMS);
|
||||
if (!heroes || heroes.length <= 0) return resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
const roleId = session.get('roleId');
|
||||
const roleName = session.get('roleName');
|
||||
const serverId = session.get('serverId');
|
||||
const guildCode = session.get('guildCode');
|
||||
const sid = session.get('sid');
|
||||
|
||||
if(!guildCode) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
|
||||
|
||||
if (!guildCode) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
|
||||
|
||||
let checkResult = await GuildActivityCityModel.checkDeclartion(serverId, guildCode);
|
||||
if(!checkResult) return resResult(STATUS.HAS_NOT_DECLARED);
|
||||
if (!checkResult) return resResult(STATUS.HAS_NOT_DECLARED);
|
||||
|
||||
let obj = getCityActivityObj();
|
||||
|
||||
const dicCity = gameData.cityActivity.get(cityId);
|
||||
|
||||
let gateHp = obj.getGateHpAndInc(serverId, cityId, dicCity.hp);
|
||||
if(gateHp <= 0) return resResult(STATUS.GATE_HP_IS_ZERO);
|
||||
if (gateHp <= 0) return resResult(STATUS.GATE_HP_IS_ZERO);
|
||||
|
||||
let statusResult = getGuildActivityStatus(this.aid);
|
||||
if(!statusResult) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if (!statusResult) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
// TODO 测试完成后去掉这条判断
|
||||
// if(!statusResult.isOpen) return resResult(STATUS.GUILD_ACTIVITY_NOT_OPEN);
|
||||
|
||||
let userGuild = await UserGuildModel.getMyGuild(roleId, 'job');
|
||||
|
||||
let guildActivityRec = await GuildActivityRecordModel.getRecord(guildCode, serverId, this.aid);
|
||||
if(!guildActivityRec) return resResult(STATUS.INTERNAL_ERR);
|
||||
if (!guildActivityRec) return resResult(STATUS.INTERNAL_ERR);
|
||||
|
||||
let { code: sourceCode } = guildActivityRec;
|
||||
|
||||
|
||||
let myGuildActivityRec = await UserGuildActivityRecModel.getRecord(roleId, roleName, guildCode, serverId, sourceCode, this.aid);
|
||||
if(costGold) {
|
||||
if (costGold) {
|
||||
let goldObj = getGoldObject(GUILDACTIVITY.CITYACTIVITY_CD_COST);
|
||||
const costRes = await handleCost(roleId, sid, [goldObj]);
|
||||
if (!costRes) {
|
||||
return resResult(STATUS.BATTLE_GOLD_NOT_ENOUGH);
|
||||
}
|
||||
} else {
|
||||
if(myGuildActivityRec.challengeTime > nowSeconds()) {
|
||||
if (myGuildActivityRec.challengeTime > nowSeconds()) {
|
||||
return resResult(STATUS.CHALLENGE_TIME_NOT_REACH);
|
||||
}
|
||||
}
|
||||
myGuildActivityRec = await UserGuildActivityRecModel.incChallengeCnt(myGuildActivityRec.code, heroes);
|
||||
|
||||
let { code } = myGuildActivityRec;
|
||||
let { code } = myGuildActivityRec;
|
||||
|
||||
// 更新公会参与的玩家
|
||||
obj.pushMembers(guildCode, roleId, userGuild.job);
|
||||
|
||||
// 返回当前军团总军功
|
||||
let r = new Rank(REDIS_KEY.CITY_ACTIVITY, { serverId, cityId }, true);
|
||||
let guildScore = await r.getMyScore({guildCode});
|
||||
let guildScore = await r.getMyScore({ guildCode });
|
||||
|
||||
const dbCities = await GuildActivityCityModel.getAllCities(serverId);
|
||||
let cityStatus = pubGetCityStatus(guildCode, cityId, dicCity, dbCities);
|
||||
@@ -217,32 +218,32 @@ export class CityActivityHandler {
|
||||
const sid = session.get('sid');
|
||||
|
||||
let { cityId, code, damage, hid, round } = msg;
|
||||
if(!damage || damage < 0) return resResult(STATUS.WRONG_PARMS);
|
||||
if (!damage || damage < 0) return resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
const dicCity = gameData.cityActivity.get(cityId);
|
||||
let obj = getCityActivityObj();
|
||||
let gateHp = obj.getGateHpAndInc(serverId, cityId, dicCity.hp);
|
||||
if(gateHp <= 0) return resResult(STATUS.GATE_HP_IS_ZERO);
|
||||
if (gateHp <= 0) return resResult(STATUS.GATE_HP_IS_ZERO);
|
||||
|
||||
let statusResult = getGuildActivityStatus(this.aid);
|
||||
if(!statusResult) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if (!statusResult) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
// TODO 测试完成后去掉这条判断
|
||||
// if(!statusResult.isOpen) return resResult(STATUS.GUILD_ACTIVITY_NOT_OPEN);
|
||||
|
||||
let pushResult = await UserGuildActivityRecModel.pushCityRecord(code, { round, hid, damage });
|
||||
if(!pushResult) return resResult(STATUS.WRONG_PARMS);
|
||||
if (!pushResult) return resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
// 更新redis数据
|
||||
let myR = new Rank(REDIS_KEY.USER_CITY_ACTIVITY, { serverId, guildCode });
|
||||
let myScore = await myR.setRankWithRoleInfo(roleId, damage, Date.now(), null, true);
|
||||
await myR.setExpire(getNextHourPoint(5));
|
||||
|
||||
let r = new Rank(REDIS_KEY.CITY_ACTIVITY, { serverId, cityId }, true );
|
||||
let r = new Rank(REDIS_KEY.CITY_ACTIVITY, { serverId, cityId }, true);
|
||||
let guildScore = await r.setRankWithGuildInfo(guildCode, damage, Date.now(), null, true);
|
||||
await r.setExpire(getNextHourPoint(5));
|
||||
|
||||
gateHp = obj.getGateHpAndInc(serverId, cityId, dicCity.hp, -1 * damage);
|
||||
if(gateHp <= 0) {
|
||||
if (gateHp <= 0) {
|
||||
// 推送 停止活动并结算奖励
|
||||
await sendSingleCityActEndMsg(cityId, serverId);
|
||||
}
|
||||
@@ -269,29 +270,31 @@ export class CityActivityHandler {
|
||||
|
||||
let { cityId, code, isSuccess } = msg;
|
||||
let obj = getCityActivityObj();
|
||||
|
||||
|
||||
let statusResult = getGuildActivityStatus(this.aid);
|
||||
if(!statusResult) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if (!statusResult) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
|
||||
let dicCity = gameData.cityActivity.get(cityId);
|
||||
if(!dicCity) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if (!dicCity) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
|
||||
// 更新userGuildActivityRecord
|
||||
let challengeTime = getBeforeSeconds(-1 * GUILDACTIVITY.CITYACTIVITY_CHALLENGE_CD);
|
||||
let challengeTime = getBeforeSeconds(-1 * GUILDACTIVITY.CITYACTIVITY_CHALLENGE_CD);
|
||||
let myGuildActivityRec = await UserGuildActivityRecModel.updateInfo(code, { isSuccess, isCompleted: true, cityId, challengeTime });
|
||||
if(!myGuildActivityRec) return resResult(STATUS.INTERNAL_ERR);
|
||||
if (!myGuildActivityRec) return resResult(STATUS.INTERNAL_ERR);
|
||||
|
||||
// 发放活跃
|
||||
await addActive(roleId, serverId, GUILD_POINT_WAYS.ACTIVITY); //获得活跃值
|
||||
// 返回当前军团总军功
|
||||
let myR = new Rank(REDIS_KEY.USER_CITY_ACTIVITY, { serverId, guildCode });
|
||||
let myScore = await myR.getMyScore({roleId});
|
||||
let myScore = await myR.getMyScore({ roleId });
|
||||
let r = new Rank(REDIS_KEY.CITY_ACTIVITY, { serverId, cityId }, true);
|
||||
let guildScore = await r.getMyScore({guildCode});
|
||||
let guildScore = await r.getMyScore({ guildCode });
|
||||
let gateHp = obj.getGateHpAndInc(serverId, cityId, dicCity.hp);
|
||||
|
||||
// 任务
|
||||
await checkTask(roleId, sid, funcs, TASK_TYPE.GUILD_ACTIVITY, 1, true, { aid: this.aid });
|
||||
//成长任务
|
||||
await accomplishTask(roleId, TASK_TYPE.GUILD_ACTIVITY, 1, { aid: this.aid })
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
isSuccess,
|
||||
|
||||
@@ -15,6 +15,7 @@ import { GuildActivityCityModel } from "../../../db/GuildActivityCity";
|
||||
import { Rank } from "../../../services/rankService";
|
||||
import { getNextHourPoint } from "../../../pubUtils/timeUtil";
|
||||
import { checkTask } from "../../../services/taskService";
|
||||
import { accomplishTask } from "../../../pubUtils/taskUtil";
|
||||
|
||||
export default function (app: Application) {
|
||||
return new GateActivityHandler(app);
|
||||
@@ -35,17 +36,17 @@ export class GateActivityHandler {
|
||||
const roleName = session.get('roleName');
|
||||
const serverId = session.get('serverId');
|
||||
const guildCode = session.get('guildCode');
|
||||
if(!guildCode) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
|
||||
if (!guildCode) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
|
||||
|
||||
let statusResult = getGuildActivityStatus(this.aid);
|
||||
if(!statusResult) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if (!statusResult) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
|
||||
let guildActivityRec = await GuildActivityRecordModel.getRecord(guildCode, serverId, this.aid);
|
||||
if(!guildActivityRec) return resResult(STATUS.INTERNAL_ERR);
|
||||
if (!guildActivityRec) return resResult(STATUS.INTERNAL_ERR);
|
||||
|
||||
let { code: sourceCode } = guildActivityRec;
|
||||
let myGuildActivityRec = await UserGuildActivityRecModel.getRecord(roleId, roleName, guildCode, serverId, sourceCode, this.aid);
|
||||
let { challengeCnt } = myGuildActivityRec;
|
||||
let { challengeCnt } = myGuildActivityRec;
|
||||
|
||||
let ranks = await getGateActivityRank(guildCode, serverId, roleId, roleName);
|
||||
|
||||
@@ -62,50 +63,50 @@ export class GateActivityHandler {
|
||||
// 开启挑战
|
||||
async checkBattle(msg: { heroes: number[] }, session: BackendSession) {
|
||||
let { heroes } = msg;
|
||||
if(!heroes || heroes.length <= 0) return resResult(STATUS.WRONG_PARMS);
|
||||
if (!heroes || heroes.length <= 0) return resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
const roleId = session.get('roleId');
|
||||
const roleName = session.get('roleName');
|
||||
const serverId = session.get('serverId');
|
||||
const guildCode = session.get('guildCode');
|
||||
if(!guildCode) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
|
||||
if (!guildCode) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
|
||||
let obj = getGateActivityObj();
|
||||
|
||||
let gateHp = obj.getGateHpAndInc(guildCode);
|
||||
if(gateHp <= 0) return resResult(STATUS.GATE_HP_IS_ZERO);
|
||||
if (gateHp <= 0) return resResult(STATUS.GATE_HP_IS_ZERO);
|
||||
|
||||
let statusResult = getGuildActivityStatus(this.aid);
|
||||
if(!statusResult) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if (!statusResult) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
// TODO 测试完成后去掉这条判断
|
||||
// if(!statusResult.isOpen) return resResult(STATUS.GUILD_ACTIVITY_NOT_OPEN);
|
||||
|
||||
let userGuild = await UserGuildModel.getMyGuild(roleId, 'job');
|
||||
|
||||
let guildActivityRec = await GuildActivityRecordModel.getRecord(guildCode, serverId, this.aid);
|
||||
if(!guildActivityRec) return resResult(STATUS.INTERNAL_ERR);
|
||||
if (!guildActivityRec) return resResult(STATUS.INTERNAL_ERR);
|
||||
|
||||
let { code: sourceCode } = guildActivityRec;
|
||||
let myGuildActivityRec = await UserGuildActivityRecModel.getRecord(roleId, roleName, guildCode, serverId, sourceCode, this.aid);
|
||||
if(myGuildActivityRec.challengeCnt > 0) {
|
||||
if (myGuildActivityRec.challengeCnt > 0) {
|
||||
return resResult(STATUS.CHALLENGE_CNT_NOT_ENOUGH);
|
||||
}
|
||||
myGuildActivityRec = await UserGuildActivityRecModel.incChallengeCnt(myGuildActivityRec.code, heroes);
|
||||
let { code, challengeCnt } = myGuildActivityRec;
|
||||
let { code, challengeCnt } = myGuildActivityRec;
|
||||
|
||||
// 更新公会参与的玩家
|
||||
obj.pushMembers(guildCode, serverId, roleId, userGuild.job);
|
||||
|
||||
// 返回当前军团总军功
|
||||
let r = new Rank(REDIS_KEY.GATE_ACTIVITY, { serverId }, true);
|
||||
let guildScore = await r.getMyScore({guildCode});
|
||||
let guildScore = await r.getMyScore({ guildCode });
|
||||
|
||||
// 前一天中位数战力
|
||||
let medianCe = await getMedianCe(serverId);
|
||||
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
code,
|
||||
...statusResult,
|
||||
guildScore: guildScore||0,
|
||||
guildScore: guildScore || 0,
|
||||
myScore: 0,
|
||||
gateHp,
|
||||
challengeCnt: GUILDACTIVITY.GATEACTIVITY_CHALLENGE_TIMES - challengeCnt,
|
||||
@@ -124,17 +125,17 @@ export class GateActivityHandler {
|
||||
let obj = getGateActivityObj();
|
||||
|
||||
let statusResult = getGuildActivityStatus(this.aid);
|
||||
if(!statusResult) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if (!statusResult) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
// TODO 测试完成后去掉这条判断
|
||||
// if(!statusResult.isOpen) return resResult(STATUS.GUILD_ACTIVITY_NOT_OPEN);
|
||||
|
||||
let gateHp = obj.getGateHpAndInc(guildCode);
|
||||
if(gateHp <= 0) return resResult(STATUS.GATE_HP_IS_ZERO);
|
||||
if (gateHp <= 0) return resResult(STATUS.GATE_HP_IS_ZERO);
|
||||
|
||||
// 计算record内得分
|
||||
let memberRecord = obj.getMemberRecord(code, roleId);
|
||||
let scoreResult = getRecordScore(this.aid, round, record, memberRecord);
|
||||
if(!scoreResult) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if (!scoreResult) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
let { score, newRecords, memberRecord: newMemberRecord } = scoreResult;
|
||||
obj.setMemberRecord(code, newMemberRecord);
|
||||
|
||||
@@ -153,8 +154,8 @@ export class GateActivityHandler {
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
code: rec.code,
|
||||
...statusResult,
|
||||
guildScore: guildScore||0,
|
||||
myScore: myScore||0,
|
||||
guildScore: guildScore || 0,
|
||||
myScore: myScore || 0,
|
||||
gateHp
|
||||
});
|
||||
}
|
||||
@@ -168,15 +169,15 @@ export class GateActivityHandler {
|
||||
let { code, damage } = msg;
|
||||
let obj = getGateActivityObj();
|
||||
let gateHp = obj.getGateHpAndInc(guildCode);
|
||||
if(gateHp <= 0) return resResult(STATUS.GATE_HP_IS_ZERO);
|
||||
if (gateHp <= 0) return resResult(STATUS.GATE_HP_IS_ZERO);
|
||||
|
||||
let statusResult = getGuildActivityStatus(this.aid);
|
||||
if(!statusResult) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if (!statusResult) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
// TODO 测试完成后去掉这条判断
|
||||
// if(!statusResult.isOpen) return resResult(STATUS.GUILD_ACTIVITY_NOT_OPEN);
|
||||
|
||||
gateHp = obj.getGateHpAndInc(guildCode, -1 * damage);
|
||||
if(gateHp <= 0) {
|
||||
if (gateHp <= 0) {
|
||||
// 推送 停止活动并结算奖励
|
||||
await sendSingleGateActEndMsg(guildCode, serverId);
|
||||
}
|
||||
@@ -186,10 +187,10 @@ export class GateActivityHandler {
|
||||
|
||||
// 返回当前军团总军功
|
||||
let myR = new Rank(REDIS_KEY.USER_GATE_ACTIVITY, { serverId, guildCode });
|
||||
let myScore = await myR.getMyScore({roleId});
|
||||
let myScore = await myR.getMyScore({ roleId });
|
||||
let r = new Rank(REDIS_KEY.GATE_ACTIVITY, { serverId }, true);
|
||||
let guildScore = await r.getMyScore({guildCode});
|
||||
|
||||
let guildScore = await r.getMyScore({ guildCode });
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
code,
|
||||
...statusResult,
|
||||
@@ -209,53 +210,55 @@ export class GateActivityHandler {
|
||||
|
||||
let { code, isSuccess } = msg;
|
||||
let obj = getGateActivityObj();
|
||||
|
||||
|
||||
let statusResult = getGuildActivityStatus(this.aid);
|
||||
if(!statusResult) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if (!statusResult) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
|
||||
// 更新userGuildActivityRecord
|
||||
let myGuildActivityRec = await UserGuildActivityRecModel.updateInfo(code, { isSuccess, isCompleted: true });
|
||||
if(!myGuildActivityRec) return resResult(STATUS.INTERNAL_ERR);
|
||||
if (!myGuildActivityRec) return resResult(STATUS.INTERNAL_ERR);
|
||||
|
||||
// 功劳簿计算
|
||||
let { record, round } = myGuildActivityRec;
|
||||
let enemyCnt = 0, littleBossCnt = 0, bossCnt = 0;
|
||||
for(let { enemyType, round: r } of record) {
|
||||
if(enemyType == ENEMIES_TYPE.ENEMY || enemyType == ENEMIES_TYPE.ELITE_ENEMY ) {
|
||||
enemyCnt ++;
|
||||
for (let { enemyType, round: r } of record) {
|
||||
if (enemyType == ENEMIES_TYPE.ENEMY || enemyType == ENEMIES_TYPE.ELITE_ENEMY) {
|
||||
enemyCnt++;
|
||||
} else if (enemyType == ENEMIES_TYPE.LITTLE_BOSS) {
|
||||
littleBossCnt ++;
|
||||
littleBossCnt++;
|
||||
} else if (enemyType == ENEMIES_TYPE.BOSS) {
|
||||
bossCnt ++;
|
||||
bossCnt++;
|
||||
}
|
||||
}
|
||||
|
||||
let myR = new Rank(REDIS_KEY.USER_GATE_ACTIVITY, { serverId, guildCode });
|
||||
let r = new Rank(REDIS_KEY.GATE_ACTIVITY, { serverId }, true);
|
||||
if(isSuccess) {
|
||||
if (isSuccess) {
|
||||
let score = gameData.gateActivityPoint.get(GET_POINT_WAYS.DEFENSE_SUCCESS);
|
||||
// 更新redis数据
|
||||
await myR.setRank({roleId}, score, Date.now(), true);
|
||||
await myR.setRank({ roleId }, score, Date.now(), true);
|
||||
|
||||
await r.setRank({guildCode}, score, Date.now(), true);
|
||||
await r.setRank({ guildCode }, score, Date.now(), true);
|
||||
}
|
||||
|
||||
// 发放活跃
|
||||
await addActive(roleId, serverId, GUILD_POINT_WAYS.ACTIVITY); //获得活跃值
|
||||
// 返回当前军团总军功
|
||||
let guildScore = await r.getMyScore({guildCode});
|
||||
let myScore = await myR.getMyScore({roleId});
|
||||
let guildScore = await r.getMyScore({ guildCode });
|
||||
let myScore = await myR.getMyScore({ roleId });
|
||||
let gateHp = obj.getGateHpAndInc(guildCode);
|
||||
|
||||
obj.delMemberRecord(code);
|
||||
let info = {
|
||||
round,
|
||||
enemyCnt, littleBossCnt, bossCnt,
|
||||
enemyCnt, littleBossCnt, bossCnt,
|
||||
isSuccess
|
||||
}
|
||||
|
||||
// 任务
|
||||
await checkTask(roleId, sid, funcs, TASK_TYPE.GUILD_ACTIVITY, 1, true, { aid: this.aid });
|
||||
//成长任务
|
||||
await accomplishTask(roleId, TASK_TYPE.GUILD_ACTIVITY, 1, { aid: this.aid })
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
code,
|
||||
...statusResult,
|
||||
@@ -267,7 +270,7 @@ export class GateActivityHandler {
|
||||
}
|
||||
|
||||
// ! 测试接口
|
||||
async debugGetPrivate(msg: { }, session: BackendSession) {
|
||||
async debugGetPrivate(msg: {}, session: BackendSession) {
|
||||
let guildCode = session.get('guildCode');
|
||||
// console.log(guildCode);
|
||||
let serverId = session.get('serverId');
|
||||
@@ -281,7 +284,7 @@ export class GateActivityHandler {
|
||||
let serverId = session.get('serverId');
|
||||
|
||||
// await GuildActivityCityModel.declare(serverId, 1, guildCode);
|
||||
let {sourceType, sourceCode} = msg;
|
||||
let { sourceType, sourceCode } = msg;
|
||||
let result = await participants(guildCode, sourceType, sourceCode);
|
||||
return result;
|
||||
|
||||
@@ -290,27 +293,27 @@ export class GateActivityHandler {
|
||||
}
|
||||
|
||||
// ! 测试接口
|
||||
async debugIncChallengeCnt(msg: { }, session: BackendSession) {
|
||||
async debugIncChallengeCnt(msg: {}, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
let res = await UserGuildActivityRecModel.updateInfoByRoleId(roleId, { challengeCnt: -100 });
|
||||
|
||||
return resResult(STATUS.SUCCESS, { challengeCnt: GUILDACTIVITY.GATEACTIVITY_CHALLENGE_TIMES - (res?.challengeCnt||0) });
|
||||
return resResult(STATUS.SUCCESS, { challengeCnt: GUILDACTIVITY.GATEACTIVITY_CHALLENGE_TIMES - (res?.challengeCnt || 0) });
|
||||
}
|
||||
|
||||
// ! 测试接口
|
||||
async debugStartActivity(msg: { aid: number }, session: BackendSession) {
|
||||
let { aid } = msg;
|
||||
let dic = gameData.guildActivity.get(aid);
|
||||
if(!dic) return resResult(STATUS.WRONG_PARMS);
|
||||
if (!dic) return resResult(STATUS.WRONG_PARMS);
|
||||
let result = await pinus.app.rpc.systimer.systimerRemote.guildActivityStart.toServer('systimer-server-1', dic);
|
||||
if(!result) {
|
||||
if (!result) {
|
||||
return resResult(STATUS.GUILD_ACTIVITY_IS_OPEN)
|
||||
}
|
||||
|
||||
// !! 注意,这条函数会改变内存中的字典表,仅用于测试中使用
|
||||
let now = new Date();
|
||||
let guildServers = pinus.app.getServersByType('guild');
|
||||
for(let server of guildServers) {
|
||||
for (let server of guildServers) {
|
||||
pinus.app.rpc.guild.guildActivityRemote.updateGuildActivityData.toServer(server.id, aid, true);
|
||||
}
|
||||
|
||||
@@ -320,10 +323,10 @@ export class GateActivityHandler {
|
||||
// ! 测试接口
|
||||
async debugSetDay(msg: { week: number }, session: BackendSession) {
|
||||
let guildServers = pinus.app.getServersByType('guild');
|
||||
for(let server of guildServers) {
|
||||
for (let server of guildServers) {
|
||||
pinus.app.rpc.guild.guildActivityRemote.setDay.toServer(server.id, msg.week);
|
||||
}
|
||||
if(msg.week <= 2) {
|
||||
if (msg.week <= 2) {
|
||||
await GuildActivityCityModel.deleteMany({});
|
||||
}
|
||||
return resResult(STATUS.SUCCESS);
|
||||
@@ -332,7 +335,7 @@ export class GateActivityHandler {
|
||||
// ! 测试接口
|
||||
async debugEndActivity(msg: { aid: number }, session: BackendSession) {
|
||||
let { aid } = msg;
|
||||
if(aid == GUILD_ACTIVITY_TYPE.GATE_ACTIVITY) {
|
||||
if (aid == GUILD_ACTIVITY_TYPE.GATE_ACTIVITY) {
|
||||
await pinus.app.rpc.systimer.systimerRemote.gateActivityEnd.toServer('systimer-server-1');
|
||||
} else if (aid == GUILD_ACTIVITY_TYPE.CITY_ACTIVITY) {
|
||||
await pinus.app.rpc.systimer.systimerRemote.cityActivityEnd.toServer('systimer-server-1');
|
||||
@@ -345,7 +348,7 @@ export class GateActivityHandler {
|
||||
// !! 注意,这条函数会改变内存中的字典表,仅用于测试中使用
|
||||
let now = new Date();
|
||||
let guildServers = pinus.app.getServersByType('guild');
|
||||
for(let server of guildServers) {
|
||||
for (let server of guildServers) {
|
||||
pinus.app.rpc.guild.guildActivityRemote.updateGuildActivityData.toServer(server.id, aid, false);
|
||||
}
|
||||
return resResult(STATUS.SUCCESS);
|
||||
@@ -360,13 +363,13 @@ export class GateActivityHandler {
|
||||
async debugAddParticipants(msg: { aid: number }, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
let guildCode = session.get('guildCode');
|
||||
if(!guildCode) return resResult(STATUS.GUILD_NOT_FOUND);
|
||||
if (!guildCode) return resResult(STATUS.GUILD_NOT_FOUND);
|
||||
let serverId = session.get('serverId');
|
||||
let { aid } = msg;
|
||||
await GuildActivityRecordModel.getRecord(guildCode, serverId, aid);
|
||||
let userGuild = await UserGuildModel.getMyGuild(roleId);
|
||||
let result = await GuildActivityRecordModel.updateInfo(guildCode, { memberCnt: 1, members: [{ roleId, job: userGuild.job }], auctionType: aid + 1 });
|
||||
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
sourceType: result.auctionType,
|
||||
sourceCode: result.code
|
||||
|
||||
@@ -8,6 +8,7 @@ import { UserGuildActivityRecModel } from "../../../db/UserGuildActivityRec";
|
||||
import { addActive } from "../../../services/guildService";
|
||||
import { Rank } from "../../../services/rankService";
|
||||
import { checkTask } from "../../../services/taskService";
|
||||
import { accomplishTask } from "../../../pubUtils/taskUtil";
|
||||
|
||||
export default function (app: Application) {
|
||||
return new RaceActivityHandler(app);
|
||||
@@ -28,14 +29,14 @@ export class RaceActivityHandler {
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
const guildCode = session.get('guildCode');
|
||||
if(!guildCode) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
|
||||
if (!guildCode) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
|
||||
|
||||
let statusResult = getGuildActivityStatus(this.aid);
|
||||
if(!statusResult) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if (!statusResult) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
|
||||
let obj = getRaceActivityObj();
|
||||
let woodenHorse = await obj.getWoodenHorse(guildCode, serverId);
|
||||
if(!woodenHorse) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
|
||||
if (!woodenHorse) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
|
||||
|
||||
let events = obj.getEvents(guildCode, woodenHorse.distance);
|
||||
let ranks = await getRaceActivityRank(guildCode, serverId);
|
||||
@@ -49,7 +50,7 @@ export class RaceActivityHandler {
|
||||
events
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// 加入木马
|
||||
async join(msg: {}, session: BackendSession) {
|
||||
|
||||
@@ -58,28 +59,28 @@ export class RaceActivityHandler {
|
||||
const serverId = session.get('serverId');
|
||||
const guildCode = session.get('guildCode');
|
||||
const sid = session.get('sid');
|
||||
if(!guildCode) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
|
||||
if (!guildCode) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
|
||||
|
||||
let statusResult = getGuildActivityStatus(this.aid);
|
||||
if(!statusResult) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if (!statusResult) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
|
||||
let obj = getRaceActivityObj();
|
||||
|
||||
let hasJoin = obj.hasJoin(guildCode, roleId);
|
||||
if(hasJoin) {
|
||||
if (hasJoin) {
|
||||
return resResult(STATUS.RACE_HAS_JOIN);
|
||||
}
|
||||
|
||||
|
||||
let guildActivityRec = await GuildActivityRecordModel.getRecord(guildCode, serverId, this.aid, obj.getEvents(guildCode, 0));
|
||||
if(!guildActivityRec) return resResult(STATUS.INTERNAL_ERR);
|
||||
if (!guildActivityRec) return resResult(STATUS.INTERNAL_ERR);
|
||||
|
||||
let { code: sourceCode } = guildActivityRec;
|
||||
let myGuildActivityRec = await UserGuildActivityRecModel.getRecord(roleId, roleName, guildCode, serverId, sourceCode, this.aid);
|
||||
|
||||
let myGuild = await UserGuildModel.getMyGuild(roleId, 'job');
|
||||
let woodenHorse = await obj.joinWoodenHorse(guildCode, roleId, roleName, serverId, sid, myGuild.job);
|
||||
if(!woodenHorse) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
|
||||
if (!woodenHorse) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
|
||||
|
||||
let events = obj.getEvents(guildCode, woodenHorse.distance);
|
||||
|
||||
@@ -91,7 +92,7 @@ export class RaceActivityHandler {
|
||||
events
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// 打开竞赛页面
|
||||
async getRace(msg: {}, session: BackendSession) {
|
||||
|
||||
@@ -99,17 +100,17 @@ export class RaceActivityHandler {
|
||||
const roleName = session.get('roleName');
|
||||
const serverId = session.get('serverId');
|
||||
const guildCode = session.get('guildCode');
|
||||
if(!guildCode) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
|
||||
if (!guildCode) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
|
||||
|
||||
let statusResult = getGuildActivityStatus(this.aid);
|
||||
if(!statusResult) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if(statusResult.status != GUILD_ACTIVITY_STATUS.START) {
|
||||
if (!statusResult) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if (statusResult.status != GUILD_ACTIVITY_STATUS.START) {
|
||||
return resResult(STATUS.GUILD_ACTIVITY_NOT_OPEN);
|
||||
}
|
||||
|
||||
let obj = getRaceActivityObj();
|
||||
let woodenHorse = await obj.getWoodenHorse(guildCode, serverId);
|
||||
if(!woodenHorse) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
|
||||
if (!woodenHorse) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
|
||||
|
||||
let events = obj.getEvents(guildCode, woodenHorse.distance);
|
||||
let hasJoin = obj.hasJoin(guildCode, roleId);
|
||||
@@ -133,15 +134,15 @@ export class RaceActivityHandler {
|
||||
let serverId = session.get('serverId');
|
||||
let guildCode = session.get('guildCode');
|
||||
let sid = session.get('sid');
|
||||
|
||||
let {id, count, toGuild} = msg;
|
||||
if(!count || count < 0) return resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
let { id, count, toGuild } = msg;
|
||||
if (!count || count < 0) return resResult(STATUS.WRONG_PARMS);
|
||||
let obj = getRaceActivityObj();
|
||||
let woodenHorse = obj.getWoodenHorse(toGuild, serverId);
|
||||
if(!woodenHorse) return resResult(STATUS.WRONG_PARMS);
|
||||
if (!woodenHorse) return resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
let event = await obj.useItem(roleId, sid, guildCode, toGuild, id, count);
|
||||
if(!event) return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
|
||||
if (!event) return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
|
||||
|
||||
await GuildActivityRecordModel.pushEvent(guildCode, event);
|
||||
|
||||
@@ -162,21 +163,23 @@ export class RaceActivityHandler {
|
||||
let { code, isSuccess } = msg;
|
||||
|
||||
let statusResult = getGuildActivityStatus(this.aid);
|
||||
if(!statusResult) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if (!statusResult) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
|
||||
// 更新userGuildActivityRecord
|
||||
let guildActivityRec = await GuildActivityRecordModel.getRecord(guildCode, serverId, this.aid);
|
||||
let myGuildActivityRec = await UserGuildActivityRecModel.updateInfo(code, { isSuccess, isCompleted: true });
|
||||
if(!guildActivityRec || !myGuildActivityRec) return resResult(STATUS.INTERNAL_ERR);
|
||||
if (!guildActivityRec || !myGuildActivityRec) return resResult(STATUS.INTERNAL_ERR);
|
||||
|
||||
// 发放活跃
|
||||
await addActive(roleId, serverId, GUILD_POINT_WAYS.ACTIVITY); //获得活跃值
|
||||
// 返回当前军团总军功
|
||||
let r = new Rank(REDIS_KEY.RACE_ACTIVITY, { serverId });
|
||||
let myGuildRank = await r.getMyRank({guildCode});
|
||||
let myGuildRank = await r.getMyRank({ guildCode });
|
||||
|
||||
// 任务
|
||||
await checkTask(roleId, sid, funcs, TASK_TYPE.GUILD_ACTIVITY, 1, true, { aid: this.aid });
|
||||
//成长任务
|
||||
await accomplishTask(roleId, TASK_TYPE.GUILD_ACTIVITY, 1, { aid: this.aid })
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
timestamp: Date.now(),
|
||||
woodenHorse: guildActivityRec.woodenHorse,
|
||||
@@ -189,7 +192,7 @@ export class RaceActivityHandler {
|
||||
let serverId = session.get('serverId');
|
||||
let obj = getRaceActivityObj();
|
||||
let woodenHorse = await obj.getWoodenHorse(guildCode, serverId);
|
||||
if(woodenHorse) {
|
||||
if (woodenHorse) {
|
||||
await raceActivitySettleReward(guildCode, woodenHorse)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Application, BackendSession } from "pinus";
|
||||
import { STATUS, EQUIP_STRENGTHEN_TYPE, CURRENCY_BY_TYPE, CURRENCY_TYPE, HERO_SYSTEM_TYPE, CONSUME_TYPE, HERO_GROW_MAX, MSG_SOURCE, JEWEL_PUSH_LV, TASK_TYPE } from "../../../consts";
|
||||
import { ItemInter } from "../../../pubUtils/interface";
|
||||
|
||||
import { resResult, parseGoodStr, getRandValueByMinMax, getRandEelm } from "../../../pubUtils/util";
|
||||
import { resResult, parseGoodStr, getRandValueByMinMax, getRandEelm } from "../../../pubUtils/util";
|
||||
import { addItems, handleCost, decreaseItems } from "../../../services/rewardService";
|
||||
import { EquipModel, EquipType } from "../../../db/Equip";
|
||||
import { HeroModel, EPlace } from "../../../db/Hero";
|
||||
@@ -16,6 +16,7 @@ import { changeEquip, dressEquip, checkMaterialEnough, takeOffEquipAndCalPlayerC
|
||||
import { indexOf, findIndex } from 'underscore';
|
||||
import { pushEquipRefineSucMsg, pushNormalEquipMsg, pushNormalItemMsg } from "../../../services/chatService";
|
||||
import { checkTaskWithHero, checkTaskWithEquip, checkTask, checkTaskWithArgs } from "../../../services/taskService";
|
||||
import { accomplishTask } from "../../../pubUtils/taskUtil";
|
||||
|
||||
export default function (app: Application) {
|
||||
return new EquipHandler(app);
|
||||
@@ -98,6 +99,8 @@ export class EquipHandler {
|
||||
let hero = await HeroModel.findByHidAndRoleWithEquip(hid, roleId);
|
||||
if (!hero) return resResult(STATUS.HERO_NOT_FIND);
|
||||
|
||||
|
||||
let changeData = [];//变化的等级数据
|
||||
let { ePlace, lv: playerLv } = hero; // 装备栏
|
||||
let oldLvs = ePlace.map(cur => cur.lv);
|
||||
let strengthenArr = new Array<EPlace>();
|
||||
@@ -110,7 +113,13 @@ export class EquipHandler {
|
||||
return resResult(STATUS.ROLE_EQUIP_PLACE_NOT_ENOUGH);
|
||||
}
|
||||
let minLv = strengthenArr[0].lv; // 从最低装备的等级开始
|
||||
for (let { lv } of strengthenArr) {
|
||||
for (let { lv, id } of strengthenArr) {
|
||||
changeData.push({
|
||||
hid: hid,
|
||||
id: id,
|
||||
oldLv: lv,
|
||||
lv: lv,
|
||||
})
|
||||
if (lv < minLv) minLv = lv;
|
||||
}
|
||||
|
||||
@@ -129,8 +138,13 @@ export class EquipHandler {
|
||||
if (!cost) { flag = true; break; }
|
||||
if (coin < costCoin + cost) { flag = true; break; }
|
||||
costCoin += cost;
|
||||
|
||||
s.lv++;
|
||||
{//记录等级变化
|
||||
let index = changeData.findIndex(obj => { return obj && obj.id == s.id })
|
||||
if (index != -1) {
|
||||
changeData[index].lv = s.lv;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (flag) break;
|
||||
@@ -152,8 +166,10 @@ export class EquipHandler {
|
||||
|
||||
// 任务
|
||||
await checkTaskWithHero(roleId, sid, funcs, TASK_TYPE.EQUIP_STRENGTHEN, hero, oldLvs);
|
||||
//成长任务
|
||||
await accomplishTask(roleId, TASK_TYPE.EQUIP_STRENGTHEN, 1, changeData)
|
||||
|
||||
const curHero = {
|
||||
const curHero = {
|
||||
hid,
|
||||
ePlace: strengthenArr
|
||||
}
|
||||
@@ -168,6 +184,7 @@ export class EquipHandler {
|
||||
let sid: string = session.get('sid');
|
||||
let funcs: number[] = session.get('funcs');
|
||||
|
||||
let changeData = [];//变化的等级数据
|
||||
let { hid, lv: maxLv } = msg; // lv: 升到哪一级
|
||||
let hero = await HeroModel.findByHidAndRoleWithEquip(hid, roleId);
|
||||
if (!hero) return resResult(STATUS.HERO_NOT_FIND);
|
||||
@@ -175,13 +192,20 @@ export class EquipHandler {
|
||||
let { ePlace, lv: playerLv } = hero; // 装备栏
|
||||
let oldLvs = ePlace.map(cur => cur.lv);
|
||||
let strengthenArr = ePlace.filter(cur => cur.equip);
|
||||
|
||||
|
||||
if (strengthenArr.length <= 0) {
|
||||
return resResult(STATUS.ROLE_EQUIP_PLACE_NOT_ENOUGH);
|
||||
}
|
||||
let minLv = strengthenArr[0].lv; // 从最低装备的等级开始
|
||||
for (let { lv } of strengthenArr) {
|
||||
for (let { lv, id } of strengthenArr) {
|
||||
changeData.push({
|
||||
hid: hid,
|
||||
id: id,
|
||||
oldLv: lv,
|
||||
lv: lv,
|
||||
})
|
||||
if (lv < minLv) minLv = lv;
|
||||
|
||||
}
|
||||
|
||||
let { coin } = await Role.findByRoleId(roleId);
|
||||
@@ -197,11 +221,17 @@ export class EquipHandler {
|
||||
costCoin += cost;
|
||||
|
||||
s.lv++;
|
||||
{//记录等级变化
|
||||
let index = changeData.findIndex(obj => { return obj && obj.id == s.id })
|
||||
if (index != -1) {
|
||||
changeData[index].lv = s.lv;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (costCoin > coin) {
|
||||
if (costCoin > coin) {
|
||||
return resResult(STATUS.ROLE_COIN_NOT_ENOUGH);
|
||||
}
|
||||
|
||||
@@ -217,8 +247,10 @@ export class EquipHandler {
|
||||
|
||||
// 任务
|
||||
await checkTaskWithHero(roleId, sid, funcs, TASK_TYPE.EQUIP_STRENGTHEN, hero, oldLvs);
|
||||
//成长任务
|
||||
await accomplishTask(roleId, TASK_TYPE.EQUIP_STRENGTHEN, 1, changeData)
|
||||
|
||||
const curHero = {
|
||||
const curHero = {
|
||||
hid,
|
||||
ePlace: strengthenArr
|
||||
}
|
||||
@@ -292,7 +324,7 @@ export class EquipHandler {
|
||||
|
||||
if (isSuccess) {
|
||||
let curEquip = <EquipType>equip;
|
||||
pushEquipRefineSucMsg(roleId, roleName, serverId, curEplace, curEquip?curEquip.quality: 0);
|
||||
pushEquipRefineSucMsg(roleId, roleName, serverId, curEplace, curEquip ? curEquip.quality : 0);
|
||||
await checkTask(roleId, sid, funcs, TASK_TYPE.EQUIP_REFINE, 1, true, {});
|
||||
}
|
||||
return resResult(STATUS.SUCCESS, { isSuccess, curHero });
|
||||
@@ -313,7 +345,7 @@ export class EquipHandler {
|
||||
return resResult(STATUS.ROLE_EQUIP_HAVE_NO_RANDSE);
|
||||
}
|
||||
let curSe = randSe.find(cur => cur.id == id);
|
||||
if(!curSe || lock == curSe.locked) {
|
||||
if (!curSe || lock == curSe.locked) {
|
||||
return resResult(STATUS.ROLE_EQUIP_DUPLICATE_LOCK);
|
||||
}
|
||||
|
||||
@@ -352,8 +384,8 @@ export class EquipHandler {
|
||||
let equip = await EquipModel.findbySeqId(eid);
|
||||
if (!equip) return resResult(STATUS.EQUIP_NOT_FIND);
|
||||
|
||||
let {id, randSe, hid, ePlaceId } = equip;
|
||||
if(!randSe || randSe.length <= 0 ) {
|
||||
let { id, randSe, hid, ePlaceId } = equip;
|
||||
if (!randSe || randSe.length <= 0) {
|
||||
return resResult(STATUS.ROLE_EQUIP_HAVE_NO_RANDSE);
|
||||
}
|
||||
|
||||
@@ -366,13 +398,13 @@ export class EquipHandler {
|
||||
|
||||
let lockNum = 0;
|
||||
let removeSeidList = new Array<number>(); // 原装备上的seid [seid, rand, ...]
|
||||
|
||||
for(let i = 0; i < randSe.length; i++) {
|
||||
|
||||
for (let i = 0; i < randSe.length; i++) {
|
||||
removeSeidList.push(randSe[i].seid, randSe[i].rand);
|
||||
|
||||
if(!randSe[i].locked) {
|
||||
if (!randSe[i].locked) {
|
||||
let random = gameData.randomEffectPool.get(randomResult[i]);
|
||||
if (!random) break ;
|
||||
if (!random) break;
|
||||
let rand = 0;
|
||||
if (random.id > 0) rand = getRandValueByMinMax(random.Min, random.Max, 0);
|
||||
randSe[i].seid = random.id;
|
||||
@@ -381,7 +413,7 @@ export class EquipHandler {
|
||||
lockNum++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (lockNum >= randSe.length) {
|
||||
return resResult(STATUS.ROLE_EQUIP_CANNOT_RESTRENGTHEN);
|
||||
}
|
||||
@@ -413,7 +445,7 @@ export class EquipHandler {
|
||||
await calPlayerCeAndSave(HERO_SYSTEM_TYPE.RESTRENGTHEN, sid, roleId, hero, {}, [ePlaceId, ...removeSeidList]);
|
||||
|
||||
await checkTask(roleId, sid, funcs, TASK_TYPE.EQUIP_RESTRENGTHEN, 1, true, {});
|
||||
return resResult(STATUS.SUCCESS,{curEquip});
|
||||
return resResult(STATUS.SUCCESS, { curEquip });
|
||||
|
||||
}
|
||||
|
||||
@@ -433,11 +465,11 @@ export class EquipHandler {
|
||||
let goodInfo = getGoodById(equip.id);
|
||||
if (!goodInfo)
|
||||
return resResult(STATUS.EQUIP_NOT_FIND);
|
||||
goods = goods.concat(goodInfo.decomposeItem);
|
||||
goods = goods.concat(goodInfo.decomposeItem);
|
||||
}
|
||||
let uids = [{ uid: roleId, sid }];
|
||||
await EquipModel.deleteEquips(originalEquip);
|
||||
this.app.get('channelService').pushMessageByUids('onEquipDel', resResult(STATUS.SUCCESS, {equips:originalEquip}), uids);
|
||||
this.app.get('channelService').pushMessageByUids('onEquipDel', resResult(STATUS.SUCCESS, { equips: originalEquip }), uids);
|
||||
let result = await addItems(roleId, roleName, sid, goods);
|
||||
return resResult(STATUS.SUCCESS, { goods: result });
|
||||
}
|
||||
@@ -452,7 +484,7 @@ export class EquipHandler {
|
||||
let goodInfo = getGoodById(equip.id);
|
||||
let obj = ITID.get(goodInfo.itid);
|
||||
let id = obj.type;
|
||||
let curEquips: Array<{ seqId: number, hid: number}> = [];
|
||||
let curEquips: Array<{ seqId: number, hid: number }> = [];
|
||||
let hero = await HeroModel.findByHidAndRoleWithEquip(hid, roleId);
|
||||
if (!hero)
|
||||
return resResult(STATUS.HERO_NOT_FIND);
|
||||
@@ -471,10 +503,10 @@ export class EquipHandler {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let equipOffInfo = <EquipType>hero.ePlace[index].equip;
|
||||
let curEquip = await changeEquip(roleId, sid, equipOffInfo, equip.hid, id, equip, funcs);
|
||||
if (!!curEquip)
|
||||
if (!!curEquip)
|
||||
curEquips.push(curEquip);
|
||||
curEquip = await dressEquip(roleId, sid, hero, equip, funcs);
|
||||
if (!!curEquip)
|
||||
if (!!curEquip)
|
||||
curEquips.push(curEquip);
|
||||
} else if (type == 2) {
|
||||
if (!equip.hid)
|
||||
@@ -524,9 +556,9 @@ export class EquipHandler {
|
||||
let oldJewelCount = equip.holes.filter(cur => cur.jewel > 0).length;
|
||||
|
||||
let { itid } = getGoodById(equip.id);
|
||||
let {equipJewel} = ITID.get(itid);
|
||||
let { equipJewel } = ITID.get(itid);
|
||||
let jewelInfo = getGoodById(jewel);
|
||||
if (jewelInfo.itid != equipJewel)
|
||||
if (jewelInfo.itid != equipJewel)
|
||||
return resResult(STATUS.EQUIP_NOT_MATCH_JEWEL);
|
||||
let index = findIndex(equip.holes, { id });
|
||||
if (index < 0)
|
||||
@@ -535,7 +567,7 @@ export class EquipHandler {
|
||||
return resResult(STATUS.EQUIP_HOLE_IS_NOT_DUG);
|
||||
let oldJewel = equip.holes[index].jewel;
|
||||
if (!!oldJewel)
|
||||
goods.push({id: oldJewel, count:1});
|
||||
goods.push({ id: oldJewel, count: 1 });
|
||||
consumes.push({ id: jewel, count: 1 });
|
||||
let result = await handleCost(roleId, sid, consumes);
|
||||
if (!result)
|
||||
@@ -554,13 +586,15 @@ export class EquipHandler {
|
||||
await checkTaskWithEquip(roleId, sid, funcs, TASK_TYPE.EQUIP_JEWEL, equip, [oldJewelCount]);
|
||||
await checkTaskWithArgs(roleId, sid, funcs, TASK_TYPE.EQUIP_JEWEL_STAGE, [jewel, oldJewel]);
|
||||
await checkTaskWithEquip(roleId, sid, funcs, TASK_TYPE.EQUIP_JEWEL_SUM, equip, [oldJewelCount]);
|
||||
//成长任务
|
||||
await accomplishTask(roleId, TASK_TYPE.EQUIP_JEWEL_SUM, 1)
|
||||
|
||||
return resResult(STATUS.SUCCESS, { curEquip: { seqId: eid, holes: equip.holes } });
|
||||
}
|
||||
|
||||
//宝石合成(一键放入type:1, 合成type:2)
|
||||
public async composeJewel(msg: { jewel: number, count: number, consumes: Array<{ id: number, count: number }>, type: number }, session: BackendSession) {
|
||||
let { count, consumes, jewel, type } = msg;
|
||||
let { count, consumes, jewel, type } = msg;
|
||||
let roleId: string = session.get('roleId');
|
||||
let roleName: string = session.get('roleName');
|
||||
let serverId: number = session.get('serverId');
|
||||
@@ -570,19 +604,19 @@ export class EquipHandler {
|
||||
if (good.type != CONSUME_TYPE.JEWEL)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let needConsumes = checkMaterialEnough(consumes, jewel, count);//检查是否可以合成,并返回最终需要消耗的材料
|
||||
if (!needConsumes)
|
||||
if (!needConsumes)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let res = await handleCost(roleId, sid, needConsumes);
|
||||
if (!res)
|
||||
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
|
||||
let result = await addItems(roleId, roleName, sid, [{ id: jewel, count: count }]);
|
||||
|
||||
|
||||
if (goodInfo.lvLimited >= JEWEL_PUSH_LV) {
|
||||
pushNormalItemMsg(roleId, roleName, serverId, MSG_SOURCE.JEWEL_COMPOSE, jewel, goodInfo.name);
|
||||
}
|
||||
if (type == 1)
|
||||
if (type == 1)
|
||||
return resResult(STATUS.SUCCESS, { goods: result });
|
||||
|
||||
|
||||
return resResult(STATUS.SUCCESS);
|
||||
}
|
||||
|
||||
@@ -619,7 +653,7 @@ export class EquipHandler {
|
||||
}
|
||||
|
||||
//宝石购买并合成
|
||||
public async composeAndPurchaseJewel(msg: { jewel: number, count: number, consumes: Array<{ id: number, count: number }>, purchaseGoods: Array<{ id: number, count: number }>}, session: BackendSession) {
|
||||
public async composeAndPurchaseJewel(msg: { jewel: number, count: number, consumes: Array<{ id: number, count: number }>, purchaseGoods: Array<{ id: number, count: number }> }, session: BackendSession) {
|
||||
let { count, consumes, jewel, purchaseGoods } = msg;
|
||||
let roleId: string = session.get('roleId');
|
||||
let roleName: string = session.get('roleName');
|
||||
@@ -634,12 +668,12 @@ export class EquipHandler {
|
||||
if (!consumes)
|
||||
consumes = [];
|
||||
let needConsumes = checkMaterialEnough(consumes.concat(purchaseGoods), jewel, count);//检查是否可以合成,并返回最终需要消耗的材料
|
||||
if (!needConsumes)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let items:Array<{id: number, count: number, ratio?:number}> = [];
|
||||
if (!needConsumes)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let items: Array<{ id: number, count: number, ratio?: number }> = [];
|
||||
for (let item of purchaseGoods) {
|
||||
items.push({id: item.id, count: item.count, ratio: 1})//加上购买的数量
|
||||
}
|
||||
items.push({ id: item.id, count: item.count, ratio: 1 })//加上购买的数量
|
||||
}
|
||||
items = items.concat(needConsumes);
|
||||
let hasError = await decreaseItems(roleId, sid, items);//合并消耗是否足够
|
||||
if (!!hasError)
|
||||
@@ -655,13 +689,13 @@ export class EquipHandler {
|
||||
* @param msg
|
||||
* @param session
|
||||
*/
|
||||
public async purchaseGoods(msg: { purchaseGoods: Array<{ id: number, count: number }>}, session: BackendSession) {
|
||||
public async purchaseGoods(msg: { purchaseGoods: Array<{ id: number, count: number }> }, session: BackendSession) {
|
||||
let { purchaseGoods } = msg;
|
||||
let roleId: string = session.get('roleId');
|
||||
let roleName: string = session.get('roleName');
|
||||
let sid: string = session.get('sid');
|
||||
let result = await addItems(roleId, roleName, sid, purchaseGoods );
|
||||
if(!result) {
|
||||
let result = await addItems(roleId, roleName, sid, purchaseGoods);
|
||||
if (!result) {
|
||||
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
|
||||
}
|
||||
return resResult(STATUS.SUCCESS);
|
||||
@@ -682,26 +716,26 @@ export class EquipHandler {
|
||||
let good = ITID.get(goodInfo.itid);
|
||||
let needUpdate = false;
|
||||
let oldJewel: number;
|
||||
let consumes: Array<{id: number, count: number, ratio?: number}> = [];
|
||||
let consumes: Array<{ id: number, count: number, ratio?: number }> = [];
|
||||
if (good.type != CONSUME_TYPE.JEWEL || !eid || eid < 0)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let equip = await EquipModel.getEquip(eid);
|
||||
if(!equip) return resResult(STATUS.EQUIP_NOT_FIND);
|
||||
if (!equip) return resResult(STATUS.EQUIP_NOT_FIND);
|
||||
|
||||
let oldJewelCount = equip.holes.filter(cur => cur.jewel > 0).length;
|
||||
|
||||
let index = findIndex(equip.holes,{id});
|
||||
let index = findIndex(equip.holes, { id });
|
||||
//装备上该位置有穿戴该宝石,且在合成的材料中
|
||||
if (!!equip.holes[index] && equip.holes[index].jewel == goodInfo.composeMaterial[0].id) {
|
||||
oldJewel = equip.holes[index].jewel;
|
||||
equip.holes[index].jewel = jewel;//合成后的新宝石穿戴到装备上
|
||||
needUpdate = true;
|
||||
consumes.push({id: goodInfo.composeMaterial[0].id, count: 1, ratio: 1});//ratio:1表示可以释放掉一颗宝石
|
||||
consumes.push({ id: goodInfo.composeMaterial[0].id, count: 1, ratio: 1 });//ratio:1表示可以释放掉一颗宝石
|
||||
}
|
||||
|
||||
consumes = consumes.concat(goodInfo.composeMaterial);
|
||||
if (goodInfo.specialMaterial.count) {
|
||||
consumes.push({id: goodInfo.specialMaterial.ids[0], count: goodInfo.specialMaterial.count})
|
||||
consumes.push({ id: goodInfo.specialMaterial.ids[0], count: goodInfo.specialMaterial.count })
|
||||
}
|
||||
let hasError = await decreaseItems(roleId, sid, consumes);//检查是消耗是否足够
|
||||
if (!!hasError)
|
||||
@@ -724,11 +758,13 @@ export class EquipHandler {
|
||||
await checkTaskWithEquip(roleId, sid, funcs, TASK_TYPE.EQUIP_JEWEL, equip, [oldJewelCount]);
|
||||
await checkTaskWithArgs(roleId, sid, funcs, TASK_TYPE.EQUIP_JEWEL_STAGE, [jewel, oldJewel]);
|
||||
await checkTaskWithEquip(roleId, sid, funcs, TASK_TYPE.EQUIP_JEWEL_SUM, equip, [oldJewelCount]);
|
||||
//成长任务
|
||||
await accomplishTask(roleId, TASK_TYPE.EQUIP_JEWEL_SUM, 1)
|
||||
|
||||
return resResult(STATUS.SUCCESS, { curEquip: { seqId: eid, holes: equip.holes } });
|
||||
} else {
|
||||
result = await addItems(roleId, roleName, sid, [{ id: jewel, count: count }]);
|
||||
return resResult(STATUS.SUCCESS, { goods: [{id: jewel, count}] });
|
||||
return resResult(STATUS.SUCCESS, { goods: [{ id: jewel, count }] });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import { STATUS } from '../../../consts/statusCode';
|
||||
import { RoleModel } from './../../../db/Role';
|
||||
import { HeroModel } from '../../../db/Hero';
|
||||
import { resResult, decodeIdCntArrayStr, parseGoodStr } from '../../../pubUtils/util';
|
||||
import {Application, BackendSession, pinus} from 'pinus';
|
||||
import { Application, BackendSession, pinus } from 'pinus';
|
||||
import { handleCost } from '../../../services/rewardService';
|
||||
import { getTitle, getTeraph, gameData, getScollByStar, getFriendLvByExp } from '../../../pubUtils/data';
|
||||
import { SCHOOL, SCROLL, EXTERIOR } from '../../../pubUtils/dicParam';
|
||||
@@ -17,8 +17,9 @@ import { checkBattleHeroesByHid } from '../../../services/normalBattleService';
|
||||
import { Rank } from '../../../services/rankService';
|
||||
import { updateUserInfo } from '../../../services/redisService';
|
||||
import { checkTaskWithHero, checkTask, checkTaskWithArgs } from '../../../services/taskService';
|
||||
import { accomplishTask } from '../../../pubUtils/taskUtil';
|
||||
|
||||
export default function(app: Application) {
|
||||
export default function (app: Application) {
|
||||
return new RoleHandler(app);
|
||||
}
|
||||
|
||||
@@ -51,12 +52,12 @@ export class RoleHandler {
|
||||
job: 1,
|
||||
star: 0,
|
||||
serverId: 1,
|
||||
skins:[{id: 41001, enable: true}]
|
||||
skins: [{ id: 41001, enable: true }]
|
||||
}
|
||||
await HeroModel.createHero(heroInfo);
|
||||
}
|
||||
|
||||
async initRole(msg: {content: string , target: string}, session: BackendSession) {
|
||||
async initRole(msg: { content: string, target: string }, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
let roleName = session.get('roleName');
|
||||
console.log('role in initRole: ', roleId, roleName);
|
||||
@@ -68,20 +69,20 @@ export class RoleHandler {
|
||||
|
||||
// let equips = await EquipModel.findbyRole(roleId);
|
||||
// if (!equips || equips.length === 0) {
|
||||
await this.initEquips(roleId, roleName);
|
||||
await this.initEquips(roleId, roleName);
|
||||
// }
|
||||
|
||||
console.log('initRole finish');
|
||||
}
|
||||
|
||||
async getRoleInfo(msg: {targetRoleId: string}, session: BackendSession) {
|
||||
async getRoleInfo(msg: { targetRoleId: string }, session: BackendSession) {
|
||||
let { targetRoleId } = msg;
|
||||
let { roleId, roleName, head = EXTERIOR.EXTERIOR_FACE, frame = EXTERIOR.EXTERIOR_FACECASE, spine = EXTERIOR.EXTERIOR_APPEARANCE, ce = 0, topLineup, topLineupCe = 0 } = await RoleModel.findByRoleId(targetRoleId);
|
||||
return resResult(STATUS.SUCCESS, { roleId, roleName, head, frame, spine, ce, topLineup, topLineupCe });
|
||||
}
|
||||
|
||||
//爵位
|
||||
async roleTitleLevelUp(msg: {}, session: BackendSession){
|
||||
async roleTitleLevelUp(msg: {}, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
let sid: string = session.get('sid');
|
||||
let funcs: number[] = session.get('funcs');
|
||||
@@ -92,11 +93,11 @@ export class RoleHandler {
|
||||
let titleInfo = getTitle(title + 1);
|
||||
if (!titleInfo)
|
||||
return resResult(STATUS.DIC_DATA_NOT_FOUND)
|
||||
if (titleInfo.lvLimited > role.lv)
|
||||
if (titleInfo.lvLimited > role.lv)
|
||||
return resResult(STATUS.COM_BATTLE_LV_NOT_ENOUGH)
|
||||
let consumes = titleInfo.material;
|
||||
let result = await handleCost(roleId, sid, consumes);
|
||||
if (!result)
|
||||
if (!result)
|
||||
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
|
||||
|
||||
let update = { title: title + 1 }
|
||||
@@ -104,43 +105,45 @@ export class RoleHandler {
|
||||
|
||||
// 任务
|
||||
await checkTask(roleId, sid, funcs, TASK_TYPE.ROLE_TITLE, 1, false, { title });
|
||||
//成长任务
|
||||
await accomplishTask(roleId, TASK_TYPE.ROLE_TITLE, update.title)
|
||||
|
||||
return resResult(STATUS.SUCCESS, { roleId, title: role.title });
|
||||
}
|
||||
|
||||
//神像强化
|
||||
async roleTeraphStrengthen(msg: {id: number, count: number}, session: BackendSession){
|
||||
let {id, count} = msg;
|
||||
async roleTeraphStrengthen(msg: { id: number, count: number }, session: BackendSession) {
|
||||
let { id, count } = msg;
|
||||
let roleId = session.get('roleId');
|
||||
let sid: string = session.get('sid');
|
||||
let funcs: number[] = session.get('funcs');
|
||||
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
let teraphs = role.teraphs;
|
||||
let index = findIndex(teraphs, {id});
|
||||
let index = findIndex(teraphs, { id });
|
||||
if (index < 0)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let teraph = teraphs[index];
|
||||
let dicTeraph = getTeraph(id, teraph.grade);
|
||||
if (!dicTeraph)
|
||||
return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
|
||||
|
||||
let attrs = new Array<number>(); // 可以强化的属性
|
||||
dicTeraph.mainAttrMax.forEach(( max, id) => {
|
||||
dicTeraph.mainAttrMax.forEach((max, id) => {
|
||||
let attrName = getAtrrNameById(id);
|
||||
if (teraph[attrName] < max) {
|
||||
attrs.push(id);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if (!attrs.length)
|
||||
return resResult(STATUS.ROLE_TERAPH_NOT_STRENGTHEN);
|
||||
return resResult(STATUS.ROLE_TERAPH_NOT_STRENGTHEN);
|
||||
|
||||
// 随机神像中的一条属性并检查道具是否足够,以及更新teraph
|
||||
let { consumes} = checkTeraphMaterialEnough(count, attrs, dicTeraph, teraph);
|
||||
let { consumes } = checkTeraphMaterialEnough(count, attrs, dicTeraph, teraph);
|
||||
|
||||
let result = await handleCost(roleId, sid, consumes);
|
||||
if (!result)
|
||||
if (!result)
|
||||
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
|
||||
|
||||
role = await calAllHeroCe(HERO_SYSTEM_TYPE.TERAPH, sid, roleId, { teraphs }, [id]);
|
||||
@@ -152,14 +155,14 @@ export class RoleHandler {
|
||||
}
|
||||
|
||||
//神像进阶
|
||||
async roleTeraphQualityUp(msg: {id: number}, session: BackendSession){
|
||||
let {id} = msg;
|
||||
async roleTeraphQualityUp(msg: { id: number }, session: BackendSession) {
|
||||
let { id } = msg;
|
||||
let roleId = session.get('roleId');
|
||||
let sid: string = session.get('sid');
|
||||
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
let teraphs = role.teraphs;
|
||||
let index = findIndex(teraphs, {id});
|
||||
let index = findIndex(teraphs, { id });
|
||||
if (index < 0)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let teraph = teraphs[index];
|
||||
@@ -167,13 +170,13 @@ export class RoleHandler {
|
||||
if (!teraphInfo)
|
||||
return resResult(STATUS.DIC_DATA_NOT_FOUND)
|
||||
|
||||
for(let [attrId, val] of teraph.attr) {
|
||||
for (let [attrId, val] of teraph.attr) {
|
||||
if (val < teraphInfo.mainAttrMax.get(attrId))
|
||||
return resResult(STATUS.ROLE_TERAPH_NOT_QUILITY);
|
||||
|
||||
|
||||
teraph.attr.set(attrId, 0);
|
||||
}
|
||||
teraph.grade ++;
|
||||
teraph.grade++;
|
||||
|
||||
|
||||
let nextTeraphInfo = getTeraph(id, teraph.grade)
|
||||
@@ -182,13 +185,13 @@ export class RoleHandler {
|
||||
|
||||
let consumes = teraphInfo.upGradeMaterial;
|
||||
let result = await handleCost(roleId, sid, consumes);
|
||||
if (!result)
|
||||
if (!result)
|
||||
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
|
||||
|
||||
role = await calAllHeroCe(HERO_SYSTEM_TYPE.TERAPH_UP, sid, roleId, { teraphs }, [id]);
|
||||
return resResult(STATUS.SUCCESS, { roleId, teraphs: role.teraphs });
|
||||
}
|
||||
|
||||
|
||||
// 获得百家学宫
|
||||
async getSchoolList(msg: {}, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
@@ -245,7 +248,7 @@ export class RoleHandler {
|
||||
}
|
||||
let isOpen = !!dicPosition.get(positionId.toString()); // 该位置是否解锁
|
||||
|
||||
if(hid > 0) {
|
||||
if (hid > 0) {
|
||||
let findHero = await SchoolModel.findByHid(roleId, hid);
|
||||
if (!!findHero) {
|
||||
return resResult(STATUS.ROLE_SCHOOL_HERO_USED);
|
||||
@@ -254,7 +257,7 @@ export class RoleHandler {
|
||||
let curHero = await HeroModel.findByHidAndRole(hid, roleId);
|
||||
if (!curHero) return resResult(STATUS.HERO_NOT_FIND);
|
||||
}
|
||||
|
||||
|
||||
let curSchool = await SchoolModel.findBySclAndPos(roleId, schoolId, positionId);
|
||||
let preHid = 0; // 原先在该位置上的武将
|
||||
if (curSchool) {
|
||||
@@ -271,7 +274,11 @@ export class RoleHandler {
|
||||
await calAllHeroCe(HERO_SYSTEM_TYPE.SCHOOL, sid, roleId, {}, [schoolId, hid, preHid]);
|
||||
|
||||
// 任务
|
||||
await checkTaskWithArgs(roleId, sid, funcs, TASK_TYPE.ROLE_SCHOOL_UNLOCK, [ hid, preHid ]);
|
||||
await checkTaskWithArgs(roleId, sid, funcs, TASK_TYPE.ROLE_SCHOOL_UNLOCK, [hid, preHid]);
|
||||
if (hid > 0) {
|
||||
//成长任务
|
||||
await accomplishTask(roleId, TASK_TYPE.ROLE_SCHOOL_PUT_HERO, 1)
|
||||
}
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
schoolId, positionId, hid, preHid, isOpen
|
||||
@@ -351,7 +358,7 @@ export class RoleHandler {
|
||||
} else {
|
||||
if (star > scrollStar) { // 可以升星
|
||||
update.scrollStar++;
|
||||
} else if (quality > scrollQuality ) { // 可以升品
|
||||
} else if (quality > scrollQuality) { // 可以升品
|
||||
update.scrollQuality++;
|
||||
} else if (colorStar > scrollColorStar) { // 可以升彩星
|
||||
update.scrollColorStar++;
|
||||
@@ -362,14 +369,14 @@ export class RoleHandler {
|
||||
}
|
||||
|
||||
let dicHeroScroll = getScollByStar(dicHero.quality, update.scrollStar, update.scrollQuality, update.scrollColorStar);
|
||||
update.scrollId = dicHeroScroll?dicHeroScroll.id: 0;
|
||||
update.scrollId = dicHeroScroll ? dicHeroScroll.id : 0;
|
||||
|
||||
let hero = await calPlayerCeAndSave(HERO_SYSTEM_TYPE.SCROLL, sid, roleId, curHero, update); // 更新单个武将战力
|
||||
calAllHeroCe(HERO_SYSTEM_TYPE.SCROLL, sid, roleId, {}, [hid]); // 全局增加战力
|
||||
|
||||
// 任务
|
||||
if(favourLv != hero.favourLv) await checkTaskWithHero(roleId, sid, funcs, TASK_TYPE.HERO_FAVOUR_LV, hero);
|
||||
if(!scrollActive) await checkTask(roleId, sid, funcs, TASK_TYPE.ROLE_SCROLL_ACTIVE, 1, true, {});
|
||||
if (favourLv != hero.favourLv) await checkTaskWithHero(roleId, sid, funcs, TASK_TYPE.HERO_FAVOUR_LV, hero);
|
||||
if (!scrollActive) await checkTask(roleId, sid, funcs, TASK_TYPE.ROLE_SCROLL_ACTIVE, 1, true, {});
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
curHero: {
|
||||
@@ -381,7 +388,7 @@ export class RoleHandler {
|
||||
scrollQuality: hero.scrollQuality,
|
||||
favour: hero.favour,
|
||||
favourLv: hero.favourLv,
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -391,7 +398,7 @@ export class RoleHandler {
|
||||
let roleId = session.get('roleId');
|
||||
let sid = session.get('sid');
|
||||
|
||||
if(type == 1) {
|
||||
if (type == 1) {
|
||||
pinus.app.channelService.pushMessageByUids('onPlayTime', resResult(STATUS.SUCCESS, {
|
||||
isGuest: true,
|
||||
guestTime: 60 * 60, // 游客已体验时间
|
||||
@@ -399,7 +406,7 @@ export class RoleHandler {
|
||||
isAdult: false, // 是否已成年
|
||||
todayPlayTime: 60 * 60, // 今天已游戏时长
|
||||
type: 1
|
||||
} ), [{uid: roleId, sid: sid}]);
|
||||
}), [{ uid: roleId, sid: sid }]);
|
||||
} else if (type == 2) {
|
||||
pinus.app.channelService.pushMessageByUids('onPlayTime', resResult(STATUS.SUCCESS, {
|
||||
isGuest: false,
|
||||
@@ -408,7 +415,7 @@ export class RoleHandler {
|
||||
isAdult: false, // 是否已成年
|
||||
todayPlayTime: 60 * 60, // 今天已游戏时长
|
||||
type: 2
|
||||
} ), [{uid: roleId, sid: sid}]);
|
||||
}), [{ uid: roleId, sid: sid }]);
|
||||
} else if (type == 3) {
|
||||
pinus.app.channelService.pushMessageByUids('onPlayTime', resResult(STATUS.SUCCESS, {
|
||||
isGuest: false,
|
||||
@@ -417,7 +424,7 @@ export class RoleHandler {
|
||||
isAdult: false, // 是否已成年
|
||||
todayPlayTime: 3 * 60 * 60, // 今天已游戏时长
|
||||
type: 3
|
||||
} ), [{uid: roleId, sid: sid}]);
|
||||
}), [{ uid: roleId, sid: sid }]);
|
||||
} else if (type == 4) {
|
||||
pinus.app.channelService.pushMessageByUids('onPlayTime', resResult(STATUS.SUCCESS, {
|
||||
isGuest: false,
|
||||
@@ -426,8 +433,8 @@ export class RoleHandler {
|
||||
isAdult: false, // 是否已成年
|
||||
todayPlayTime: 1.5 * 60 * 60, // 今天已游戏时长
|
||||
type: 4
|
||||
} ), [{uid: roleId, sid: sid}]);
|
||||
}
|
||||
}), [{ uid: roleId, sid: sid }]);
|
||||
}
|
||||
|
||||
return resResult(STATUS.SUCCESS);
|
||||
}
|
||||
@@ -439,9 +446,9 @@ export class RoleHandler {
|
||||
let serverId = session.get('serverId');
|
||||
|
||||
let checkHeroes = await checkBattleHeroesByHid(roleId, showLineup);
|
||||
if(showLineup.length > 0 && !checkHeroes) return resResult(STATUS.BATTLE_HERO_NOT_FOUND);
|
||||
if (showLineup.length > 0 && !checkHeroes) return resResult(STATUS.BATTLE_HERO_NOT_FOUND);
|
||||
|
||||
if(showLineup.length > LINEUP_NUM) {
|
||||
if (showLineup.length > LINEUP_NUM) {
|
||||
return resResult(STATUS.LINEUP_MAX);
|
||||
}
|
||||
|
||||
@@ -457,16 +464,16 @@ export class RoleHandler {
|
||||
let { id } = msg;
|
||||
let roleId = session.get('roleId');
|
||||
let role = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_HEADS);
|
||||
if(!role) return resResult(STATUS.ROLE_NOT_FOUND);
|
||||
if (!role) return resResult(STATUS.ROLE_NOT_FOUND);
|
||||
|
||||
let { heads } = role;
|
||||
let curHead = heads.find(cur => cur.id == id);
|
||||
if(!curHead) return resResult(STATUS.HEAD_NOT_FOUND);
|
||||
if(curHead.enable) return resResult(STATUS.HEAD_IS_WEARING);
|
||||
if(!curHead.status) return resResult(STATUS.HEAD_IS_LOCKED);
|
||||
if (!curHead) return resResult(STATUS.HEAD_NOT_FOUND);
|
||||
if (curHead.enable) return resResult(STATUS.HEAD_IS_WEARING);
|
||||
if (!curHead.status) return resResult(STATUS.HEAD_IS_LOCKED);
|
||||
|
||||
let oldHead = heads.find(cur => cur.enable); // 穿戴中的头像
|
||||
if(oldHead) {
|
||||
if (oldHead) {
|
||||
oldHead.enable = false;
|
||||
}
|
||||
curHead.enable = true;
|
||||
@@ -482,16 +489,16 @@ export class RoleHandler {
|
||||
let { id } = msg;
|
||||
let roleId = session.get('roleId');
|
||||
let role = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_HEADS);
|
||||
if(!role) return resResult(STATUS.ROLE_NOT_FOUND);
|
||||
if (!role) return resResult(STATUS.ROLE_NOT_FOUND);
|
||||
|
||||
let { frames } = role;
|
||||
let curFrame = frames.find(cur => cur.id == id);
|
||||
if(!curFrame) return resResult(STATUS.FRAME_NOT_FOUND);
|
||||
if(curFrame.enable) return resResult(STATUS.FRAME_IS_WEARING);
|
||||
if(!curFrame.status) return resResult(STATUS.FRAME_IS_LOCKED);
|
||||
if (!curFrame) return resResult(STATUS.FRAME_NOT_FOUND);
|
||||
if (curFrame.enable) return resResult(STATUS.FRAME_IS_WEARING);
|
||||
if (!curFrame.status) return resResult(STATUS.FRAME_IS_LOCKED);
|
||||
|
||||
let oldHead = frames.find(cur => cur.enable); // 穿戴中的头像
|
||||
if(oldHead) {
|
||||
if (oldHead) {
|
||||
oldHead.enable = false;
|
||||
}
|
||||
curFrame.enable = true;
|
||||
@@ -507,16 +514,16 @@ export class RoleHandler {
|
||||
let { id } = msg;
|
||||
let roleId = session.get('roleId');
|
||||
let role = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_HEADS);
|
||||
if(!role) return resResult(STATUS.ROLE_NOT_FOUND);
|
||||
if (!role) return resResult(STATUS.ROLE_NOT_FOUND);
|
||||
|
||||
let { spines } = role;
|
||||
let curSpine = spines.find(cur => cur.id == id);
|
||||
if(!curSpine) return resResult(STATUS.SPINE_NOT_FOUND);
|
||||
if(curSpine.enable) return resResult(STATUS.SPINE_IS_WEARING);
|
||||
if(!curSpine.status) return resResult(STATUS.SPINE_IS_LOCKED);
|
||||
if (!curSpine) return resResult(STATUS.SPINE_NOT_FOUND);
|
||||
if (curSpine.enable) return resResult(STATUS.SPINE_IS_WEARING);
|
||||
if (!curSpine.status) return resResult(STATUS.SPINE_IS_LOCKED);
|
||||
|
||||
let oldHead = spines.find(cur => cur.enable); // 穿戴中的头像
|
||||
if(oldHead) {
|
||||
if (oldHead) {
|
||||
oldHead.enable = false;
|
||||
}
|
||||
curSpine.enable = true;
|
||||
@@ -532,16 +539,16 @@ export class RoleHandler {
|
||||
let { roleName } = msg;
|
||||
let roleId = session.get('roleId');
|
||||
let serverId = session.get('serverId');
|
||||
|
||||
|
||||
let checkName = await RoleModel.checkName(roleName, serverId);
|
||||
if(checkName) return resResult(STATUS.NAME_HAS_USED);
|
||||
if (checkName) return resResult(STATUS.NAME_HAS_USED);
|
||||
|
||||
let role = await RoleModel.updateRoleInfo(roleId, { roleName });
|
||||
session.set('roleName', role.roleName);
|
||||
session.push('roleName', () => {});
|
||||
session.push('roleName', () => { });
|
||||
await updateUserInfo(REDIS_KEY.USER_INFO, roleId, [{ field: 'roleName', value: roleName }]);
|
||||
|
||||
return resResult(STATUS.SUCCESS, { roleName: role.roleName });
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ActivityModel, ActivityModelType } from '../db/Activity';
|
||||
import { ActivityGrowthModel, ActivityGrowthModelType } from '../db/ActivityGrowth';
|
||||
import { GrowthData } from '../domain/activityField/growthField';
|
||||
import { GrowthData, GrowthItem } from '../domain/activityField/growthField';
|
||||
|
||||
/**
|
||||
* 获取活动数据
|
||||
@@ -30,8 +30,7 @@ export async function getPlayerGrowthData(activityId: number, serverId: number,
|
||||
let playerData = new GrowthData(activityData);
|
||||
playerData.setPlayerRecords(playerRecords);
|
||||
|
||||
return { data: playerData };
|
||||
return playerData;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import { sendMail } from "./mailService";
|
||||
import { initSingleRank, getRoleOnlineInfo, updateUserInfo } from "./redisService";
|
||||
import { GuildRankParam, GuildLeader } from "../domain/rank";
|
||||
import { lockData, lockDataNoRetry } from '../services/redLockService';
|
||||
import { ErrLogModel } from '../db/ErrLog';
|
||||
import { ErrLogModel } from '../db/ErrLog';
|
||||
import { MailType, MailModel } from '../db/Mail';
|
||||
import { pushMail } from '../pubUtils/interface';
|
||||
import { getMailContent } from '../services/mailService';
|
||||
@@ -21,6 +21,7 @@ import { DATA_NAME } from '../consts/dataName';
|
||||
import { addRoleToGuildChannel } from "./chatService";
|
||||
import { Rank } from "./rankService";
|
||||
import { checkTask } from "./taskService";
|
||||
import { accomplishTask } from "../pubUtils/taskUtil";
|
||||
|
||||
/**
|
||||
* @description 检查该玩家是否有权限做操作
|
||||
@@ -31,7 +32,7 @@ export async function checkAuth(func: number, roleId: string, code?: string, use
|
||||
const auth = await UserGuildModel.getMyAuth(roleId, code, userGuild);
|
||||
const dicGuildAuth = gameData.guildAuth.get(func);
|
||||
// console.log('*checkAuth*', auth, dicGuildAuth)
|
||||
if(!dicGuildAuth) return false;
|
||||
if (!dicGuildAuth) return false;
|
||||
|
||||
return dicGuildAuth.includes(auth);
|
||||
}
|
||||
@@ -46,30 +47,30 @@ export async function joinGuild(code: string, guildName: string, lv: number, rol
|
||||
|
||||
// 周结算锁
|
||||
let weeklySumLock = await lockDataNoRetry(serverId, DATA_NAME.WEEKLY_GUILD_SUM, code);
|
||||
if(!!weeklySumLock.err) {
|
||||
if (!!weeklySumLock.err) {
|
||||
weeklySumLock.releaseCallback();
|
||||
return { status: -1, resResult: resResult(STATUS.GUILD_WEEKLY_SUM) };
|
||||
}
|
||||
weeklySumLock.releaseCallback();
|
||||
|
||||
// 人数锁
|
||||
let res:any = await lockData(serverId, DATA_NAME.JOIN_GUILD, code);// 加锁
|
||||
let res: any = await lockData(serverId, DATA_NAME.JOIN_GUILD, code);// 加锁
|
||||
if (!!res.err) return { status: -1, resResult: resResult(STATUS.REDLOCK_ERR) };
|
||||
|
||||
|
||||
const result = await RoleModel.joinGuild(roleId, code, guildName);
|
||||
if(!result) {
|
||||
if (!result) {
|
||||
res.releaseCallback();//解锁
|
||||
return { status: -1, resResult: resResult(STATUS.GUILD_HAS_JOIN) };
|
||||
}
|
||||
|
||||
const dicCenterBase = gameData.centerBase.get(lv);
|
||||
if(!dicCenterBase) {
|
||||
if (!dicCenterBase) {
|
||||
res.releaseCallback();//解锁
|
||||
return { status: -1, resResult: resResult(STATUS.DIC_DATA_NOT_FOUND) };
|
||||
}
|
||||
const maxMemberCnt = dicCenterBase.peopleNum;
|
||||
const guild = await GuildModel.addMember(code, roleId, maxMemberCnt, serverId, result.ce);
|
||||
if(!guild) {
|
||||
if (!guild) {
|
||||
res.releaseCallback();//解锁
|
||||
return { status: -1, resResult: resResult(STATUS.GUILD_MEMBER_MAX) };
|
||||
} else {
|
||||
@@ -78,7 +79,7 @@ export async function joinGuild(code: string, guildName: string, lv: number, rol
|
||||
|
||||
const role = await RoleModel.findByRoleId(roleId);
|
||||
const userGuild = await UserGuildModel.createUserGuild(guild.code, role, false);
|
||||
if(!userGuild) {
|
||||
if (!userGuild) {
|
||||
res.releaseCallback();//解锁
|
||||
return { status: -1, resResult: resResult(STATUS.GUILD_CREATE_ERROR) };
|
||||
}
|
||||
@@ -91,8 +92,11 @@ export async function joinGuild(code: string, guildName: string, lv: number, rol
|
||||
await addRoleToGuildChannel(roleId, sid, code);
|
||||
}
|
||||
|
||||
//成长任务-加入军团
|
||||
await accomplishTask(roleId, TASK_TYPE.GUILD_JOIN, 1);
|
||||
|
||||
session.set('guildCode', code);
|
||||
session.push('guildCode', () => {});
|
||||
session.push('guildCode', () => { });
|
||||
return { status: 0, guild, userGuild, roleName: role.roleName, memberCnt: guild.memberCnt, guildCe: guild.guildCe }
|
||||
}
|
||||
|
||||
@@ -102,21 +106,21 @@ export async function joinGuild(code: string, guildName: string, lv: number, rol
|
||||
* @param serverId 区
|
||||
*/
|
||||
export async function getGuildWithRefActive(guildCode: string, serverId: number) {
|
||||
|
||||
let res:any = await lockData(serverId, DATA_NAME.REFRESH_ACTIVE, guildCode);// 加锁
|
||||
|
||||
let res: any = await lockData(serverId, DATA_NAME.REFRESH_ACTIVE, guildCode);// 加锁
|
||||
if (!!res.err) return false;
|
||||
|
||||
let guild = await GuildModel.findByCode(guildCode, serverId, '+refTimeDaily');
|
||||
if(!guild) {
|
||||
if (!guild) {
|
||||
res.releaseCallback();//解锁
|
||||
return false;
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
let { activeDaily, refTimeDaily} = guild;
|
||||
let { activeDaily, refTimeDaily } = guild;
|
||||
|
||||
let isRefDaily = shouldRefresh(refTimeDaily, now, 0);
|
||||
if(isRefDaily) {
|
||||
if (isRefDaily) {
|
||||
activeDaily = 0; refTimeDaily = now;
|
||||
guild = await GuildModel.updateInfoWithLeader(guildCode, { activeDaily, refTimeDaily }, {});
|
||||
}
|
||||
@@ -136,45 +140,45 @@ export async function getGuildWithRefActive(guildCode: string, serverId: number)
|
||||
export async function addActive(roleId: string, serverId: number, id: number, type: number = 1, active?: number) {
|
||||
|
||||
let dicActiveWay = gameData.guildActiveWays.get(id);
|
||||
if(id && !dicActiveWay) {
|
||||
if (id && !dicActiveWay) {
|
||||
return { status: 0, resResult: resResult(STATUS.DIC_DATA_NOT_FOUND) };
|
||||
}
|
||||
if(!active) {
|
||||
if (!active) {
|
||||
active = getGuildActiveByIdAndType(id, type);
|
||||
}
|
||||
|
||||
let userGuild = await getUserGuildWithRefActive(roleId, 'activeRecord receivedActive activeDaily activeWeekly guildCode');
|
||||
if(!userGuild) return { status: 0, resResult: resResult(STATUS.GUILD_NOT_FOUND) };
|
||||
if (!userGuild) return { status: 0, resResult: resResult(STATUS.GUILD_NOT_FOUND) };
|
||||
|
||||
let guildCode = userGuild.guildCode;
|
||||
let guild = await getGuildWithRefActive(guildCode, serverId);
|
||||
if(!guild) return { status: 0, resResult: resResult(STATUS.GUILD_NOT_FOUND) };
|
||||
if (!guild) return { status: 0, resResult: resResult(STATUS.GUILD_NOT_FOUND) };
|
||||
|
||||
// 周结算锁
|
||||
let weeklySumLock = await lockDataNoRetry(serverId, DATA_NAME.WEEKLY_GUILD_SUM, guildCode);
|
||||
if(!!weeklySumLock.err) {
|
||||
if (!!weeklySumLock.err) {
|
||||
weeklySumLock.releaseCallback();
|
||||
return { status: 0, resResult: resResult(STATUS.GUILD_WEEKLY_SUM) };
|
||||
}
|
||||
weeklySumLock.releaseCallback();
|
||||
|
||||
let {activeRecord} = userGuild;
|
||||
if(id != 0) { // 用于debug,传0时直接增加活跃
|
||||
let { activeRecord } = userGuild;
|
||||
if (id != 0) { // 用于debug,传0时直接增加活跃
|
||||
let curActiveRecord = activeRecord.find(cur => cur.id == id);
|
||||
if( curActiveRecord ) {
|
||||
curActiveRecord.count ++;
|
||||
if (curActiveRecord) {
|
||||
curActiveRecord.count++;
|
||||
} else {
|
||||
curActiveRecord = {id, count: 1};
|
||||
curActiveRecord = { id, count: 1 };
|
||||
activeRecord.push(curActiveRecord);
|
||||
}
|
||||
if(curActiveRecord.count > dicActiveWay.count) { // 次数超过时,不增加活跃
|
||||
if (curActiveRecord.count > dicActiveWay.count) { // 次数超过时,不增加活跃
|
||||
active = 0;
|
||||
}
|
||||
}
|
||||
userGuild = await UserGuildModel.updateInfo(roleId, { activeRecord, activeUpdateTime: nowSeconds() }, { activeDaily: active, activeWeekly: active });
|
||||
|
||||
guild = await GuildModel.updateInfo(guildCode, { activeUpdateTime: nowSeconds() }, { activeDaily: active, activeWeekly: active });
|
||||
|
||||
|
||||
// 排行榜更新
|
||||
let r = new Rank(REDIS_KEY.GUILD_ACTIVE_RANK, { serverId });
|
||||
await r.setRankWithGuildInfo(guildCode, guild.activeWeekly, guild.activeUpdateTime, guild);
|
||||
@@ -188,37 +192,37 @@ export async function addActive(roleId: string, serverId: number, id: number, ty
|
||||
* @param select 筛选字段
|
||||
*/
|
||||
export async function getUserGuildWithRefActive(roleId: string, select: string, notPush?: boolean) {
|
||||
let userGuild = await UserGuildModel.getMyGuild(roleId, select? select + ' wishGoods +refTimeDaily': '+refTimeDaily');
|
||||
let userGuild = await UserGuildModel.getMyGuild(roleId, select ? select + ' wishGoods +refTimeDaily' : '+refTimeDaily');
|
||||
// console.log(JSON.stringify(userGuild))
|
||||
if(!userGuild) return false;
|
||||
if (!userGuild) return false;
|
||||
let { receivedActive, refTimeDaily, activeDaily, activeRecord, wishGoods } = userGuild;
|
||||
|
||||
const now = new Date();
|
||||
let isRefDaily = shouldRefresh(refTimeDaily, now, 0);
|
||||
if(isRefDaily) {
|
||||
if (isRefDaily) {
|
||||
let mails = new Array<MailType>();
|
||||
let pushMessage = new Array<pushMail>();
|
||||
wishGoods.map(async function ({donateNames, goodId, drawCnt}) {
|
||||
wishGoods.map(async function ({ donateNames, goodId, drawCnt }) {
|
||||
let goodInfo = getGoodById(goodId)
|
||||
if (!goodInfo)
|
||||
if (!goodInfo)
|
||||
return;
|
||||
for (let i = 0; i < drawCnt; i++ ) {
|
||||
for (let i = 0; i < drawCnt; i++) {
|
||||
let donateName = donateNames[donateNames.length - i - 1];
|
||||
await getMailContent(roleId, MAIL_TYPE.WISH_POOL_REWARD, [donateName, goodInfo.name], [{id: goodId, count: drawCnt}], mails, pushMessage);
|
||||
await getMailContent(roleId, MAIL_TYPE.WISH_POOL_REWARD, [donateName, goodInfo.name], [{ id: goodId, count: drawCnt }], mails, pushMessage);
|
||||
}
|
||||
});
|
||||
if (!!mails.length) {
|
||||
await MailModel.addMails(mails);
|
||||
if (!notPush) {
|
||||
pushMessage.forEach(({route, data, uids })=>{
|
||||
pinus.app.channelService.pushMessageByUids(route, resResult(STATUS.SUCCESS, { mails:data }), uids);
|
||||
pushMessage.forEach(({ route, data, uids }) => {
|
||||
pinus.app.channelService.pushMessageByUids(route, resResult(STATUS.SUCCESS, { mails: data }), uids);
|
||||
});
|
||||
}
|
||||
}
|
||||
receivedActive = []; refTimeDaily = now; activeDaily = 0; activeRecord = []; wishGoods = [];
|
||||
let receiveBoxs = [], wishDntCnt = 0, donateCnt = 0;
|
||||
userGuild = await UserGuildModel.updateInfo(roleId, { receivedActive, refTimeDaily, activeDaily, activeRecord, wishGoods, receiveBoxs, wishDntCnt, donateCnt }, {}, select);
|
||||
if(!userGuild) return false;
|
||||
if (!userGuild) return false;
|
||||
}
|
||||
|
||||
return userGuild;
|
||||
@@ -233,8 +237,8 @@ export async function settleGuildWeekly() {
|
||||
const guildList = await GuildModel.findAllGuild('code activeWeekly memberCnt serverId');
|
||||
|
||||
// 周结算时,1. 不能变动memberCnt 2.玩家activeWeekly不能变动 3.公会activeWeekly不能变动
|
||||
for(let { code, memberCnt, serverId } of guildList) {
|
||||
let res:any = await lockDataNoRetry(serverId, DATA_NAME.WEEKLY_GUILD_SUM, code);//加锁
|
||||
for (let { code, memberCnt, serverId } of guildList) {
|
||||
let res: any = await lockDataNoRetry(serverId, DATA_NAME.WEEKLY_GUILD_SUM, code);//加锁
|
||||
if (!!res.err) {
|
||||
await ErrLogModel.create(`settle guild lock data error: ${res.err}`)
|
||||
}
|
||||
@@ -243,33 +247,33 @@ export async function settleGuildWeekly() {
|
||||
let otherMemberCnt = 0; // 除了大将军以外从活跃高到底成员人数,用户计算活跃排名百分比
|
||||
let members = new Map<string, number>();
|
||||
|
||||
for(let {roleId, auth, activeWeekly} of userGuildList) {
|
||||
for (let { roleId, auth, activeWeekly } of userGuildList) {
|
||||
let job = 0;
|
||||
|
||||
if(auth == GUILD_AUTH.LEADER) {
|
||||
|
||||
if (auth == GUILD_AUTH.LEADER) {
|
||||
job = GUILD_JOB.DAJIANGJUN;
|
||||
} else if (activeWeekly <= ARMY.ARMY_WEEKHONOUR_LIMIT) {
|
||||
job = GUILD_JOB.SHIBING;
|
||||
} else {
|
||||
otherMemberCnt++;
|
||||
for(let [id, {rankProportion}] of gameData.guildPosition) {
|
||||
for (let [id, { rankProportion }] of gameData.guildPosition) {
|
||||
let rankCnt = Math.ceil(memberCnt * rankProportion / 100);
|
||||
job = id;
|
||||
if(otherMemberCnt <= rankCnt) break;
|
||||
if (otherMemberCnt <= rankCnt) break;
|
||||
}
|
||||
}
|
||||
await UserGuildModel.updateInfo(roleId, { job, activeWeekly: 0 }, {});
|
||||
|
||||
if(activeWeekly > ARMY.ARMY_WEEKHONOUR_LIMIT) { // 低于一定不发奖励
|
||||
if (activeWeekly > ARMY.ARMY_WEEKHONOUR_LIMIT) { // 低于一定不发奖励
|
||||
members.set(roleId, job);
|
||||
}
|
||||
}
|
||||
|
||||
// 转换周活跃奖励
|
||||
let r = new Rank(REDIS_KEY.GUILD_ACTIVE_RANK, { serverId });
|
||||
let rank = await r.getMyRank({guildCode: code});
|
||||
let rank = await r.getMyRank({ guildCode: code });
|
||||
let allWeeklyReward = getGuildActiveWeekReward(rank);
|
||||
for(let [roleId, job] of members) {
|
||||
for (let [roleId, job] of members) {
|
||||
let jobActiveRatio = gameData.guildPosition.get(job).activeRatio;
|
||||
let reward = allWeeklyReward.map(cur => {
|
||||
return {
|
||||
@@ -286,6 +290,6 @@ export async function settleGuildWeekly() {
|
||||
res.releaseCallback();//解锁
|
||||
}
|
||||
await initSingleRank(REDIS_KEY.GUILD_ACTIVE_RANK);
|
||||
await SystemConfigModel.updateSystemConfig({settleGuildWeeklyTime: nowSeconds()}); // 记录一下
|
||||
await SystemConfigModel.updateSystemConfig({ settleGuildWeeklyTime: nowSeconds() }); // 记录一下
|
||||
console.log('————— settleGuildWeekly结束 —————');
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
import { HeroModel } from '../db/Hero';
|
||||
import { HeroModel } from '../db/Hero';
|
||||
import Role, { RoleModel } from '../db/Role'
|
||||
import { getLvByExp, getExpByLv, gameData } from '../pubUtils/data';
|
||||
import { updateUserInfo } from './redisService';
|
||||
@@ -9,12 +9,13 @@ import { BackendSession } from 'pinus';
|
||||
import { REDIS_KEY } from '../consts';
|
||||
import { Rank } from './rankService';
|
||||
import { checkTask } from './taskService';
|
||||
import { accomplishTask } from '../pubUtils/taskUtil';
|
||||
|
||||
export async function roleLevelup(roleId: string, kingExp: number, session: BackendSession) {
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
let {lv = 1, exp = 0} = role;
|
||||
let { lv = 1, exp = 0 } = role;
|
||||
let canGetExp = lv < gameData.maxPlayerLv; // 当主公超过最大级后,挑战结算不再获得经验值
|
||||
let newExp = canGetExp? exp + kingExp: exp;
|
||||
let newExp = canGetExp ? exp + kingExp : exp;
|
||||
let newLv = getLvByExp(newExp);
|
||||
// 等级超过最高级之后,经验依然可以稍微溢出一些,以备下一次提升等级
|
||||
// let nextExpObj = getExpByLv(newLv + 1);
|
||||
@@ -22,50 +23,53 @@ export async function roleLevelup(roleId: string, kingExp: number, session: Back
|
||||
// if(curExpObj && !nextExpObj && newExp > curExpObj.sum) {
|
||||
// newExp = curExpObj.sum;
|
||||
// }
|
||||
|
||||
|
||||
role = await RoleModel.levelup(roleId, newLv, newExp);
|
||||
if(newLv > lv) { // 升级
|
||||
await switchOnFunc(roleId, FUNC_OPT_TYPE.LEVEL_UP, newLv, session);
|
||||
await updateUserInfo(REDIS_KEY.USER_INFO, roleId, [{field: 'lv', value: newLv}]);
|
||||
if (newLv > lv) { // 升级
|
||||
await switchOnFunc(roleId, FUNC_OPT_TYPE.LEVEL_UP, newLv, session);
|
||||
await updateUserInfo(REDIS_KEY.USER_INFO, roleId, [{ field: 'lv', value: newLv }]);
|
||||
|
||||
let r = new Rank(REDIS_KEY.USER_LV, { serverId: role.serverId });
|
||||
await r.setRankWithRoleInfo(roleId, newLv, Date.now(), role);
|
||||
|
||||
// 任务
|
||||
await checkTask(roleId, session.get('sid'), session.get('funcs'), TASK_TYPE.ROLE_LV, newLv, false, {});
|
||||
//成长任务
|
||||
await accomplishTask(roleId, TASK_TYPE.ROLE_LV, newLv);
|
||||
|
||||
}
|
||||
let actordata = [];
|
||||
for(let i = lv; i <= newLv; i++) {
|
||||
for (let i = lv; i <= newLv; i++) {
|
||||
let lvObj = getExpByLv(i);
|
||||
|
||||
if(!lvObj) break;
|
||||
let {sum, cur} = lvObj;
|
||||
if (!lvObj) break;
|
||||
let { sum, cur } = lvObj;
|
||||
let lastSum = sum - cur;
|
||||
// console.log(sum, cur, lastSum, exp, newExp);
|
||||
|
||||
let startExp = exp > lastSum? exp - lastSum: 0;
|
||||
let getExp = newExp > sum? cur - startExp: newExp - lastSum - startExp;
|
||||
let startExp = exp > lastSum ? exp - lastSum : 0;
|
||||
let getExp = newExp > sum ? cur - startExp : newExp - lastSum - startExp;
|
||||
actordata.push({
|
||||
lv : i,
|
||||
exp : startExp, // 升级前经验
|
||||
getExp : getExp > 0? getExp: 0, // 获得的经验
|
||||
mostExp : cur
|
||||
lv: i,
|
||||
exp: startExp, // 升级前经验
|
||||
getExp: getExp > 0 ? getExp : 0, // 获得的经验
|
||||
mostExp: cur
|
||||
});
|
||||
}
|
||||
return {actordata, lv: newLv, exp: newExp, kingExp: newExp - exp};
|
||||
return { actordata, lv: newLv, exp: newExp, kingExp: newExp - exp };
|
||||
}
|
||||
|
||||
|
||||
export async function checkBattleHeroes(roleId: string, seqIds: Array<number>) {
|
||||
let heroes: number[] = [];
|
||||
let flag = true;
|
||||
if(seqIds.length <= 0) flag = false;
|
||||
if (seqIds.length <= 0) flag = false;
|
||||
|
||||
const findHeroes = await HeroModel.findBySeqIdRange(seqIds, roleId);
|
||||
if(findHeroes.length != seqIds.length) flag = false;
|
||||
for(let seqId of seqIds) {
|
||||
if (findHeroes.length != seqIds.length) flag = false;
|
||||
for (let seqId of seqIds) {
|
||||
let hero = findHeroes.find(cur => cur.seqId == seqId);
|
||||
if(!hero) {
|
||||
if (!hero) {
|
||||
flag = false; break;
|
||||
}
|
||||
heroes.push(hero.hid);
|
||||
@@ -75,24 +79,24 @@ export async function checkBattleHeroes(roleId: string, seqIds: Array<number>) {
|
||||
|
||||
export async function checkBattleHeroesByHid(roleId: string, heroes: Array<number>) {
|
||||
let flag = true;
|
||||
if(heroes.length <= 0) flag = false;
|
||||
if (heroes.length <= 0) flag = false;
|
||||
|
||||
const findHeroes = await HeroModel.findByHidRange(heroes, roleId);
|
||||
if(findHeroes.length != heroes.length) flag = false;
|
||||
for(let hid of heroes) {
|
||||
if (findHeroes.length != heroes.length) flag = false;
|
||||
for (let hid of heroes) {
|
||||
let hero = findHeroes.find(cur => cur.hid == hid);
|
||||
if(!hero) flag = false;
|
||||
if (!hero) flag = false;
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
export async function updateWarStar(roleId: string, battleId: number, warType: number, star: number) {
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
let { warStar = new Array<{id: number, warType: number, star: number}>() } = role;
|
||||
let { warStar = new Array<{ id: number, warType: number, star: number }>() } = role;
|
||||
let curStar = warStar.find(cur => cur.id == battleId);
|
||||
let result: Role;
|
||||
if(curStar) {
|
||||
if(star > curStar.star) {
|
||||
if (curStar) {
|
||||
if (star > curStar.star) {
|
||||
result = await Role.updateWarStar(roleId, battleId, star);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -16,9 +16,9 @@ import { gameData } from '../pubUtils/data';
|
||||
import { getCurWeekDate, getSeconds } from '../pubUtils/timeUtil';
|
||||
|
||||
export async function checkTaskWithRoles(roleId: string, sid: string, funcs: number[], taskType: number, roles: RoleType[]) {
|
||||
for(let role of roles) {
|
||||
if(role) {
|
||||
await checkTaskWithRole(role.roleId, role.roleId == roleId? sid: null, role.roleId == roleId? funcs: null, taskType, role);
|
||||
for (let role of roles) {
|
||||
if (role) {
|
||||
await checkTaskWithRole(role.roleId, role.roleId == roleId ? sid : null, role.roleId == roleId ? funcs : null, taskType, role);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,14 +59,14 @@ export async function checkTask(roleId: string, sid: string, funcs: number[], ta
|
||||
}
|
||||
|
||||
export async function pushTaskUpdate(roleId: string, sid: string, funcs: number[], pushMessage: TaskListReturn[]) {
|
||||
if(pushMessage.length > 0) {
|
||||
if(!sid || !funcs) {
|
||||
if (pushMessage.length > 0) {
|
||||
if (!sid || !funcs) {
|
||||
let onlineUser = await getRoleOnlineInfo(roleId);
|
||||
sid = onlineUser.sid;
|
||||
funcs = onlineUser.funcs||[];
|
||||
funcs = onlineUser.funcs || [];
|
||||
}
|
||||
if(!!sid) {
|
||||
let uids = [{uid: roleId, sid}];
|
||||
if (!!sid) {
|
||||
let uids = [{ uid: roleId, sid }];
|
||||
pinus.app.get('channelService').pushMessageByUids('onTaskUpdate', resResult(STATUS.SUCCESS, pushMessage), uids);
|
||||
}
|
||||
}
|
||||
@@ -86,12 +86,14 @@ export async function checkTaskInBattleEnd(roleId: string, sid: string, funcs: n
|
||||
await checkTaskWithWar(roleId, sid, funcs, TASK_TYPE.BATTLE_TOWER, battleId, heroes, 1, star);
|
||||
await checkTaskWithWar(roleId, sid, funcs, TASK_TYPE.BATTLE_VESTIGE, battleId, heroes, 1, star);
|
||||
await checkTaskWithWar(roleId, sid, funcs, TASK_TYPE.BATTLE_EXPEDITION, battleId, heroes, 1, star);
|
||||
//成长任务
|
||||
await taskUtil.accomplishTask(roleId, TASK_TYPE.BATTLE_MAIN, 1, { warId: battleId })
|
||||
|
||||
}
|
||||
|
||||
export async function checkTaskInComBattleEnd(roleIds: string[], capId: string, quality: number) {
|
||||
for(let roleId of roleIds) {
|
||||
if(roleId == capId && roleIds.length > 1) { // 招募队友
|
||||
for (let roleId of roleIds) {
|
||||
if (roleId == capId && roleIds.length > 1) { // 招募队友
|
||||
await checkTask(roleId, null, null, TASK_TYPE.COM_BATTLE_CREATE_TEAM, 1, true, {});
|
||||
} else if (roleId !== capId) { // 协助寻宝
|
||||
await checkTask(roleId, null, null, TASK_TYPE.COM_BATTLE_ASSIST_TEAM, 1, true, {});
|
||||
@@ -103,7 +105,7 @@ export async function checkTaskInComBattleEnd(roleIds: string[], capId: string,
|
||||
|
||||
export async function checkTaskInPvpEnd(roleId: string, sid: string, funcs: number[], isSuccess: boolean, heroScores: HeroScores[]) {
|
||||
await checkTask(roleId, sid, funcs, TASK_TYPE.PVP, 1, true, {});
|
||||
if(isSuccess) {
|
||||
if (isSuccess) {
|
||||
await checkTask(roleId, sid, funcs, TASK_TYPE.PVP_WIN, 1, true, {});
|
||||
await checkTask(roleId, sid, funcs, TASK_TYPE.PVP_WIN_SERIES, 1, true, {});
|
||||
} else {
|
||||
@@ -120,19 +122,19 @@ export async function getCurTask(roleId: string, session: FrontendOrBackendSessi
|
||||
|
||||
let { dailyTaskRefWeekly, dailyTaskRef } = userTask;
|
||||
let curWeekStart = getCurWeekDate(1, 5);
|
||||
if(dailyTaskRefWeekly < curWeekStart) { // 刷新周宝箱
|
||||
if (dailyTaskRefWeekly < curWeekStart) { // 刷新周宝箱
|
||||
dailyTaskRefWeekly = curWeekStart;
|
||||
}
|
||||
session.set('refWeekly', getSeconds(dailyTaskRefWeekly));
|
||||
session.push('refWeekly', ()=> {});
|
||||
|
||||
if(shouldRefresh(dailyTaskRef, new Date(), 5)) {
|
||||
session.push('refWeekly', () => { });
|
||||
|
||||
if (shouldRefresh(dailyTaskRef, new Date(), 5)) {
|
||||
dailyTaskRef = new Date();
|
||||
userTask = await UserTaskModel.updateInfo(roleId, { dailyTaskRef });
|
||||
await removeHistoryTask(roleId, TASK_FUN_TYPE.DAILY);
|
||||
}
|
||||
session.set('refDaily', getSeconds(dailyTaskRef));
|
||||
session.push('refDaily', ()=> {});
|
||||
session.push('refDaily', () => { });
|
||||
|
||||
let mainTask = await getMainTask(roleId, userTask);
|
||||
let dailyTask = await getDailyTask(roleId, userTask);
|
||||
@@ -146,10 +148,10 @@ export async function getMainTask(roleId: string, userTask: UserTaskType) {
|
||||
let recMap = await UserTaskRecModel.findByRoleAndType(roleId, type); // group=>userTaskRec
|
||||
|
||||
let taskList: TaskListReturn[] = [];
|
||||
for(let [id, dic] of gameData.mainTask) {
|
||||
if(dic.taskStage == stage) {
|
||||
for (let [id, dic] of gameData.mainTask) {
|
||||
if (dic.taskStage == stage) {
|
||||
let dbRec = recMap.get(dic.taskType)?.get(dic.group);
|
||||
if(dbRec) {
|
||||
if (dbRec) {
|
||||
taskList.push({ type, id, count: dbRec.count, received: dbRec.received.includes(id) });
|
||||
} else {
|
||||
taskList.push({ type, id, count: 0, received: false });
|
||||
@@ -163,7 +165,7 @@ export async function getDailyTask(roleId: string, userTask: UserTaskType) {
|
||||
let type = TASK_FUN_TYPE.DAILY;
|
||||
let { dailyTaskPoint: point, dailyTaskRefWeekly, dailyTaskPointWeekly: weeklyPoint, dailyTaskBox: box } = userTask;
|
||||
let curWeekStart = getCurWeekDate(1, 5);
|
||||
if(dailyTaskRefWeekly < curWeekStart) { // 刷新
|
||||
if (dailyTaskRefWeekly < curWeekStart) { // 刷新
|
||||
dailyTaskRefWeekly = curWeekStart;
|
||||
weeklyPoint = 0;
|
||||
box = [];
|
||||
@@ -171,9 +173,9 @@ export async function getDailyTask(roleId: string, userTask: UserTaskType) {
|
||||
let recMap = await UserTaskRecModel.findByRoleAndType(roleId, type); // group=>userTaskRec
|
||||
|
||||
let taskList: TaskListReturn[] = [];
|
||||
for(let [id, dic] of gameData.dailyTask) {
|
||||
for (let [id, dic] of gameData.dailyTask) {
|
||||
let dbRec = recMap.get(dic.taskType)?.get(dic.group);
|
||||
if(dbRec) {
|
||||
if (dbRec) {
|
||||
taskList.push({ type, id, count: dbRec.count, received: dbRec.received.includes(id) });
|
||||
} else {
|
||||
taskList.push({ type, id, count: 0, received: false });
|
||||
@@ -188,9 +190,9 @@ export async function getAchievement(roleId: string, userTask: UserTaskType) {
|
||||
let recMap = await UserTaskRecModel.findByRoleAndType(roleId, type); // group=>userTaskRec
|
||||
|
||||
let taskList: TaskListReturn[] = [];
|
||||
for(let [id, dic] of gameData.achievement) {
|
||||
for (let [id, dic] of gameData.achievement) {
|
||||
let dbRec = recMap.get(dic.taskType)?.get(dic.group);
|
||||
if(dbRec) {
|
||||
if (dbRec) {
|
||||
taskList.push({ type, id, count: dbRec.count, received: dbRec.received.includes(id) });
|
||||
} else {
|
||||
taskList.push({ type, id, count: 0, received: false });
|
||||
@@ -207,7 +209,7 @@ export async function refDailyTask(roleId: string, sid: string) {
|
||||
// 转移每日任务
|
||||
await removeHistoryTask(roleId, TASK_FUN_TYPE.DAILY);
|
||||
|
||||
let uids = [{uid: roleId, sid}];
|
||||
let uids = [{ uid: roleId, sid }];
|
||||
pinus.app.get('channelService').pushMessageByUids('onDailyTaskRefresh', resResult(STATUS.SUCCESS, { taskList }), uids);
|
||||
|
||||
}
|
||||
@@ -216,21 +218,21 @@ export async function removeHistoryTask(roleId: string, type: number, today?: Da
|
||||
|
||||
// 转移每日任务
|
||||
let history = await UserTaskRecModel.getHistoryRec(roleId, type, today);
|
||||
if(history.length > 0) {
|
||||
if (history.length > 0) {
|
||||
await UserTaskHistoryModel.pushUserTask(roleId, history);
|
||||
await UserTaskRecModel.deleteHistory(history);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 刷新每日宝箱数量
|
||||
export async function refDailyTaskBox(roleId: string, sid: string, debug = false) {
|
||||
let userTask = await UserTaskModel.refreshWeekly(roleId, debug);
|
||||
if(userTask) {
|
||||
if (userTask) {
|
||||
let { dailyTaskPoint: point, dailyTaskPointWeekly: weeklyPoint, dailyTaskBox: box } = userTask;
|
||||
let uids = [{uid: roleId, sid}];
|
||||
pinus.app.get('channelService').pushMessageByUids('onTaskBoxRefresh', resResult(STATUS.SUCCESS, {
|
||||
let uids = [{ uid: roleId, sid }];
|
||||
pinus.app.get('channelService').pushMessageByUids('onTaskBoxRefresh', resResult(STATUS.SUCCESS, {
|
||||
type: TASK_FUN_TYPE.DAILY,
|
||||
point, weeklyPoint, box
|
||||
}), uids);
|
||||
}), uids);
|
||||
}
|
||||
}
|
||||
@@ -6,4 +6,5 @@
|
||||
|
||||
export enum ACTIVITY_TYPE {
|
||||
SEVEN_DAYS = 1, // 七天乐活动
|
||||
TASK_GROWTH = 2, // 成长任务活动
|
||||
}
|
||||
@@ -535,10 +535,10 @@ export enum POPULATE_TYPE {
|
||||
}
|
||||
|
||||
export enum BLOCK_OPEATE {
|
||||
ADD = 1,
|
||||
REMOVE_BLACK = 2,
|
||||
REMOVE_AND_APPLY = 3,
|
||||
REMOVE_FRIEND = 4
|
||||
ADD = 1,
|
||||
REMOVE_BLACK = 2,
|
||||
REMOVE_AND_APPLY = 3,
|
||||
REMOVE_FRIEND = 4
|
||||
}
|
||||
|
||||
export enum TIME_FORMAT {
|
||||
@@ -653,6 +653,7 @@ export enum TASK_TYPE {
|
||||
GUILD_BOSS = 69, // 军团演武台挑战
|
||||
GUILD_TRAIN = 70, // 挑战练兵场
|
||||
GUILD_ACTIVITY = 71, // 军团活动
|
||||
GUILD_JOIN = 72, // 加入军团
|
||||
}
|
||||
|
||||
// 卡池类型
|
||||
@@ -672,10 +673,10 @@ export enum GACHA_FLOOR_TYPE {
|
||||
|
||||
// 抽卡对应保底类型
|
||||
export const GACHA_TO_FLOOR = new Map([
|
||||
[ GACHA_ID.NORMAL, [ GACHA_FLOOR_TYPE.PURPLE, GACHA_FLOOR_TYPE.GOLD ] ],
|
||||
[ GACHA_ID.FRDPOINT, [] ],
|
||||
[ GACHA_ID.ASSIGN, [ GACHA_FLOOR_TYPE.ASSIGN ] ],
|
||||
[ GACHA_ID.TIMELIMIT, [ GACHA_FLOOR_TYPE.ASSIGN ] ]
|
||||
[GACHA_ID.NORMAL, [GACHA_FLOOR_TYPE.PURPLE, GACHA_FLOOR_TYPE.GOLD]],
|
||||
[GACHA_ID.FRDPOINT, []],
|
||||
[GACHA_ID.ASSIGN, [GACHA_FLOOR_TYPE.ASSIGN]],
|
||||
[GACHA_ID.TIMELIMIT, [GACHA_FLOOR_TYPE.ASSIGN]]
|
||||
])
|
||||
|
||||
// 抽卡里的卡池道具类型
|
||||
|
||||
@@ -329,6 +329,10 @@ export const STATUS = {
|
||||
UPDATE_PRIVATE_MSG_READ_TIME_ERR: { code: 40001, simStr: '更新私聊阅读时间失败' },
|
||||
// 运营模块相关状态 50000 - 59999
|
||||
ACTIVITY_MISSING: { code: 50000, simStr: '活动丢失' },
|
||||
ACTIVITY_DATA_ERROR: { code: 50001, simStr: '数据错误' },
|
||||
ACTIVITY_TASK_UNCOMPLETED: { code: 50002, simStr: '任务还未完成' },
|
||||
ACTIVITY_NO_POINT: { code: 50003, simStr: '奖章不足' },
|
||||
ACTIVITY_REWARDED: { code: 50004, simStr: '已经领取过' },
|
||||
// GM后台相关状态 60000 - 69999
|
||||
GM_ERR_PASSWORD: { code: 60001, simStr: '账号或密码错误' },
|
||||
GM_MISS_API: { code: 60002, simStr: '未找到该接口' },
|
||||
|
||||
@@ -18,6 +18,18 @@ export default class Activity extends BaseModel {
|
||||
@prop({ required: true })
|
||||
data: string; // 活动表中的数据
|
||||
|
||||
//根据活动类型查询开启的活动数据
|
||||
public static async findOpenActivityByType(type: number, date: Date, lean = true) {
|
||||
let result: ActivityModelType[] = await ActivityModel.find({ type, beginTime: { $lte: date }, endTime: { $gte: date } }).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动类型查询活动数据
|
||||
public static async findActivityByType(type: number, lean = true) {
|
||||
let result: ActivityModelType[] = await ActivityModel.find({ type }).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动id查询活动数据
|
||||
public static async findActivity(acvitityId: number, lean = true) {
|
||||
let result: ActivityModelType = await ActivityModel.findOne({ acvitityId }).lean(lean);
|
||||
|
||||
@@ -20,12 +20,39 @@ export default class ActivityGrowth extends BaseModel {
|
||||
@prop({ required: true })
|
||||
totalCount: number; // 累计达成次数
|
||||
@prop({ required: true })
|
||||
count: number; // 领取次数
|
||||
receiveRewardCount: number; // 领取奖励次数
|
||||
@prop({ required: true, default: 0 })
|
||||
addPointCount: number; // 获得奖章个数
|
||||
@prop({ required: true, default: false })
|
||||
pointReward: boolean; // 是否兑换领取奖章奖励
|
||||
getPointReward: boolean; // 是否兑换领取奖章奖励
|
||||
|
||||
//任务领取记录
|
||||
public static async addCellRecord(acvitityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number, count: number, lean = true) {
|
||||
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOneAndUpdate({ roleId, acvitityId, dayIndex, cellIndex, type },
|
||||
{ $inc: { receiveRewardCount: count } }, { upsert: true, new: true }).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
//当日奖章领取记录
|
||||
public static async addDayRecord(acvitityId: number, roleId: string, dayIndex: number, cellIndex: number, lean = true) {
|
||||
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOneAndUpdate({ roleId, acvitityId, dayIndex, cellIndex },
|
||||
{ $set: { getPointReward: true } }, { upsert: true, new: true }).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动统计完成任务次数
|
||||
public static async setTaskCount(acvitityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number, count: number, lean = true) {
|
||||
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOneAndUpdate({ roleId, acvitityId, dayIndex, cellIndex, type },
|
||||
{ $set: { totalCount: count } }, { upsert: true, new: true }).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动统计完成任务次数
|
||||
public static async addTaskCount(acvitityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number, addCount: number, lean = true) {
|
||||
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOneAndUpdate({ roleId, acvitityId, dayIndex, cellIndex, type },
|
||||
{ $inc: { totalCount: addCount } }, { upsert: true, new: true }).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动id查询活动数据
|
||||
public static async findData(acvitityId: number, roleId: string, lean = true) {
|
||||
|
||||
@@ -1,23 +1,112 @@
|
||||
import { prop } from '@typegoose/typegoose';
|
||||
import { TASK_TYPE } from '../../consts';
|
||||
import { ActivityModelType } from '../../db/Activity';
|
||||
import { ActivityGrowthModelType } from '../../db/ActivityGrowth';
|
||||
import { RewardInter } from '../../pubUtils/interface';
|
||||
import { parseGoodStrWithType, splitString } from '../../pubUtils/util';
|
||||
import { ActivityBase } from './activityField';
|
||||
|
||||
|
||||
// 每日配置数据
|
||||
export class GrowthItem {
|
||||
dayIndex: number = 0;
|
||||
cellIndex: number = 0;
|
||||
count: number = 0;
|
||||
total: number = 0;
|
||||
isReceive: boolean = false;
|
||||
dayIndex: number; // 第几天,从1开始
|
||||
cellIndex: number; // 当天第几行,从1开始
|
||||
name: string; // 任务名称
|
||||
taskType: number; // 任务类型 dic_zyz_taskType.json
|
||||
taskParam: string; //任务数据 dic_zyz_taskType.json
|
||||
taskParamArray: Array<number>; //任务数据 dic_zyz_taskType.json
|
||||
point: number; // 任务达成获得的奖章数量,只在当前活动中有用,虚拟
|
||||
reward: string; // 任务奖励,格式:1&3&1(类型&id&数量) 类型定义:1.英雄,2.物品
|
||||
consumePoint: number; // 奖章兑换奖品,需要消耗的奖章个数
|
||||
pointReward: string; // 奖章兑换奖品,奖励内容,格式:1&3&1(类型&id&数量) 类型定义:1.英雄,2.物品
|
||||
|
||||
constructor(dayIndex: number, cellIndex: number, count: number, total: number, isReceive: boolean) {
|
||||
this.dayIndex = dayIndex;//第几天奖励
|
||||
this.cellIndex = cellIndex;//某天第几个奖励
|
||||
this.count = count;//已经领取奖励的次数
|
||||
this.total = total;//总共可领取奖励次数
|
||||
this.isReceive = isReceive;//是否领取
|
||||
totalCount: number = 0; //完成任务累计次数
|
||||
receiveRewardCount: number = 0; //领取奖励次数
|
||||
addPointCount: number = 0; // 获得奖章个数
|
||||
getPointReward: boolean = false; // 是否兑换领取奖章奖励
|
||||
|
||||
constructor(data: any) {
|
||||
this.dayIndex = data.dayIndex;
|
||||
this.cellIndex = data.cellIndex;
|
||||
this.name = data.name;
|
||||
this.taskType = data.taskType;
|
||||
this.taskParam = data.taskParam;
|
||||
this.point = data.point;
|
||||
this.reward = data.reward;
|
||||
this.consumePoint = data.consumePoint;
|
||||
this.pointReward = data.pointReward;
|
||||
|
||||
this.taskParamArray = splitString(data.taskParam, '&')
|
||||
}
|
||||
|
||||
public heroReward(): RewardInter[] {
|
||||
let rewardArray = [];
|
||||
let rewardData = this.reward.split('|').filter(obj => { return obj && obj != '' });
|
||||
for (let objStr of rewardData) {
|
||||
let reward = parseGoodStrWithType(objStr);
|
||||
rewardArray.push(reward);
|
||||
}
|
||||
return rewardArray.find(obj => { return obj && obj.type == 1 })
|
||||
}
|
||||
|
||||
public goodReward(): RewardInter[] {
|
||||
let rewardArray = [];
|
||||
let rewardData = this.reward.split('|').filter(obj => { return obj && obj != '' });
|
||||
for (let objStr of rewardData) {
|
||||
let reward = parseGoodStrWithType(objStr);
|
||||
rewardArray.push(reward);
|
||||
}
|
||||
return rewardArray.find(obj => { return obj && obj.type == 2 })
|
||||
}
|
||||
|
||||
public canReceive(): boolean {
|
||||
return this.receiveRewardCount != 0;
|
||||
}
|
||||
|
||||
public isComplete(): boolean {
|
||||
let complete = false;
|
||||
switch (this.taskType) {
|
||||
case TASK_TYPE.ROLE_LV:
|
||||
complete = this.totalCount >= this.taskParamArray[0];
|
||||
break;
|
||||
case TASK_TYPE.GUILD_JOIN:
|
||||
complete = this.totalCount >= this.taskParamArray[0];
|
||||
break;
|
||||
case TASK_TYPE.LOGIN_SUM:
|
||||
complete = this.totalCount >= this.taskParamArray[0];
|
||||
break;
|
||||
case TASK_TYPE.HERO_NUM:
|
||||
complete = this.totalCount >= this.taskParamArray[0];
|
||||
break;
|
||||
case TASK_TYPE.ROLE_TITLE:
|
||||
complete = this.totalCount >= this.taskParamArray[0];
|
||||
break;
|
||||
case TASK_TYPE.GASHA:
|
||||
complete = this.totalCount >= this.taskParamArray[0];
|
||||
break;
|
||||
case TASK_TYPE.EQUIP_STRENGTHEN:
|
||||
complete = this.totalCount >= this.taskParamArray[0];
|
||||
break;
|
||||
case TASK_TYPE.BATTLE_MAIN:
|
||||
complete = this.totalCount >= this.taskParamArray[0];
|
||||
break;
|
||||
case TASK_TYPE.EQUIP_JEWEL_SUM:
|
||||
complete = this.totalCount >= this.taskParamArray[0];
|
||||
break;
|
||||
case TASK_TYPE.GUILD_TRAIN:
|
||||
complete = this.totalCount >= this.taskParamArray[0];
|
||||
break;
|
||||
case TASK_TYPE.ROLE_SCHOOL_PUT_HERO:
|
||||
complete = this.totalCount >= this.taskParamArray[0];
|
||||
break;
|
||||
case TASK_TYPE.GUILD_ACTIVITY:
|
||||
complete = this.totalCount >= this.taskParamArray[0];
|
||||
break;
|
||||
default:
|
||||
complete = false;
|
||||
break;
|
||||
}
|
||||
return complete;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,13 +114,41 @@ export class GrowthItem {
|
||||
// 成长活动数据
|
||||
export class GrowthData extends ActivityBase {
|
||||
list: Array<GrowthItem> = [];
|
||||
totalPoint: number = 0;//获得奖章总数
|
||||
totalConsumePoint: number = 0;//消耗奖章总数
|
||||
|
||||
//第几天的奖章兑换
|
||||
public findDayItem(dayIndex: number) {
|
||||
let index = this.list.findIndex(obj => { return obj && obj.dayIndex == dayIndex && obj.cellIndex == 1 })
|
||||
return (index != -1) ? this.list[index] : null;
|
||||
}
|
||||
|
||||
public findGrowthItem(dayIndex: number, cellIndex: number, type: number) {
|
||||
let index = this.list.findIndex(obj => { return obj && obj.dayIndex == dayIndex && obj.cellIndex == cellIndex && obj.taskType == type })
|
||||
return (index != -1) ? this.list[index] : null;
|
||||
}
|
||||
|
||||
public findTaskByType(type: TASK_TYPE) {
|
||||
return this.list.filter(obj => {
|
||||
return obj && obj.taskType == type;
|
||||
})
|
||||
}
|
||||
|
||||
//解析玩家领取记录
|
||||
public setPlayerRecords(data: ActivityGrowthModelType[]) {
|
||||
this.totalPoint = 0;
|
||||
this.totalConsumePoint = 0;
|
||||
for (let obj of this.list) {
|
||||
let index = data.findIndex(record => { return obj.dayIndex == record.dayIndex && obj.cellIndex == record.cellIndex })
|
||||
if (index != -1) {
|
||||
obj.count = data[index].count;
|
||||
obj.totalCount = data[index].totalCount;
|
||||
obj.receiveRewardCount = data[index].receiveRewardCount;
|
||||
obj.addPointCount = data[index].addPointCount;
|
||||
obj.getPointReward = data[index].getPointReward;
|
||||
this.totalPoint += data[index].addPointCount;
|
||||
if (data[index].getPointReward) {
|
||||
this.totalConsumePoint += data[index].addPointCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,7 +156,7 @@ export class GrowthData extends ActivityBase {
|
||||
public initData(data: string) {
|
||||
let arr = JSON.parse(data);
|
||||
for (let obj of arr) {
|
||||
this.list.push(new GrowthItem(obj.dayIndex, obj.cellIndex, obj.count, 0, false));
|
||||
this.list.push(new GrowthItem(obj))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ export interface EquipInter {
|
||||
};
|
||||
|
||||
|
||||
export interface BagInter {id: number, itemName: string, count: number, type: number, hid:number, times?: number};
|
||||
export interface ItemInter {id?: number, count?: number, seqId?: number, type?: number};
|
||||
export interface BagInter { id: number, itemName: string, count: number, type: number, hid: number, times?: number };
|
||||
export interface ItemInter { id?: number, count?: number, seqId?: number, type?: number };
|
||||
|
||||
// 百家学宫,布阵武将位置
|
||||
export interface SclPosInter {
|
||||
@@ -66,16 +66,16 @@ export interface oppHeroesDefenseInter {
|
||||
initial_ai: number; // ai类型
|
||||
attribute: Attribute;
|
||||
star: number; // 星级
|
||||
skill: string|number; // 技能
|
||||
skill: string | number; // 技能
|
||||
seid: string; // 技能
|
||||
spine: string|number; // 动画
|
||||
spine: string | number; // 动画
|
||||
|
||||
}
|
||||
|
||||
export interface pvpEndParamInter {
|
||||
hid: number;
|
||||
damage: number;
|
||||
heal: number;
|
||||
hid: number;
|
||||
damage: number;
|
||||
heal: number;
|
||||
underDamage: number;
|
||||
}
|
||||
|
||||
@@ -99,4 +99,4 @@ export interface mailData {
|
||||
status: number;
|
||||
mailType: number;
|
||||
sendName: string;
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ import { RoleModel, RoleType } from '../db/Role';
|
||||
import { Figure } from '../domain/dbGeneral';
|
||||
import { getBeforeDaySeconds, nowSeconds } from './timeUtil';
|
||||
import { calPlayerCeAndSave, reCalAllHeroCe } from './playerCe';
|
||||
import { checkTask, checkTaskWithHeroes, checkTaskWithEquip } from './taskUtil';
|
||||
import { checkTask, checkTaskWithHeroes, checkTaskWithEquip, accomplishTask } from './taskUtil';
|
||||
|
||||
export async function addSkins(roleId: string, id: number) {
|
||||
let skinInfo = gameData.fashion.get(id);
|
||||
@@ -37,7 +37,7 @@ export async function addBags(roleId: string, roleName: string, data: BagInter)
|
||||
|
||||
export async function addEquips(roleId: string, roleName: string, weapon: EquipInter) {
|
||||
let { id, name, quality, suitId, hole, randomEffect, itid, hid } = weapon;
|
||||
let {type} = ITID.get(itid);
|
||||
let { type } = ITID.get(itid);
|
||||
|
||||
let randomNum = RANDOM_SE_COUNT.get(quality);
|
||||
let randomResult: number[] = getRandEelm(randomEffect, randomNum);
|
||||
@@ -45,7 +45,7 @@ export async function addEquips(roleId: string, roleName: string, weapon: EquipI
|
||||
let randSe: Array<RandSe> = randomResult.map((id: number, i: number) => {
|
||||
let random = gameData.randomEffectPool.get(id)
|
||||
let rand = 0;
|
||||
if(random.id > 0) rand = getRandValueByMinMax(random.Min, random.Max, 0);
|
||||
if (random.id > 0) rand = getRandValueByMinMax(random.Min, random.Max, 0);
|
||||
return {
|
||||
id: i + 1,
|
||||
seid: random.id,
|
||||
@@ -53,16 +53,16 @@ export async function addEquips(roleId: string, roleName: string, weapon: EquipI
|
||||
locked: false
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
let randRange = getRandValueByMinMax(0 - FIX_ATTRIBUTES_RAN, FIX_ATTRIBUTES_RAN, 0);
|
||||
|
||||
|
||||
let holes = new Array<Holes>();
|
||||
for(let i = 0; i < hole; i++) {
|
||||
holes.push({id: i+1, isOpen: false, jewel: 0})
|
||||
for (let i = 0; i < hole; i++) {
|
||||
holes.push({ id: i + 1, isOpen: false, jewel: 0 })
|
||||
}
|
||||
|
||||
const equip = await EquipModel.createEquip({roleId, roleName, id, name, quality, suitId, randRange, ePlaceId: type, randSe, holes, hid});
|
||||
|
||||
const equip = await EquipModel.createEquip({ roleId, roleName, id, name, quality, suitId, randRange, ePlaceId: type, randSe, holes, hid });
|
||||
|
||||
// 任务
|
||||
let pushMessage = await checkTaskWithEquip(roleId, TASK_TYPE.EQUIP_SUIT, equip);
|
||||
|
||||
@@ -74,7 +74,7 @@ export async function addEquips(roleId: string, roleName: string, weapon: EquipI
|
||||
* @param count 元宝数量
|
||||
*/
|
||||
export function getGoldObject(count: number) {
|
||||
return { id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD), count};
|
||||
return { id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD), count };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,7 +82,7 @@ export function getGoldObject(count: number) {
|
||||
* @param count 友情点数量
|
||||
*/
|
||||
export function getFriendPointObject(count: number) {
|
||||
return { id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.FRIEND_POINT), count};
|
||||
return { id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.FRIEND_POINT), count };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,7 +90,7 @@ export function getFriendPointObject(count: number) {
|
||||
* @param count 功勋数量
|
||||
*/
|
||||
export function getHonourObject(count: number) {
|
||||
return { id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.HONOUR), count};
|
||||
return { id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.HONOUR), count };
|
||||
}
|
||||
/**
|
||||
* 解锁头像/相框
|
||||
@@ -99,47 +99,47 @@ export function getHonourObject(count: number) {
|
||||
* @param role 如果已查询过role表就直接可以使用
|
||||
*/
|
||||
export async function unlockFigure(roleId: string, conditions: { type: number, paramHid?: number, paramFavourLv?: number, paramSkinId?: number }[], role?: RoleType) {
|
||||
if(!role || !role.heads || !role.frames) {
|
||||
if (!role || !role.heads || !role.frames) {
|
||||
role = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_HEADS);
|
||||
}
|
||||
let { heads, frames, spines } = role;
|
||||
let figureInfo = { heads: new Array<Figure>(), frames: new Array<Figure>(), spines: new Array<Figure>() };
|
||||
for(let {type, paramHid, paramFavourLv, paramSkinId } of conditions) {
|
||||
for (let { type, paramHid, paramFavourLv, paramSkinId } of conditions) {
|
||||
let canUnLockList = gameData.figureCondition.get(type);
|
||||
if(canUnLockList) {
|
||||
for(let {id, params, gid} of canUnLockList) {
|
||||
if (canUnLockList) {
|
||||
for (let { id, params, gid } of canUnLockList) {
|
||||
let flag = false; // 是否达成条件
|
||||
if(type == FIGURE_UNLOCK_CONDITION.GET_HERO) {
|
||||
let [ hid ] = params;
|
||||
if(paramHid == hid) flag = true;
|
||||
if (type == FIGURE_UNLOCK_CONDITION.GET_HERO) {
|
||||
let [hid] = params;
|
||||
if (paramHid == hid) flag = true;
|
||||
} else if (type == FIGURE_UNLOCK_CONDITION.HERO_FAVOR) {
|
||||
let [ hid, favourLv ] = params;
|
||||
if(paramHid == hid && paramFavourLv >= favourLv) flag = true;
|
||||
} else if ( type == FIGURE_UNLOCK_CONDITION.GET_SKIN) {
|
||||
let [ id ] = params;
|
||||
if(paramSkinId == id) flag = true;
|
||||
let [hid, favourLv] = params;
|
||||
if (paramHid == hid && paramFavourLv >= favourLv) flag = true;
|
||||
} else if (type == FIGURE_UNLOCK_CONDITION.GET_SKIN) {
|
||||
let [id] = params;
|
||||
if (paramSkinId == id) flag = true;
|
||||
}
|
||||
if(!flag) continue;
|
||||
if (!flag) continue;
|
||||
let dicGood = gameData.goods.get(gid);
|
||||
if(!dicGood) continue;
|
||||
if (!dicGood) continue;
|
||||
let dicItid = ITID.get(dicGood.itid);
|
||||
if(!dicItid) continue;
|
||||
|
||||
if(dicItid.type == CONSUME_TYPE.HEAD) {
|
||||
if (!dicItid) continue;
|
||||
|
||||
if (dicItid.type == CONSUME_TYPE.HEAD) {
|
||||
let figure = unlockSingleFigure(heads, gid, false, id);
|
||||
if(figure && figure.unlocked) figureInfo.heads.push(figure);
|
||||
if (figure && figure.unlocked) figureInfo.heads.push(figure);
|
||||
} else if (dicItid.type == CONSUME_TYPE.FRAME) {
|
||||
let figure = unlockSingleFigure(frames, gid, false, id);
|
||||
if(figure && figure.unlocked) figureInfo.frames.push(figure);
|
||||
if (figure && figure.unlocked) figureInfo.frames.push(figure);
|
||||
} else if (dicItid.type == CONSUME_TYPE.SPINE) {
|
||||
let figure = unlockSingleFigure(spines, gid, false, id);
|
||||
if(figure && figure.unlocked) figureInfo.spines.push(figure);
|
||||
if (figure && figure.unlocked) figureInfo.spines.push(figure);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
role = await RoleModel.updateRoleInfo(roleId, { heads, frames, spines });
|
||||
@@ -151,30 +151,30 @@ export async function unlockFigure(roleId: string, conditions: { type: number, p
|
||||
export async function addFigure(roleId: string, ids: number[]) {
|
||||
let role = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_HEADS);
|
||||
|
||||
if(!role) return false;
|
||||
if (!role) return false;
|
||||
let { heads, frames, spines } = role;
|
||||
|
||||
let figureInfo = { heads: [], frames: [], spines: [] };
|
||||
for(let gid of ids) {
|
||||
for (let gid of ids) {
|
||||
let dicGoods = gameData.goods.get(gid);
|
||||
if(!dicGoods) continue;
|
||||
if (!dicGoods) continue;
|
||||
let dicItid = ITID.get(dicGoods.itid);
|
||||
if(!dicItid) continue;
|
||||
|
||||
if(dicItid.type == CONSUME_TYPE.HEAD) {
|
||||
if (!dicItid) continue;
|
||||
|
||||
if (dicItid.type == CONSUME_TYPE.HEAD) {
|
||||
let figure = unlockSingleFigure(heads, gid, true);
|
||||
if(figure && figure.unlocked) figureInfo.heads.push(figure);
|
||||
if (figure && figure.unlocked) figureInfo.heads.push(figure);
|
||||
} else if (dicItid.type == CONSUME_TYPE.FRAME) {
|
||||
let figure = unlockSingleFigure(frames, gid, true);
|
||||
if(figure && figure.unlocked) figureInfo.frames.push(figure);
|
||||
if (figure && figure.unlocked) figureInfo.frames.push(figure);
|
||||
} else if (dicItid.type == CONSUME_TYPE.SPINE) {
|
||||
let figure = unlockSingleFigure(spines, gid, true);
|
||||
if(figure && figure.unlocked) figureInfo.spines.push(figure);
|
||||
if (figure && figure.unlocked) figureInfo.spines.push(figure);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
role = await RoleModel.updateRoleInfo(roleId, { heads, frames, spines });
|
||||
return figureInfo;
|
||||
}
|
||||
@@ -188,32 +188,32 @@ export async function addFigure(roleId: string, ids: number[]) {
|
||||
*/
|
||||
function unlockSingleFigure(dbFigures: Figure[], id: number, unlockDirect = false, conditionId?: number) {
|
||||
let figure = dbFigures.find(cur => cur.id == id);
|
||||
if(!figure) {
|
||||
if (!figure) {
|
||||
figure = new Figure(id, false);
|
||||
dbFigures.push(figure);
|
||||
}
|
||||
if(figure.unlocked) return; // 已解锁过
|
||||
if(!figure.unlockedId) figure.unlockedId = new Array<number>();
|
||||
if (figure.unlocked) return; // 已解锁过
|
||||
if (!figure.unlockedId) figure.unlockedId = new Array<number>();
|
||||
|
||||
let dicGoods = gameData.goods.get(id);
|
||||
|
||||
let hasUnlockedAll = true;
|
||||
if(!unlockDirect) { // 不能直接获得,需要通过type解锁
|
||||
if(figure.unlockedId.includes(conditionId)) return;
|
||||
if (!unlockDirect) { // 不能直接获得,需要通过type解锁
|
||||
if (figure.unlockedId.includes(conditionId)) return;
|
||||
|
||||
figure.unlockedId.push(conditionId);
|
||||
|
||||
for(let { id: cid } of dicGoods.condition) {
|
||||
if(!figure.unlockedId.includes(cid)) {
|
||||
|
||||
for (let { id: cid } of dicGoods.condition) {
|
||||
if (!figure.unlockedId.includes(cid)) {
|
||||
hasUnlockedAll = false; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(hasUnlockedAll) {
|
||||
if (hasUnlockedAll) {
|
||||
figure.unlocked = true;
|
||||
delete figure.unlockedId;
|
||||
|
||||
if(dicGoods.timeLimit) {
|
||||
if (dicGoods.timeLimit) {
|
||||
figure.time = getBeforeDaySeconds(-1 * dicGoods.timeLimit); // timeLimit天以后
|
||||
}
|
||||
}
|
||||
@@ -227,13 +227,13 @@ export async function createHero(roleId: string, heroInfo: HeroUpdate) {
|
||||
}
|
||||
|
||||
export async function createHeroes(roleId: string, heroInfos: HeroUpdate[]) {
|
||||
|
||||
|
||||
let heroNum = 0;
|
||||
let skinIds = new Array<number>();
|
||||
let conditions = new Array<{type: number, paramHid?: number, paramFavourLv?: number, paramSkinId?: number }>();
|
||||
let conditions = new Array<{ type: number, paramHid?: number, paramFavourLv?: number, paramSkinId?: number }>();
|
||||
let heroes: HeroType[] = [], calHeroResults = [], calAllHeroResults = [];
|
||||
|
||||
for(let heroInfo of heroInfos) {
|
||||
for (let heroInfo of heroInfos) {
|
||||
let curHero = await HeroModel.createHero(heroInfo); heroes.push(curHero);
|
||||
let calHeroResult = await calPlayerCeAndSave(HERO_SYSTEM_TYPE.INIT, roleId, curHero, {}); calHeroResults.push(calHeroResult);
|
||||
let calAllHeroResult = await reCalAllHeroCe(HERO_SYSTEM_TYPE.ADD_SKIN, roleId, {}, skinIds); calAllHeroResults.push(calAllHeroResult);
|
||||
@@ -241,9 +241,9 @@ export async function createHeroes(roleId: string, heroInfos: HeroUpdate[]) {
|
||||
conditions.push({ type: FIGURE_UNLOCK_CONDITION.GET_HERO, paramHid: heroInfo.hid });
|
||||
heroInfo.skins.forEach(cur => {
|
||||
skinIds.push(cur.id);
|
||||
conditions.push({type: FIGURE_UNLOCK_CONDITION.GET_SKIN, paramSkinId: cur.id});
|
||||
conditions.push({ type: FIGURE_UNLOCK_CONDITION.GET_SKIN, paramSkinId: cur.id });
|
||||
});
|
||||
heroNum ++;
|
||||
heroNum++;
|
||||
}
|
||||
let figureInfo = await unlockFigure(roleId, conditions); // 解锁头像
|
||||
|
||||
@@ -254,5 +254,7 @@ export async function createHeroes(roleId: string, heroInfos: HeroUpdate[]) {
|
||||
let m3 = await checkTaskWithHeroes(roleId, TASK_TYPE.HERO_QUALITY_STAR_UP, heroes);
|
||||
let m4 = await checkTaskWithHeroes(roleId, TASK_TYPE.HERO_LV, heroes);
|
||||
let taskPushMessage = m1.concat(m2, m3, m4);
|
||||
//成长任务
|
||||
await accomplishTask(roleId, TASK_TYPE.HERO_NUM, heroNum)
|
||||
return { role, figureInfo, heroes, calHeroResults, calAllHeroResults, taskPushMessage }
|
||||
}
|
||||
@@ -8,11 +8,16 @@ import { getTodayZeroPoint } from './timeUtil';
|
||||
import { HeroType } from '../db/Hero';
|
||||
import { EquipType, EquipModel } from '../db/Equip';
|
||||
import { ItemInter } from './interface';
|
||||
import { GrowthData } from '../domain/activityField/growthField';
|
||||
import { splitString } from './util';
|
||||
import { ActivityModel, ActivityModelType } from '../db/Activity';
|
||||
import { ACTIVITY_TYPE } from '../consts/constModules/activityConst';
|
||||
import { ActivityGrowthModel } from '../db/ActivityGrowth';
|
||||
|
||||
export async function checkTaskWithRoles(taskType: number, roles: RoleType[], funcs?: number[]) {
|
||||
let pushMessage = new Array<TaskListReturn>();
|
||||
for(let role of roles) {
|
||||
if(role) {
|
||||
for (let role of roles) {
|
||||
if (role) {
|
||||
let singlePush = await checkTaskWithRole(role.roleId, taskType, role, funcs);
|
||||
pushMessage.concat(singlePush);
|
||||
}
|
||||
@@ -23,26 +28,25 @@ export async function checkTaskWithRoles(taskType: number, roles: RoleType[], fu
|
||||
export async function checkTaskWithRole(roleId: string, taskType: number, role: RoleType, funcs?: number[]) {
|
||||
let pushMessage = new Array<TaskListReturn>();
|
||||
|
||||
if(taskType == TASK_TYPE.LOGIN_SUM)
|
||||
{
|
||||
if (taskType == TASK_TYPE.LOGIN_SUM) {
|
||||
let today = getTodayZeroPoint();
|
||||
if(today > role.loginTime) {
|
||||
if (today > role.loginTime) {
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, {}, funcs);
|
||||
//成长任务-累计登录游戏天数
|
||||
await accomplishTask(roleId, taskType, 1)
|
||||
}
|
||||
}
|
||||
else if (taskType == TASK_TYPE.LOGIN_SERIES)
|
||||
{
|
||||
else if (taskType == TASK_TYPE.LOGIN_SERIES) {
|
||||
let today = getTodayZeroPoint();
|
||||
if(today > role.loginTime) {
|
||||
if(today - role.loginTime > 24 * 60 * 60 ) {
|
||||
if (today > role.loginTime) {
|
||||
if (today - role.loginTime > 24 * 60 * 60) {
|
||||
pushMessage = await checkTask(roleId, taskType, 0, false, {}, funcs);
|
||||
} else {
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, {}, funcs);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (taskType == TASK_TYPE.FRIEND_NUM)
|
||||
{
|
||||
else if (taskType == TASK_TYPE.FRIEND_NUM) {
|
||||
let { friendCnt } = role;
|
||||
pushMessage = await checkTask(roleId, taskType, friendCnt, false, {}, funcs);
|
||||
}
|
||||
@@ -53,7 +57,7 @@ export async function checkTaskWithRole(roleId: string, taskType: number, role:
|
||||
|
||||
export async function checkTaskWithHeroes(roleId: string, taskType: number, heroes: HeroType[], funcs?: number[]) {
|
||||
let pushMessage = new Array<TaskListReturn>();
|
||||
for(let hero of heroes) {
|
||||
for (let hero of heroes) {
|
||||
let singlePush = await checkTaskWithHero(roleId, taskType, hero, [], funcs);
|
||||
pushMessage.concat(singlePush);
|
||||
}
|
||||
@@ -62,67 +66,57 @@ export async function checkTaskWithHeroes(roleId: string, taskType: number, hero
|
||||
|
||||
export async function checkTaskWithHero(roleId: string, taskType: number, hero: HeroType, args: number[] = [], funcs?: number[]) {
|
||||
let pushMessage = new Array<TaskListReturn>();
|
||||
if(taskType == TASK_TYPE.HERO_STAR_UP)
|
||||
{
|
||||
if (taskType == TASK_TYPE.HERO_STAR_UP) {
|
||||
let dicHero = gameData.hero.get(hero.hid);
|
||||
let starUp = hero.star - dicHero.initialStars;
|
||||
if(hero.colorStar > 1) starUp += hero.colorStar - 1;
|
||||
if (hero.colorStar > 1) starUp += hero.colorStar - 1;
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, { star: starUp }, funcs)
|
||||
}
|
||||
else if(taskType == TASK_TYPE.HERO_QUALITY)
|
||||
{
|
||||
else if (taskType == TASK_TYPE.HERO_QUALITY) {
|
||||
let dicHero = gameData.hero.get(hero.hid);
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, { quality: dicHero.quality }, funcs);
|
||||
}
|
||||
else if (taskType == TASK_TYPE.HERO_QUALITY_STAR_UP)
|
||||
{
|
||||
else if (taskType == TASK_TYPE.HERO_QUALITY_STAR_UP) {
|
||||
let dicHero = gameData.hero.get(hero.hid);
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, { quality: dicHero.quality, star: hero.star }, funcs);
|
||||
}
|
||||
else if (taskType == TASK_TYPE.HERO_LV)
|
||||
{
|
||||
else if (taskType == TASK_TYPE.HERO_LV) {
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, { lv: hero.lv }, funcs);
|
||||
}
|
||||
else if (taskType == TASK_TYPE.HERO_TRAIN)
|
||||
{
|
||||
else if (taskType == TASK_TYPE.HERO_TRAIN) {
|
||||
let dicHero = gameData.hero.get(hero.hid);
|
||||
let initGrage = gameData.job.get(dicHero.jobid).grade;
|
||||
let curGrade = gameData.job.get(hero.job).grade;
|
||||
let count = (curGrade - initGrage) * (ABI_STAGE.END - ABI_STAGE.START) + (hero.jobStage - ABI_STAGE.START); // 训练次数
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, { count }, funcs);
|
||||
}
|
||||
else if (taskType == TASK_TYPE.HERO_QUALITY_UP)
|
||||
{
|
||||
else if (taskType == TASK_TYPE.HERO_QUALITY_UP) {
|
||||
let dicHero = gameData.hero.get(hero.hid);
|
||||
if(hero.quality - dicHero.quality == 1) { // 每个武将升品算一次
|
||||
if (hero.quality - dicHero.quality == 1) { // 每个武将升品算一次
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, {}, funcs);
|
||||
}
|
||||
}
|
||||
else if (taskType == TASK_TYPE.HERO_STAGE_UP)
|
||||
{
|
||||
else if (taskType == TASK_TYPE.HERO_STAGE_UP) {
|
||||
let dicHero = gameData.hero.get(hero.hid);
|
||||
let initGrage = gameData.job.get(dicHero.jobid).grade;
|
||||
let curGrade = gameData.job.get(hero.job).grade;
|
||||
let count = curGrade - initGrage; // 进阶次数
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, { count }, funcs);
|
||||
}
|
||||
else if (taskType == TASK_TYPE.HERO_FAVOUR_LV)
|
||||
{
|
||||
else if (taskType == TASK_TYPE.HERO_FAVOUR_LV) {
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, { favourLv: hero.favourLv }, funcs)
|
||||
}
|
||||
else if (taskType == TASK_TYPE.EQUIP_BY_HERO)
|
||||
{
|
||||
else if (taskType == TASK_TYPE.EQUIP_BY_HERO) {
|
||||
// arg[0] 1:穿上 -1:脱下
|
||||
let { ePlace } = hero;
|
||||
let count = ePlace.filter(cur => cur.equip).length;
|
||||
pushMessage = await checkTask(roleId, taskType, args[0], true, { count, isPutOn: args[0] }, funcs);
|
||||
}
|
||||
else if (taskType == TASK_TYPE.EQUIP_STRENGTHEN)
|
||||
{
|
||||
else if (taskType == TASK_TYPE.EQUIP_STRENGTHEN) {
|
||||
// args: 依次为原先的装备的强化等级
|
||||
let { ePlace } = hero;
|
||||
let index = 0;
|
||||
for(let { lv } of ePlace) {
|
||||
for (let { lv } of ePlace) {
|
||||
let p = await checkTask(roleId, taskType, 1, true, { oldLv: args[index++], lv }, funcs);
|
||||
pushMessage = pushMessage.concat(p);
|
||||
}
|
||||
@@ -134,57 +128,52 @@ export async function checkTaskWithHero(roleId: string, taskType: number, hero:
|
||||
|
||||
export async function checkTaskWithEquip(roleId: string, taskType: number, equip: EquipType, args: number[] = [], funcs?: number[]) {
|
||||
let pushMessage = new Array<TaskListReturn>();
|
||||
if(taskType == TASK_TYPE.EQUIP_QUALITY)
|
||||
{
|
||||
if (taskType == TASK_TYPE.EQUIP_QUALITY) {
|
||||
// args[0] 1:装上 -1:脱下
|
||||
let dicGood = gameData.goods.get(equip.id);
|
||||
pushMessage = await checkTask(roleId, taskType, args[0], true, { quality: dicGood.quality }, funcs)
|
||||
}
|
||||
else if (taskType == TASK_TYPE.EQUIP_JEWEL)
|
||||
{
|
||||
else if (taskType == TASK_TYPE.EQUIP_JEWEL) {
|
||||
// args[0] 原来镶嵌了多少宝石
|
||||
let { holes } = equip;
|
||||
let jewelCount = holes.filter(cur => cur.jewel > 0).length;
|
||||
if(jewelCount > 0 && args[0] <= 0) { // 原来没有,镶嵌上了
|
||||
if (jewelCount > 0 && args[0] <= 0) { // 原来没有,镶嵌上了
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, {}, funcs);
|
||||
} else if (jewelCount <= 0 && args[0] > 0) { // 原来镶嵌着,现在没了
|
||||
pushMessage = await checkTask(roleId, taskType, -1, true, {}, funcs);
|
||||
}
|
||||
}
|
||||
else if (taskType == TASK_TYPE.EQUIP_COMPOSE_SUIT)
|
||||
{
|
||||
else if (taskType == TASK_TYPE.EQUIP_COMPOSE_SUIT) {
|
||||
let dicGood = gameData.goods.get(equip.id);
|
||||
if(dicGood.suitId) {
|
||||
if (dicGood.suitId) {
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, {}, funcs);
|
||||
}
|
||||
}
|
||||
else if (taskType == TASK_TYPE.EQUIP_SUIT)
|
||||
{
|
||||
else if (taskType == TASK_TYPE.EQUIP_SUIT) {
|
||||
let dicGood = gameData.goods.get(equip.id);
|
||||
if(dicGood.suitId) {
|
||||
if (dicGood.suitId) {
|
||||
let suit = gameData.suit.get(dicGood.suitId);
|
||||
let equips = await EquipModel.getEquipsByIds(roleId, suit.tireInfo);
|
||||
let everyEquip = new Map<number, number>();
|
||||
for(let equip of equips) {
|
||||
if(everyEquip.has(equip.id)) {
|
||||
for (let equip of equips) {
|
||||
if (everyEquip.has(equip.id)) {
|
||||
everyEquip.set(equip.id, everyEquip.get(equip.id) + 1);
|
||||
} else {
|
||||
everyEquip.set(equip.id, 1);
|
||||
}
|
||||
}
|
||||
let minCount = 0, curCount = 0;
|
||||
for(let id of suit.tireInfo) {
|
||||
let count = everyEquip.get(id)||0;
|
||||
if(minCount > count) minCount = count;
|
||||
if(id == equip.id) curCount = count;
|
||||
for (let id of suit.tireInfo) {
|
||||
let count = everyEquip.get(id) || 0;
|
||||
if (minCount > count) minCount = count;
|
||||
if (id == equip.id) curCount = count;
|
||||
}
|
||||
if(curCount == minCount) {
|
||||
if (curCount == minCount) {
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, {}, funcs);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (taskType == TASK_TYPE.EQUIP_JEWEL_SUM)
|
||||
{
|
||||
else if (taskType == TASK_TYPE.EQUIP_JEWEL_SUM) {
|
||||
// args[0] 原来镶嵌了多少宝石
|
||||
let { holes } = equip;
|
||||
let jewelCount = holes.filter(cur => cur.jewel > 0).length;
|
||||
@@ -196,32 +185,29 @@ export async function checkTaskWithEquip(roleId: string, taskType: number, equip
|
||||
export async function checkTaskWithArgs(roleId: string, taskType: number, args: number[], funcs?: number[]) {
|
||||
let pushMessage = new Array<TaskListReturn>();
|
||||
|
||||
if(taskType == TASK_TYPE.ROLE_SCHOOL_PUT_HERO)
|
||||
{
|
||||
let [ hid, preHid ] = args;
|
||||
if(hid > 0 && preHid <= 0) { // 放置
|
||||
if (taskType == TASK_TYPE.ROLE_SCHOOL_PUT_HERO) {
|
||||
let [hid, preHid] = args;
|
||||
if (hid > 0 && preHid <= 0) { // 放置
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, {}, funcs);
|
||||
} else if (hid <= 0 && preHid > 0) { // 卸下
|
||||
pushMessage = await checkTask(roleId, taskType, -1, true, {}, funcs);
|
||||
}
|
||||
}
|
||||
else if (taskType == TASK_TYPE.EQUIP_JEWEL_STAGE)
|
||||
{
|
||||
else if (taskType == TASK_TYPE.EQUIP_JEWEL_STAGE) {
|
||||
// args 装上的, 卸下的
|
||||
let [putOnJewel, putOffJewel] = args;
|
||||
if(putOnJewel > 0) {
|
||||
if (putOnJewel > 0) {
|
||||
let dicGood = gameData.goods.get(putOnJewel);
|
||||
let push = await checkTask(roleId, taskType, 1, true, { stage: dicGood.lvLimited }, funcs);
|
||||
pushMessage.concat(push);
|
||||
}
|
||||
if(putOffJewel > 0) {
|
||||
if (putOffJewel > 0) {
|
||||
let dicGood = gameData.goods.get(putOffJewel);
|
||||
let push = await checkTask(roleId, taskType, -1, true, { stage: dicGood.lvLimited }, funcs);
|
||||
pushMessage.concat(push);
|
||||
}
|
||||
}
|
||||
else if (taskType == TASK_TYPE.CHAT)
|
||||
{
|
||||
else if (taskType == TASK_TYPE.CHAT) {
|
||||
// args[0] 聊天type 1-系统 2-世界 3-军团 4-组队 5-私聊
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, { chatType: args[0] }, funcs)
|
||||
}
|
||||
@@ -232,61 +218,51 @@ export async function checkTaskWithArgs(roleId: string, taskType: number, args:
|
||||
export async function checkTaskWithWar(roleId: string, taskType: number, warId: number, heroes: number[], count: number, star: number, funcs?: number[]) {
|
||||
let dicWar = gameData.war.get(warId);
|
||||
let pushMessage = new Array<TaskListReturn>();
|
||||
if(taskType == TASK_TYPE.BATTLE_WITH_HERO)
|
||||
{
|
||||
if (taskType == TASK_TYPE.BATTLE_WITH_HERO) {
|
||||
pushMessage = await checkTask(roleId, taskType, count, true, { warId, heroes }, funcs);
|
||||
}
|
||||
else if (taskType == TASK_TYPE.BATTLE_MAIN)
|
||||
{
|
||||
if(dicWar.warType == WAR_TYPE.NORMAL) {
|
||||
else if (taskType == TASK_TYPE.BATTLE_MAIN) {
|
||||
if (dicWar.warType == WAR_TYPE.NORMAL) {
|
||||
pushMessage = await checkTask(roleId, taskType, count, true, { warId }, funcs);
|
||||
}
|
||||
}
|
||||
else if (taskType == TASK_TYPE.BATTLE_MAIN_SWEEP)
|
||||
{
|
||||
if(dicWar.warType == WAR_TYPE.NORMAL) {
|
||||
else if (taskType == TASK_TYPE.BATTLE_MAIN_SWEEP) {
|
||||
if (dicWar.warType == WAR_TYPE.NORMAL) {
|
||||
pushMessage = await checkTask(roleId, taskType, count, true, {}, funcs);
|
||||
}
|
||||
}
|
||||
else if (taskType == TASK_TYPE.BATTLE_DAILY_STAR)
|
||||
{
|
||||
if(dicWar.warType == WAR_TYPE.DAILY) {
|
||||
else if (taskType == TASK_TYPE.BATTLE_DAILY_STAR) {
|
||||
if (dicWar.warType == WAR_TYPE.DAILY) {
|
||||
pushMessage = await checkTask(roleId, taskType, count, true, { warId, star }, funcs);
|
||||
}
|
||||
}
|
||||
else if (taskType == TASK_TYPE.BATTLE_DAILY)
|
||||
{
|
||||
if(dicWar.warType == WAR_TYPE.DAILY) {
|
||||
else if (taskType == TASK_TYPE.BATTLE_DAILY) {
|
||||
if (dicWar.warType == WAR_TYPE.DAILY) {
|
||||
pushMessage = await checkTask(roleId, taskType, count, true, { dailyType: dicWar.dailyType }, funcs)
|
||||
}
|
||||
}
|
||||
else if (taskType == TASK_TYPE.BATTLE_DUNGEON)
|
||||
{
|
||||
if(dicWar.warType == WAR_TYPE.MYSTERY||dicWar.warType == WAR_TYPE.MYSTERY_ELITE) {
|
||||
else if (taskType == TASK_TYPE.BATTLE_DUNGEON) {
|
||||
if (dicWar.warType == WAR_TYPE.MYSTERY || dicWar.warType == WAR_TYPE.MYSTERY_ELITE) {
|
||||
pushMessage = await checkTask(roleId, taskType, count, true, {}, funcs);
|
||||
}
|
||||
}
|
||||
else if (taskType == TASK_TYPE.BATTLE_DUNGEON_WAR)
|
||||
{
|
||||
if(dicWar.warType == WAR_TYPE.MYSTERY||dicWar.warType == WAR_TYPE.MYSTERY_ELITE) {
|
||||
else if (taskType == TASK_TYPE.BATTLE_DUNGEON_WAR) {
|
||||
if (dicWar.warType == WAR_TYPE.MYSTERY || dicWar.warType == WAR_TYPE.MYSTERY_ELITE) {
|
||||
pushMessage = await checkTask(roleId, taskType, count, true, { warId }, funcs);
|
||||
}
|
||||
}
|
||||
else if (taskType == TASK_TYPE.BATTLE_TOWER)
|
||||
{
|
||||
if(dicWar.warType == WAR_TYPE.TOWER) {
|
||||
else if (taskType == TASK_TYPE.BATTLE_TOWER) {
|
||||
if (dicWar.warType == WAR_TYPE.TOWER) {
|
||||
pushMessage = await checkTask(roleId, taskType, count, true, {}, funcs);
|
||||
}
|
||||
}
|
||||
else if (taskType == TASK_TYPE.BATTLE_VESTIGE)
|
||||
{
|
||||
if(dicWar.warType == WAR_TYPE.VESTIGE) {
|
||||
else if (taskType == TASK_TYPE.BATTLE_VESTIGE) {
|
||||
if (dicWar.warType == WAR_TYPE.VESTIGE) {
|
||||
pushMessage = await checkTask(roleId, taskType, count, true, {}, funcs);
|
||||
}
|
||||
}
|
||||
else if (taskType == TASK_TYPE.BATTLE_EXPEDITION)
|
||||
{
|
||||
if(dicWar.warType == WAR_TYPE.EXPEDITION) {
|
||||
else if (taskType == TASK_TYPE.BATTLE_EXPEDITION) {
|
||||
if (dicWar.warType == WAR_TYPE.EXPEDITION) {
|
||||
pushMessage = await checkTask(roleId, taskType, count, true, {}, funcs);
|
||||
}
|
||||
}
|
||||
@@ -296,9 +272,8 @@ export async function checkTaskWithWar(roleId: string, taskType: number, warId:
|
||||
|
||||
export async function checkTaskWithGoods(roleId: string, taskType: number, goods: ItemInter[], funcs?: number[]) {
|
||||
let pushMessage = new Array<TaskListReturn>();
|
||||
if(taskType == TASK_TYPE.COM_BATTLE_DROP)
|
||||
{
|
||||
for(let { id, count } of goods) {
|
||||
if (taskType == TASK_TYPE.COM_BATTLE_DROP) {
|
||||
for (let { id, count } of goods) {
|
||||
let push = await checkTask(roleId, taskType, count, true, { gid: id }, funcs);
|
||||
pushMessage.concat(push);
|
||||
}
|
||||
@@ -308,30 +283,30 @@ export async function checkTaskWithGoods(roleId: string, taskType: number, goods
|
||||
|
||||
// 根据taskType判断有哪些任务需要check的
|
||||
export async function checkTask(roleId: string, taskType: number, count: number, isInc: boolean, param: TaskParam, funcs?: number[]) {
|
||||
let tasks = gameData.taskType.get(taskType)||[];
|
||||
let tasks = gameData.taskType.get(taskType) || [];
|
||||
let pushMessage = new Array<TaskListReturn>();
|
||||
let groups = new Map<string, { task0: DicTask, tasks: DicTask[] }>();
|
||||
for(let dicTask of tasks) {
|
||||
if(!groups.has(`${dicTask.type}_${dicTask.group}`)) {
|
||||
for (let dicTask of tasks) {
|
||||
if (!groups.has(`${dicTask.type}_${dicTask.group}`)) {
|
||||
groups.set(`${dicTask.type}_${dicTask.group}`, { task0: dicTask, tasks: new Array<DicTask>() });
|
||||
}
|
||||
groups.get(`${dicTask.type}_${dicTask.group}`).tasks.push(dicTask);
|
||||
}
|
||||
if(!funcs) {
|
||||
if (!funcs) {
|
||||
let role = await RoleModel.findByRoleId(roleId, 'funcs');
|
||||
funcs = role.funcs||[];
|
||||
funcs = role.funcs || [];
|
||||
}
|
||||
|
||||
for(let [ typeAndGroup, { task0, tasks } ] of groups) {
|
||||
|
||||
for (let [typeAndGroup, { task0, tasks }] of groups) {
|
||||
let arr = typeAndGroup.split('_');
|
||||
let type = parseInt(arr[0]);
|
||||
let group = parseInt(arr[1]);
|
||||
|
||||
let rec = await checkTaskRec(roleId, type, group, task0, count, isInc, param, funcs);
|
||||
if(rec) {
|
||||
for(let dicTask of tasks) {
|
||||
if(checkRecResult(rec, dicTask.id, dicTask.condition)) {
|
||||
let received = rec.received||[];
|
||||
if (rec) {
|
||||
for (let dicTask of tasks) {
|
||||
if (checkRecResult(rec, dicTask.id, dicTask.condition)) {
|
||||
let received = rec.received || [];
|
||||
pushMessage.push({ type: dicTask.type, id: dicTask.id, count: rec.count, received: received.includes(dicTask.id) });
|
||||
}
|
||||
}
|
||||
@@ -341,18 +316,18 @@ export async function checkTask(roleId: string, taskType: number, count: number,
|
||||
}
|
||||
|
||||
// 检查各项任务是否达成,达成了就保存到数据库
|
||||
export async function checkTaskRec(roleId: string, type: number, group: number, dicTask: DicTask, count: number, isInc: boolean, param: TaskParam, funcs: number[] ) {
|
||||
export async function checkTaskRec(roleId: string, type: number, group: number, dicTask: DicTask, count: number, isInc: boolean, param: TaskParam, funcs: number[]) {
|
||||
let { taskParam, taskType } = dicTask;
|
||||
|
||||
let sp = [TASK_TYPE.LOGIN_SUM, TASK_TYPE.LOGIN_SERIES];
|
||||
if(type == TASK_FUN_TYPE.DAILY && funcs.indexOf(FUNCS_ID.DAILY_TASK) == -1 && sp.indexOf(taskType) == -1) { // 功能未开启
|
||||
if (type == TASK_FUN_TYPE.DAILY && funcs.indexOf(FUNCS_ID.DAILY_TASK) == -1 && sp.indexOf(taskType) == -1) { // 功能未开启
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
let isMatch = true; // 条件是否满足
|
||||
let checkHistory = false; // 是否检查历史
|
||||
switch(taskType) {
|
||||
switch (taskType) {
|
||||
case TASK_TYPE.ROLE_TITLE:
|
||||
isMatch = taskParam[0] == param.title;
|
||||
checkHistory = true;
|
||||
@@ -375,13 +350,13 @@ export async function checkTaskRec(roleId: string, type: number, group: number,
|
||||
break;
|
||||
case TASK_TYPE.HERO_FAVOUR_LV:
|
||||
isMatch = taskParam[1] == param.favourLv;
|
||||
break;
|
||||
break;
|
||||
case TASK_TYPE.HERO_CONNECT:
|
||||
isMatch = taskParam[1] == param.connectLv;
|
||||
break;
|
||||
case TASK_TYPE.EQUIP_BY_HERO:
|
||||
isMatch = false;
|
||||
if(param.isPutOn && param.count == taskParam[1]) { // 装上之后达到 +1
|
||||
if (param.isPutOn && param.count == taskParam[1]) { // 装上之后达到 +1
|
||||
isMatch = true;
|
||||
} else if (!param.isPutOn && param.count < taskParam[1]) { // 脱下后不能达到 -1
|
||||
isMatch = true;
|
||||
@@ -423,12 +398,12 @@ export async function checkTaskRec(roleId: string, type: number, group: number,
|
||||
isMatch = checkIdList(taskParam, 1, param.gid);
|
||||
break;
|
||||
case TASK_TYPE.PVP_HERO_SCORE:
|
||||
for(let { score } of param.heroScores) {
|
||||
if(score >= taskParam[0]) {
|
||||
for (let { score } of param.heroScores) {
|
||||
if (score >= taskParam[0]) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if(count <= 0) isMatch = false;
|
||||
if (count <= 0) isMatch = false;
|
||||
break;
|
||||
case TASK_TYPE.PVP_RANK:
|
||||
isMatch = taskParam[0] <= param.rankLv;
|
||||
@@ -444,12 +419,12 @@ export async function checkTaskRec(roleId: string, type: number, group: number,
|
||||
}
|
||||
console.log('****isMatch', isMatch, checkHistory, type, taskType, group, count)
|
||||
|
||||
if(isMatch) {
|
||||
if(isInc) {
|
||||
if (isMatch) {
|
||||
if (isInc) {
|
||||
let rec = await UserTaskRecModel.incTaskRec(roleId, type, taskType, group, count);
|
||||
return rec;
|
||||
} else {
|
||||
if(checkHistory) {
|
||||
if (checkHistory) {
|
||||
let rec = await UserTaskRecModel.checkHistoryAndSetTaskRec(roleId, type, taskType, group, count);
|
||||
return rec;
|
||||
} else {
|
||||
@@ -468,7 +443,7 @@ export async function checkTaskRec(roleId: string, type: number, group: number,
|
||||
*/
|
||||
function checkIdList(taskParam: number[], index: number, id: number) {
|
||||
let count = taskParam[index];
|
||||
if(!count) return false;
|
||||
if (!count) return false;
|
||||
let idList = taskParam.slice(index + 1, index + 1 + count);
|
||||
return idList.indexOf(id) != -1;
|
||||
}
|
||||
@@ -479,12 +454,110 @@ function checkHero(taskParam: number[], index: number, heroes: number[]) {
|
||||
}
|
||||
|
||||
function checkRecResult(rec: UserTaskRecType, id: number, condition: number) {
|
||||
if(!rec) return false;
|
||||
if(rec.received && rec.received.includes(id)) return false; // 已领取,不再推送
|
||||
if (!rec) return false;
|
||||
if (rec.received && rec.received.includes(id)) return false; // 已领取,不再推送
|
||||
|
||||
if(rec.count >= condition) {
|
||||
if (rec.count >= condition) {
|
||||
return rec
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 任务统计
|
||||
*
|
||||
* @param {number} serverId 区Id
|
||||
* @param {string} roleId 角色Id
|
||||
* @param {number} taskType 任务类型
|
||||
* @param {number} count 任务数据
|
||||
* @param {number} parma 参数
|
||||
*
|
||||
*/
|
||||
export async function accomplishTask(roleId: string, taskType: TASK_TYPE, count: number, parma?: any) {
|
||||
let allActivity: ActivityModelType[] = await ActivityModel.findOpenActivityByType(ACTIVITY_TYPE.TASK_GROWTH, new Date());
|
||||
for (let activity of allActivity) {
|
||||
let growthActivity = new GrowthData(activity);
|
||||
let taskArray = growthActivity.findTaskByType(taskType);
|
||||
for (let task of taskArray) {
|
||||
let addCount = isComplete(roleId, task.taskType, task.taskParam, count, parma);
|
||||
if (addCount) {
|
||||
if (taskType == TASK_TYPE.ROLE_LV || taskType == TASK_TYPE.ROLE_TITLE) {
|
||||
await ActivityGrowthModel.setTaskCount(growthActivity.activityId, roleId, task.dayIndex, task.cellIndex, task.taskType, addCount);
|
||||
} else {
|
||||
await ActivityGrowthModel.addTaskCount(growthActivity.activityId, roleId, task.dayIndex, task.cellIndex, task.taskType, addCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 达成任务标准
|
||||
*
|
||||
* @param {string} roleId 角色Id
|
||||
* @param {number} taskType 任务类型
|
||||
* @param {number} taskParam 任务条件数据
|
||||
* @param {number} count 数据
|
||||
* @param {number} parma 参数
|
||||
*
|
||||
*/
|
||||
|
||||
export function isComplete(roleId: string, taskType: TASK_TYPE, taskParam: string, count: number, paramObj?: any): number {
|
||||
console.log('达成任务标准', roleId, taskType, taskParam, count, paramObj)
|
||||
let param = splitString(taskParam, '&');
|
||||
let addCount: number = 0; // 条件是否满足
|
||||
switch (taskType) {
|
||||
case TASK_TYPE.ROLE_LV://重置数据
|
||||
addCount = param[0] <= count ? count : 0;
|
||||
break;
|
||||
case TASK_TYPE.GUILD_JOIN:
|
||||
addCount = count;
|
||||
break;
|
||||
case TASK_TYPE.LOGIN_SUM:
|
||||
addCount = count;
|
||||
break;
|
||||
case TASK_TYPE.HERO_NUM:
|
||||
addCount = count;
|
||||
break;
|
||||
case TASK_TYPE.ROLE_TITLE://重置数据
|
||||
addCount = param[0] <= count ? count : 0;
|
||||
break;
|
||||
case TASK_TYPE.GASHA:
|
||||
addCount = count;
|
||||
break;
|
||||
case TASK_TYPE.EQUIP_STRENGTHEN:
|
||||
for (let obj of paramObj) {
|
||||
// obj.hid;//英雄di
|
||||
// obj.oldLv;//栏位升级前等级
|
||||
// obj.lv;//栏位升级后等级
|
||||
// obj.id;//栏位id
|
||||
if (param[1] > obj.oldLv && param[1] <= obj.lv) {
|
||||
addCount++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TASK_TYPE.BATTLE_MAIN:
|
||||
addCount = param[0] == paramObj.warId ? 1 : 0;
|
||||
break;
|
||||
case TASK_TYPE.EQUIP_JEWEL_SUM:
|
||||
addCount = count;
|
||||
break;
|
||||
case TASK_TYPE.GUILD_TRAIN:
|
||||
addCount = count;
|
||||
break;
|
||||
case TASK_TYPE.ROLE_SCHOOL_PUT_HERO:
|
||||
addCount = count;
|
||||
break;
|
||||
case TASK_TYPE.GUILD_ACTIVITY:
|
||||
addCount = count;
|
||||
break;
|
||||
default:
|
||||
addCount = 0;
|
||||
break;
|
||||
|
||||
}
|
||||
return addCount;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ export function aesEncryptcfb(data, key, iv) {
|
||||
}
|
||||
|
||||
export function aesDecryptcfb(data, key, iv) {
|
||||
if(data) {
|
||||
if (data) {
|
||||
const decipher = crypto.createDecipheriv('aes-192-cfb', key, iv);
|
||||
let decrypted = decipher.update(data, 'hex', 'utf8');
|
||||
decrypted += decipher.final('utf8');
|
||||
@@ -279,7 +279,7 @@ export function shouldRefreshWeek(preTime: Date, now: Date, day: number, hour: n
|
||||
let refreshTime = getWeekDate(now, day, hour);
|
||||
let refeshTime = refreshTime.getTime();
|
||||
|
||||
if (refeshTime - preTime.getTime() > (deltaWeek >= 1 ? deltaWeek - 1 : 0) * 7* 24 * 60 * 60 * 1000 && curTime.getTime() >= refeshTime) {
|
||||
if (refeshTime - preTime.getTime() > (deltaWeek >= 1 ? deltaWeek - 1 : 0) * 7 * 24 * 60 * 60 * 1000 && curTime.getTime() >= refeshTime) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -334,7 +334,7 @@ export function getRandEelm<T>(source: Array<T> = [], cnt = 1): Array<T> {
|
||||
*/
|
||||
export function sortArrRandom(source = []) {
|
||||
let arr = deepCopy(source);
|
||||
return arr.sort(() => { return Math.random()-0.5; });
|
||||
return arr.sort(() => { return Math.random() - 0.5; });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -525,6 +525,20 @@ export function parseGoodStr(str: string) {
|
||||
}
|
||||
return result
|
||||
}
|
||||
// 根据类型解析物品 {"type":number, "id": number, "count": number} 格式
|
||||
//type 1.英雄,2.物品
|
||||
export function parseGoodStrWithType(str: string) {
|
||||
let result = new Array<{ type: number, id: number, count: number }>();
|
||||
if (!str) return result;
|
||||
let decodeArr = decodeArrayListStr(str);
|
||||
for (let [type, id, count] of decodeArr) {
|
||||
if (isNaN(parseInt(type)) || isNaN(parseInt(id)) || isNaN(parseInt(count))) {
|
||||
throw new Error('data table format wrong');
|
||||
}
|
||||
result.push({ type: parseInt(type), id: parseInt(id), count: parseInt(count) });
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// 数字列表
|
||||
export function parseNumberList(str: string) {
|
||||
@@ -599,4 +613,16 @@ export function getRobotInfo() {
|
||||
robotRoleName: getChineseName(),
|
||||
robotRoleId: genCode(8)
|
||||
}
|
||||
}
|
||||
|
||||
export function splitString(dataString: string, key: string) {
|
||||
if (!dataString) {
|
||||
return [];
|
||||
}
|
||||
let array = dataString.split(key).filter(obj => { return obj && obj != '' });
|
||||
let numberArray = [];
|
||||
for (let num of array) {
|
||||
numberArray.push(Number(num));
|
||||
}
|
||||
return numberArray;
|
||||
}
|
||||
@@ -1063,5 +1063,20 @@
|
||||
"__EMPTY_3": 0,
|
||||
"__EMPTY_4": 0,
|
||||
"__EMPTY_5": 0
|
||||
},
|
||||
{
|
||||
"id": 72,
|
||||
"name": "加入军团",
|
||||
"info": "加入军团",
|
||||
"param": "count&",
|
||||
"string": "加入军团次数&",
|
||||
"content": 0,
|
||||
"condition": "count",
|
||||
"__EMPTY": 0,
|
||||
"__EMPTY_1": 0,
|
||||
"__EMPTY_2": 0,
|
||||
"__EMPTY_3": 0,
|
||||
"__EMPTY_4": 0,
|
||||
"__EMPTY_5": 0
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user