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