装备:任务

This commit is contained in:
luying
2022-02-22 10:56:31 +08:00
parent 56f2c23929
commit 3f5371df79
11 changed files with 598 additions and 262 deletions

View File

@@ -1,11 +1,11 @@
import { gameData } from './data';
import { gameData, getEquipSuitByHero } from './data';
import { DicTask } from './dictionary/DicTask';
import { TASK_TYPE, ABI_STAGE, WAR_TYPE, GUILD_JOB, TASK_SUM_TYPE } from '../consts';
import { UserTaskRecModel, UserTaskRecType } from '../db/UserTaskRec'
import { RoleType, RoleModel } from '../db/Role';
import { TaskParam, TaskListReturn } from '../domain/roleField/task';
import { getZeroPoint } from './timeUtil';
import { HeroType } from '../db/Hero';
import { EPlace, HeroType } from '../db/Hero';
import { ItemInter } from './interface';
import { DailyChallengesData } from '../domain/activityField/dailyChallengesField';
import { splitString } from './util';
@@ -31,6 +31,8 @@ import { GuildModel } from '../db/Guild';
import { RefreshTaskData } from '../domain/activityField/refreshTaskField';
import { ActivityRefreshTaskModel } from '../db/ActivityRefreshTask';
import { ActivityInRemote, transActivityInRemoteToModelType } from '../domain/activityField/activityField';
import { JewelType } from '../db/Jewel';
import { isRandSeUnLock } from './playerCe';
@@ -113,10 +115,7 @@ export async function checkTaskWithHero(roleId: string, taskType: number, hero:
pushMessage = await checkTask(roleId, taskType, 1, true, { count, oldCount });
}
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, {});
}
pushMessage = await checkTask(roleId, taskType, 1, true, { hid: hero.hid });
}
else if (taskType == TASK_TYPE.HERO_STAGE_UP) {
let dicHero = gameData.hero.get(hero.hid);
@@ -128,25 +127,128 @@ export async function checkTaskWithHero(roleId: string, taskType: number, hero:
else if (taskType == TASK_TYPE.HERO_FAVOUR_LV) {
pushMessage = await checkTask(roleId, taskType, 1, true, { favourLv: hero.favourLv, oldLv: args[0] })
}
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], oldCount: args[1] });
}
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 });
pushMessage = pushMessage.concat(p);
return pushMessage
}
export async function checkTaskWithEplaces(roleId: string, taskType: number, oldEplace: EPlace[], newEplace: EPlace[], eplaceIds: number[], params?: Param) {
let pushMessage = new Array<TaskListReturn>();
if(taskType == TASK_TYPE.EQUIP_SUIT_SEID_NUM) {
let dicEquipSuit = getEquipSuitByHero(params.hid);
let oldSuitStars: number[] = [], newSuitStars: number[] = [];
for(let equipId of dicEquipSuit.equips) {
let oldEquip = oldEplace.find(cur => cur.equipId == equipId);
oldSuitStars.push(oldEquip? oldEquip.star: 0);
let newEquip = newEplace.find(cur => cur.equipId == equipId);
newSuitStars.push(newEquip? newEquip.star: 0);
}
let oldStar = Math.min(...oldSuitStars);
let newStar = Math.min(...newSuitStars);
let oldCount = 0, count = 0;
for(let { star } of dicEquipSuit.effect) {
if(oldStar >= star) oldCount++;
if(newStar >= star) count++;
}
pushMessage = await checkTask(roleId, taskType, 1, true, { oldCount, count });
}
else if (taskType == TASK_TYPE.EQUIP_COMPOSE_CNT) {
pushMessage = await checkTask(roleId, taskType, newEplace.length - oldEplace.length, true, {});
} else {
for(let eplaceId of eplaceIds) {
let oldEquip = oldEplace.find(cur => cur.id == eplaceId)||new EPlace(eplaceId, 0);
let newEquip = newEplace.find(cur => cur.id == eplaceId)||new EPlace(eplaceId, 0);
let result = await checkTaskWithEplace(roleId, taskType, oldEquip, newEquip, params);
pushMessage.push(...result);
}
}
return pushMessage
}
interface Param {
jewels?: JewelType[];
hid?: number;
}
export async function checkTaskWithEplace(roleId: string, taskType: number, oldEquip: EPlace, newEquip: EPlace, params?: Param) {
let pushMessage = new Array<TaskListReturn>();
if (taskType == TASK_TYPE.EQUIP_LV_TO) {
pushMessage = await checkTask(roleId, taskType, 1, true, { oldLv: oldEquip.lv, lv: newEquip.lv })
}
else if (taskType == TASK_TYPE.EQUIP_PUT_JEWEL) {
let jewels: JewelType[] = params.jewels;
let oldJewel = jewels.find(cur => cur && cur.seqId == oldEquip.jewel);
let oldLv = gameData.jewel.get(oldJewel?.id)?.lv || 0;
let newJewel = jewels.find(cur => cur && cur.seqId == newEquip.jewel);
let lv = gameData.jewel.get(newJewel?.id)?.lv || 0;
pushMessage = await checkTask(roleId, taskType, 1, true, { oldLv, lv });
}
else if (taskType == TASK_TYPE.EQUIP_PUT_STONE) {
let oldStoneCnt = oldEquip.stones.filter(cur => cur.stone != 0).length;
let newStoneCnt = newEquip.stones.filter(cur => cur.stone != 0).length;
pushMessage = await checkTask(roleId, taskType, 1, true, { oldCount: oldStoneCnt, count: newStoneCnt });
}
else if (taskType == TASK_TYPE.EQUIP_STAR_UP_TO) {
pushMessage = await checkTask(roleId, taskType, 1, true, { oldStar: oldEquip?.star||0, star: newEquip?.star||0 });
}
else if (taskType == TASK_TYPE.EQUIP_QUALITY_UP) {
pushMessage = await checkTask(roleId, taskType, 1, true, { hid: params.hid, eplaceId: newEquip.id });
}
else if (taskType == TASK_TYPE.EQUIP_QUALITY_UP_TO) {
pushMessage = await checkTask(roleId, taskType, 1, true, { oldQuality: oldEquip?.quality||0, quality: newEquip?.quality||0 });
}
else if (taskType == TASK_TYPE.EQUIP_PUT_JEWEL_CNT) {
if(oldEquip.jewel && !newEquip.jewel) {
pushMessage = await checkTask(roleId, taskType, -1, true, { });
} else if (!oldEquip.jewel && newEquip.jewel) {
pushMessage = await checkTask(roleId, taskType, 1, true, { });
}
}
else if (taskType == TASK_TYPE.EQUIP_PUT_STONE_CNT) {
let oldStoneCnt = oldEquip.stones.filter(cur => cur.stone != 0).length;
let newStoneCnt = newEquip.stones.filter(cur => cur.stone != 0).length;
if(oldStoneCnt > 0 && newStoneCnt == 0) {
pushMessage = await checkTask(roleId, taskType, -1, true, { });
} else if (oldStoneCnt == 0 && newStoneCnt > 0) {
pushMessage = await checkTask(roleId, taskType, 1, true, { });
}
}
else if (taskType == TASK_TYPE.EQUIP_STONE_CNT) {
let oldStoneCnt = oldEquip.stones.filter(cur => cur.stone != 0).length;
let newStoneCnt = newEquip.stones.filter(cur => cur.stone != 0).length;
pushMessage = await checkTask(roleId, taskType, newStoneCnt - oldStoneCnt, true, { });
}
else if (taskType == TASK_TYPE.EQUIP_STONE_CNT_LV) {
let oldStoneLvs = oldEquip.stones.map(cur => {
let dicStone = gameData.stone.get(cur.stone);
return dicStone?dicStone.lv: 0;
});
let newStoneLvs = newEquip.stones.map(cur => {
let dicStone = gameData.stone.get(cur.stone);
return dicStone?dicStone.lv: 0;
});
pushMessage = await checkTask(roleId, taskType, 1, true, { oldStoneLvs, newStoneLvs });
}
else if (taskType == TASK_TYPE.EQUIP_JEWEL_RANDSE_CNT) {
let jewels: JewelType[] = params.jewels;
let oldJewel = jewels.find(cur => cur && cur.seqId == oldEquip.jewel);
let oldRandSe = oldJewel.randSe||[];
let oldUnlockSeCnt = oldRandSe.filter(se => {
return isRandSeUnLock(oldJewel.id, se.id, oldEquip.stones);
}).length;
let newJewel = jewels.find(cur => cur && cur.seqId == newEquip.jewel);
let newRandSe = newJewel.randSe||[];
let newUnlockSeCnt = newRandSe.filter(se => {
return isRandSeUnLock(newJewel.id, se.id, newEquip.stones);
}).length;
pushMessage = await checkTask(roleId, taskType, 1, true, { oldCount: oldUnlockSeCnt, count: newUnlockSeCnt });
}
return pushMessage
}
// export async function checkTaskWithEquip(roleId: string, taskType: number, equip: EquipType, args: number[] = []) {
// let pushMessage = new Array<TaskListReturn>();
@@ -215,20 +317,6 @@ export async function checkTaskWithArgs(roleId: string, taskType: number, args:
pushMessage = await checkTask(roleId, taskType, -1, true, {});
}
}
else if (taskType == TASK_TYPE.EQUIP_JEWEL_STAGE) {
// // 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 });
// pushMessage.push(...push);
// }
// if (putOffJewel > 0) {
// let dicGood = gameData.goods.get(putOffJewel);
// let push = await checkTask(roleId, taskType, -1, true, { stage: dicGood.lvLimited });
// pushMessage.push(...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] })
@@ -340,6 +428,7 @@ export async function checkTaskRec(roleId: string, type: number, group: string,
let isMatch = true; // 条件是否满足
let checkHistory = false; // 是否检查历史
let checkRecord = ''; // 检查记录
switch (taskType) {
case TASK_TYPE.ROLE_TITLE:
isMatch = param.title >= taskParam[0] && param.oldTitle < taskParam[0];
@@ -351,8 +440,9 @@ export async function checkTaskRec(roleId: string, type: number, group: string,
case TASK_TYPE.HERO_QUALITY:
isMatch = taskParam[1] == param.quality;
break;
case TASK_TYPE.EQUIP_QUALITY:
isMatch = taskParam[1] <= param.quality;
case TASK_TYPE.HERO_QUALITY_UP:
isMatch = true;
checkRecord = `${param.hid}`;
break;
case TASK_TYPE.HERO_QUALITY_STAR_UP:
isMatch = taskParam[1] == param.quality && taskParam[2] == param.star;
@@ -369,20 +459,6 @@ export async function checkTaskRec(roleId: string, type: number, group: string,
case TASK_TYPE.HERO_CONNECT:
isMatch = taskParam[1] == param.connectLv;
break;
case TASK_TYPE.EQUIP_BY_HERO:
isMatch = false;
if (param.isPutOn == 1 && param.count >= taskParam[1] && param.oldCount < taskParam[1] ) { // 装上之后达到 +1
isMatch = true;
} else if (param.isPutOn == -1 && param.count < taskParam[1] && param.oldCount >= taskParam[1]) { // 脱下后不能达到 -1
isMatch = true;
}
break;
case TASK_TYPE.EQUIP_STRENGTHEN:
isMatch = param.oldLv < taskParam[1] && param.lv >= taskParam[1];
break;
case TASK_TYPE.EQUIP_JEWEL_STAGE:
isMatch = param.stage >= taskParam[1];
break;
case TASK_TYPE.CHAT:
isMatch = taskParam[0] == 0 || param.chatType == taskParam[0];
break;
@@ -431,6 +507,57 @@ export async function checkTaskRec(roleId: string, type: number, group: string,
case TASK_TYPE.GUILD_REFINE:
isMatch = taskParam[0] == 0 || param.quality == taskParam[0];
break;
case TASK_TYPE.EQUIP_LV_TO:
isMatch = param.lv >= taskParam[1] && param.oldLv < taskParam[1];
break;
case TASK_TYPE.EQUIP_PUT_JEWEL:
if(param.lv >= taskParam[1] && param.oldLv < taskParam[1]) {
isMatch = true;
} else if (param.lv < taskParam[1] && param.oldLv >= taskParam[1]) {
isMatch = true;
count = -1;
}
break;
case TASK_TYPE.EQUIP_PUT_STONE:
if(param.oldCount < taskParam[1] && param.count >= taskParam[1]) {
isMatch = true;
} else if (param.oldCount >= taskParam[1] && param.count < taskParam[1]) {
isMatch = true;
count = -1;
}
break;
case TASK_TYPE.EQUIP_STAR_UP_TO:
isMatch = param.oldStar < taskParam[1] && param.star >= taskParam[1];
break;
case TASK_TYPE.EQUIP_SUIT_SEID_NUM:
isMatch = param.oldCount < taskParam[1] && param.count >= taskParam[1];
break;
case TASK_TYPE.EQUIP_QUALITY_UP:
isMatch = true;
checkRecord = `${param.hid}_${param.eplaceId}`;
break;
case TASK_TYPE.EQUIP_QUALITY_UP_TO:
isMatch = param.oldQuality < taskParam[1] && param.quality >= taskParam[1];
break;
case TASK_TYPE.EQUIP_STONE_CNT_LV:
let oldCount = param.oldStoneLvs.filter(lv => lv >= taskParam[2]).length;
let newCount = param.newStoneLvs.filter(lv => lv >= taskParam[2]).length;
if(oldCount < taskParam[1] && newCount >= taskParam[1]) {
isMatch = true;
} else if (oldCount >= taskParam[1] && newCount < taskParam[1]) {
isMatch = false;
count = -1;
}
break;
case TASK_TYPE.EQUIP_JEWEL_RANDSE_CNT:
if(param.oldCount < taskParam[1] && param.count >= taskParam[1]) {
isMatch = true;
} else if (param.oldCount >= taskParam[1] && param.count < taskParam[1]) {
isMatch = true;
count = -1;
}
break;
}
// console.log('****isMatch', isMatch, checkHistory, type, taskType, group, count)
if (param.isDebug) {
@@ -439,8 +566,13 @@ export async function checkTaskRec(roleId: string, type: number, group: string,
if (isMatch) {
if (isInc) {
let rec = await UserTaskRecModel.incTaskRec(roleId, type, taskType, group, count);
return rec;
if(checkRecord != '') {
let rec = await UserTaskRecModel.checkRecordAndIncTaskRec(roleId, type, taskType, group, count, checkRecord);
return rec;
} else {
let rec = await UserTaskRecModel.incTaskRec(roleId, type, taskType, group, count);
return rec;
}
} else {
if (checkHistory) {
let rec = await UserTaskRecModel.checkHistoryAndSetTaskRec(roleId, type, taskType, group, count);
@@ -689,26 +821,7 @@ export async function accomplishTask(serverId: number, roleId: string, taskType:
// console.log('***** thirtyDay before', Date.now());
//30天任务统计
if (taskType === TASK_TYPE.HERO_QUALITY_STAR_UP ||
taskType === TASK_TYPE.HERO_QUALITY_TO_QUALITY_COUNT ||
taskType === TASK_TYPE.HERO_QUALITY_WAKE_UP_COUNT ||
taskType === TASK_TYPE.HERO_WAKE_UP_STAR_UP_COUNT ||
taskType === TASK_TYPE.HERO_WAKE_UP_COUNT ||
taskType === TASK_TYPE.HERO_QUALITY ||
taskType === TASK_TYPE.GUILD_TRAIN_COUNT ||
taskType === TASK_TYPE.HERO_UNLOCK ||
taskType === TASK_TYPE.GACHA_QUALITY_COUNT ||
taskType === TASK_TYPE.ROLE_TERAPH_STAGE_UP ||
taskType === TASK_TYPE.EQUIP_QUALITY_COUNT ||
taskType === TASK_TYPE.EQUIP_STRENGTHEN ||
taskType === TASK_TYPE.EQUIP_REFINE_LV ||
taskType === TASK_TYPE.HERO_STAGE_UP ||
taskType === TASK_TYPE.EQUIP_JEWEL_SUM ||
taskType === TASK_TYPE.EQUIP_JEWEL_STAGE ||
taskType === TASK_TYPE.EQUIP_SUIT_JEWEL_STAGE ||
taskType === TASK_TYPE.EQUIP_QUALITY
) {
{
allActivity = await findActivitiesByTypes([ACTIVITY_TYPE.THIRTY_DAYS]);
for (let activity of allActivity) {
let thirtyDaysActivity = new ThirtyDaysData(activity, createTime);
@@ -757,7 +870,7 @@ export async function accomplishTask(serverId: number, roleId: string, taskType:
let playerRecord = await ActivityPopUpShopModel.addTaskPushMessage(serverId, activity.activityId, roleId, task.id, task.taskType, count, beginTime, endTime);
popShopData.setPlayerRecords(playerRecord)
pushMessage = pushMessage.concat(popShopData);
} else if (taskType == TASK_TYPE.EQUIP_QUALITY_COUNT || taskType == TASK_TYPE.GACHA_QUALITY_COUNT || taskType == TASK_TYPE.GUILD_ACTIVITY) {//每天统计
} else if ( taskType == TASK_TYPE.GACHA_QUALITY_COUNT || taskType == TASK_TYPE.GUILD_ACTIVITY) {//每天统计
let recordDate = moment(new Date()).startOf('d').toDate()
let recordData: ActivityPopUpShopRecordModelType = await ActivityPopUpShopRecordModel.findRecordData(serverId, activity.activityId, roleId, task.id, task.taskType, recordDate)
let { addCount } = isComplete(roleId, task.taskType, task.taskParam, count, activity.activityId, parma, null);
@@ -918,15 +1031,6 @@ export function isComplete(_roleId: string, taskType: TASK_TYPE, taskParam: stri
let dicJob = gameData.job.get(paramObj.job);
addCount = (param[1] == dicJob.grade) ? count : 0;
break;
case TASK_TYPE.EQUIP_JEWEL_STAGE://count&stage&
addCount = (param[1] <= paramObj.stage) ? count : 0;
break;
case TASK_TYPE.EQUIP_SUIT_JEWEL_STAGE://count&stage&
addCount = (param[1] == paramObj.stage) ? count : 0;
break;
case TASK_TYPE.EQUIP_QUALITY:
addCount = param[1] <= paramObj.quality ? count : 0;
break;
case TASK_TYPE.ROLE_TITLE://重置数据
addCount = param[0] <= count ? count : 0;
@@ -934,30 +1038,9 @@ export function isComplete(_roleId: string, taskType: TASK_TYPE, taskParam: stri
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.EQUIP_REFINE_LV:
addCount = (param[1] == paramObj.lv) ? count : 0;
break;
case TASK_TYPE.EQUIP_REFINE:
addCount = count;
break;
case TASK_TYPE.BATTLE_MAIN:
addCount = (param[1] == paramObj.warId) ? 1 : 0;
break;
case TASK_TYPE.EQUIP_JEWEL_SUM:
addCount = count;
break;
case TASK_TYPE.GUILD_TRAIN:
addCount = count;
break;
@@ -972,9 +1055,6 @@ export function isComplete(_roleId: string, taskType: TASK_TYPE, taskParam: stri
}
break;
}
case TASK_TYPE.EQUIP_SUM:
addCount = count;
break;
case TASK_TYPE.HERO_LV://{ hid, lv}
{
let hid = paramObj.hid;
@@ -1141,13 +1221,6 @@ export function isComplete(_roleId: string, taskType: TASK_TYPE, taskParam: stri
record.push(hid)
break;
}
case TASK_TYPE.EQUIP_QUALITY_COUNT:
{
let quality = param[1]
let equips = paramObj.equips.filter(equip => { return equip.quality == quality })
addCount = equips.length;
break;
}
case TASK_TYPE.COM_BATTLE:
{
addCount = count;