diff --git a/game-server/app/servers/battle/handler/comBattleHandler.ts b/game-server/app/servers/battle/handler/comBattleHandler.ts index a8e8b7939..99bab1fd0 100644 --- a/game-server/app/servers/battle/handler/comBattleHandler.ts +++ b/game-server/app/servers/battle/handler/comBattleHandler.ts @@ -13,7 +13,7 @@ import { Application, BackendSession } from 'pinus'; import { resResult, getRandomByLen, calculateNum, getRandValue, ratioReward } from '../../../pubUtils/util'; import { RoleStatus } from '../../../db/ComBattleTeam'; import { ItemModel } from '../../../db/Item'; -import { handleFixedReward, addItems } from '../../../services/rewardService'; +import { handleFixedReward, addItems, handleCost } from '../../../services/rewardService'; import { checkRoleInQueue, getTeamSearchByQuality, rmRoleFromQueue, setTeamSearchReq } from '../../../services/redisService'; import { transBossHpArr } from '../../../services/battleService'; import { getRandBlueprtId, getRandComBtlRobots, checkComBattleResult, clearComBtlTimer, getRealReward, getAssistTimesByQuality, getFrd } from '../../../services/comBattleService'; @@ -812,17 +812,15 @@ export class ComBattleHandler { count: dicCompose.coinNum }); // 消耗藏宝图和寻宝币 - const rec = await ItemModel.decreaseItems(roleId, original); - if(rec.hasError) { - return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH); - } + + let costResult = await handleCost(roleId, sid, original); + if(!costResult) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH); const targetList = getBluePrtByQuality(dicCompose.targetQuality); const target = getRandomByLen(targetList); const reward = [{id: target, count: 1}]; const goods = await addItems(roleId, roleName, sid, reward); - return resResult(STATUS.SUCCESS, { goods, costGold: 0 }); } } diff --git a/game-server/app/servers/battle/handler/dailyBattleHandler.ts b/game-server/app/servers/battle/handler/dailyBattleHandler.ts index 74c47c6a8..0a6af1bbb 100644 --- a/game-server/app/servers/battle/handler/dailyBattleHandler.ts +++ b/game-server/app/servers/battle/handler/dailyBattleHandler.ts @@ -1,11 +1,12 @@ import { Application, BackendSession } from 'pinus'; import { DailyRecordModel } from '../../../db/DailyRecord'; import { getGamedata } from '../../../pubUtils/gamedata'; -import { GOLD_COST_RATIO } from '../../../consts'; +import { GOLD_COST_RATIO, CURRENCY_BY_TYPE, CURRENCY_TYPE } from '../../../consts'; import { STATUS } from '../../../consts/statusCode'; import { resResult, calculateNum } from '../../../pubUtils/util'; import { RoleModel } from '../../../db/Role'; import { getDailyNum } from '../../../services/dailyBattleService'; +import { handleCost } from '../../../services/rewardService'; export default function(app: Application) { return new DailyBattleHandler(app); @@ -67,6 +68,7 @@ export class DailyBattleHandler { let {type, count} = msg; if(count < 0) return resResult(STATUS.WRONG_PARMS); const roleId = session.get('roleId'); + const sid = session.get('sid'); const dicDaily = getGamedata('dic_zyz_daily'); const curDaily = dicDaily.find(cur => cur.dailyType == type); @@ -89,7 +91,8 @@ export class DailyBattleHandler { if(buyCost > gold) { return resResult(STATUS.DAILY_REFRESH_GOLD_LACK); } - await RoleModel.costGold(roleId, buyCost); + + await handleCost(roleId, sid, [{id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD), count: buyCost}]); let newDailyRecord = await DailyRecordModel.increseBuyCount(roleId, type, count); let checkDailyResult = await getDailyNum(newDailyRecord, timesPerDay, timesCanBuy); diff --git a/game-server/app/servers/battle/handler/dungeonBattleHandler.ts b/game-server/app/servers/battle/handler/dungeonBattleHandler.ts index e17bdd841..8cf92b0c8 100644 --- a/game-server/app/servers/battle/handler/dungeonBattleHandler.ts +++ b/game-server/app/servers/battle/handler/dungeonBattleHandler.ts @@ -1,8 +1,9 @@ import { Application, BackendSession } from 'pinus'; -import { GOLD_COST_RATIO, DUNGEON_CONST } from '../../../consts'; +import { GOLD_COST_RATIO, DUNGEON_CONST, CURRENCY_TYPE, CURRENCY_BY_TYPE } from '../../../consts'; import { STATUS } from '../../../consts/statusCode'; import { resResult, calculateNum, shouldRefresh } from '../../../pubUtils/util'; import { RoleModel } from '../../../db/Role'; +import { handleCost } from '../../../services/rewardService'; export default function(app: Application) { return new DungeonBattleHandler(app); @@ -35,6 +36,8 @@ export class DungeonBattleHandler { let { count } = msg; if(count < 0) return resResult(STATUS.WRONG_PARMS); const roleId = session.get('roleId'); + const sid = session.get('sid'); + let { dungeonCnt = 0, dungeonBuyCnt = 0, dungeonRefTime } = await RoleModel.findByRoleId(roleId); let curTime = new Date(); let needRefresh = shouldRefresh(dungeonRefTime, curTime, DUNGEON_CONST.REFRESH_TIME); @@ -59,7 +62,7 @@ export class DungeonBattleHandler { if(buyCost > gold) { return resResult(STATUS.DAILY_REFRESH_GOLD_LACK); } - await RoleModel.costGold(roleId, buyCost); + await handleCost(roleId, sid, [{id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD), count: buyCost}]); await RoleModel.buyCnt(roleId, needRefresh, count, curTime); let nextCostGold = calculateNum(GOLD_COST_RATIO.DUNGRON_BUY_NUM, {num: dungeonBuyCnt + count + 1 }, 50); diff --git a/game-server/app/servers/battle/handler/towerBattleHandler.ts b/game-server/app/servers/battle/handler/towerBattleHandler.ts index 7dbd83a9f..a27f7fa93 100644 --- a/game-server/app/servers/battle/handler/towerBattleHandler.ts +++ b/game-server/app/servers/battle/handler/towerBattleHandler.ts @@ -1,5 +1,5 @@ import { STATUS } from './../../../consts/statusCode'; -import { HANG_UP_CONSTS, GOLD_COST_RATIO, TOWER_TASK_CONST, REDIS_KEY } from './../../../consts'; +import { HANG_UP_CONSTS, GOLD_COST_RATIO, TOWER_TASK_CONST, REDIS_KEY, CURRENCY_BY_TYPE, CURRENCY_TYPE } from './../../../consts'; import { TowerTaskRecModel } from './../../../db/TowerTaskRec'; import { HangUpSpdUpRecModel } from './../../../db/HangUpSpdUpRec'; import { HangUpRecordModel } from './../../../db/HangUpRecord'; @@ -9,7 +9,7 @@ import { Application, BackendSession } from 'pinus'; import { getTaskById, getTowerDataByLv } from '../../../pubUtils/gamedata'; import { decodeArrayStr, resResult, shouldRefresh, calculateNum, getRefTime, genCode } from '../../../pubUtils/util'; import { calcuHangUpReward, checkTaskConditions, checkHangUpSpdUpCnt, createCurTasks, treatTask, getRemainTime, getTasksReward, getTaskStatus, getDoingOrWaitingTasks } from '../../../services/battleService'; -import { handleFixedReward, addItems } from '../../../services/rewardService'; +import { handleFixedReward, addItems, handleCost } from '../../../services/rewardService'; import { checkBattleHeroes } from '../../../services/normalBattleService'; import { getRank, setRank, initRank, existsRank } from '../../../services/redisService'; @@ -132,7 +132,8 @@ export class TowerBattleHandler { if(costGold > gold) { return resResult(STATUS.TOWER_GOLD_NOT_ENOUGH); } - await RoleModel.costGold(roleId, costGold); + + await handleCost(roleId, sid, [{id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD), count: costGold}]) const spdUpResult = await RoleModel.hangUpSpdUp(roleId, msg.speedUpCnt, curTime); if (!spdUpResult) {