diff --git a/game-server/app/servers/role/handler/heroHandler.ts b/game-server/app/servers/role/handler/heroHandler.ts index d25c4684c..641ccb363 100644 --- a/game-server/app/servers/role/handler/heroHandler.ts +++ b/game-server/app/servers/role/handler/heroHandler.ts @@ -257,8 +257,10 @@ export class HeroHandler { await checkTaskWithHero(roleId, sid, funcs, TASK_TYPE.HERO_STAR_UP, hero); await checkTaskWithHero(roleId, sid, funcs, TASK_TYPE.HERO_QUALITY_STAR_UP, hero); //成长任务 - let dicHero = gameData.hero.get(hero.hid); await accomplishTask(roleId, TASK_TYPE.HERO_QUALITY_STAR_UP, 1, { quality: dicHero.quality, star: hero.star }); + if (hero.colorStar) {//觉醒升星 + await accomplishTask(roleId, TASK_TYPE.HERO_WAKE_UP_STAR_UP_COUNT, 1, { quality: dicHero.quality, star: hero.star }); + } } const curHero = { @@ -313,6 +315,8 @@ export class HeroHandler { // 任务 await checkTaskWithHero(roleId, sid, funcs, TASK_TYPE.HERO_QUALITY_UP, hero); + // 任务 + await accomplishTask(roleId, TASK_TYPE.HERO_QUALITY_TO_QUALITY_COUNT, 1, { oldQuality, quality: hero.quality }); const curHero = { hid, @@ -375,6 +379,7 @@ export class HeroHandler { // 任务 await checkTaskWithHero(roleId, sid, funcs, TASK_TYPE.HERO_STAR_UP, hero); await checkTask(roleId, sid, funcs, TASK_TYPE.HERO_WAKE_UP, 1, true, {}); + await accomplishTask(roleId, TASK_TYPE.HERO_WAKE_UP_COUNT, 1, { quality: hero.quality }); } const curHero = { hid, diff --git a/shared/consts/constModules/sysConst.ts b/shared/consts/constModules/sysConst.ts index 92cba4e78..b5401b046 100644 --- a/shared/consts/constModules/sysConst.ts +++ b/shared/consts/constModules/sysConst.ts @@ -649,6 +649,9 @@ export enum TASK_TYPE { GUILD_ACTIVITY = 71, // 军团活动 GUILD_JOIN = 72, // 加入军团 BATTLE_MAIN_ELITE = 73, // 精英通关 + HERO_QUALITY_TO_QUALITY_COUNT = 74,// *名武将*品升*品 + HERO_WAKE_UP_COUNT = 75, // *名武将*品觉醒 + HERO_WAKE_UP_STAR_UP_COUNT = 76, // *名武将升至觉醒*星 } // 卡池类型 diff --git a/shared/db/Hero.ts b/shared/db/Hero.ts index 02b31e4cb..8644c5cab 100644 --- a/shared/db/Hero.ts +++ b/shared/db/Hero.ts @@ -1,6 +1,6 @@ import BaseModel from './BaseModel'; import { index, getModelForClass, prop, Ref, mongoose, DocumentType } from '@typegoose/typegoose'; -import Equip, { } from './Equip'; +import Equip, { } from './Equip'; import { CounterModel } from './Counter'; import { COUNTER, EQUIP_TYPE } from '../consts'; import { reduceCe } from '../pubUtils/util'; @@ -54,7 +54,7 @@ export class EPlace { // 初始化 function getInitialEplace() { let ePlace = new Array(); - for(let i = EQUIP_TYPE.START; i <= EQUIP_TYPE.END; i++) { + for (let i = EQUIP_TYPE.START; i <= EQUIP_TYPE.END; i++) { let p = new EPlace(); p.id = i; p.equip = null; @@ -90,11 +90,11 @@ export default class Hero extends BaseModel { lv: number; // 武将等级 @prop({ required: true, default: 0, set: (val: number) => val, get: (val: number) => reduceCe(val) }) ce: number; // 武将战力 - @prop({ required: false, set: (val: boolean) => val, get: () => true }) + @prop({ required: false, set: (val: boolean) => val, get: () => true }) isReducedCe: boolean; // 如果战力没有缩过就会返回false,缩过了就会返回true @prop({ required: true, default: 0 }) historyCe: number; // 武将历史最高战力 - @prop({required: true, type: CeAttrData, default: [], _id: false }) + @prop({ required: true, type: CeAttrData, default: [], _id: false }) attr: CeAttrData[]; // 影响战力的属性 @prop({ required: true, default: 1 }) @@ -105,7 +105,7 @@ export default class Hero extends BaseModel { colorStar: number; // 觉醒, 彩星 @prop({ required: true, default: 0 }) colorStarStage: number; // 觉醒六维阶段 - + @prop({ required: true, default: 0 }) quality: number; // 品质 @@ -129,17 +129,17 @@ export default class Hero extends BaseModel { favour: number; // 好感度 @prop({ required: true, default: 1 }) favourLv: number; // 好感等级 - @prop({ required: true, type:Connect, default: [], _id: false }) + @prop({ required: true, type: Connect, default: [], _id: false }) connections: Connect[]; // 羁绊 @prop({ required: true, type: Skin, default: [], _id: false }) skins: Skin[]; // 皮肤 @prop({ required: true, type: EPlace, default: getInitialEplace(), _id: false }) ePlace: EPlace[]; // 武将装备引用数组 - + public static async findByRole(roleId: string, sort: { field: string, sortBy: number }[] = [], select?: string, getters = false) { let sortParam = {}; - for(let {field, sortBy} of sort) { + for (let { field, sortBy } of sort) { sortParam[field] = sortBy; } const heros: HeroType[] = await HeroModel.find({ roleId }).sort(sortParam).select(select).lean({ getters }); @@ -147,19 +147,19 @@ export default class Hero extends BaseModel { } public static async findBySeqIdRange(seqIds: Array, roleId: string, lean = true) { - const hero: HeroType[] = await HeroModel.find({ seqId: {$in: seqIds}, roleId }).lean(lean); + const hero: HeroType[] = await HeroModel.find({ seqId: { $in: seqIds }, roleId }).lean(lean); return hero; } public static async findByHidRange(hids: Array, roleId: string, select?: string, getters = false) { - const hero: HeroType[] = await HeroModel.find({ hid: {$in: hids}, roleId }).select(select).lean({ getters }); + const hero: HeroType[] = await HeroModel.find({ hid: { $in: hids }, roleId }).select(select).lean({ getters }); return hero; } public static async findMapByHidRange(hids: Array, roleId: string, select?: string, getters = false) { const hero = await HeroModel.findByHidRange(hids, roleId, select, getters); let map = new Map(); - for(let h of hero) { + for (let h of hero) { map.set(h.hid, h); } return map; @@ -181,93 +181,93 @@ export default class Hero extends BaseModel { public static async addEquip(roleId: string, hid: number, ePlaceId: number, equipId: string, lean = true) { const hero: HeroType = await HeroModel.findOneAndUpdate( - { roleId, hid, 'ePlace.id': ePlaceId }, - {$set: { 'ePlace.$.equip': equipId }}, - {new: true}).populate('ePlace.equip').lean(lean); + { roleId, hid, 'ePlace.id': ePlaceId }, + { $set: { 'ePlace.$.equip': equipId } }, + { new: true }).populate('ePlace.equip').lean(lean); if (hero) { - await Equip.putOnOrOff( equipId, hero.hid ); + await Equip.putOnOrOff(equipId, hero.hid); } return hero; } public static async removeEquip(roleId: string, hid: number, ePlaceId: number, equipId: string, lean = true) { const hero: HeroType = await HeroModel.findOneAndUpdate( - { roleId, hid, 'ePlace.id': ePlaceId }, - {$set: {'ePlace.$.equip': null}}, - {new: true}).populate('ePlace.equip').lean(lean); + { roleId, hid, 'ePlace.id': ePlaceId }, + { $set: { 'ePlace.$.equip': null } }, + { new: true }).populate('ePlace.equip').lean(lean); if (hero) { - await Equip.putOnOrOff( equipId, 0 ); + await Equip.putOnOrOff(equipId, 0); } return hero; } public static async createHero(heroInfo: HeroUpdate, lean = true) { const doc = new HeroModel(); - const seqId = await CounterModel.getNewCounter(COUNTER.HID)||-1; - const update = Object.assign(doc.toJSON(), heroInfo, {seqId}); + const seqId = await CounterModel.getNewCounter(COUNTER.HID) || -1; + const update = Object.assign(doc.toJSON(), heroInfo, { seqId }); delete update._id; - const hero: HeroType = await HeroModel.findOneAndUpdate({roleId: heroInfo.roleId, hid: heroInfo.hid}, update, {upsert: true, new: true}).lean(lean); + const hero: HeroType = await HeroModel.findOneAndUpdate({ roleId: heroInfo.roleId, hid: heroInfo.hid }, update, { upsert: true, new: true }).lean(lean); return hero; } public static async sumTopHeroCe(roleId: string, num: number) { - let ce: Array<{historyCe: number}> = await HeroModel.aggregate([ - { $match : { roleId } }, - { $sort: {historyCe: -1} }, - { $limit: num }, - { $group: { _id: null, historyCe: { $sum: '$historyCe' } } } + let ce: Array<{ historyCe: number }> = await HeroModel.aggregate([ + { $match: { roleId } }, + { $sort: { historyCe: -1 } }, + { $limit: num }, + { $group: { _id: null, historyCe: { $sum: '$historyCe' } } } ]); - return ce.length > 0?ce[0].historyCe:0; + return ce.length > 0 ? ce[0].historyCe : 0; } public static async sumHeroCe(roleId: string) { - let ce: Array<{ce: number}> = await HeroModel.aggregate([ - { $match : { roleId } }, - { $group: { _id: null, ce: { $sum: '$ce' } } } + let ce: Array<{ ce: number }> = await HeroModel.aggregate([ + { $match: { roleId } }, + { $group: { _id: null, ce: { $sum: '$ce' } } } ]); - return ce.length > 0?ce[0].ce:0; + return ce.length > 0 ? ce[0].ce : 0; } public static async getTopHero(roleId: string, num: number, lean = true) { - const heroes: HeroType[] = await HeroModel.find({roleId}).limit(num).sort({ce: -1}).lean(lean); + const heroes: HeroType[] = await HeroModel.find({ roleId }).limit(num).sort({ ce: -1 }).lean(lean); return heroes; } public static async updateCe(roleId: string, hid: number, ce: number, oldCe: number, historyCe: number, lean = true) { let distance = ce - oldCe; - let historyDistance = ce > historyCe ?ce - historyCe: 0; - let result: HeroType = await HeroModel.findOneAndUpdate({roleId, hid}, {$inc:{ce: distance, historyCe: historyDistance}}).lean(lean); + let historyDistance = ce > historyCe ? ce - historyCe : 0; + let result: HeroType = await HeroModel.findOneAndUpdate({ roleId, hid }, { $inc: { ce: distance, historyCe: historyDistance } }).lean(lean); return result; } public static async deleteAccount(roleId: string) { - let result = await HeroModel.deleteMany({roleId}); + let result = await HeroModel.deleteMany({ roleId }); return result; } public static async deleteHero(roleId: string, hid: number) { - let result = await HeroModel.deleteMany({roleId, hid}); + let result = await HeroModel.deleteMany({ roleId, hid }); return result; } - public static async updateHeroInfo(roleId: string, hid:number, heroUpdate:HeroUpdate, select?: string, getters = false) { + public static async updateHeroInfo(roleId: string, hid: number, heroUpdate: HeroUpdate, select?: string, getters = false) { delete heroUpdate._id; - let result: HeroType = await HeroModel.findOneAndUpdate({roleId, hid}, {$set:heroUpdate}, {new: true}).select(select).lean({ getters }); + let result: HeroType = await HeroModel.findOneAndUpdate({ roleId, hid }, { $set: heroUpdate }, { new: true }).select(select).lean({ getters }); return result; } - + public static async unloadHeroAndEquip(roleId: string, hid: number, id: number, lean = true) { const hero: HeroType = await HeroModel.findOneAndUpdate( - { roleId, hid, 'ePlace.id': id }, - {$set: {'ePlace.$.equip': null}}, - {new: true}).lean(lean); + { roleId, hid, 'ePlace.id': id }, + { $set: { 'ePlace.$.equip': null } }, + { new: true }).lean(lean); return hero; } - public static async findByField(field: string, value?: number|string, lean = true) { + public static async findByField(field: string, value?: number | string, lean = true) { let searchObj = {}; - if(field != 'all') { - if(field == 'roleName') { + if (field != 'all') { + if (field == 'roleName') { searchObj['roleName'] = { $regex: new RegExp(value.toString(), 'i') } } else { searchObj[field] = value; @@ -279,22 +279,22 @@ export default class Hero extends BaseModel { } public static async getAllRank(serverId: number, select?: string, limit = 200) { - let result: HeroType[] = await HeroModel.find({serverId}, { _id: false} ).select(select).limit(limit).sort({ ce: -1, updatedAt: 1 }).lean({ getters: true }); + let result: HeroType[] = await HeroModel.find({ serverId }, { _id: false }).select(select).limit(limit).sort({ ce: -1, updatedAt: 1 }).lean({ getters: true }); return result; } public static async getMyTopHero(roleId: string, select?: string) { - let result: HeroType = await HeroModel.findOne({ roleId }, { _id: false} ).select(select).sort({ ce: -1, updatedAt: 1 }).lean({ getters: true }); + let result: HeroType = await HeroModel.findOne({ roleId }, { _id: false }).select(select).sort({ ce: -1, updatedAt: 1 }).lean({ getters: true }); return result; } public static async getRank(hid: number, serverId: number, select?: string, limit = 200) { - let result: HeroType[] = await HeroModel.find({serverId, hid}, { _id: false} ).select(select).limit(limit).lean({ getters: true }); + let result: HeroType[] = await HeroModel.find({ serverId, hid }, { _id: false }).select(select).limit(limit).lean({ getters: true }); return result; } } export const HeroModel = getModelForClass(Hero); - -export interface HeroType extends Pick, keyof Hero>{}; + +export interface HeroType extends Pick, keyof Hero> { }; export type HeroUpdate = Partial; // 将所有字段变成可选项 diff --git a/shared/pubUtils/taskUtil.ts b/shared/pubUtils/taskUtil.ts index 28eba4097..78ce50786 100644 --- a/shared/pubUtils/taskUtil.ts +++ b/shared/pubUtils/taskUtil.ts @@ -517,21 +517,24 @@ export async function accomplishTask(roleId: string, taskType: TASK_TYPE, count: } //30天任务统计 - allActivity = await ActivityModel.findOpenActivityByType(ACTIVITY_TYPE.THIRTY_DAYS, new Date()); - for (let activity of allActivity) { - let thirtyDaysActivity = new ThirtyDaysData(activity); - let taskArray = thirtyDaysActivity.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 ActivityThirtyDaysModel.setTaskCount(thirtyDaysActivity.activityId, roleId, task.pageIndex, task.cellIndex, task.taskType, addCount); - } else { + if (taskType === TASK_TYPE.HERO_QUALITY_STAR_UP || + taskType === TASK_TYPE.HERO_QUALITY_TO_QUALITY_COUNT || + taskType === TASK_TYPE.HERO_WAKE_UP_COUNT || + taskType === TASK_TYPE.HERO_WAKE_UP_STAR_UP_COUNT) { + allActivity = await ActivityModel.findOpenActivityByType(ACTIVITY_TYPE.THIRTY_DAYS, new Date()); + for (let activity of allActivity) { + let thirtyDaysActivity = new ThirtyDaysData(activity); + let taskArray = thirtyDaysActivity.findTaskByType(taskType); + for (let task of taskArray) { + let addCount = isComplete(roleId, task.taskType, task.taskParam, count, parma); + if (addCount) { await ActivityThirtyDaysModel.addTaskCount(thirtyDaysActivity.activityId, roleId, task.pageIndex, task.cellIndex, task.taskType, addCount); } } } } + + } /** @@ -562,9 +565,21 @@ export function isComplete(roleId: string, taskType: TASK_TYPE, taskParam: strin case TASK_TYPE.HERO_NUM: addCount = count; break; + case TASK_TYPE.HERO_QUALITY_STAR_UP://herocount&quality&star& addCount = (param[1] == paramObj.quality) && (param[2] == paramObj.star) ? count : 0; break; + case TASK_TYPE.HERO_QUALITY_TO_QUALITY_COUNT://herocount&quality&star& {oldQuality, quality: hero.quality} + addCount = (param[1] == paramObj.oldQuality) && (param[2] == paramObj.quality) ? count : 0; + break; + case TASK_TYPE.HERO_WAKE_UP_COUNT://herocount&quality + addCount = (param[1] == paramObj.quality) ? count : 0; + break; + case TASK_TYPE.HERO_WAKE_UP_STAR_UP_COUNT://herocount&star& + addCount = (param[1] == paramObj.star) ? count : 0; + break; + + case TASK_TYPE.ROLE_TITLE://重置数据 addCount = param[0] <= count ? count : 0; break; diff --git a/shared/resource/jsons/dic_zyz_taskType.json b/shared/resource/jsons/dic_zyz_taskType.json index ea9c7e11f..e79d4377a 100644 --- a/shared/resource/jsons/dic_zyz_taskType.json +++ b/shared/resource/jsons/dic_zyz_taskType.json @@ -1093,5 +1093,50 @@ "__EMPTY_3": 0, "__EMPTY_4": 0, "__EMPTY_5": 0 + }, + { + "id": 74, + "name": "武将", + "info": "x名x品质武将升至X品质", + "param": "herocount&quality&quality", + "string": "武将数量&武将初始品质&武将升级后品质", + "content": 0, + "condition": "herocount", + "__EMPTY": 0, + "__EMPTY_1": 0, + "__EMPTY_2": 0, + "__EMPTY_3": 0, + "__EMPTY_4": 0, + "__EMPTY_5": 0 + }, + { + "id": 75, + "name": "武将", + "info": "x名x品质武将觉醒", + "param": "herocount&quality", + "string": "武将数量&武将初始品质", + "content": 0, + "condition": "herocount", + "__EMPTY": 0, + "__EMPTY_1": 0, + "__EMPTY_2": 0, + "__EMPTY_3": 0, + "__EMPTY_4": 0, + "__EMPTY_5": 0 + }, + { + "id": 76, + "name": "武将", + "info": "x名武将觉醒后升至x星", + "param": "herocount&star", + "string": "武将数量&星级", + "content": 0, + "condition": "herocount", + "__EMPTY": 0, + "__EMPTY_1": 0, + "__EMPTY_2": 0, + "__EMPTY_3": 0, + "__EMPTY_4": 0, + "__EMPTY_5": 0 } ] \ No newline at end of file