装备:装备逻辑变化
This commit is contained in:
@@ -66,99 +66,11 @@ export function checkMaterialEnough(consumes: Array<{ id: number, count: number
|
||||
let isEnough = checkCurMeterial(jewel, jewelCount);
|
||||
return isEnough? needConsumes: false;
|
||||
}
|
||||
/**
|
||||
* 将装备卸载下来,并检查是否有替换装备的武将,若有则替换
|
||||
* 武将A(装备A)&武将B(装备B) ==> 武将A(装备B)&武将B(装备A)
|
||||
* 武将A(装备A)& 装备B ==> 武将A(装备B)& 装备A
|
||||
* @param roleId 玩家id
|
||||
* @param sid
|
||||
* @param equip 目标武将要卸下的装备,装备A
|
||||
* @param hid 要装上的装备备原来装备着的武将id, 武将B
|
||||
* @param id 装备类型
|
||||
* @param seqId 要装上的装备的唯一id 装备B
|
||||
*/
|
||||
export async function changeEquip(serverId: number, roleId: string, sid: string, equipA: EquipType, hid: number, id: number, equipB: EquipType, funcs: number[]) {
|
||||
let heroB: HeroType;
|
||||
if (!!hid) //需要卸下或者替换的武将
|
||||
heroB = await HeroModel.findByHidAndRoleWithEquip(hid, roleId);//需要替换的武将
|
||||
|
||||
if (!!equipA) {//需要卸下的装备
|
||||
if (!!heroB) {
|
||||
let goodInfo = getGoodById(equipA.id);
|
||||
if (goodInfo.lvLimited > heroB.lv || !checkEquipCanPut(hid, equipA.id)) { // 不能穿,就只卸载
|
||||
let res = await takeOffEquipAndCalPlayerCe(roleId, sid, heroB, equipB, id, funcs);//卸下装备并重算战力
|
||||
return res;
|
||||
} else {
|
||||
let res = await dressEquip(serverId, roleId, sid, heroB, equipA, funcs);//替换给武将,并计算战力
|
||||
return res;
|
||||
}
|
||||
} else {
|
||||
let res = await takeOffEquipAndCalPlayerCe(roleId, sid, null, equipA, id, funcs);//卸下装备并重算战力
|
||||
return res;
|
||||
}
|
||||
} else if (!!heroB) {//从穿戴装备的武将上卸下装备
|
||||
let res = await takeOffEquipAndCalPlayerCe(roleId, sid, heroB, equipB, id, funcs);//卸下装备并重算战力
|
||||
return res
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 从穿戴装备的武将上卸下装备,并重算战力
|
||||
* @param roleId
|
||||
* @param sid
|
||||
* @param seqId
|
||||
* @param hero
|
||||
* @param id
|
||||
*/
|
||||
export async function takeOffEquipAndCalPlayerCe(roleId: string, sid: string, hero: HeroType, equip: EquipType, id: number, funcs: number[]) {
|
||||
console.log('***takeOffEquipAndCalPlayerCe', roleId, sid, hero&&hero.hid, equip.seqId, id)
|
||||
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 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, id: equip.id, ePlaceId: equip.ePlaceId }];
|
||||
}
|
||||
/**
|
||||
* 穿戴装备并重算战力
|
||||
* @param roleId
|
||||
* @param sid
|
||||
* @param hero
|
||||
* @param equip
|
||||
*/
|
||||
export async function dressEquip(serverId: number, roleId: string, sid: string, hero: HeroType, equip: EquipType, funcs: number[]) {
|
||||
console.log('***dressEquip', roleId, sid, hero&&hero.hid, equip.seqId)
|
||||
|
||||
let args = calEquipSeids(hero);
|
||||
let index = hero.ePlace.findIndex(cur => cur.id == equip.ePlaceId);
|
||||
let equipOffInfo = <EquipType>hero.ePlace[index].equip;
|
||||
hero = await HeroModel.addEquip(roleId, hero.hid, equip.ePlaceId, equip._id, equipOffInfo?._id);
|
||||
await calPlayerCeAndSave(HERO_SYSTEM_TYPE.EQUIP, sid, roleId, hero, {}, args);
|
||||
|
||||
// 任务
|
||||
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 checkActivityTask(serverId, sid, funcs, roleId, TASK_TYPE.EQUIP_QUALITY, 1, { quality: equip.quality })
|
||||
await checkActivityTask(serverId, sid, funcs, roleId, TASK_TYPE.EQUIP_SUM, 1)
|
||||
|
||||
let res = [
|
||||
{ seqId: equip.seqId, hid: hero.hid, id: equip.id, ePlaceId: equip.ePlaceId }
|
||||
];
|
||||
if(equipOffInfo) {
|
||||
res.push({ seqId: equipOffInfo.seqId, hid: 0, id: equipOffInfo.id, ePlaceId: equipOffInfo.ePlaceId })
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
export function checkEquipCanPut(hid: number, id: number) {
|
||||
export function checkEquipCanPut(hero: HeroType, id: number) {
|
||||
let hid = hero.hid;
|
||||
let dicGood = gameData.goods.get(id);
|
||||
if(dicGood.lvLimited > hero.lv) return false;
|
||||
let dicHero = gameData.hero.get(hid);
|
||||
let dicJob = gameData.job.get(dicHero.jobid);
|
||||
if(dicGood.jobLimited.indexOf(0) == -1 && dicGood.jobLimited.indexOf(dicJob.job_class) == -1) return false;
|
||||
|
||||
Reference in New Issue
Block a user