diff --git a/game-server/app/servers/battle/handler/dailyBattleHandler.ts b/game-server/app/servers/battle/handler/dailyBattleHandler.ts index 3ad2cb95c..29040d590 100644 --- a/game-server/app/servers/battle/handler/dailyBattleHandler.ts +++ b/game-server/app/servers/battle/handler/dailyBattleHandler.ts @@ -1,10 +1,9 @@ import { Application, BackendSession } from 'pinus'; import { DailyRecordModel } from '../../../db/DailyRecord'; -import { GOLD_COST_RATIO } from '../../../consts'; import { STATUS } from '../../../consts/statusCode'; -import { resResult, calculateNum } from '../../../pubUtils/util'; +import { resResult } from '../../../pubUtils/util'; import { RoleModel } from '../../../db/Role'; -import { getDailyNum, getDailyBattleList } from '../../../services/dailyBattleService'; +import { getDailyNum, getDailyBattleList, getDailyBuyCountCost } from '../../../services/dailyBattleService'; import { handleCost } from '../../../services/rewardService'; import { getGoldObject } from '../../../pubUtils/itemUtils'; import { gameData } from '../../../pubUtils/data'; @@ -48,7 +47,7 @@ export class DailyBattleHandler { let buyCost = 0; for(let i = 1; i <= count; i++) { let num = buyCount + i; - buyCost += calculateNum(GOLD_COST_RATIO.DAILY_REF_NUM, {num}, 50); + buyCost += getDailyBuyCountCost(num); } let {gold} = await RoleModel.findByRoleId(roleId); if(buyCost > gold) { diff --git a/game-server/app/servers/battle/handler/dungeonBattleHandler.ts b/game-server/app/servers/battle/handler/dungeonBattleHandler.ts index f114b5f11..ca960fab3 100644 --- a/game-server/app/servers/battle/handler/dungeonBattleHandler.ts +++ b/game-server/app/servers/battle/handler/dungeonBattleHandler.ts @@ -1,11 +1,11 @@ import { Application, BackendSession } from 'pinus'; -import { GOLD_COST_RATIO, DUNGEON_CONST } from '../../../consts'; import { STATUS } from '../../../consts/statusCode'; -import { resResult, calculateNum, shouldRefresh } from '../../../pubUtils/util'; +import { resResult, shouldRefresh } from '../../../pubUtils/util'; import { RoleModel } from '../../../db/Role'; import { handleCost } from '../../../services/rewardService'; import { getGoldObject } from '../../../pubUtils/itemUtils'; -import { getDungeonData } from '../../../services/dungeonService'; +import { getDungeonData, getDungeonBuyCountCost } from '../../../services/dungeonService'; +import * as dicParam from '../../../pubUtils/dicParam'; export default function(app: Application) { return new DungeonBattleHandler(app); @@ -37,7 +37,7 @@ export class DungeonBattleHandler { dungeonCnt = 0; dungeonBuyCnt = 0; } - let timesCanBuy = DUNGEON_CONST.MAX_BUY_CNT; + let timesCanBuy = dicParam.DUNGEON_CONST.DUNGEON_CONST_BUY; let { vLv } = await RoleModel.findByRoleId(roleId); if(vLv > 0) { timesCanBuy += 0; // 暂留,用于处理vip等级增加最大购买次数 @@ -47,8 +47,7 @@ export class DungeonBattleHandler { } let buyCost = 0; for(let i = 1; i <= count; i++) { - let num = dungeonBuyCnt + i; - buyCost += calculateNum(GOLD_COST_RATIO.DUNGRON_BUY_NUM, {num}, 50); + buyCost += getDungeonBuyCountCost(dungeonBuyCnt + i); } let {gold} = await RoleModel.findByRoleId(roleId); if(buyCost > gold) { @@ -57,12 +56,12 @@ export class DungeonBattleHandler { await handleCost(roleId, sid, [getGoldObject(buyCost)]); await RoleModel.buyCnt(roleId, needRefresh, count, curTime); - let nextCostGold = calculateNum(GOLD_COST_RATIO.DUNGRON_BUY_NUM, {num: dungeonBuyCnt + count + 1 }, 50); + let nextCostGold = getDungeonBuyCountCost(dungeonBuyCnt + count + 1); return resResult(STATUS.SUCCESS, { costGold: buyCost, nextCostGold, - battleCount: DUNGEON_CONST.MAX_CNT + dungeonBuyCnt + count - dungeonCnt, - buyCount: DUNGEON_CONST.MAX_BUY_CNT - dungeonBuyCnt - count + battleCount: dicParam.DUNGEON_CONST.DUNGEON_CONST_FREE + dungeonBuyCnt + count - dungeonCnt, + buyCount: dicParam.DUNGEON_CONST.DUNGEON_CONST_BUY - dungeonBuyCnt - count }); } } \ No newline at end of file diff --git a/game-server/app/servers/battle/handler/expeditionBattleHandler.ts b/game-server/app/servers/battle/handler/expeditionBattleHandler.ts index 917bc1b93..b8dd5b541 100644 --- a/game-server/app/servers/battle/handler/expeditionBattleHandler.ts +++ b/game-server/app/servers/battle/handler/expeditionBattleHandler.ts @@ -6,7 +6,7 @@ import { ExpeditionPointModel } from '../../../db/ExpeditionPoint'; import { RoleModel } from '../../../db/Role'; import { calculateSumCE, genCode } from '../../../pubUtils/util'; import { getPointRewardStatus, getResetRemainCnt, findOrCreateEnemies, getExpeditionStatus } from '../../../services/expeditionService'; -import { EXPEDITION_CONST, EXPEDITION_WAR_RECORD_STATUS, KING_EXP_RATIO_TYPE, LINEUP_NUM, TASK_TYPE } from '../../../consts'; +import { EXPEDITION_WAR_RECORD_STATUS, KING_EXP_RATIO_TYPE, LINEUP_NUM, TASK_TYPE } from '../../../consts'; import { WarReward } from '../../../services/warRewardService'; import { addItems } from '../../../services/rewardService'; import { getAp, setAp } from '../../../services/actionPointService'; @@ -15,6 +15,7 @@ import { resResult } from '../../../pubUtils/util'; import { checkBattleHeroes, roleLevelup } from '../../../services/normalBattleService'; import { checkActivityTask, checkTask, checkTaskInBattleEnd } from '../../../services/taskService'; import { gameData } from '../../../pubUtils/data'; +import * as dicParam from '../../../pubUtils/dicParam'; export default function (app: Application) { new HandlerService(app, {}); @@ -226,7 +227,7 @@ export class ExpeditionBattleHandler { $set: { status: isSuccess ? 1 : 2, star } }, true); // 更新点数 - role = await RoleModel.increaseExpeditionPoint(roleId, isSuccess ? EXPEDITION_CONST.INCREASE_POINT : 0); + role = await RoleModel.increaseExpeditionPoint(roleId, isSuccess ? dicParam.EXPEDITION_CONST.EXPEDITION_CONST_POINTS : 0); let { expeditionPoint = 0 } = role; // 关卡奖励 diff --git a/game-server/app/servers/battle/handler/towerBattleHandler.ts b/game-server/app/servers/battle/handler/towerBattleHandler.ts index f4497bbb0..45cafc9d3 100644 --- a/game-server/app/servers/battle/handler/towerBattleHandler.ts +++ b/game-server/app/servers/battle/handler/towerBattleHandler.ts @@ -1,12 +1,12 @@ import { STATUS } from './../../../consts/statusCode'; -import { HANG_UP_CONSTS, GOLD_COST_RATIO, REDIS_KEY } from './../../../consts'; +import { HANG_UP_CONSTS, REDIS_KEY } from './../../../consts'; import { TowerTaskRecModel, TowerTaskRecType } from './../../../db/TowerTaskRec'; import { HangUpSpdUpRecModel } from './../../../db/HangUpSpdUpRec'; import { HangUpRecordModel } from './../../../db/HangUpRecord'; import { RoleModel } from './../../../db/Role'; import { TowerRecordModel } from './../../../db/TowerRecord'; import { Application, BackendSession } from 'pinus'; -import { resResult, shouldRefresh, calculateNum, genCode } from '../../../pubUtils/util'; +import { resResult, shouldRefresh, genCode } from '../../../pubUtils/util'; import { calcuHangUpReward, checkTaskConditions, checkHangUpSpdUpCnt, refreshTasks, treatTask, getRemainTime, getDoingOrWaitingTasks, getTowerStatus, getHungupRewards, getTasks, checkTaskRewards, getTowerTaskCostGold, getHangSpdUpCostGold, getManyHangSpdUpCostGold } from '../../../services/battleService'; import { addItems, handleCost } from '../../../services/rewardService'; import { checkBattleHeroes } from '../../../services/normalBattleService'; diff --git a/game-server/app/services/battleService.ts b/game-server/app/services/battleService.ts index ef8e3f3ad..e333b1881 100644 --- a/game-server/app/services/battleService.ts +++ b/game-server/app/services/battleService.ts @@ -1,11 +1,10 @@ import { HeroModel } from './../db/Hero'; import { HangUpRecordModel } from './../db/HangUpRecord'; -import { pinus } from 'pinus'; import { HANG_UP_CONSTS, REDIS_KEY, TASK_TYPE, TOWER_FORBIDDEN_CHARA_TYPE, TOWER_TASK_STATUS, MAIL_TYPE } from './../consts'; import { BattleRecordModel } from './../db/BattleRecord'; import { TowerRecordModel } from './../db/TowerRecord'; import { RoleModel, RoleType } from './../db/Role'; -import { shouldRefresh, resResult, cal, getRandEelmWithWeight, calculateNum, genCode, getRandEelm } from '../pubUtils/util'; +import { shouldRefresh, resResult, cal, getRandEelmWithWeight, genCode, } from '../pubUtils/util'; import { STATUS } from '../consts/statusCode'; import { HangUpSpdUpRecModel } from '../db/HangUpSpdUpRec'; import { TowerTaskRecModel, TowerTaskRecType } from '../db/TowerTaskRec'; @@ -212,7 +211,7 @@ export async function towerBattleEnd(sid: string, funcs: number[], roleId: strin let { towerLv, roleName } = await RoleModel.findByRoleId(roleId); let { warStatus, heroes: recHeroes } = await TowerRecordModel.getRecordByLv(roleId, towerLv); - console.log('*******', towerLv, heroes.join(), recHeroes.join()) + // console.log('*******', towerLv, heroes.join(), recHeroes.join()) for (let hid of heroes) { if (recHeroes.indexOf(hid) !== -1) { return { status: -1, resResult: resResult(STATUS.TOWER_DUPLICATE_HERO) }; diff --git a/game-server/app/services/dailyBattleService.ts b/game-server/app/services/dailyBattleService.ts index 7657fec8a..e4c06a983 100644 --- a/game-server/app/services/dailyBattleService.ts +++ b/game-server/app/services/dailyBattleService.ts @@ -9,6 +9,7 @@ import { RoleModel, RoleType } from '../db/Role'; import { gameData } from '../pubUtils/data'; import { DicWar } from '../pubUtils/dictionary/DicWar'; import { WarStar } from '../domain/dbGeneral'; +import * as dicParam from '../pubUtils/dicParam'; /** * 获取全部每日关卡列表 @@ -121,4 +122,17 @@ export async function getDailyNum(dailyRecord: DailyRecord, timesPerDay?: number timesCanBuy += 0; // 暂留,用于处理vip等级增加最大购买次数 } return {count: timesPerDay - count + buyCount, buyCount: timesCanBuy - buyCount} +} + +/** + * 每日购买次数的花费 + * @param num 如果没有买过次数,那么这里算第一次,传1 + * @returns + */ +export function getDailyBuyCountCost(num: number) { + let cost = ( num - 1 ) * dicParam.DAILY_CONST.DAILY_CONST_UP + dicParam.DAILY_CONST.DAILY_CONST_BASE; + if(cost > dicParam.DAILY_CONST.DAILY_CONST_TOP) { + cost = dicParam.DAILY_CONST.DAILY_CONST_TOP; + } + return cost; } \ No newline at end of file diff --git a/game-server/app/services/dungeonService.ts b/game-server/app/services/dungeonService.ts index df1963dd2..c74fa62d7 100644 --- a/game-server/app/services/dungeonService.ts +++ b/game-server/app/services/dungeonService.ts @@ -2,10 +2,10 @@ * 每日本相关 */ -import { resResult, shouldRefresh, calculateNum } from '../pubUtils/util'; +import { resResult, shouldRefresh, } from '../pubUtils/util'; import { STATUS } from '../consts/statusCode'; import { RoleModel, RoleType } from '../db/Role'; -import { DUNGEON_CONST, GOLD_COST_RATIO } from '../consts'; +import * as dicParam from '../pubUtils/dicParam'; /** * 获取秘境本数据 @@ -18,12 +18,12 @@ export async function getDungeonData(role: RoleType) { dungeonCnt = 0; dungeonBuyCnt = 0; } - let nextCostGold = calculateNum(GOLD_COST_RATIO.DUNGRON_BUY_NUM, {num: dungeonBuyCnt + 1 }, 50); + let nextCostGold = getDungeonBuyCountCost(dungeonBuyCnt + 1); return { nextCostGold, dungeonHeroes, - battleCount: DUNGEON_CONST.MAX_CNT + dungeonBuyCnt - dungeonCnt, - buyCount: DUNGEON_CONST.MAX_BUY_CNT - dungeonBuyCnt + battleCount: dicParam.DUNGEON_CONST.DUNGEON_CONST_FREE + dungeonBuyCnt - dungeonCnt, + buyCount: dicParam.DUNGEON_CONST.DUNGEON_CONST_BUY - dungeonBuyCnt } } @@ -35,14 +35,14 @@ export async function checkDungeonNum(roleId: string, inc: number) { if(needRefresh) { dungeonCnt = 0; dungeonBuyCnt = 0; } - if(dungeonCnt + inc > DUNGEON_CONST.MAX_CNT + dungeonBuyCnt) { + if(dungeonCnt + inc > dicParam.DUNGEON_CONST.DUNGEON_CONST_FREE + dungeonBuyCnt) { return {status: -1, resResult: resResult(STATUS.DUNGEON_TIMES_LACK)} } await RoleModel.increaseDungeonCnt(roleId, needRefresh, 0, curTime); return { status: 0, data: { - battleCount: DUNGEON_CONST.MAX_CNT + dungeonBuyCnt - dungeonCnt, - buyCount: DUNGEON_CONST.MAX_BUY_CNT - dungeonBuyCnt + battleCount: dicParam.DUNGEON_CONST.DUNGEON_CONST_FREE + dungeonBuyCnt - dungeonCnt, + buyCount: dicParam.DUNGEON_CONST.DUNGEON_CONST_BUY - dungeonBuyCnt }}; } @@ -63,13 +63,26 @@ export async function checkDungeonAndIncrease(roleId: string, inc: number, isRef dungeonCnt = 0; dungeonBuyCnt = 0; } - if(dungeonCnt + inc > DUNGEON_CONST.MAX_CNT + dungeonBuyCnt ) { + if(dungeonCnt + inc > dicParam.DUNGEON_CONST.DUNGEON_CONST_FREE + dungeonBuyCnt ) { return { status: -1, resResult: resResult(STATUS.DUNGEON_TIMES_LACK) } } // console.log('needRefresh', needRefresh); await RoleModel.increaseDungeonCnt(roleId, needRefresh, inc, curTime); return {status: 1, data: { - battleCount: DUNGEON_CONST.MAX_CNT + dungeonBuyCnt - dungeonCnt - inc, - buyCount: DUNGEON_CONST.MAX_BUY_CNT - dungeonBuyCnt + battleCount: dicParam.DUNGEON_CONST.DUNGEON_CONST_FREE + dungeonBuyCnt - dungeonCnt - inc, + buyCount: dicParam.DUNGEON_CONST.DUNGEON_CONST_BUY - dungeonBuyCnt }}; +} + +/** + * 秘境购买次数的花费 + * @param num 如果没有买过次数,那么这里算第一次,传1 + * @returns + */ +export function getDungeonBuyCountCost(num:number) { + let cost = (num - 1) * dicParam.DUNGEON_CONST.DUNGEON_CONST_UP + dicParam.DUNGEON_CONST.DUNGEON_CONST_BASE; + if(cost > dicParam.DUNGEON_CONST.DUNGEON_CONST_TOP) { + cost = dicParam.DUNGEON_CONST.DUNGEON_CONST_TOP; + } + return cost; } \ No newline at end of file diff --git a/game-server/app/services/expeditionService.ts b/game-server/app/services/expeditionService.ts index 1dc746b29..cb31ac9c5 100644 --- a/game-server/app/services/expeditionService.ts +++ b/game-server/app/services/expeditionService.ts @@ -4,7 +4,7 @@ import Role, { RoleModel, RoleType } from '../db/Role'; import { PvpDefenseModel } from '../db/PvpDefense'; import { shouldRefresh, calculateSumCE, getRandSingleEelm } from '../pubUtils/util'; -import { EXPEDITION_CONST, LINEUP_NUM, EXPEDITION_WAR_RECORD_STATUS, ABI_TYPE } from '../consts'; +import { LINEUP_NUM, EXPEDITION_WAR_RECORD_STATUS, ABI_TYPE } from '../consts'; import { ExpeditionWarRecordModel } from '../db/ExpeditionWarRecord'; import { HeroType } from '../db/Hero'; import { gameData } from '../pubUtils/data'; @@ -12,6 +12,7 @@ import { getPlayerAttribute, getRobotAttribute } from './pvpService'; import { getTimeFunD } from '../pubUtils/timeUtil'; import { ExpeditionRecordModel } from '../db/ExpeditionRecord'; import { Attribute } from '../domain/roleField/attribute'; +import * as dicParam from '../pubUtils/dicParam'; /** * 获取远征关卡列表 @@ -260,7 +261,7 @@ export async function getResetRemainCnt(curTime: Date, roleId: string, role?: Ro expeditionResetCnt = 0; expeditionResetRefTime = curTime; } - let maxCnt = EXPEDITION_CONST.RESET_CNT; + let maxCnt = dicParam.EXPEDITION_CONST.EXPEDITION_CONST_TIMES; return { resetCnt: maxCnt - expeditionResetCnt, diff --git a/shared/consts/constModules/battleConst.ts b/shared/consts/constModules/battleConst.ts index 82b849ced..756785d50 100644 --- a/shared/consts/constModules/battleConst.ts +++ b/shared/consts/constModules/battleConst.ts @@ -90,28 +90,12 @@ export const HANG_UP_CONSTS = { SPD_UP_REC_TIME: dicParam.TOWER_HANG_UP.TOWE_HANG_UP_SPD_UP_REC_TIME * 60 * 60 * 1000 // 加速直接获得6小时收益 } -export const DAILY_CONST = { - REFRESH_TIME: 5 // 每天加点刷新 -} - -export const DUNGEON_CONST = { - REFRESH_TIME: 5, // 每天加点刷新 - MAX_CNT: 100, // 最大挑战次数 - MAX_BUY_CNT: 10 // 最大购买次数 -} - export const PVP_CONST = { REFRESH_TIME: 5, // 每天加点刷新 SCORE_LINE: 3000, // 超过这个分数之后可以刷人类对手 ENEMY_CE: 10000 // 对手战力 } -export const EXPEDITION_CONST = { - REFRESH_TIME: 5, // 重置次数刷新时间 - INCREASE_POINT: 1, // 远征每成功一次累计的点数 - RESET_CNT: 1 // 可以免费重置的次数 -} - export const EVENT_QUIZ_NUM = 3; diff --git a/shared/consts/constModules/calcuConst.ts b/shared/consts/constModules/calcuConst.ts deleted file mode 100644 index b50a46d13..000000000 --- a/shared/consts/constModules/calcuConst.ts +++ /dev/null @@ -1,14 +0,0 @@ -export const GONGSHI = { - "TOWER_HANG_UP_SPEED_COST": "50", - "TOWER_TASK_REF_COST": "200", - "DAILY_REFRESH_NUM_COST": "50*num" -}; - -/** - * 计算元宝和次数相关的系数 - * 公式: A * num + B - */ -export const GOLD_COST_RATIO = { - "DAILY_REF_NUM": { "A": 50, "B": 0 }, // 每日购买次数花费 - "DUNGRON_BUY_NUM": { "A": 0, "B": 50 } // 秘境购买次数花费 -} diff --git a/shared/consts/index.ts b/shared/consts/index.ts index 7e1b2022c..78f5b53c7 100644 --- a/shared/consts/index.ts +++ b/shared/consts/index.ts @@ -1,7 +1,6 @@ export * from './constModules/abilityConst'; export * from './constModules/activityConst'; export * from './constModules/battleConst'; -export * from './constModules/calcuConst'; export * from './constModules/heroConst'; export * from './constModules/itemConst'; export * from './constModules/sysConst'; diff --git a/shared/pubUtils/util.ts b/shared/pubUtils/util.ts index 2423f178e..5184044b8 100644 --- a/shared/pubUtils/util.ts +++ b/shared/pubUtils/util.ts @@ -329,23 +329,23 @@ export const cal = { }; //计算公式 -export function calculateNum(ratio: { A: number, B: number }, params: { num: number }, defaultVal = 0) { - // result = a * num + b - try { - let { A, B } = ratio; - let { num } = params; - let result = A * num + B; - if (isNaN(result)) { - console.error('calculate wrong: ', A, B, num) - return defaultVal; - } else { - return result; - } - } catch (e) { - console.error(e); - return defaultVal; - } -} +// export function calculateNum(ratio: { A: number, B: number }, params: { num: number }, defaultVal = 0) { +// // result = a * num + b +// try { +// let { A, B } = ratio; +// let { num } = params; +// let result = A * num + B; +// if (isNaN(result)) { +// console.error('calculate wrong: ', A, B, num) +// return defaultVal; +// } else { +// return result; +// } +// } catch (e) { +// console.error(e); +// return defaultVal; +// } +// } export function ratioReward(reward: {id: number, count: number}[], ratio: number): {id: number, count: number}[] { return reward.map(cur => {