神像强化十次

This commit is contained in:
mamengke01
2020-12-26 12:14:56 +08:00
parent bfa0755739
commit 667c85e686
4 changed files with 97 additions and 23 deletions

View File

@@ -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);

View File

@@ -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<any>, 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};
}

View File

@@ -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,

View File

@@ -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;
}