装备:任务
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Application, BackendSession, HandlerService, } from "pinus";
|
||||
import { STATUS, HERO_SYSTEM_TYPE, ITEM_CHANGE_REASON } from "../../../consts";
|
||||
import { STATUS, HERO_SYSTEM_TYPE, ITEM_CHANGE_REASON, TASK_TYPE } from "../../../consts";
|
||||
import { ItemInter, RewardInter } from "../../../pubUtils/interface";
|
||||
|
||||
import { resResult, parseGoodStr } from "../../../pubUtils/util";
|
||||
@@ -13,6 +13,7 @@ import { getRandSeResult, updateEplace, updateEplaces, checkJewelCanPutOnEquip,
|
||||
import { isNumber, pick } from 'underscore';
|
||||
import { JewelModel } from "../../../db/Jewel";
|
||||
import { getJewelRandSe } from "../../../pubUtils/itemUtils";
|
||||
import { checkTask, checkTaskInPutJewel, checkTaskWithEplaces, checkTaskWithHero } from "../../../services/taskService";
|
||||
|
||||
export default function (app: Application) {
|
||||
new HandlerService(app, {});
|
||||
@@ -32,8 +33,9 @@ export class EquipHandler {
|
||||
|
||||
let hero = await HeroModel.findByHidAndRole(hid, roleId);
|
||||
if(!hero) return resResult(STATUS.HERO_NOT_FIND);
|
||||
|
||||
let curEquip = hero.ePlace?.find(equip => equip.id == ePlaceId );
|
||||
|
||||
let oldEplace = hero.ePlace||[];
|
||||
let curEquip = oldEplace.find(equip => equip.id == ePlaceId );
|
||||
if(curEquip) return resResult(STATUS.EQUIP_HAS_COMPOSE);
|
||||
|
||||
let dicHero = gameData.hero.get(hid);
|
||||
@@ -44,10 +46,13 @@ export class EquipHandler {
|
||||
if(!consumeResult) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
|
||||
let newEquip = new EPlace(ePlaceId, dicEquip.id);
|
||||
let newEplace = hero.ePlace? [...hero.ePlace, newEquip]: [newEquip];
|
||||
let newEplace = [...oldEplace, newEquip];
|
||||
|
||||
hero = await calPlayerCeAndSave(HERO_SYSTEM_TYPE.COMPOSE_EQUIP, sid, roleId, hero, { ePlace: newEplace }, [ePlaceId]);
|
||||
|
||||
await checkTask(roleId, sid, TASK_TYPE.EQUIP_COMPOSE, 1, true, {});
|
||||
await checkTaskWithEplaces(roleId, sid, TASK_TYPE.EQUIP_COMPOSE_CNT, oldEplace, newEplace, [ePlaceId], {});
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
curHero: {
|
||||
hid: hero.hid,
|
||||
@@ -67,8 +72,8 @@ export class EquipHandler {
|
||||
let { hid, ePlaceId, isOneClick } = msg;
|
||||
let hero = await HeroModel.findByHidAndRole(hid, roleId);
|
||||
if (!hero) return resResult(STATUS.HERO_NOT_FIND);
|
||||
|
||||
let curEquip = hero.ePlace?.find(cur => cur.id == ePlaceId);
|
||||
let oldEplace = hero.ePlace||[];
|
||||
let curEquip = oldEplace.find(cur => cur.id == ePlaceId);
|
||||
if(!curEquip) return resResult(STATUS.EQUIP_NOT_FIND);
|
||||
if(curEquip.lv >= hero.lv) return resResult(STATUS.ROLE_EQUIP_REACH_MAX);
|
||||
let fromLv = curEquip.lv;
|
||||
@@ -87,11 +92,12 @@ export class EquipHandler {
|
||||
let result = await handleCost(roleId, sid, consumes, ITEM_CHANGE_REASON.EQUIP_STRENTHEN);
|
||||
if (!result) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
|
||||
let { newEplace, updatedEplace } = updateEplace(hero.ePlace, ePlaceId, { lv: newLv });
|
||||
let { newEplace, updatedEplace } = updateEplace(oldEplace, ePlaceId, { lv: newLv });
|
||||
|
||||
hero = await calPlayerCeAndSave(HERO_SYSTEM_TYPE.EQUIP_STRENGTH, sid, roleId, hero, { ePlace: newEplace }, [ePlaceId]);
|
||||
|
||||
// TODO 任务
|
||||
await checkTaskWithEplaces(roleId, sid, TASK_TYPE.EQUIP_LV_TO, oldEplace, newEplace, [ePlaceId]);
|
||||
await checkTask(roleId, sid, TASK_TYPE.EQUIP_LV_UP, 1, true, {});
|
||||
|
||||
const curHero = {
|
||||
hid,
|
||||
@@ -135,11 +141,12 @@ export class EquipHandler {
|
||||
let result = await handleCost(roleId, sid, consumes, ITEM_CHANGE_REASON.EQUIP_STRENTHEN);
|
||||
if (!result) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
|
||||
let { newEplace, updatedEplace } = updateEplaces(hero.ePlace, eplaceIds);
|
||||
let { newEplace, updatedEplace } = updateEplaces(ePlace, eplaceIds);
|
||||
|
||||
await calPlayerCeAndSave(HERO_SYSTEM_TYPE.EQUIP_STRENGTH, sid, roleId, hero, { ePlace: newEplace }, [...eplaceIds.keys()]);
|
||||
|
||||
// TODO 任务
|
||||
await checkTaskWithEplaces(roleId, sid, TASK_TYPE.EQUIP_LV_TO, ePlace, newEplace, [...eplaceIds.keys()]);
|
||||
await checkTask(roleId, sid, TASK_TYPE.EQUIP_LV_UP, eplaceIds.size, true, {});
|
||||
|
||||
const curHero = {
|
||||
hid,
|
||||
@@ -161,7 +168,8 @@ export class EquipHandler {
|
||||
let hero = await HeroModel.findByHidAndRole(hid, roleId);
|
||||
if (!hero) return resResult(STATUS.HERO_NOT_FIND);
|
||||
|
||||
let curEquip = hero.ePlace?.find(cur => cur.id == ePlaceId);
|
||||
let oldEplace = hero.ePlace||[];
|
||||
let curEquip = oldEplace.find(cur => cur.id == ePlaceId);
|
||||
if(!curEquip) return resResult(STATUS.EQUIP_NOT_FIND);
|
||||
|
||||
let nextEquipQuality = getNextEquipQuality(curEquip.equipId, curEquip.quality, curEquip.qualityStage);
|
||||
@@ -198,10 +206,13 @@ export class EquipHandler {
|
||||
|
||||
let isUpQuality = update.quality != curEquip.quality;
|
||||
|
||||
let { newEplace, updatedEplace } = updateEplace(hero.ePlace, ePlaceId, update);
|
||||
let { newEplace, updatedEplace } = updateEplace(oldEplace, ePlaceId, update);
|
||||
hero = await calPlayerCeAndSave(HERO_SYSTEM_TYPE.EQUIP_QUALITY, sid, roleId, hero, { ePlace: newEplace }, [ePlaceId]);
|
||||
|
||||
// TODO 任务
|
||||
if(isUpQuality) {
|
||||
await checkTaskWithEplaces(roleId, sid, TASK_TYPE.EQUIP_QUALITY_UP, oldEplace, newEplace, [ePlaceId], { hid });
|
||||
await checkTask(roleId, sid, TASK_TYPE.EQUIP_QUALITY_UP_CNT, 1, true, {});
|
||||
}
|
||||
const curHero = {
|
||||
hid,
|
||||
isUpQuality,
|
||||
@@ -222,7 +233,8 @@ export class EquipHandler {
|
||||
let hero = await HeroModel.findByHidAndRole(hid, roleId);
|
||||
if (!hero) return resResult(STATUS.HERO_NOT_FIND);
|
||||
|
||||
let curEquip = hero.ePlace?.find(cur => cur.id == ePlaceId);
|
||||
let oldEplace = hero.ePlace||[];
|
||||
let curEquip = oldEplace.find(cur => cur.id == ePlaceId);
|
||||
if(!curEquip) return resResult(STATUS.EQUIP_NOT_FIND);
|
||||
|
||||
let update = {
|
||||
@@ -267,10 +279,14 @@ export class EquipHandler {
|
||||
let result = await handleCost(roleId, sid, consumes, ITEM_CHANGE_REASON.EQUIP_STARUP);
|
||||
if (!result) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
|
||||
let { newEplace, updatedEplace } = updateEplace(hero.ePlace, ePlaceId, update);
|
||||
let { newEplace, updatedEplace } = updateEplace(oldEplace, ePlaceId, update);
|
||||
hero = await calPlayerCeAndSave(HERO_SYSTEM_TYPE.EQUIP_STAR, sid, roleId, hero, { ePlace: newEplace }, [ePlaceId]);
|
||||
|
||||
// TODO 任务
|
||||
if(isUpStar) {
|
||||
await checkTaskWithEplaces(roleId, sid, TASK_TYPE.EQUIP_STAR_UP_TO, oldEplace, newEplace, [ePlaceId]);
|
||||
await checkTask(roleId, sid, TASK_TYPE.EQUIP_STAR_UP_CNT, 1, true, {});
|
||||
await checkTaskWithEplaces(roleId, sid, TASK_TYPE.EQUIP_SUIT_SEID_NUM, oldEplace, newEplace, [ePlaceId], { hid });
|
||||
}
|
||||
|
||||
const curHero = {
|
||||
hid,
|
||||
@@ -290,7 +306,8 @@ export class EquipHandler {
|
||||
let hero = await HeroModel.findByHidAndRole(hid, roleId);
|
||||
if (!hero) return resResult(STATUS.HERO_NOT_FIND);
|
||||
|
||||
let curEquip = hero.ePlace?.find(cur => cur.id == ePlaceId);
|
||||
let oldEplace = hero.ePlace||[];
|
||||
let curEquip = oldEplace.find(cur => cur.id == ePlaceId);
|
||||
if(!curEquip) return resResult(STATUS.EQUIP_NOT_FIND);
|
||||
let jewel = await JewelModel.findbySeqId(seqId);
|
||||
if(!jewel) return resResult(STATUS.JEWEL_IS_NOT_FIND);
|
||||
@@ -304,12 +321,15 @@ export class EquipHandler {
|
||||
let canSentMineToOrigin = false; // 自己的能不能塞到对方身上
|
||||
if(jewel.hid != 0) { // 如果天晶石原本镶嵌在其他武将身上,把自己的给他
|
||||
let originHero = await HeroModel.findByHidAndRole(jewel.hid, roleId);
|
||||
let originEquip = originHero?.ePlace?.find(cur => cur.jewel == seqId);
|
||||
let originEplace = originHero?.ePlace||[];
|
||||
let originEquip = originEplace.find(cur => cur.jewel == seqId);
|
||||
if(originEquip) {
|
||||
let canChange = originJewel && checkJewelCanPutOnEquip(originEquip, originJewel);
|
||||
if(canChange) canSentMineToOrigin = true;
|
||||
let { newEplace, updatedEplace } = updateEplace(originHero.ePlace, ePlaceId, { jewel: canChange? originJewel.seqId: 0 });
|
||||
let { newEplace, updatedEplace } = updateEplace(originEplace, ePlaceId, { jewel: canChange? originJewel.seqId: 0 });
|
||||
await calPlayerCeAndSave(HERO_SYSTEM_TYPE.EQUIP_JEWEL, sid, roleId, originHero, { ePlace: newEplace }, [ePlaceId], { oldJewel: jewel, newJewel: canChange? originJewel:null });
|
||||
await checkTaskInPutJewel(roleId, sid, originEplace, newEplace, ePlaceId, jewel, canChange? originJewel:null);
|
||||
|
||||
originHeroResult = { hid: originHero.hid, ePlace: updatedEplace };
|
||||
}
|
||||
}
|
||||
@@ -319,8 +339,10 @@ export class EquipHandler {
|
||||
|
||||
// 目标镶嵌上
|
||||
let curJewel = await JewelModel.putOnOrOff(seqId, hid, ePlaceId);
|
||||
let { newEplace, updatedEplace } = updateEplace(hero.ePlace, ePlaceId, { jewel: seqId });
|
||||
let { newEplace, updatedEplace } = updateEplace(oldEplace, ePlaceId, { jewel: seqId });
|
||||
await calPlayerCeAndSave(HERO_SYSTEM_TYPE.EQUIP_JEWEL, sid, roleId, hero, { ePlace: newEplace }, [ePlaceId], { oldJewel: originJewel, newJewel: curJewel });
|
||||
await checkTaskInPutJewel(roleId, sid, oldEplace, newEplace, ePlaceId, originJewel, curJewel);
|
||||
|
||||
let curHero = {
|
||||
hid,
|
||||
eplace: updatedEplace
|
||||
@@ -338,13 +360,16 @@ export class EquipHandler {
|
||||
let hero = await HeroModel.findByHidAndRole(hid, roleId);
|
||||
if (!hero) return resResult(STATUS.HERO_NOT_FIND);
|
||||
|
||||
let curEquip = hero.ePlace?.find(cur => cur.id == ePlaceId);
|
||||
let oldEplace = hero.ePlace||[];
|
||||
let curEquip = oldEplace.find(cur => cur.id == ePlaceId);
|
||||
if(!curEquip) return resResult(STATUS.EQUIP_NOT_FIND);
|
||||
if(curEquip.jewel == 0) return resResult(STATUS.JEWEL_NOT_SUIT);
|
||||
|
||||
let curJewel = await JewelModel.putOnOrOff(curEquip.jewel, 0, 0);
|
||||
let { newEplace, updatedEplace } = updateEplace(hero.ePlace, ePlaceId, { jewel: 0 });
|
||||
let { newEplace, updatedEplace } = updateEplace(oldEplace, ePlaceId, { jewel: 0 });
|
||||
await calPlayerCeAndSave(HERO_SYSTEM_TYPE.EQUIP_JEWEL, sid, roleId, hero, { ePlace: newEplace }, [ePlaceId], { oldJewel: curJewel });
|
||||
await checkTaskInPutJewel(roleId, sid, oldEplace, newEplace, ePlaceId, null, curJewel);
|
||||
|
||||
let curHero = {
|
||||
hid,
|
||||
eplace: updatedEplace
|
||||
@@ -363,7 +388,8 @@ export class EquipHandler {
|
||||
let hero = await HeroModel.findByHidAndRole(hid, roleId);
|
||||
if (!hero) return resResult(STATUS.HERO_NOT_FIND);
|
||||
|
||||
let curEquip = hero.ePlace?.find(cur => cur.id == ePlaceId);
|
||||
let oldEplace = hero.ePlace||[];
|
||||
let curEquip = oldEplace.find(cur => cur.id == ePlaceId);
|
||||
if(!curEquip) return resResult(STATUS.EQUIP_NOT_FIND);
|
||||
|
||||
let curStone = curEquip.stones?.find(cur => cur.id == stonesId)||{ id: stonesId, stone: 0 };
|
||||
@@ -382,9 +408,14 @@ export class EquipHandler {
|
||||
}
|
||||
|
||||
let newStone = updateStone(curEquip.stones, stonesId, gid);
|
||||
let { newEplace, updatedEplace } = updateEplace(hero.ePlace, ePlaceId, { stones: newStone });
|
||||
let { newEplace, updatedEplace } = updateEplace(oldEplace, ePlaceId, { stones: newStone });
|
||||
let jewel = await JewelModel.findbySeqId(curEquip.jewel);
|
||||
await calPlayerCeAndSave(HERO_SYSTEM_TYPE.EQUIP_STONE, sid, roleId, hero, { ePlace: newEplace }, [ePlaceId], { jewel });
|
||||
await checkTaskWithEplaces(roleId, sid, TASK_TYPE.EQUIP_PUT_STONE, oldEplace, newEplace, [ePlaceId]);
|
||||
await checkTaskWithEplaces(roleId, sid, TASK_TYPE.EQUIP_STONE_CNT, oldEplace, newEplace, [ePlaceId]);
|
||||
await checkTaskWithEplaces(roleId, sid, TASK_TYPE.EQUIP_STONE_CNT_LV, oldEplace, newEplace, [ePlaceId]);
|
||||
await checkTaskWithEplaces(roleId, sid, TASK_TYPE.EQUIP_JEWEL_RANDSE_CNT, oldEplace, newEplace, [ePlaceId], { jewels: [ jewel ] });
|
||||
|
||||
let curHero = {
|
||||
hid,
|
||||
eplace: updatedEplace
|
||||
@@ -506,8 +537,7 @@ export class EquipHandler {
|
||||
await calPlayerCeAndSave(HERO_SYSTEM_TYPE.JEWEL_RESET_RANDSE, sid, roleId, hero, {}, [ePlaceId], { oldJewel: jewel, newJewel });
|
||||
}
|
||||
|
||||
// TODO 任务
|
||||
// await checkTask(roleId, sid, TASK_TYPE.EQUIP_RESTRENGTHEN, 1, true, {});
|
||||
await checkTask(roleId, sid, TASK_TYPE.JEWEL_RESET, 1, true, {});
|
||||
|
||||
return resResult(STATUS.SUCCESS, { curJewel: pick(newJewel, ['seqId', 'id', 'hid', 'ePlaceId', 'randSe', 'previewRandSe']) });
|
||||
|
||||
@@ -590,8 +620,8 @@ export class EquipHandler {
|
||||
await calPlayerCeAndSave(HERO_SYSTEM_TYPE.JEWEL_QUENCH, sid, roleId, hero, {}, [ePlaceId], { oldJewel: jewel, newJewel });
|
||||
}
|
||||
|
||||
// TODO 任务
|
||||
// await checkTask(roleId, sid, TASK_TYPE.EQUIP_RESTRENGTHEN, 1, true, {});
|
||||
await checkTask(roleId, sid, TASK_TYPE.JEWEL_QUENCH, 1, true, {});
|
||||
if(isSuccess) await checkTask(roleId, sid, TASK_TYPE.JEWEL_QUENCH_SUCCESS, 1, true, {});
|
||||
|
||||
return resResult(STATUS.SUCCESS, { isSuccess, curJewel: pick(newJewel, ['seqId', 'id', 'hid', 'ePlaceId', 'randSe', 'previewRandSe']) });
|
||||
|
||||
@@ -668,6 +698,7 @@ export class EquipHandler {
|
||||
if (!costResult) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
|
||||
let goods = await addItems(roleId, roleName, sid, [{ id, count }], ITEM_CHANGE_REASON.COMPOSE_STONE);
|
||||
await checkTask(roleId, sid, TASK_TYPE.STONE_COMPOSE, count, true, {});
|
||||
return resResult(STATUS.SUCCESS, { goods });
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { pinus, FrontendOrBackendSession } from 'pinus';
|
||||
import { resResult, shouldRefresh } from '../pubUtils/util';
|
||||
import { STATUS, TASK_TYPE, TASK_FUN_TYPE, SHOP_REFRESH_TYPE, WAR_TYPE } from '../consts';
|
||||
import { TaskParam, TaskListReturn } from '../domain/roleField/task';
|
||||
import { HeroType } from '../db/Hero';
|
||||
import { EPlace, HeroType } from '../db/Hero';
|
||||
import { getRoleOnlineInfo } from './redisService';
|
||||
import { HeroScores } from '../db/PvpHistoryOpp';
|
||||
import { ItemInter } from '../pubUtils/interface';
|
||||
@@ -15,6 +15,7 @@ import { gameData } from '../pubUtils/data';
|
||||
import { getSeconds, getZeroPointD } from '../pubUtils/timeUtil';
|
||||
import { RoleStatus } from '../db/ComBattleTeam';
|
||||
import { getActivities } from './activity/activityService';
|
||||
import { JewelType } from '../db/Jewel';
|
||||
|
||||
export async function checkTaskWithRoles(serverId: number, roleId: string, sid: string, taskType: number, roles: RoleType[]) {
|
||||
for (let role of roles) {
|
||||
@@ -34,6 +35,11 @@ export async function checkTaskWithHero(roleId: string, sid: string, taskType: n
|
||||
pushTaskUpdate(roleId, sid, pushMessage);
|
||||
}
|
||||
|
||||
export async function checkTaskWithEplaces(roleId: string, sid: string, taskType: number, eplace: EPlace[], newEplace: EPlace[], eplaceIds: number[], params?: any) {
|
||||
let pushMessage = await taskUtil.checkTaskWithEplaces(roleId, taskType, eplace, newEplace, eplaceIds, params);
|
||||
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);
|
||||
@@ -294,6 +300,12 @@ export async function getPvpTask(roleId: string) {
|
||||
return { taskList }
|
||||
}
|
||||
|
||||
export async function checkTaskInPutJewel(roleId: string, sid: string, oldEplace: EPlace[], newEplace: EPlace[], ePlaceId: number, originJewel: JewelType, curJewel: JewelType) {
|
||||
await checkTaskWithEplaces(roleId, sid, TASK_TYPE.EQUIP_PUT_JEWEL, oldEplace, newEplace, [ePlaceId], { jewels: [originJewel, curJewel ] });
|
||||
await checkTaskWithEplaces(roleId, sid, TASK_TYPE.EQUIP_PUT_JEWEL_CNT, oldEplace, newEplace, [ePlaceId]);
|
||||
await checkTaskWithEplaces(roleId, sid, TASK_TYPE.EQUIP_JEWEL_RANDSE_CNT, oldEplace, newEplace, [ePlaceId], { jewels: [originJewel, curJewel ] });
|
||||
}
|
||||
|
||||
// 刷新每日任务
|
||||
export async function refDailyTask(roleId: string, sid: string) {
|
||||
let userTask = await UserTaskModel.findByRole(roleId);
|
||||
|
||||
Reference in New Issue
Block a user