神像强化十次
This commit is contained in:
@@ -10,7 +10,8 @@ import { getTeraphAttr } from '../../../consts/constModules/abilityConst'
|
|||||||
const _ = require('underscore');
|
const _ = require('underscore');
|
||||||
import { SclResultInter, SclPosInter } from '../../../pubUtils/interface';
|
import { SclResultInter, SclPosInter } from '../../../pubUtils/interface';
|
||||||
import { SchoolModel } from '../../../db/School';
|
import { SchoolModel } from '../../../db/School';
|
||||||
|
import { TERAPH_RANDOM } from '../../../consts/consts';
|
||||||
|
import { checkMaterialEnough } from '../../../services/roleService'
|
||||||
export default function(app: Application) {
|
export default function(app: Application) {
|
||||||
return new RoleHandler(app);
|
return new RoleHandler(app);
|
||||||
}
|
}
|
||||||
@@ -105,23 +106,18 @@ export class RoleHandler {
|
|||||||
let teraphInfo = getTeraph(id, teraph.grade);
|
let teraphInfo = getTeraph(id, teraph.grade);
|
||||||
if (!teraphInfo)
|
if (!teraphInfo)
|
||||||
return resResult(STATUS.DIC_DATA_NOT_FOUND)
|
return resResult(STATUS.DIC_DATA_NOT_FOUND)
|
||||||
let falg = true;
|
let attrs = [];
|
||||||
for (let attrName in getTeraphAttr()) {
|
for (let attrName in getTeraphAttr()) {
|
||||||
if (teraph[attrName] != teraphInfo[attrName]) {
|
let attrNameMax = attrName+'Max';
|
||||||
falg = false;
|
if (teraph[attrName] < teraphInfo[attrNameMax]) {
|
||||||
break;
|
attrs.push(attrName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!!falg)
|
if (!attrs.length)
|
||||||
return resResult(STATUS.ROLE_TERAPH_NOT_STRENGTHEN);
|
return resResult(STATUS.ROLE_TERAPH_NOT_STRENGTHEN);
|
||||||
//TODO强化属性
|
let {attr, consumes} = checkMaterialEnough(type, attrs, teraphInfo, teraph);
|
||||||
let consumes;
|
for (let key in attr) {
|
||||||
if (type == 1) {
|
teraph[key] += attr[key];
|
||||||
consumes = teraphInfo.upMaterial;
|
|
||||||
} else if (type == 2) {
|
|
||||||
consumes = teraphInfo.upMaterial;
|
|
||||||
} else {
|
|
||||||
return resResult(STATUS.WRONG_PARMS);
|
|
||||||
}
|
}
|
||||||
let result = await handleCost(roleId, sid, consumes);
|
let result = await handleCost(roleId, sid, consumes);
|
||||||
if (!result)
|
if (!result)
|
||||||
@@ -144,17 +140,12 @@ export class RoleHandler {
|
|||||||
if (!teraphInfo)
|
if (!teraphInfo)
|
||||||
return resResult(STATUS.DIC_DATA_NOT_FOUND)
|
return resResult(STATUS.DIC_DATA_NOT_FOUND)
|
||||||
for (let attrName in getTeraphAttr()) {
|
for (let attrName in getTeraphAttr()) {
|
||||||
if (teraph[attrName] != teraphInfo[attrName])
|
if (teraph[attrName] != teraphInfo[attrName +'Max'])
|
||||||
return resResult(STATUS.ROLE_TERAPH_NOT_QUILITY);
|
return resResult(STATUS.ROLE_TERAPH_NOT_QUILITY);
|
||||||
|
teraph[attrName] = 0;
|
||||||
}
|
}
|
||||||
teraph.grade++;
|
teraph.grade++;
|
||||||
teraph.atk = 0;
|
if (!getTeraph(index, teraph.grade))
|
||||||
teraph.agi = 0;
|
|
||||||
teraph.def = 0;
|
|
||||||
teraph.hp = 0;
|
|
||||||
teraph.luk = 0;
|
|
||||||
teraph.mdef = 0;
|
|
||||||
if (getTeraph(index, teraph.grade))
|
|
||||||
return resResult(STATUS.DIC_DATA_NOT_FOUND)
|
return resResult(STATUS.DIC_DATA_NOT_FOUND)
|
||||||
let consumes = teraphInfo.upGradeMaterial;
|
let consumes = teraphInfo.upGradeMaterial;
|
||||||
let result = await handleCost(roleId, sid, consumes);
|
let result = await handleCost(roleId, sid, consumes);
|
||||||
|
|||||||
@@ -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};
|
||||||
|
}
|
||||||
@@ -354,6 +354,11 @@ export const JOB_TYPE = {
|
|||||||
MAGIC: 2
|
MAGIC: 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const TERAPH_RANDOM = {
|
||||||
|
MIN: 2,
|
||||||
|
MAX: 4
|
||||||
|
}
|
||||||
|
|
||||||
export const SPECIAL_ATTR = {
|
export const SPECIAL_ATTR = {
|
||||||
WAR_ID: 1,
|
WAR_ID: 1,
|
||||||
TREASURE_ID: 2,
|
TREASURE_ID: 2,
|
||||||
|
|||||||
@@ -528,3 +528,22 @@ export function returnHeroCeRatio(hero: HeroType) {
|
|||||||
export function reduceCe(ce: number = 0) {
|
export function reduceCe(ce: number = 0) {
|
||||||
return Math.floor(ce / HERO_CE_RATIO / HERO_CE_RATIO)
|
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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user