活动:成长活动统计任务,领取奖励接口
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user