活动:统计套装宝石相同阶数的任务

This commit is contained in:
qiaoxin
2021-05-08 15:19:08 +08:00
parent 96804c4055
commit 43bca3a5b7
8 changed files with 157 additions and 55 deletions

View File

@@ -4,7 +4,7 @@ import { ItemInter } from "../../../pubUtils/interface";
import { resResult, parseGoodStr, getRandValueByMinMax, getRandEelm } from "../../../pubUtils/util";
import { addItems, handleCost, decreaseItems } from "../../../services/rewardService";
import { EquipModel, EquipType } from "../../../db/Equip";
import Equip, { EquipModel, EquipType } from "../../../db/Equip";
import { HeroModel, EPlace } from "../../../db/Hero";
import Role from "../../../db/Role";
import { calPlayerCeAndSave } from "../../../services/playerCeService";
@@ -15,7 +15,7 @@ import { changeEquip, dressEquip, checkMaterialEnough, takeOffEquipAndCalPlayerC
import { indexOf, findIndex } from 'underscore';
import { pushEquipRefineSucMsg, pushNormalEquipMsg, pushNormalItemMsg } from "../../../services/chatService";
import { checkTaskWithHero, checkTaskWithEquip, checkTask, checkTaskWithArgs } from "../../../services/taskService";
import { checkTaskWithHero, checkTaskWithEquip, checkTask, checkTaskWithArgs, checkTaskConditionEquipSuitJewelStage } from "../../../services/taskService";
import { accomplishTask } from "../../../pubUtils/taskUtil";
export default function (app: Application) {
@@ -509,12 +509,20 @@ export class EquipHandler {
curEquip = await dressEquip(roleId, sid, hero, equip, funcs);
if (!!curEquip)
curEquips.push(curEquip);
//任务
//英雄满装备且都镶嵌相同阶数的宝石
let { isTask, jewelLevel } = await checkTaskConditionEquipSuitJewelStage(hero)
if (isTask) {
await accomplishTask(roleId, TASK_TYPE.EQUIP_SUIT_JEWEL_STAGE, 1, { stage: jewelLevel })
}
} else if (type == 2) {
if (!equip.hid)
return resResult(STATUS.EQUIP_NOT_EQUIPED);
let curEquip = await takeOffEquipAndCalPlayerCe(roleId, sid, hero, equip, id, funcs);
curEquips.push(curEquip);
}
return resResult(STATUS.SUCCESS, { curEquips: curEquips });
}
@@ -581,6 +589,12 @@ export class EquipHandler {
if (!!equip.hid) {
let hero = await HeroModel.findByHidAndRole(equip.hid, roleId);
await calPlayerCeAndSave(HERO_SYSTEM_TYPE.JEWEL_ON, sid, roleId, hero, {}, [jewel, oldJewel]);
//任务
//英雄满装备且都镶嵌相同阶数的宝石
let { isTask, jewelLevel } = await checkTaskConditionEquipSuitJewelStage(hero)
if (isTask) {
await accomplishTask(roleId, TASK_TYPE.EQUIP_SUIT_JEWEL_STAGE, 1, { stage: jewelLevel })
}
}
// 任务
@@ -589,6 +603,7 @@ export class EquipHandler {
await checkTaskWithEquip(roleId, sid, funcs, TASK_TYPE.EQUIP_JEWEL_SUM, equip, [oldJewelCount]);
//成长任务
await accomplishTask(roleId, TASK_TYPE.EQUIP_JEWEL_SUM, 1)
await accomplishTask(roleId, TASK_TYPE.EQUIP_JEWEL_STAGE, 1)
return resResult(STATUS.SUCCESS, { curEquip: { seqId: eid, holes: equip.holes } });
}
@@ -753,6 +768,13 @@ export class EquipHandler {
if (!!equip.hid) {
let hero = await HeroModel.findByHidAndRole(equip.hid, roleId);
await calPlayerCeAndSave(HERO_SYSTEM_TYPE.JEWEL_ON, sid, roleId, hero, {}, [jewel, oldJewel]);
//任务
//英雄满装备且都镶嵌相同阶数的宝石
let { isTask, jewelLevel } = await checkTaskConditionEquipSuitJewelStage(hero)
if (isTask) {
await accomplishTask(roleId, TASK_TYPE.EQUIP_SUIT_JEWEL_STAGE, 1, { stage: jewelLevel })
}
}
// 任务
@@ -760,7 +782,7 @@ export class EquipHandler {
await checkTaskWithArgs(roleId, sid, funcs, TASK_TYPE.EQUIP_JEWEL_STAGE, [jewel, oldJewel]);
await checkTaskWithEquip(roleId, sid, funcs, TASK_TYPE.EQUIP_JEWEL_SUM, equip, [oldJewelCount]);
//成长任务
await accomplishTask(roleId, TASK_TYPE.EQUIP_JEWEL_SUM, 1)
await accomplishTask(roleId, TASK_TYPE.EQUIP_JEWEL_SUM, count)
return resResult(STATUS.SUCCESS, { curEquip: { seqId: eid, holes: equip.holes } });
} else {

View File

@@ -8,22 +8,23 @@ import { EquipType } from "../db/Equip";
import { calEquipSeids } from '../pubUtils/playerCe';
import { indexOf, findIndex } from 'underscore';
import { checkTask, checkTaskWithHero, checkTaskWithEquip } from './taskService';
import { accomplishTask } from '../pubUtils/taskUtil';
/**
* 校验前端传入的消耗数量是否准确并返回消耗的道具并加上特殊材料needConsumes
* @param consumes
* @param jewel
* @param jewelCount
*/
export function checkMaterialEnough(consumes:Array<{id: number, count: number}>, jewel: number, jewelCount: number) {
export function checkMaterialEnough(consumes: Array<{ id: number, count: number }>, jewel: number, jewelCount: number) {
let comJewelMap = {};
consumes = mergeSameGoods(consumes);
let needConsumes: Array<{id: number, count: number}> = [];
let needConsumes: Array<{ id: number, count: number }> = [];
let gidJewelInfo = getGoodById(jewel);//目标宝石信息
for (let { id, count } of consumes) {
let jewelInfo = getJewelById(id);
if (!jewelInfo || !jewelInfo.count) //筛选出特殊材料特殊材料没有合成下一级需要的count数量
continue;
needConsumes.push({ id, count});//将该宝石加入消耗中
needConsumes.push({ id, count });//将该宝石加入消耗中
comJewelMap[id] = count + (comJewelMap[id] || 0);
for (let i = jewelInfo.lvLimited; i < gidJewelInfo.lvLimited; i++) {//当前消耗的宝石升级到目标宝石的消耗
if (((comJewelMap[id] || 0) % jewelInfo.count != 0)) {//jewelInfo的count表示宝石id合成下一级需要的数量
@@ -32,11 +33,11 @@ export function checkMaterialEnough(consumes:Array<{id: number, count: number}>,
let comcount = Math.floor(((comJewelMap[id] || 0)) / jewelInfo.count);
if (comcount < 1) {
break;//不能合成,跳出循环,等待下次合成
}
}
comJewelMap[jewelInfo.nextJewelId] = comcount + (comJewelMap[jewelInfo.nextJewelId] || 0);//jewelInfo的nextJewelId表示宝石id合成下一级的宝石good_id
delete comJewelMap[id];
if (!!jewelInfo.specialCount)
needConsumes.push({ count: jewelInfo.specialCount * comcount, id: jewelInfo.nextSpecialId});//消耗中曾加合成下一级需要的特殊消耗物品的数量
needConsumes.push({ count: jewelInfo.specialCount * comcount, id: jewelInfo.nextSpecialId });//消耗中曾加合成下一级需要的特殊消耗物品的数量
jewelInfo = getJewelById(jewelInfo.nextJewelId);
}
}
@@ -93,21 +94,21 @@ export async function changeEquip(roleId: string, sid: string, equipA: EquipType
* @param hero
* @param id
*/
export async function takeOffEquipAndCalPlayerCe(roleId: string, sid: string, hero:HeroType, equip: EquipType, id: number, funcs: number[] ) {
export async function takeOffEquipAndCalPlayerCe(roleId: string, sid: string, hero: HeroType, equip: EquipType, id: number, funcs: number[]) {
console.log(roleId, sid, hero, equip, id)
if(hero) {
if (hero) {
let args = calEquipSeids(hero);
hero = await HeroModel.removeEquip(roleId, hero.hid, id, equip._id);
await calPlayerCeAndSave(HERO_SYSTEM_TYPE.EQUIP, sid, roleId, hero, {}, args);
await checkTaskWithHero(roleId, sid, funcs, TASK_TYPE.EQUIP_BY_HERO, hero, [-1]);
} else {
await EquipModel.putOnOrOff( equip._id, 0 );
await EquipModel.putOnOrOff(equip._id, 0);
}
// 任务
await checkTask(roleId, sid, funcs, TASK_TYPE.EQUIP_SUM, -1, true, {});
await checkTaskWithEquip(roleId, sid, funcs, TASK_TYPE.EQUIP_QUALITY, equip, [-1]);
return { seqId: equip.seqId, hid: 0};
return { seqId: equip.seqId, hid: 0 };
}
/**
* 穿戴装备并重算战力
@@ -116,7 +117,7 @@ export async function takeOffEquipAndCalPlayerCe(roleId: string, sid: string, he
* @param hero
* @param equip
*/
export async function dressEquip(roleId: string, sid: string, hero:HeroType, equip: EquipType, funcs: number[]) {
export async function dressEquip(roleId: string, sid: string, hero: HeroType, equip: EquipType, funcs: number[]) {
let args = calEquipSeids(hero);
hero = await HeroModel.addEquip(roleId, hero.hid, equip.ePlaceId, equip._id);
@@ -126,6 +127,7 @@ export async function dressEquip(roleId: string, sid: string, hero:HeroType, equ
await checkTask(roleId, sid, funcs, TASK_TYPE.EQUIP_SUM, 1, true, {});
await checkTaskWithHero(roleId, sid, funcs, TASK_TYPE.EQUIP_BY_HERO, hero, [1]);
await checkTaskWithEquip(roleId, sid, funcs, TASK_TYPE.EQUIP_QUALITY, equip, [1]);
await accomplishTask(roleId, TASK_TYPE.EQUIP_QUALITY, 1, { quality: equip.quality })
return { seqId: equip.seqId, hid: hero.hid };
}

View File

@@ -12,7 +12,7 @@ import { ItemInter } from '../pubUtils/interface';
import { UserTaskModel, UserTaskType } from '../db/UserTask';
import { UserTaskRecModel } from '../db/UserTaskRec';
import { UserTaskHistoryModel } from '../db/UserTaskHistory';
import { gameData } from '../pubUtils/data';
import { gameData, getGoodById } from '../pubUtils/data';
import { getCurWeekDate, getSeconds } from '../pubUtils/timeUtil';
import { RoleStatus } from '../db/ComBattleTeam';
@@ -95,7 +95,7 @@ export async function checkTaskInBattleEnd(roleId: string, sid: string, funcs: n
export async function checkTaskInComBattleEnd(roleStatus: RoleStatus[], capId: string, quality: number) {
console.log('********', JSON.stringify(roleStatus), capId, quality)
for (let { roleId, isRobot } of roleStatus) {
if(!isRobot) {
if (!isRobot) {
if (roleId == capId && roleStatus.length > 1) { // 招募队友
await checkTask(roleId, null, null, TASK_TYPE.COM_BATTLE_CREATE_TEAM, 1, true, {});
} else if (roleId !== capId) { // 协助寻宝
@@ -239,4 +239,33 @@ export async function refDailyTaskBox(roleId: string, sid: string, debug = false
point, weeklyPoint, box
}), uids);
}
}
//任务条件
//英雄满装备且都镶嵌相同阶数的宝石
export async function checkTaskConditionEquipSuitJewelStage(hero: HeroType) {
let isTask = true;//是否满足任务条件
let jewelLevel = -1;//宝石阶数
for (let i = 0; i < hero.ePlace.length; i++) {
let equipObj = <EquipType>hero.ePlace[i].equip;
let equipObjInfo = getGoodById(equipObj.id);
if (equipObj.holes.length == equipObjInfo.hole && equipObjInfo.hole > 0) {
for (let j = 0; j < equipObj.holes.length; j++) {
let jewel = equipObj.holes[j].jewel;
let jewelInfo = getGoodById(jewel);
if (jewelLevel == -1) {
jewelLevel = jewelInfo.lvLimited;
} else if (jewelInfo.lvLimited != jewelLevel) {
//宝石阶数不同
isTask = false;
break;
}
}
} else {
//宝石没有镶满
isTask = false;
break;
}
}
return { isTask, jewelLevel };
}

View File

@@ -653,6 +653,7 @@ export enum TASK_TYPE {
HERO_WAKE_UP_COUNT = 75, // *名武将*品觉醒
HERO_WAKE_UP_STAR_UP_COUNT = 76, // *名武将升至觉醒*星
EQUIP_REFINE_LV = 77, // *件装备成功精炼到*级
EQUIP_SUIT_JEWEL_STAGE = 78, // *次触发,一个武将满装备情况下,必须都镶嵌有相同阶的宝石(阶数大于等于x情况下都算达成)
}
// 卡池类型

View File

@@ -25,13 +25,13 @@ export class Holes {
}
interface equipUpdate {
hid?: number;
quality?: number;
wearLv?: number;
_id?:number;
holes?:Array<Holes>;
hid?: number;
quality?: number;
wearLv?: number;
_id?: number;
holes?: Array<Holes>;
randSe?: Array<RandSe>;
ePlaceId?:number;
ePlaceId?: number;
}
@index({ roleId: 1, hid: 1, id: 1 })
@@ -50,7 +50,7 @@ export default class Equip extends BaseModel {
id: number; // 装备 id
@prop({ required: true })
name: string; // 装备名称
@prop({ required: false, default: 0 })
@prop({ required: false, default: 0 })
hid: number; // 装备此装备的武将 id
@prop({ required: false, default: 0 })
ePlaceId: number; // 武将装备的部位
@@ -75,24 +75,24 @@ export default class Equip extends BaseModel {
}
public static async findbySeqId(seqId: number, lean = true) {
const equip: EquipType = await EquipModel.findOne({ seqId }).lean(lean);
return equip;
const equip: EquipType = await EquipModel.findOne({ seqId }).lean(lean);
return equip;
}
public static async createEquip(equipInfo: {roleId: string, roleName: string, id: number, name: string, quality: number, suitId: number, ePlaceId: number, randSe: RandSe[], randRange: number, holes: Holes[], hid?: number}, lean = true) {
const seqId = await CounterModel.getNewCounter(COUNTER.EID);
const doc = new EquipModel();
const update = Object.assign(doc.toJSON(), seqId, equipInfo);
const equip: EquipType = await EquipModel.findOneAndUpdate({ seqId }, update, {upsert: true, new: true}).lean(lean);
if(equipInfo.hid > 0) {
await HeroModel.findOneAndUpdate(
{ roleId: equipInfo.roleId, hid: equipInfo.hid, 'ePlace.id': equipInfo.ePlaceId },
{$set: {'ePlace.$.equip': equip._id}},
{new: true}).lean(lean);
public static async createEquip(equipInfo: { roleId: string, roleName: string, id: number, name: string, quality: number, suitId: number, ePlaceId: number, randSe: RandSe[], randRange: number, holes: Holes[], hid?: number }, lean = true) {
const seqId = await CounterModel.getNewCounter(COUNTER.EID);
const doc = new EquipModel();
const update = Object.assign(doc.toJSON(), seqId, equipInfo);
const equip: EquipType = await EquipModel.findOneAndUpdate({ seqId }, update, { upsert: true, new: true }).lean(lean);
if (equipInfo.hid > 0) {
await HeroModel.findOneAndUpdate(
{ roleId: equipInfo.roleId, hid: equipInfo.hid, 'ePlace.id': equipInfo.ePlaceId },
{ $set: { 'ePlace.$.equip': equip._id } },
{ new: true }).lean(lean);
}
return equip;
}
return equip;
}
public static async putOnOrOff(equipId: string, hid: number, lean = true) {
const equip: EquipType = await EquipModel.findOneAndUpdate({ _id: equipId }, { hid }, { new: true }).lean(lean);
@@ -108,6 +108,11 @@ export default class Equip extends BaseModel {
return result;
}
public static async getEquipsByID(ids: Array<string>) {
let result = await EquipModel.find({ _id: { $in: ids } });
return result;
}
public static async getEquips(ids: Array<number>) {
let result = await EquipModel.find({ seqId: { $in: ids } });
return result;
@@ -118,20 +123,20 @@ export default class Equip extends BaseModel {
return equip;
}
public static async updateEquipInfo(seqId:number, equipUpdate: equipUpdate, lean = true) {
public static async updateEquipInfo(seqId: number, equipUpdate: equipUpdate, lean = true) {
delete equipUpdate._id;
let result: EquipType = await EquipModel.findOneAndUpdate({seqId}, {$set: equipUpdate}, {new: true}).lean(lean);
let result: EquipType = await EquipModel.findOneAndUpdate({ seqId }, { $set: equipUpdate }, { new: true }).lean(lean);
return result;
}
public static async lock(roleId: string, seqId: number, id: number, lock: boolean) {
let result: EquipType = await EquipModel.findOneAndUpdate({roleId, seqId, 'randSe.id': id}, {$set: {'randSe.$.locked': lock}}, {new: true, upsert: false}).select('seqId id randSe').lean();
return result;
let result: EquipType = await EquipModel.findOneAndUpdate({ roleId, seqId, 'randSe.id': id }, { $set: { 'randSe.$.locked': lock } }, { new: true, upsert: false }).select('seqId id randSe').lean();
return result;
}
public static async updateEquipInfobyObjectId(_id: string, equipUpdate: equipUpdate, lean = true) {
delete equipUpdate._id;
let result: EquipType = await EquipModel.findOneAndUpdate({_id}, {$set: equipUpdate}, {new: true}).lean(lean);
let result: EquipType = await EquipModel.findOneAndUpdate({ _id }, { $set: equipUpdate }, { new: true }).lean(lean);
return result;
}
@@ -141,10 +146,10 @@ export default class Equip extends BaseModel {
}
public static async findByField(field: string, value?: number|string, select?: string) {
public static async findByField(field: string, value?: number | string, select?: string) {
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;

View File

@@ -132,6 +132,20 @@ export class ThirtyDaysData extends ActivityBase {
totalPoint: number = 0;//总共点数
consumePoint: number = 0;//消耗掉的点数
//未完成的任务
public findUncompleteTaskByType(type: number) {
let task = [];
for (let i = 0; i < this.list.length; i++) {
let items = this.list[i].item;
for (let itemData of items) {
if (itemData.taskType == type && !itemData.isComplete) {
task.push(itemData);
}
}
}
return task;
}
public findTaskByType(type: number) {
let task = [];
for (let i = 0; i < this.list.length; i++) {

View File

@@ -16,7 +16,7 @@ import { ACTIVITY_TYPE } from '../consts/constModules/activityConst';
import { ActivityGrowthModel } from '../db/ActivityGrowth';
import { ActivityDailyChallengesModel } from '../db/ActivityDailyChallenges';
import { ThirtyDaysData } from '../domain/activityField/thirtyDaysField';
import { ActivityThirtyDaysModel } from '../db/ActivityThirtyDays';
import { ActivityThirtyDaysModel, ActivityThirtyDaysModelType } from '../db/ActivityThirtyDays';
@@ -524,13 +524,19 @@ export async function accomplishTask(roleId: string, taskType: TASK_TYPE, count:
taskType === TASK_TYPE.EQUIP_STRENGTHEN ||
taskType === TASK_TYPE.EQUIP_REFINE_LV ||
taskType === TASK_TYPE.HERO_STAGE_UP
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 ActivityModel.findOpenActivityByType(ACTIVITY_TYPE.THIRTY_DAYS, new Date());
for (let activity of allActivity) {
let thirtyDaysActivity = new ThirtyDaysData(activity);
let taskArray = thirtyDaysActivity.findTaskByType(taskType);
let playerRecords: ActivityThirtyDaysModelType[] = await ActivityThirtyDaysModel.findData(activity.acvitityId, roleId);
thirtyDaysActivity.setPlayerRecords(playerRecords);
let taskArray = thirtyDaysActivity.findUncompleteTaskByType(taskType);
for (let task of taskArray) {
let addCount = isComplete(roleId, task.taskType, task.taskParam, count, parma);
if (addCount) {
@@ -587,7 +593,15 @@ export function isComplete(roleId: string, taskType: TASK_TYPE, taskParam: strin
case TASK_TYPE.HERO_STAGE_UP://herocount&star&
addCount = (param[1] == paramObj.job) ? 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;

View File

@@ -1083,7 +1083,7 @@
"id": 73,
"name": "精英任务",
"info": "精英通关第x关",
"param": "warid",
"param": "warid&",
"string": "关卡id",
"content": 0,
"condition": "warid",
@@ -1098,7 +1098,7 @@
"id": 74,
"name": "武将",
"info": "x名x品质武将升至X品质",
"param": "herocount&quality&quality",
"param": "herocount&quality&quality&",
"string": "武将数量&武将初始品质&武将升级后品质",
"content": 0,
"condition": "herocount",
@@ -1113,7 +1113,7 @@
"id": 75,
"name": "武将",
"info": "x名x品质武将觉醒",
"param": "herocount&quality",
"param": "herocount&quality&",
"string": "武将数量&武将初始品质",
"content": 0,
"condition": "herocount",
@@ -1128,7 +1128,7 @@
"id": 76,
"name": "武将",
"info": "x名武将觉醒后升至x星",
"param": "herocount&star",
"param": "herocount&star&",
"string": "武将数量&星级",
"content": 0,
"condition": "herocount",
@@ -1143,7 +1143,7 @@
"id": 77,
"name": "装备",
"info": "x件装备成功精炼到x级",
"param": "count&lv",
"param": "count&lv&",
"string": "装备件数&精炼等级",
"content": 0,
"condition": "count",
@@ -1153,5 +1153,20 @@
"__EMPTY_3": 0,
"__EMPTY_4": 0,
"__EMPTY_5": 0
},
{
"id": 78,
"name": "装备",
"info": "一个武将满装备情况下,必须都镶嵌有相同阶的宝石(阶数大于等于x情况下都算达成),触发x次数",
"param": "count&stage&",
"string": "发生次数&宝石阶数&",
"content": 0,
"condition": "count",
"__EMPTY": 0,
"__EMPTY_1": 0,
"__EMPTY_2": 0,
"__EMPTY_3": 0,
"__EMPTY_4": 0,
"__EMPTY_5": 0
}
]