98 lines
4.8 KiB
TypeScript
98 lines
4.8 KiB
TypeScript
import * as taskUtil from '../pubUtils/taskUtil';
|
|
import { RoleType } from '../db/Role';
|
|
import { pinus } from 'pinus';
|
|
import { resResult } from '../pubUtils/util';
|
|
import { STATUS, TASK_TYPE } from '../consts';
|
|
import { TaskParam } from '../domain/roleField/task';
|
|
import { HeroType } from '../db/Hero';
|
|
import { EquipType } from '../db/Equip';
|
|
import { getRoleOnlineInfo } from './redisService';
|
|
import { HeroScores } from '../db/PvpHistoryOpp';
|
|
|
|
export async function checkTaskWithRoles(roleId: string, sid: string, taskType: number, roles: RoleType[]) {
|
|
for(let role of roles) {
|
|
await checkTaskWithRole(role.roleId, role.roleId == roleId? sid: null, taskType, role);
|
|
}
|
|
}
|
|
|
|
export async function checkTaskWithRole(roleId: string, sid: string, taskType: number, role: RoleType) {
|
|
let pushMessage = await taskUtil.checkTaskWithRole(roleId, taskType, role);
|
|
pushTaskUpdate(roleId, sid, pushMessage);
|
|
}
|
|
|
|
export async function checkTaskWithHero(roleId: string, sid: string, taskType: number, hero: HeroType, args?: number[]) {
|
|
let pushMessage = await taskUtil.checkTaskWithHero(roleId, taskType, hero, args);
|
|
pushTaskUpdate(roleId, sid, pushMessage);
|
|
}
|
|
|
|
export async function checkTaskWithEquip(roleId: string, sid: string, taskType: number, equip: EquipType, args?: number[]) {
|
|
let pushMessage = await taskUtil.checkTaskWithEquip(roleId, taskType, equip, args);
|
|
pushTaskUpdate(roleId, sid, pushMessage);
|
|
}
|
|
|
|
export async function checkTaskWithArgs(roleId: string, sid: string, taskType: number, args: number[]) {
|
|
let pushMessage = await taskUtil.checkTaskWithArgs(roleId, taskType, args);
|
|
pushTaskUpdate(roleId, sid, pushMessage);
|
|
}
|
|
|
|
export async function checkTaskWithWar(roleId: string, sid: string, taskType: number, warId: number, heroes: number[], count: number, star: number) {
|
|
let pushMessage = await taskUtil.checkTaskWithWar(roleId, taskType, warId, heroes, count, star);
|
|
pushTaskUpdate(roleId, sid, pushMessage);
|
|
}
|
|
|
|
export async function checkTask(roleId: string, sid: string, taskType: number, count: number, isInc: boolean, param: TaskParam) {
|
|
let pushMessage = await taskUtil.checkTask(roleId, taskType, count, isInc, param);
|
|
pushTaskUpdate(roleId, sid, pushMessage);
|
|
}
|
|
|
|
export async function pushTaskUpdate(roleId: string, sid: string, pushMessage: {type: number, id: number, count: number, received: boolean}[]) {
|
|
if(!sid) {
|
|
let onlineUser = await getRoleOnlineInfo(roleId);
|
|
sid = onlineUser.sid;
|
|
}
|
|
if(!!sid) {
|
|
let uids = [{uid: roleId, sid}];
|
|
pinus.app.get('channelService').pushMessageByUids('onTaskUpdate', resResult(STATUS.SUCCESS, pushMessage), uids);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* battle.normalBattleHandler.battleEnd 中会触发的任务,因为有点多提出来了
|
|
*/
|
|
export async function checkTaskInBattleEnd(roleId: string, sid: string, battleId: number, heroes: number[], star: number) {
|
|
|
|
await checkTaskWithWar(roleId, sid, TASK_TYPE.BATTLE_WITH_HERO, battleId, heroes, 1, star);
|
|
await checkTaskWithWar(roleId, sid, TASK_TYPE.BATTLE_MAIN, battleId, heroes, 1, star);
|
|
await checkTaskWithWar(roleId, sid, TASK_TYPE.BATTLE_DAILY_STAR, battleId, heroes, 1, star);
|
|
await checkTaskWithWar(roleId, sid, TASK_TYPE.BATTLE_DAILY, battleId, heroes, 1, star);
|
|
await checkTaskWithWar(roleId, sid, TASK_TYPE.BATTLE_DUNGEON, battleId, heroes, 1, star);
|
|
await checkTaskWithWar(roleId, sid, TASK_TYPE.BATTLE_DUNGEON_WAR, battleId, heroes, 1, star);
|
|
await checkTaskWithWar(roleId, sid, TASK_TYPE.BATTLE_TOWER, battleId, heroes, 1, star);
|
|
await checkTaskWithWar(roleId, sid, TASK_TYPE.BATTLE_VESTIGE, battleId, heroes, 1, star);
|
|
await checkTaskWithWar(roleId, sid, TASK_TYPE.BATTLE_EXPEDITION, battleId, heroes, 1, star);
|
|
|
|
}
|
|
|
|
export async function checkTaskInComBattleEnd(roleIds: string[], capId: string, quality: number) {
|
|
for(let roleId of roleIds) {
|
|
if(roleId == capId && roleIds.length > 1) { // 招募队友
|
|
await checkTask(roleId, null, TASK_TYPE.COM_BATTLE_CREATE_TEAM, 1, true, {});
|
|
} else if (roleId !== capId) { // 协助寻宝
|
|
await checkTask(roleId, null, TASK_TYPE.COM_BATTLE_ASSIST_TEAM, 1, true, {});
|
|
}
|
|
await checkTask(roleId, null, TASK_TYPE.COM_BATTLE, 1, true, {});
|
|
await checkTask(roleId, null, TASK_TYPE.COM_BATTLE_QUALITY, 1, true, { quality });
|
|
}
|
|
}
|
|
|
|
export async function checkTaskInPvpEnd(roleId: string, sid: string, isSuccess: boolean, heroScores: HeroScores[]) {
|
|
await checkTask(roleId, sid, TASK_TYPE.PVP, 1, true, {});
|
|
if(isSuccess) {
|
|
await checkTask(roleId, sid, TASK_TYPE.PVP_WIN, 1, true, {});
|
|
await checkTask(roleId, sid, TASK_TYPE.PVP_WIN_SERIES, 1, true, {});
|
|
} else {
|
|
await checkTask(roleId, sid, TASK_TYPE.PVP_WIN_SERIES, 0, false, {});
|
|
}
|
|
|
|
await checkTask(roleId, sid, TASK_TYPE.PVP, 0, false, { heroScores });
|
|
} |