活动:成长活动统计任务,领取奖励接口
This commit is contained in:
@@ -2,7 +2,7 @@ import { Application, BackendSession } from "pinus";
|
||||
import { STATUS, EQUIP_STRENGTHEN_TYPE, CURRENCY_BY_TYPE, CURRENCY_TYPE, HERO_SYSTEM_TYPE, CONSUME_TYPE, HERO_GROW_MAX, MSG_SOURCE, JEWEL_PUSH_LV, TASK_TYPE } from "../../../consts";
|
||||
import { ItemInter } from "../../../pubUtils/interface";
|
||||
|
||||
import { resResult, parseGoodStr, getRandValueByMinMax, getRandEelm } from "../../../pubUtils/util";
|
||||
import { resResult, parseGoodStr, getRandValueByMinMax, getRandEelm } from "../../../pubUtils/util";
|
||||
import { addItems, handleCost, decreaseItems } from "../../../services/rewardService";
|
||||
import { EquipModel, EquipType } from "../../../db/Equip";
|
||||
import { HeroModel, EPlace } from "../../../db/Hero";
|
||||
@@ -16,6 +16,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 { accomplishTask } from "../../../pubUtils/taskUtil";
|
||||
|
||||
export default function (app: Application) {
|
||||
return new EquipHandler(app);
|
||||
@@ -98,6 +99,8 @@ export class EquipHandler {
|
||||
let hero = await HeroModel.findByHidAndRoleWithEquip(hid, roleId);
|
||||
if (!hero) return resResult(STATUS.HERO_NOT_FIND);
|
||||
|
||||
|
||||
let changeData = [];//变化的等级数据
|
||||
let { ePlace, lv: playerLv } = hero; // 装备栏
|
||||
let oldLvs = ePlace.map(cur => cur.lv);
|
||||
let strengthenArr = new Array<EPlace>();
|
||||
@@ -110,7 +113,13 @@ export class EquipHandler {
|
||||
return resResult(STATUS.ROLE_EQUIP_PLACE_NOT_ENOUGH);
|
||||
}
|
||||
let minLv = strengthenArr[0].lv; // 从最低装备的等级开始
|
||||
for (let { lv } of strengthenArr) {
|
||||
for (let { lv, id } of strengthenArr) {
|
||||
changeData.push({
|
||||
hid: hid,
|
||||
id: id,
|
||||
oldLv: lv,
|
||||
lv: lv,
|
||||
})
|
||||
if (lv < minLv) minLv = lv;
|
||||
}
|
||||
|
||||
@@ -129,8 +138,13 @@ export class EquipHandler {
|
||||
if (!cost) { flag = true; break; }
|
||||
if (coin < costCoin + cost) { flag = true; break; }
|
||||
costCoin += cost;
|
||||
|
||||
s.lv++;
|
||||
{//记录等级变化
|
||||
let index = changeData.findIndex(obj => { return obj && obj.id == s.id })
|
||||
if (index != -1) {
|
||||
changeData[index].lv = s.lv;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (flag) break;
|
||||
@@ -152,8 +166,10 @@ export class EquipHandler {
|
||||
|
||||
// 任务
|
||||
await checkTaskWithHero(roleId, sid, funcs, TASK_TYPE.EQUIP_STRENGTHEN, hero, oldLvs);
|
||||
//成长任务
|
||||
await accomplishTask(roleId, TASK_TYPE.EQUIP_STRENGTHEN, 1, changeData)
|
||||
|
||||
const curHero = {
|
||||
const curHero = {
|
||||
hid,
|
||||
ePlace: strengthenArr
|
||||
}
|
||||
@@ -168,6 +184,7 @@ export class EquipHandler {
|
||||
let sid: string = session.get('sid');
|
||||
let funcs: number[] = session.get('funcs');
|
||||
|
||||
let changeData = [];//变化的等级数据
|
||||
let { hid, lv: maxLv } = msg; // lv: 升到哪一级
|
||||
let hero = await HeroModel.findByHidAndRoleWithEquip(hid, roleId);
|
||||
if (!hero) return resResult(STATUS.HERO_NOT_FIND);
|
||||
@@ -175,13 +192,20 @@ export class EquipHandler {
|
||||
let { ePlace, lv: playerLv } = hero; // 装备栏
|
||||
let oldLvs = ePlace.map(cur => cur.lv);
|
||||
let strengthenArr = ePlace.filter(cur => cur.equip);
|
||||
|
||||
|
||||
if (strengthenArr.length <= 0) {
|
||||
return resResult(STATUS.ROLE_EQUIP_PLACE_NOT_ENOUGH);
|
||||
}
|
||||
let minLv = strengthenArr[0].lv; // 从最低装备的等级开始
|
||||
for (let { lv } of strengthenArr) {
|
||||
for (let { lv, id } of strengthenArr) {
|
||||
changeData.push({
|
||||
hid: hid,
|
||||
id: id,
|
||||
oldLv: lv,
|
||||
lv: lv,
|
||||
})
|
||||
if (lv < minLv) minLv = lv;
|
||||
|
||||
}
|
||||
|
||||
let { coin } = await Role.findByRoleId(roleId);
|
||||
@@ -197,11 +221,17 @@ export class EquipHandler {
|
||||
costCoin += cost;
|
||||
|
||||
s.lv++;
|
||||
{//记录等级变化
|
||||
let index = changeData.findIndex(obj => { return obj && obj.id == s.id })
|
||||
if (index != -1) {
|
||||
changeData[index].lv = s.lv;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (costCoin > coin) {
|
||||
if (costCoin > coin) {
|
||||
return resResult(STATUS.ROLE_COIN_NOT_ENOUGH);
|
||||
}
|
||||
|
||||
@@ -217,8 +247,10 @@ export class EquipHandler {
|
||||
|
||||
// 任务
|
||||
await checkTaskWithHero(roleId, sid, funcs, TASK_TYPE.EQUIP_STRENGTHEN, hero, oldLvs);
|
||||
//成长任务
|
||||
await accomplishTask(roleId, TASK_TYPE.EQUIP_STRENGTHEN, 1, changeData)
|
||||
|
||||
const curHero = {
|
||||
const curHero = {
|
||||
hid,
|
||||
ePlace: strengthenArr
|
||||
}
|
||||
@@ -292,7 +324,7 @@ export class EquipHandler {
|
||||
|
||||
if (isSuccess) {
|
||||
let curEquip = <EquipType>equip;
|
||||
pushEquipRefineSucMsg(roleId, roleName, serverId, curEplace, curEquip?curEquip.quality: 0);
|
||||
pushEquipRefineSucMsg(roleId, roleName, serverId, curEplace, curEquip ? curEquip.quality : 0);
|
||||
await checkTask(roleId, sid, funcs, TASK_TYPE.EQUIP_REFINE, 1, true, {});
|
||||
}
|
||||
return resResult(STATUS.SUCCESS, { isSuccess, curHero });
|
||||
@@ -313,7 +345,7 @@ export class EquipHandler {
|
||||
return resResult(STATUS.ROLE_EQUIP_HAVE_NO_RANDSE);
|
||||
}
|
||||
let curSe = randSe.find(cur => cur.id == id);
|
||||
if(!curSe || lock == curSe.locked) {
|
||||
if (!curSe || lock == curSe.locked) {
|
||||
return resResult(STATUS.ROLE_EQUIP_DUPLICATE_LOCK);
|
||||
}
|
||||
|
||||
@@ -352,8 +384,8 @@ export class EquipHandler {
|
||||
let equip = await EquipModel.findbySeqId(eid);
|
||||
if (!equip) return resResult(STATUS.EQUIP_NOT_FIND);
|
||||
|
||||
let {id, randSe, hid, ePlaceId } = equip;
|
||||
if(!randSe || randSe.length <= 0 ) {
|
||||
let { id, randSe, hid, ePlaceId } = equip;
|
||||
if (!randSe || randSe.length <= 0) {
|
||||
return resResult(STATUS.ROLE_EQUIP_HAVE_NO_RANDSE);
|
||||
}
|
||||
|
||||
@@ -366,13 +398,13 @@ export class EquipHandler {
|
||||
|
||||
let lockNum = 0;
|
||||
let removeSeidList = new Array<number>(); // 原装备上的seid [seid, rand, ...]
|
||||
|
||||
for(let i = 0; i < randSe.length; i++) {
|
||||
|
||||
for (let i = 0; i < randSe.length; i++) {
|
||||
removeSeidList.push(randSe[i].seid, randSe[i].rand);
|
||||
|
||||
if(!randSe[i].locked) {
|
||||
if (!randSe[i].locked) {
|
||||
let random = gameData.randomEffectPool.get(randomResult[i]);
|
||||
if (!random) break ;
|
||||
if (!random) break;
|
||||
let rand = 0;
|
||||
if (random.id > 0) rand = getRandValueByMinMax(random.Min, random.Max, 0);
|
||||
randSe[i].seid = random.id;
|
||||
@@ -381,7 +413,7 @@ export class EquipHandler {
|
||||
lockNum++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (lockNum >= randSe.length) {
|
||||
return resResult(STATUS.ROLE_EQUIP_CANNOT_RESTRENGTHEN);
|
||||
}
|
||||
@@ -413,7 +445,7 @@ export class EquipHandler {
|
||||
await calPlayerCeAndSave(HERO_SYSTEM_TYPE.RESTRENGTHEN, sid, roleId, hero, {}, [ePlaceId, ...removeSeidList]);
|
||||
|
||||
await checkTask(roleId, sid, funcs, TASK_TYPE.EQUIP_RESTRENGTHEN, 1, true, {});
|
||||
return resResult(STATUS.SUCCESS,{curEquip});
|
||||
return resResult(STATUS.SUCCESS, { curEquip });
|
||||
|
||||
}
|
||||
|
||||
@@ -433,11 +465,11 @@ export class EquipHandler {
|
||||
let goodInfo = getGoodById(equip.id);
|
||||
if (!goodInfo)
|
||||
return resResult(STATUS.EQUIP_NOT_FIND);
|
||||
goods = goods.concat(goodInfo.decomposeItem);
|
||||
goods = goods.concat(goodInfo.decomposeItem);
|
||||
}
|
||||
let uids = [{ uid: roleId, sid }];
|
||||
await EquipModel.deleteEquips(originalEquip);
|
||||
this.app.get('channelService').pushMessageByUids('onEquipDel', resResult(STATUS.SUCCESS, {equips:originalEquip}), uids);
|
||||
this.app.get('channelService').pushMessageByUids('onEquipDel', resResult(STATUS.SUCCESS, { equips: originalEquip }), uids);
|
||||
let result = await addItems(roleId, roleName, sid, goods);
|
||||
return resResult(STATUS.SUCCESS, { goods: result });
|
||||
}
|
||||
@@ -452,7 +484,7 @@ export class EquipHandler {
|
||||
let goodInfo = getGoodById(equip.id);
|
||||
let obj = ITID.get(goodInfo.itid);
|
||||
let id = obj.type;
|
||||
let curEquips: Array<{ seqId: number, hid: number}> = [];
|
||||
let curEquips: Array<{ seqId: number, hid: number }> = [];
|
||||
let hero = await HeroModel.findByHidAndRoleWithEquip(hid, roleId);
|
||||
if (!hero)
|
||||
return resResult(STATUS.HERO_NOT_FIND);
|
||||
@@ -471,10 +503,10 @@ export class EquipHandler {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let equipOffInfo = <EquipType>hero.ePlace[index].equip;
|
||||
let curEquip = await changeEquip(roleId, sid, equipOffInfo, equip.hid, id, equip, funcs);
|
||||
if (!!curEquip)
|
||||
if (!!curEquip)
|
||||
curEquips.push(curEquip);
|
||||
curEquip = await dressEquip(roleId, sid, hero, equip, funcs);
|
||||
if (!!curEquip)
|
||||
if (!!curEquip)
|
||||
curEquips.push(curEquip);
|
||||
} else if (type == 2) {
|
||||
if (!equip.hid)
|
||||
@@ -524,9 +556,9 @@ export class EquipHandler {
|
||||
let oldJewelCount = equip.holes.filter(cur => cur.jewel > 0).length;
|
||||
|
||||
let { itid } = getGoodById(equip.id);
|
||||
let {equipJewel} = ITID.get(itid);
|
||||
let { equipJewel } = ITID.get(itid);
|
||||
let jewelInfo = getGoodById(jewel);
|
||||
if (jewelInfo.itid != equipJewel)
|
||||
if (jewelInfo.itid != equipJewel)
|
||||
return resResult(STATUS.EQUIP_NOT_MATCH_JEWEL);
|
||||
let index = findIndex(equip.holes, { id });
|
||||
if (index < 0)
|
||||
@@ -535,7 +567,7 @@ export class EquipHandler {
|
||||
return resResult(STATUS.EQUIP_HOLE_IS_NOT_DUG);
|
||||
let oldJewel = equip.holes[index].jewel;
|
||||
if (!!oldJewel)
|
||||
goods.push({id: oldJewel, count:1});
|
||||
goods.push({ id: oldJewel, count: 1 });
|
||||
consumes.push({ id: jewel, count: 1 });
|
||||
let result = await handleCost(roleId, sid, consumes);
|
||||
if (!result)
|
||||
@@ -554,13 +586,15 @@ export class EquipHandler {
|
||||
await checkTaskWithEquip(roleId, sid, funcs, TASK_TYPE.EQUIP_JEWEL, equip, [oldJewelCount]);
|
||||
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)
|
||||
|
||||
return resResult(STATUS.SUCCESS, { curEquip: { seqId: eid, holes: equip.holes } });
|
||||
}
|
||||
|
||||
//宝石合成(一键放入type:1, 合成type:2)
|
||||
public async composeJewel(msg: { jewel: number, count: number, consumes: Array<{ id: number, count: number }>, type: number }, session: BackendSession) {
|
||||
let { count, consumes, jewel, type } = msg;
|
||||
let { count, consumes, jewel, type } = msg;
|
||||
let roleId: string = session.get('roleId');
|
||||
let roleName: string = session.get('roleName');
|
||||
let serverId: number = session.get('serverId');
|
||||
@@ -570,19 +604,19 @@ export class EquipHandler {
|
||||
if (good.type != CONSUME_TYPE.JEWEL)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let needConsumes = checkMaterialEnough(consumes, jewel, count);//检查是否可以合成,并返回最终需要消耗的材料
|
||||
if (!needConsumes)
|
||||
if (!needConsumes)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let res = await handleCost(roleId, sid, needConsumes);
|
||||
if (!res)
|
||||
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
|
||||
let result = await addItems(roleId, roleName, sid, [{ id: jewel, count: count }]);
|
||||
|
||||
|
||||
if (goodInfo.lvLimited >= JEWEL_PUSH_LV) {
|
||||
pushNormalItemMsg(roleId, roleName, serverId, MSG_SOURCE.JEWEL_COMPOSE, jewel, goodInfo.name);
|
||||
}
|
||||
if (type == 1)
|
||||
if (type == 1)
|
||||
return resResult(STATUS.SUCCESS, { goods: result });
|
||||
|
||||
|
||||
return resResult(STATUS.SUCCESS);
|
||||
}
|
||||
|
||||
@@ -619,7 +653,7 @@ export class EquipHandler {
|
||||
}
|
||||
|
||||
//宝石购买并合成
|
||||
public async composeAndPurchaseJewel(msg: { jewel: number, count: number, consumes: Array<{ id: number, count: number }>, purchaseGoods: Array<{ id: number, count: number }>}, session: BackendSession) {
|
||||
public async composeAndPurchaseJewel(msg: { jewel: number, count: number, consumes: Array<{ id: number, count: number }>, purchaseGoods: Array<{ id: number, count: number }> }, session: BackendSession) {
|
||||
let { count, consumes, jewel, purchaseGoods } = msg;
|
||||
let roleId: string = session.get('roleId');
|
||||
let roleName: string = session.get('roleName');
|
||||
@@ -634,12 +668,12 @@ export class EquipHandler {
|
||||
if (!consumes)
|
||||
consumes = [];
|
||||
let needConsumes = checkMaterialEnough(consumes.concat(purchaseGoods), jewel, count);//检查是否可以合成,并返回最终需要消耗的材料
|
||||
if (!needConsumes)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let items:Array<{id: number, count: number, ratio?:number}> = [];
|
||||
if (!needConsumes)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let items: Array<{ id: number, count: number, ratio?: number }> = [];
|
||||
for (let item of purchaseGoods) {
|
||||
items.push({id: item.id, count: item.count, ratio: 1})//加上购买的数量
|
||||
}
|
||||
items.push({ id: item.id, count: item.count, ratio: 1 })//加上购买的数量
|
||||
}
|
||||
items = items.concat(needConsumes);
|
||||
let hasError = await decreaseItems(roleId, sid, items);//合并消耗是否足够
|
||||
if (!!hasError)
|
||||
@@ -655,13 +689,13 @@ export class EquipHandler {
|
||||
* @param msg
|
||||
* @param session
|
||||
*/
|
||||
public async purchaseGoods(msg: { purchaseGoods: Array<{ id: number, count: number }>}, session: BackendSession) {
|
||||
public async purchaseGoods(msg: { purchaseGoods: Array<{ id: number, count: number }> }, session: BackendSession) {
|
||||
let { purchaseGoods } = msg;
|
||||
let roleId: string = session.get('roleId');
|
||||
let roleName: string = session.get('roleName');
|
||||
let sid: string = session.get('sid');
|
||||
let result = await addItems(roleId, roleName, sid, purchaseGoods );
|
||||
if(!result) {
|
||||
let result = await addItems(roleId, roleName, sid, purchaseGoods);
|
||||
if (!result) {
|
||||
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
|
||||
}
|
||||
return resResult(STATUS.SUCCESS);
|
||||
@@ -682,26 +716,26 @@ export class EquipHandler {
|
||||
let good = ITID.get(goodInfo.itid);
|
||||
let needUpdate = false;
|
||||
let oldJewel: number;
|
||||
let consumes: Array<{id: number, count: number, ratio?: number}> = [];
|
||||
let consumes: Array<{ id: number, count: number, ratio?: number }> = [];
|
||||
if (good.type != CONSUME_TYPE.JEWEL || !eid || eid < 0)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let equip = await EquipModel.getEquip(eid);
|
||||
if(!equip) return resResult(STATUS.EQUIP_NOT_FIND);
|
||||
if (!equip) return resResult(STATUS.EQUIP_NOT_FIND);
|
||||
|
||||
let oldJewelCount = equip.holes.filter(cur => cur.jewel > 0).length;
|
||||
|
||||
let index = findIndex(equip.holes,{id});
|
||||
let index = findIndex(equip.holes, { id });
|
||||
//装备上该位置有穿戴该宝石,且在合成的材料中
|
||||
if (!!equip.holes[index] && equip.holes[index].jewel == goodInfo.composeMaterial[0].id) {
|
||||
oldJewel = equip.holes[index].jewel;
|
||||
equip.holes[index].jewel = jewel;//合成后的新宝石穿戴到装备上
|
||||
needUpdate = true;
|
||||
consumes.push({id: goodInfo.composeMaterial[0].id, count: 1, ratio: 1});//ratio:1表示可以释放掉一颗宝石
|
||||
consumes.push({ id: goodInfo.composeMaterial[0].id, count: 1, ratio: 1 });//ratio:1表示可以释放掉一颗宝石
|
||||
}
|
||||
|
||||
consumes = consumes.concat(goodInfo.composeMaterial);
|
||||
if (goodInfo.specialMaterial.count) {
|
||||
consumes.push({id: goodInfo.specialMaterial.ids[0], count: goodInfo.specialMaterial.count})
|
||||
consumes.push({ id: goodInfo.specialMaterial.ids[0], count: goodInfo.specialMaterial.count })
|
||||
}
|
||||
let hasError = await decreaseItems(roleId, sid, consumes);//检查是消耗是否足够
|
||||
if (!!hasError)
|
||||
@@ -724,11 +758,13 @@ export class EquipHandler {
|
||||
await checkTaskWithEquip(roleId, sid, funcs, TASK_TYPE.EQUIP_JEWEL, equip, [oldJewelCount]);
|
||||
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)
|
||||
|
||||
return resResult(STATUS.SUCCESS, { curEquip: { seqId: eid, holes: equip.holes } });
|
||||
} else {
|
||||
result = await addItems(roleId, roleName, sid, [{ id: jewel, count: count }]);
|
||||
return resResult(STATUS.SUCCESS, { goods: [{id: jewel, count}] });
|
||||
return resResult(STATUS.SUCCESS, { goods: [{ id: jewel, count }] });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user