diff --git a/game-server/app/servers/role/handler/heroHandler.ts b/game-server/app/servers/role/handler/heroHandler.ts index 89875bd17..76b4e27a7 100644 --- a/game-server/app/servers/role/handler/heroHandler.ts +++ b/game-server/app/servers/role/handler/heroHandler.ts @@ -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 }); } //穿带时装 diff --git a/shared/consts/constModules/itemConst.ts b/shared/consts/constModules/itemConst.ts index 36d89b537..845e9eb99 100644 --- a/shared/consts/constModules/itemConst.ts +++ b/shared/consts/constModules/itemConst.ts @@ -197,8 +197,9 @@ const currencyArr = [ { "gid": 72021, "name": "天机骰子", "type": CURRENCY_TYPE.SPECIAL_DICE }, { "gid": 72030, "name": "主公经验", "type": CURRENCY_TYPE.KING_EXP }, { "gid": 81000, "name": "英杰券", "type": CURRENCY_TYPE.VOUCHER}, - { "gid": 81001, "name": "英杰币", "type": CURRENCY_TYPE.VOUCHER_COIN}, + { "gid": 81001, "name": "英杰币", "type": CURRENCY_TYPE.VOUCHER_COIN} ]; + export const CURRENCY = new Map(); export const CURRENCY_BY_TYPE = new Map(); for (let obj of currencyArr) { @@ -229,6 +230,7 @@ export function getSpineItid() { return dicItid?.id; } + export enum QUALITY_TYPE { BLUE = 1, // 蓝 PURPLE = 2, // 紫 @@ -308,4 +310,6 @@ export enum QUENCH_TYPE { export enum REFINE_TYPE { ONCE = 1, // 精炼一次 ONE_LEVEL = 2, // 精炼一级 -} \ No newline at end of file +} + +export const DELICACY_GID = 11011; \ No newline at end of file diff --git a/shared/pubUtils/data.ts b/shared/pubUtils/data.ts index e378f0257..f5a7a2763 100644 --- a/shared/pubUtils/data.ts +++ b/shared/pubUtils/data.ts @@ -422,12 +422,16 @@ export function getConnectMaxLv(actorId: number, shipId: number) { */ export function getConnectLvByExp(actorId: number, shipId: number, newExp: number) { let exps = gameData.friendShips.get(`${actorId}_${shipId}`) || []; + let overExp = 0; exps.sort((a, b) => a.level - b.level); let newLv = 0; for (let { level, shipExp } of exps) { - if (newExp >= shipExp) newLv = level; + if (newExp >= shipExp) { + newLv = level; + overExp = newExp - shipExp; + } } - return newLv + return { newLv, overExp } } export function getBossHpByWarId(warId: number) {