This commit is contained in:
mamengke01
2020-12-25 14:15:03 +08:00
parent 0c5cb1daac
commit 04fa4e79cf
14 changed files with 304 additions and 27 deletions

View File

@@ -1,6 +1,10 @@
import { mergeSameGoods } from '../pubUtils/util';
import { getGoodById } from '../pubUtils/gamedata';
import { getJewelById } from '../pubUtils/data';
import { EquipModel } from "../db/Equip";
import { HeroModel, EPlace } 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";
const _ = require('underscore');
export function checkMaterialEnough(consumes:Array<{id: number, count: number}>, jewel: number, jewelCount: number) {
@@ -33,3 +37,47 @@ export function checkMaterialEnough(consumes:Array<{id: number, count: number}>,
return false;
return needConsumes;
}
export async function changeEquip(roleId: string, sid: string, objectId: string, hid: number, id: number, seqId: number) {
let hero;
if (!!hid)
hero = await HeroModel.findByHidAndRole(hid, roleId);
if (!!objectId) {
let equip = await EquipModel.getEquipByObjectId(objectId);
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);
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, ePlaceId};
}
} else {
return takeOffEquip(objectId);
}
}
if (!!hero) {
let index = _.findIndex(hero.ePlace, { id });
if (index < 0)
return;
hero.ePlace[index].equip = null;
await EquipModel.updateEquipInfo(seqId, { hid: 0, ePlaceId: 0 });
await calPlayerCeAndSave(sid, roleId, [hero]);
}
}
async function takeOffEquip(objectId: string) {
let {seqId, ePlaceId} = await EquipModel.updateEquipInfobyObjectId(objectId, { hid: 0, ePlaceId: 0 });
return { seqId, hid: 0, ePlaceId};
}