战力
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
import { mergeSameGoods } from '../pubUtils/util';
|
||||
import { EquipModel } from "../db/Equip";
|
||||
import { HeroModel, EPlace } from "../db/Hero";
|
||||
import { HeroModel, EPlace, HeroType } from "../db/Hero";
|
||||
import { ITID } from "../consts/constModules/itemConst";
|
||||
import { getHeroJob, getGoodById, gameData, getJewelById, getHeroEquipByClassId } from "../pubUtils/data";
|
||||
import { calPlayerCeAndSave } from "./playerCeService";
|
||||
import { HERO_SYSTEM_TYPE } from "../consts";
|
||||
import { EquipType } from "../db/Equip";
|
||||
import { calEquipSeids } from '../pubUtils/playerCe';
|
||||
const _ = require('underscore');
|
||||
|
||||
export function checkMaterialEnough(consumes:Array<{id: number, count: number}>, jewel: number, jewelCount: number) {
|
||||
let comJewelMap = {};
|
||||
consumes = mergeSameGoods(consumes);
|
||||
@@ -38,46 +39,48 @@ export function checkMaterialEnough(consumes:Array<{id: number, count: number}>,
|
||||
return needConsumes;
|
||||
}
|
||||
|
||||
export async function changeEquip(roleId: string, sid: string, objectId: string, hid: number, id: number, seqId: number) {
|
||||
export async function changeEquip(roleId: string, sid: string, equip: EquipType, hid: number, id: number, seqId: number) {
|
||||
let hero;
|
||||
if (!!hid)
|
||||
if (!!hid) //需要卸下或者替换的武将
|
||||
hero = await HeroModel.findByHidAndRole(hid, roleId);
|
||||
if (!!objectId) {
|
||||
let equip = await EquipModel.getEquipByObjectId(objectId);
|
||||
if (!!hero) {
|
||||
if (!!equip) {//需要卸下的装备
|
||||
if (!!hero) {//判断是否替换装备
|
||||
let goodInfo = getGoodById(equip.id);
|
||||
let obj = ITID.get(goodInfo.itid);
|
||||
let ePlaceId = obj.type;
|
||||
if (goodInfo.lvLimited > hero.lv)
|
||||
return takeOffEquip(objectId);
|
||||
if (goodInfo.lvLimited > hero.lv)
|
||||
return takeOffEquip(equip.seqId);
|
||||
let { jobid } = gameData.hero.get(hid);
|
||||
let { job_class } = getHeroJob(jobid);
|
||||
let { classId } = getHeroEquipByClassId(goodInfo.itid);
|
||||
if (_.indexOf(classId, job_class) < 0)
|
||||
return takeOffEquip(objectId);
|
||||
hero = await HeroModel.addEquip(roleId, hero.hid, ePlaceId, objectId);
|
||||
// await calPlayerCeAndSave(sid, roleId, [hero], HERO_SYSTEM_TYPE.EQUIP, []);
|
||||
if (!!hero) {
|
||||
await calPlayerCeAndSave(sid, roleId, [hero]);
|
||||
let ePlaces = <EPlace>hero.ePlace;
|
||||
let ePlace= _.findWhere(ePlaces,{ id: ePlaceId });
|
||||
return { seqId: ePlace.equip.seqId, hid };
|
||||
}
|
||||
if (_.indexOf(classId, job_class) < 0)
|
||||
return takeOffEquip(equip.seqId);
|
||||
return dressEquip(roleId, sid, hero, equip);
|
||||
} else {
|
||||
return takeOffEquip(objectId);
|
||||
return takeOffEquip(equip.seqId);
|
||||
}
|
||||
}
|
||||
if (!!hero) {
|
||||
let index = _.findIndex(hero.ePlace, { id });
|
||||
if (index < 0)
|
||||
return;
|
||||
hero.ePlace[index].equip = null;
|
||||
await EquipModel.updateEquipInfo(seqId, { hid: 0 });
|
||||
await calPlayerCeAndSave(sid, roleId, [hero]);
|
||||
} else if (!!hero) {//从穿戴装备的武将上卸下装备
|
||||
await takeOffEquipAndCalPlayerCe(roleId, sid, seqId, hero, id);//卸下装备并重算战力
|
||||
}
|
||||
}
|
||||
|
||||
async function takeOffEquip(objectId: string) {
|
||||
let { seqId } = await EquipModel.updateEquipInfobyObjectId(objectId, { hid: 0 });
|
||||
export async function takeOffEquipAndCalPlayerCe(roleId: string, sid: string, seqId: number, hero:HeroType, id: number ) {
|
||||
let index = _.findIndex(hero.ePlace, { id });
|
||||
if (index < 0)
|
||||
return;
|
||||
await EquipModel.updateEquipInfo(seqId, { hid: 0 });
|
||||
hero.ePlace[index].equip = null;
|
||||
let args = calEquipSeids(hero);
|
||||
await calPlayerCeAndSave(sid, roleId, [hero], HERO_SYSTEM_TYPE.EQUIP, args);
|
||||
return { seqId, hid: 0};
|
||||
}
|
||||
|
||||
export async function dressEquip(roleId: string, sid: string, hero:HeroType, equip: EquipType) {
|
||||
hero = await HeroModel.addEquip(roleId, hero.hid, equip.ePlaceId, equip._id);
|
||||
let args = calEquipSeids(hero);
|
||||
await calPlayerCeAndSave(sid, roleId, [hero], HERO_SYSTEM_TYPE.EQUIP, args);
|
||||
return { seqId: equip.seqId, hid: hero.hid };
|
||||
}
|
||||
|
||||
async function takeOffEquip(seqId: number) {
|
||||
await EquipModel.updateEquipInfo(seqId, { hid: 0 });
|
||||
return { seqId, hid: 0};
|
||||
}
|
||||
@@ -5,7 +5,11 @@
|
||||
import { pinus } from 'pinus';
|
||||
import { STATUS } from '../consts/statusCode';
|
||||
|
||||
<<<<<<< HEAD
|
||||
import { resResult, reduceCe } from '../pubUtils/util';
|
||||
=======
|
||||
import { resResult, reduceCe } from '../pubUtils/util';
|
||||
>>>>>>> cb1f9ea... 战力
|
||||
import { calPlayerCeAndSave as pubCalPlayerCeAndSave, reCalAllHeroCe } from '../pubUtils/playerCe';
|
||||
import { HeroType } from '../db/Hero';
|
||||
const _ = require('underscore');
|
||||
@@ -16,19 +20,27 @@ export async function calPlayerCeAndSave(sid: string, roleId: string, heros: Arr
|
||||
let {role, pushHeros} = await pubCalPlayerCeAndSave(roleId, heros, type, args);
|
||||
//下发战力
|
||||
let uids = [{ uid: roleId, sid }];
|
||||
<<<<<<< HEAD
|
||||
let pushHerosReduced = pushHeros.map(cur => {
|
||||
return { hid: cur.hid, ce: reduceCe(cur.ce), incHeroCe: reduceCe(cur.incHeroCe) }
|
||||
});
|
||||
pinus.app.get('channelService').pushMessageByUids('onPlayerCeUpdate', resResult(STATUS.SUCCESS, { ce: reduceCe(role.ce) , heros: pushHerosReduced, topFiveCe: 0 }), uids);
|
||||
=======
|
||||
pinus.app.get('channelService').pushMessageByUids('onPlayerCeUpdate', resResult(STATUS.SUCCESS, { ce: reduceCe(role.ce), heros: pushHeros, topFiveCe: 0 }), uids);
|
||||
>>>>>>> cb1f9ea... 战力
|
||||
return heros;
|
||||
}
|
||||
|
||||
export async function calAllHeroCe(sid: string, roleId: string, type:number, args:Array<number>) {
|
||||
export async function calAllHeroCe(sid: string, roleId: string, type?:number, args?:Array<number>) {
|
||||
let {ce, pushHeros}= await reCalAllHeroCe(roleId,type, args);
|
||||
let uids = [{ uid: roleId, sid }];
|
||||
<<<<<<< HEAD
|
||||
let pushHerosReduced = pushHeros.map(cur => {
|
||||
return { hid: cur.hid, ce: reduceCe(cur.ce), incHeroCe: reduceCe(cur.incHeroCe) }
|
||||
});
|
||||
pinus.app.get('channelService').pushMessageByUids('onPlayerCeUpdate', resResult(STATUS.SUCCESS, { ce: reduceCe(ce), heros: pushHerosReduced, topFiveCe: 0 }), uids);
|
||||
=======
|
||||
pinus.app.get('channelService').pushMessageByUids('onPlayerCeUpdate', resResult(STATUS.SUCCESS, { ce: reduceCe(ce), heros: pushHeros, topFiveCe: 0 }), uids);
|
||||
>>>>>>> cb1f9ea... 战力
|
||||
return;
|
||||
}
|
||||
Reference in New Issue
Block a user