From 667c85e686de4455fe738c918a3415ee6d139668 Mon Sep 17 00:00:00 2001 From: mamengke01 <794347210@qq.com> Date: Sat, 26 Dec 2020 12:14:56 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A5=9E=E5=83=8F=E5=BC=BA=E5=8C=96=E5=8D=81?= =?UTF-8?q?=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/servers/role/handler/roleHandler.ts | 37 +++++------- game-server/app/services/roleService.ts | 59 +++++++++++++++++++ shared/consts/consts.ts | 5 ++ shared/pubUtils/util.ts | 19 ++++++ 4 files changed, 97 insertions(+), 23 deletions(-) create mode 100644 game-server/app/services/roleService.ts diff --git a/game-server/app/servers/role/handler/roleHandler.ts b/game-server/app/servers/role/handler/roleHandler.ts index 23a7fda87..bab2e279f 100644 --- a/game-server/app/servers/role/handler/roleHandler.ts +++ b/game-server/app/servers/role/handler/roleHandler.ts @@ -10,7 +10,8 @@ import { getTeraphAttr } from '../../../consts/constModules/abilityConst' const _ = require('underscore'); import { SclResultInter, SclPosInter } from '../../../pubUtils/interface'; import { SchoolModel } from '../../../db/School'; - +import { TERAPH_RANDOM } from '../../../consts/consts'; +import { checkMaterialEnough } from '../../../services/roleService' export default function(app: Application) { return new RoleHandler(app); } @@ -105,23 +106,18 @@ export class RoleHandler { let teraphInfo = getTeraph(id, teraph.grade); if (!teraphInfo) return resResult(STATUS.DIC_DATA_NOT_FOUND) - let falg = true; + let attrs = []; for (let attrName in getTeraphAttr()) { - if (teraph[attrName] != teraphInfo[attrName]) { - falg = false; - break; + let attrNameMax = attrName+'Max'; + if (teraph[attrName] < teraphInfo[attrNameMax]) { + attrs.push(attrName); } } - if (!!falg) + if (!attrs.length) return resResult(STATUS.ROLE_TERAPH_NOT_STRENGTHEN); - //TODO强化属性 - let consumes; - if (type == 1) { - consumes = teraphInfo.upMaterial; - } else if (type == 2) { - consumes = teraphInfo.upMaterial; - } else { - return resResult(STATUS.WRONG_PARMS); + let {attr, consumes} = checkMaterialEnough(type, attrs, teraphInfo, teraph); + for (let key in attr) { + teraph[key] += attr[key]; } let result = await handleCost(roleId, sid, consumes); if (!result) @@ -144,17 +140,12 @@ export class RoleHandler { if (!teraphInfo) return resResult(STATUS.DIC_DATA_NOT_FOUND) for (let attrName in getTeraphAttr()) { - if (teraph[attrName] != teraphInfo[attrName]) + if (teraph[attrName] != teraphInfo[attrName +'Max']) return resResult(STATUS.ROLE_TERAPH_NOT_QUILITY); + teraph[attrName] = 0; } - teraph.grade++; - teraph.atk = 0; - teraph.agi = 0; - teraph.def = 0; - teraph.hp = 0; - teraph.luk = 0; - teraph.mdef = 0; - if (getTeraph(index, teraph.grade)) + teraph.grade++; + if (!getTeraph(index, teraph.grade)) return resResult(STATUS.DIC_DATA_NOT_FOUND) let consumes = teraphInfo.upGradeMaterial; let result = await handleCost(roleId, sid, consumes); diff --git a/game-server/app/services/roleService.ts b/game-server/app/services/roleService.ts new file mode 100644 index 000000000..271375d86 --- /dev/null +++ b/game-server/app/services/roleService.ts @@ -0,0 +1,59 @@ +import { getRandNum, getRandomArr } from '../pubUtils/util'; +import { EquipModel } from "../db/Equip"; +import { HeroModel, EPlace } from "../db/Hero"; +import { ITID } from "../consts/constModules/itemConst"; +import { getHeroJob, getGoodById, gameData, getJewelById, getHeroEquipByClassId } from "../pubUtils/data"; +import { calPlayerCeAndSave } from "./playerCeService"; +import { TERAPH_RANDOM } from "../consts/consts"; +import { getTeraphAttr } from '../consts/constModules/abilityConst'; +const _ = require('underscore'); +const TERAPH_STRENGTHEN = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; +export function checkMaterialEnough(type: number, attrs:Array, teraphInfo: any, teraph: any) { + let res = {}; + let consumes = []; + let times = 0; + if (type == 1) { + let num = getRandNum(TERAPH_RANDOM.MIN, TERAPH_RANDOM.MAX); + let arr = getRandomArr(attrs, num) + let critical = getRandNum(0, 100); + let criEffect = 1; + if (critical <= teraphInfo.criRate) + criEffect = teraphInfo.criEffect; + for (let attrName of arr) { + let attrNameMax = attrName+'Max'; + res[attrName] = teraphInfo[attrName] * criEffect; + if (teraph[attrName] + res[attrName] > teraphInfo[attrNameMax]) { + res[attrName] = teraphInfo[attrNameMax] - teraph[attrName]; + } + } + times++; + } else { + let criticalArr = getRandomArr(TERAPH_STRENGTHEN, 2); + for (let item of TERAPH_STRENGTHEN) { + if (!attrs.length) { + break; + } + let criEffect = 1; + let index = _.indexOf(criticalArr, {item}); + if (index > 0) { + criEffect = teraphInfo.criEffect; + } + let num = getRandNum(TERAPH_RANDOM.MIN, TERAPH_RANDOM.MAX); + let arr = getRandomArr(attrs, num); + for (let attrName of arr) { + res[attrName] = (res[attrName]||0) + teraphInfo[attrName] * criEffect; + let attrNameMax = attrName+'Max'; + if (teraph[attrName] + res[attrName] > teraphInfo[attrNameMax]) { + res[attrName] = teraphInfo[attrNameMax] - teraph[attrName]; + let attrIndex = _.indexOf(criticalArr, {attrName}); + attrs.splice(attrIndex, 1); + } + } + times++; + } + } + for (let {id, count} of teraphInfo.upMaterial) { + consumes.push({ id, count: count*times}); + } + return {attr: res, consumes}; +} \ No newline at end of file diff --git a/shared/consts/consts.ts b/shared/consts/consts.ts index 1f594b86a..d7d5c5983 100644 --- a/shared/consts/consts.ts +++ b/shared/consts/consts.ts @@ -354,6 +354,11 @@ export const JOB_TYPE = { MAGIC: 2 } +export const TERAPH_RANDOM = { + MIN: 2, + MAX: 4 +} + export const SPECIAL_ATTR = { WAR_ID: 1, TREASURE_ID: 2, diff --git a/shared/pubUtils/util.ts b/shared/pubUtils/util.ts index 039c861f5..ea5a33319 100644 --- a/shared/pubUtils/util.ts +++ b/shared/pubUtils/util.ts @@ -527,4 +527,23 @@ export function returnHeroCeRatio(hero: HeroType) { // 缩小战力 export function reduceCe(ce: number = 0) { return Math.floor(ce / HERO_CE_RATIO / HERO_CE_RATIO) +} + +export function getRandNum(min, max) { + let randNum = min + Math.floor(Math.random()*(max - min + 1)); + return randNum; +} + +export function getRandomArr(allarr, ranNum) { + let arr = deepCopy(allarr); + var result = []; + if (arr.length <= ranNum) { + result = result.concat(arr); + return result; + } + for (var i = 0; i < ranNum; i++) { + var ran = Math.floor(Math.random() * arr.length); + result.push(arr.splice(ran, 1)[0]); + }; + return result; } \ No newline at end of file