🐞 fix(优化): 羁绊溢出替换道具

This commit is contained in:
luying
2023-08-14 21:11:23 +08:00
parent 9a94762e46
commit 4be52d3dfe
3 changed files with 32 additions and 8 deletions

View File

@@ -8,7 +8,7 @@ import { RoleModel } from '../../../db/Role';
import { ItemModel } from '../../../db/Item';
import { gameData, getHeroExpByLv, getHeroStarByQuality, getHeroWakeByQuality, getHeroLvByExp, getMaxGradeByjobClass, getJobByGradeAndClass, getConnectLvByExp, getEquipByJobClassAndEPlace, getScollByStar, getExpByLv, getConnectMaxLv, getFriendShipByIdAndLv } from '../../../pubUtils/data';
import { ItemInter, RewardInter } from '../../../pubUtils/interface';
import { getDropItems, FIGURE_UNLOCK_CONDITION, ITID } from '../../../consts/constModules/itemConst'
import { getDropItems, FIGURE_UNLOCK_CONDITION, ITID, DELICACY_GID } from '../../../consts/constModules/itemConst'
import { pushHeroStarMax, pushHeroWakeUp } from '../../../services/chatService';
import { PvpDefenseModel } from '../../../db/PvpDefense';
import { checkTask, checkTaskInHeroGiveFavor, checkTaskInHeroQUalityUp, checkTaskInHeroStarUp, checkTaskInHeroTrain, checkTaskInHeroWakeUp } from '../../../services/task/taskService';
@@ -433,6 +433,7 @@ export class HeroHandler {
//赠送(包括一键赠送)
async heroGiveFavor(msg: { hid: number, shipId: number, type: number }, session: BackendSession) {
let roleId: string = session.get('roleId');
let roleName: string = session.get('roleName');
let sid: string = session.get('sid');
let serverId: number = session.get('serverId');
@@ -490,19 +491,34 @@ export class HeroHandler {
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
}
let newLevel = getConnectLvByExp(hid, shipId, newExp);
let addItem: RewardInter[] = [];
let { newLv: newLevel, overExp } = getConnectLvByExp(hid, shipId, newExp);
let saveMaterial: RewardInter[] = [];
for(let { id, count } of material) {
if(count > 0) saveMaterial.push({ id, count});
}
if(newLevel == maxLv && overExp > 0 && material.length > 0) {
let dicGoods = gameData.goods.get(saveMaterial[0].id);
if(!dicGoods) return resResult(STATUS.DIC_DATA_NOT_FOUND);
addItem.push({ id: DELICACY_GID, count: Math.floor(overExp/10) });
saveMaterial.push({ id: DELICACY_GID, count: Math.floor((dicGoods.value - overExp)/10) });
saveMaterial[0].count--;
saveMaterial = saveMaterial.filter(cur => cur.count > 0);
}
let result = await handleCost(roleId, sid, material, ITEM_CHANGE_REASON.HERO_GIVE_FAVOR);
if (!result) {
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
}
let updateConsume = addConsumeToHero(hero.consumes, material);
let updateConsume = addConsumeToHero(hero.consumes, saveMaterial);
let newConnections = addConnect(connections, { shipId, level: newLevel, exp: newExp });
let update = {
connections: newConnections,
consumes: updateConsume
}
let goods = await addItems(roleId, roleName, sid, addItem, ITEM_CHANGE_REASON.HERO_GIVE_FAVOR);
let isLv = oldLv != newLevel;
let { curHero } = await calculateCeWithHero(HERO_SYSTEM_TYPE.CONNECT, roleId, serverId, sid, hero.hid, update, { shipId });
@@ -510,7 +526,7 @@ export class HeroHandler {
// await unlockFigure(sid, roleId, [{ type: FIGURE_UNLOCK_CONDITION.HERO_FAVOR, paramHid: curHero.hid, paramFavourLv: curHero.favourLv }]);
await checkTaskInHeroGiveFavor(serverId, roleId, sid, shipId, newConnections, connections);
}
return resResult(STATUS.SUCCESS, { curHero: { ...pick(curHero, ['hid', 'connections']), shipId } });
return resResult(STATUS.SUCCESS, { curHero: { ...pick(curHero, ['hid', 'connections']), shipId }, goods });
}
//穿带时装