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

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
+13 -11
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 };
}