任务:任务去除funcs的判断,直接达成
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { gameData } from './data';
|
||||
import { DicTask } from './dictionary/DicTask';
|
||||
import { TASK_TYPE, ABI_STAGE, WAR_TYPE, GUILD_JOB, TASK_FUN_TYPE, FUNCS_ID } from '../consts';
|
||||
import { TASK_TYPE, ABI_STAGE, WAR_TYPE, GUILD_JOB } from '../consts';
|
||||
import { UserTaskRecModel, UserTaskRecType } from '../db/UserTaskRec'
|
||||
import { RoleType, RoleModel } from '../db/Role';
|
||||
import { TaskParam, TaskListReturn } from '../domain/roleField/task';
|
||||
@@ -34,24 +34,24 @@ import { ActivityRefreshTaskModel } from '../db/ActivityRefreshTask';
|
||||
|
||||
|
||||
|
||||
export async function checkTaskWithRoles(serverId: number, taskType: number, roles: RoleType[], funcs?: number[]) {
|
||||
export async function checkTaskWithRoles(serverId: number, taskType: number, roles: RoleType[]) {
|
||||
let pushMessage = new Array<TaskListReturn>();
|
||||
for (let role of roles) {
|
||||
if (role) {
|
||||
let singlePush = await checkTaskWithRole(serverId, role.roleId, taskType, role, funcs);
|
||||
let singlePush = await checkTaskWithRole(serverId, role.roleId, taskType, role);
|
||||
pushMessage.concat(singlePush);
|
||||
}
|
||||
}
|
||||
return pushMessage
|
||||
}
|
||||
|
||||
export async function checkTaskWithRole(serverId: number, roleId: string, taskType: number, role: RoleType, funcs?: number[]) {
|
||||
export async function checkTaskWithRole(serverId: number, roleId: string, taskType: number, role: RoleType) {
|
||||
let pushMessage = new Array<TaskListReturn>();
|
||||
|
||||
if (taskType == TASK_TYPE.LOGIN_SUM) {
|
||||
let today = getZeroPoint();
|
||||
if (today > role.loginTime) {
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, {}, funcs);
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, {});
|
||||
//成长任务-累计登录游戏天数
|
||||
await accomplishTask(serverId, roleId, taskType, 1)
|
||||
}
|
||||
@@ -60,60 +60,60 @@ export async function checkTaskWithRole(serverId: number, roleId: string, taskTy
|
||||
let today = getZeroPoint();
|
||||
if (today > role.loginTime) {
|
||||
if (today - role.loginTime > 24 * 60 * 60) {
|
||||
pushMessage = await checkTask(roleId, taskType, 1, false, {}, funcs);
|
||||
pushMessage = await checkTask(roleId, taskType, 1, false, {});
|
||||
} else {
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, {}, funcs);
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, {});
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (taskType == TASK_TYPE.FRIEND_NUM) {
|
||||
let { friendCnt } = role;
|
||||
pushMessage = await checkTask(roleId, taskType, friendCnt, false, {}, funcs);
|
||||
pushMessage = await checkTask(roleId, taskType, friendCnt, false, {});
|
||||
}
|
||||
|
||||
return pushMessage
|
||||
}
|
||||
|
||||
|
||||
export async function checkTaskWithHeroes(roleId: string, taskType: number, heroes: HeroType[], funcs?: number[]) {
|
||||
export async function checkTaskWithHeroes(roleId: string, taskType: number, heroes: HeroType[]) {
|
||||
let pushMessage = new Array<TaskListReturn>();
|
||||
for (let hero of heroes) {
|
||||
let singlePush = await checkTaskWithHero(roleId, taskType, hero, [], funcs);
|
||||
let singlePush = await checkTaskWithHero(roleId, taskType, hero, []);
|
||||
pushMessage.concat(singlePush);
|
||||
}
|
||||
return pushMessage
|
||||
}
|
||||
|
||||
export async function checkTaskWithHero(roleId: string, taskType: number, hero: HeroType, args: number[] = [], funcs?: number[]) {
|
||||
export async function checkTaskWithHero(roleId: string, taskType: number, hero: HeroType, args: number[] = []) {
|
||||
let pushMessage = new Array<TaskListReturn>();
|
||||
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;
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, { star: starUp }, funcs)
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, { star: starUp })
|
||||
}
|
||||
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);
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, { quality: dicHero.quality });
|
||||
}
|
||||
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);
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, { quality: dicHero.quality, star: hero.star });
|
||||
}
|
||||
else if (taskType == TASK_TYPE.HERO_LV) {
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, { lv: hero.lv, oldLv: args[0] }, funcs);
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, { lv: hero.lv, oldLv: args[0] });
|
||||
}
|
||||
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);
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, { count });
|
||||
}
|
||||
else if (taskType == TASK_TYPE.HERO_QUALITY_UP) {
|
||||
let dicHero = gameData.hero.get(hero.hid);
|
||||
if (hero.quality - dicHero.quality == 1) { // 每个武将升品算一次
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, {}, funcs);
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, {});
|
||||
}
|
||||
}
|
||||
else if (taskType == TASK_TYPE.HERO_STAGE_UP) {
|
||||
@@ -121,23 +121,23 @@ export async function checkTaskWithHero(roleId: string, taskType: number, hero:
|
||||
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);
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, { count });
|
||||
}
|
||||
else if (taskType == TASK_TYPE.HERO_FAVOUR_LV) {
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, { favourLv: hero.favourLv }, funcs)
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, { favourLv: hero.favourLv })
|
||||
}
|
||||
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);
|
||||
pushMessage = await checkTask(roleId, taskType, args[0], true, { count, isPutOn: args[0] });
|
||||
}
|
||||
else if (taskType == TASK_TYPE.EQUIP_STRENGTHEN) {
|
||||
// args: 依次为原先的装备的强化等级
|
||||
let { ePlace } = hero;
|
||||
let index = 0;
|
||||
for (let { lv } of ePlace) {
|
||||
let p = await checkTask(roleId, taskType, 1, true, { oldLv: args[index++], lv }, funcs);
|
||||
let p = await checkTask(roleId, taskType, 1, true, { oldLv: args[index++], lv });
|
||||
pushMessage = pushMessage.concat(p);
|
||||
}
|
||||
}
|
||||
@@ -146,27 +146,27 @@ export async function checkTaskWithHero(roleId: string, taskType: number, hero:
|
||||
}
|
||||
|
||||
|
||||
export async function checkTaskWithEquip(roleId: string, taskType: number, equip: EquipType, args: number[] = [], funcs?: number[]) {
|
||||
export async function checkTaskWithEquip(roleId: string, taskType: number, equip: EquipType, args: number[] = []) {
|
||||
let pushMessage = new Array<TaskListReturn>();
|
||||
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)
|
||||
pushMessage = await checkTask(roleId, taskType, args[0], true, { quality: dicGood.quality })
|
||||
}
|
||||
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) { // 原来没有,镶嵌上了
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, {}, funcs);
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, {});
|
||||
} else if (jewelCount <= 0 && args[0] > 0) { // 原来镶嵌着,现在没了
|
||||
pushMessage = await checkTask(roleId, taskType, -1, true, {}, funcs);
|
||||
pushMessage = await checkTask(roleId, taskType, -1, true, {});
|
||||
}
|
||||
}
|
||||
else if (taskType == TASK_TYPE.EQUIP_COMPOSE_SUIT) {
|
||||
let dicGood = gameData.goods.get(equip.id);
|
||||
if (dicGood.suitId) {
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, {}, funcs);
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, {});
|
||||
}
|
||||
}
|
||||
else if (taskType == TASK_TYPE.EQUIP_SUIT) {
|
||||
@@ -189,7 +189,7 @@ export async function checkTaskWithEquip(roleId: string, taskType: number, equip
|
||||
if (id == equip.id) curCount = count;
|
||||
}
|
||||
if (curCount == minCount) {
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, {}, funcs);
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, {});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -197,20 +197,20 @@ export async function checkTaskWithEquip(roleId: string, taskType: number, equip
|
||||
// args[0] 原来镶嵌了多少宝石
|
||||
let { holes } = equip;
|
||||
let jewelCount = holes.filter(cur => cur.jewel > 0).length;
|
||||
pushMessage = await checkTask(roleId, taskType, jewelCount - args[0], true, {}, funcs);
|
||||
pushMessage = await checkTask(roleId, taskType, jewelCount - args[0], true, {});
|
||||
}
|
||||
return pushMessage
|
||||
}
|
||||
|
||||
export async function checkTaskWithArgs(roleId: string, taskType: number, args: number[], funcs?: number[]) {
|
||||
export async function checkTaskWithArgs(roleId: string, taskType: number, args: number[]) {
|
||||
let pushMessage = new Array<TaskListReturn>();
|
||||
|
||||
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);
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, {});
|
||||
} else if (hid <= 0 && preHid > 0) { // 卸下
|
||||
pushMessage = await checkTask(roleId, taskType, -1, true, {}, funcs);
|
||||
pushMessage = await checkTask(roleId, taskType, -1, true, {});
|
||||
}
|
||||
}
|
||||
else if (taskType == TASK_TYPE.EQUIP_JEWEL_STAGE) {
|
||||
@@ -218,83 +218,83 @@ export async function checkTaskWithArgs(roleId: string, taskType: number, args:
|
||||
let [putOnJewel, putOffJewel] = args;
|
||||
if (putOnJewel > 0) {
|
||||
let dicGood = gameData.goods.get(putOnJewel);
|
||||
let push = await checkTask(roleId, taskType, 1, true, { stage: dicGood.lvLimited }, funcs);
|
||||
let push = await checkTask(roleId, taskType, 1, true, { stage: dicGood.lvLimited });
|
||||
pushMessage.concat(push);
|
||||
}
|
||||
if (putOffJewel > 0) {
|
||||
let dicGood = gameData.goods.get(putOffJewel);
|
||||
let push = await checkTask(roleId, taskType, -1, true, { stage: dicGood.lvLimited }, funcs);
|
||||
let push = await checkTask(roleId, taskType, -1, true, { stage: dicGood.lvLimited });
|
||||
pushMessage.concat(push);
|
||||
}
|
||||
}
|
||||
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)
|
||||
pushMessage = await checkTask(roleId, taskType, 1, true, { chatType: args[0] })
|
||||
}
|
||||
|
||||
return pushMessage
|
||||
}
|
||||
|
||||
export async function checkTaskWithWar(roleId: string, taskType: number, warId: number, heroes: number[], count: number, star: number, funcs?: number[]) {
|
||||
export async function checkTaskWithWar(roleId: string, taskType: number, warId: number, heroes: number[], count: number, star: number) {
|
||||
let dicWar = gameData.war.get(warId);
|
||||
let pushMessage = new Array<TaskListReturn>();
|
||||
if (taskType == TASK_TYPE.BATTLE_WITH_HERO) {
|
||||
pushMessage = await checkTask(roleId, taskType, count, true, { warId, heroes }, funcs);
|
||||
pushMessage = await checkTask(roleId, taskType, count, true, { warId, heroes });
|
||||
}
|
||||
else if (taskType == TASK_TYPE.BATTLE_MAIN) {
|
||||
if (dicWar.warType == WAR_TYPE.NORMAL) {
|
||||
pushMessage = await checkTask(roleId, taskType, count, true, { warId }, funcs);
|
||||
pushMessage = await checkTask(roleId, taskType, count, true, { warId });
|
||||
}
|
||||
}
|
||||
else if (taskType == TASK_TYPE.BATTLE_MAIN_SWEEP) {
|
||||
if (dicWar.warType == WAR_TYPE.NORMAL) {
|
||||
pushMessage = await checkTask(roleId, taskType, count, true, {}, funcs);
|
||||
pushMessage = await checkTask(roleId, taskType, count, true, {});
|
||||
}
|
||||
}
|
||||
else if (taskType == TASK_TYPE.BATTLE_DAILY_STAR) {
|
||||
if (dicWar.warType == WAR_TYPE.DAILY) {
|
||||
pushMessage = await checkTask(roleId, taskType, count, true, { warId, star }, funcs);
|
||||
pushMessage = await checkTask(roleId, taskType, count, true, { warId, star });
|
||||
}
|
||||
}
|
||||
else if (taskType == TASK_TYPE.BATTLE_DAILY) {
|
||||
if (dicWar.warType == WAR_TYPE.DAILY) {
|
||||
pushMessage = await checkTask(roleId, taskType, count, true, { dailyType: dicWar.dailyType }, funcs)
|
||||
pushMessage = await checkTask(roleId, taskType, count, true, { dailyType: dicWar.dailyType })
|
||||
}
|
||||
}
|
||||
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);
|
||||
pushMessage = await checkTask(roleId, taskType, count, true, {});
|
||||
}
|
||||
}
|
||||
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);
|
||||
pushMessage = await checkTask(roleId, taskType, count, true, { warId });
|
||||
}
|
||||
}
|
||||
else if (taskType == TASK_TYPE.BATTLE_TOWER) {
|
||||
if (dicWar.warType == WAR_TYPE.TOWER) {
|
||||
pushMessage = await checkTask(roleId, taskType, count, true, {}, funcs);
|
||||
pushMessage = await checkTask(roleId, taskType, count, true, {});
|
||||
}
|
||||
}
|
||||
else if (taskType == TASK_TYPE.BATTLE_VESTIGE) {
|
||||
if (dicWar.warType == WAR_TYPE.VESTIGE) {
|
||||
pushMessage = await checkTask(roleId, taskType, count, true, {}, funcs);
|
||||
pushMessage = await checkTask(roleId, taskType, count, true, {});
|
||||
}
|
||||
}
|
||||
else if (taskType == TASK_TYPE.BATTLE_EXPEDITION) {
|
||||
if (dicWar.warType == WAR_TYPE.EXPEDITION) {
|
||||
pushMessage = await checkTask(roleId, taskType, count, true, {}, funcs);
|
||||
pushMessage = await checkTask(roleId, taskType, count, true, {});
|
||||
}
|
||||
}
|
||||
return pushMessage
|
||||
}
|
||||
|
||||
|
||||
export async function checkTaskWithGoods(roleId: string, taskType: number, goods: ItemInter[], funcs?: number[]) {
|
||||
export async function checkTaskWithGoods(roleId: string, taskType: number, goods: ItemInter[]) {
|
||||
let pushMessage = new Array<TaskListReturn>();
|
||||
if (taskType == TASK_TYPE.COM_BATTLE_DROP) {
|
||||
for (let { id, count } of goods) {
|
||||
let push = await checkTask(roleId, taskType, count, true, { gid: id }, funcs);
|
||||
let push = await checkTask(roleId, taskType, count, true, { gid: id });
|
||||
pushMessage.concat(push);
|
||||
}
|
||||
}
|
||||
@@ -302,8 +302,8 @@ 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[]) {
|
||||
// console.log('******checkTask', roleId, taskType, count, isInc, param, funcs)
|
||||
export async function checkTask(roleId: string, taskType: number, count: number, isInc: boolean, param: TaskParam) {
|
||||
// console.log('******checkTask', roleId, taskType, count, isInc, param)
|
||||
let tasks = gameData.taskType.get(taskType) || [];
|
||||
let pushMessage = new Array<TaskListReturn>();
|
||||
let groups = new Map<string, { task0: DicTask, tasks: DicTask[] }>();
|
||||
@@ -313,17 +313,13 @@ export async function checkTask(roleId: string, taskType: number, count: number,
|
||||
}
|
||||
groups.get(`${dicTask.type}_${dicTask.group}`).tasks.push(dicTask);
|
||||
}
|
||||
if (!funcs) {
|
||||
let role = await RoleModel.findByRoleId(roleId, 'funcs');
|
||||
funcs = role.funcs || [];
|
||||
}
|
||||
|
||||
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);
|
||||
let rec = await checkTaskRec(roleId, type, group, task0, count, isInc, param);
|
||||
if (rec) {
|
||||
for (let dicTask of tasks) {
|
||||
if (checkRecResult(rec, dicTask.id)) {
|
||||
@@ -337,15 +333,9 @@ 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) {
|
||||
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) { // 功能未开启
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
let isMatch = true; // 条件是否满足
|
||||
let checkHistory = false; // 是否检查历史
|
||||
switch (taskType) {
|
||||
@@ -1233,23 +1223,4 @@ export function isComplete(_roleId: string, taskType: TASK_TYPE, taskParam: stri
|
||||
}
|
||||
// console.log('dddddddddddd', addCount, record)
|
||||
return { addCount, record };
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建账号时临时获得可开启功能,主要用于check 主公升级任务
|
||||
* 该函数不会存储funcs,如pvp开启会在entryHandler里面再查一次funcs,那时候正式开启
|
||||
* @param dataFuncs
|
||||
* @param lv
|
||||
*/
|
||||
export async function getCreateUserFuncs(dataFuncs: number[], lv: number) {
|
||||
let addFuncs: number[] = [];
|
||||
for (let [id, dicFunSwitch] of gameData.funcsSwitch) {
|
||||
if (dataFuncs.includes(id)) continue; // 已开启过了
|
||||
|
||||
if (dicFunSwitch && lv >= dicFunSwitch.param) {
|
||||
addFuncs.push(id);
|
||||
}
|
||||
return addFuncs;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user