属性随机使用既有方法
This commit is contained in:
@@ -6,7 +6,7 @@ import { EquipModel, RandSe, Holes } from './../db/Equip';
|
||||
import { BagInter, EquipInter } from './interface';
|
||||
import { gameData } from './data';
|
||||
import { RANDOM_SE_COUNT, FIX_ATTRIBUTES_RAN, ITID } from '../consts';
|
||||
import { getRandomByLen } from './util';
|
||||
import { getRandValueByMinMax, getRandEelm } from './util';
|
||||
|
||||
const _ = require('underscore');
|
||||
|
||||
@@ -35,24 +35,22 @@ export async function addEquips(roleId: string, roleName: string, weapon: EquipI
|
||||
let {type} = ITID.get(itid);
|
||||
|
||||
let randomNum = RANDOM_SE_COUNT.get(quality);
|
||||
let pool = randomEffect.map(cur => gameData.randomEffectPool.get(cur));
|
||||
let chosen = new Array<number>();
|
||||
let randSe = new Array<RandSe>();
|
||||
for(let i = 0; i < randomNum; i++) {
|
||||
pool = pool.filter(cur => !chosen.includes(cur.id));
|
||||
let random = getRandomByLen(pool);
|
||||
if(!random) break;
|
||||
chosen.push(random.id);
|
||||
let randomResult: number[] = getRandEelm(randomEffect, randomNum);
|
||||
|
||||
let randSe: Array<RandSe> = randomResult.map((id: number, i: number) => {
|
||||
let random = gameData.randomEffectPool.get(id)
|
||||
let rand = 0;
|
||||
if(random.id > 0) rand = Math.floor(Math.random() * (random.Max - random.Min) + random.Min);
|
||||
randSe.push({
|
||||
if(random.id > 0) rand = getRandValueByMinMax(random.Min, random.Max, 0);
|
||||
return {
|
||||
id: i + 1,
|
||||
seid: random.id,
|
||||
rand,
|
||||
locked: false
|
||||
});
|
||||
}
|
||||
let randRange = Math.floor(Math.random() * FIX_ATTRIBUTES_RAN * 2) - FIX_ATTRIBUTES_RAN;
|
||||
};
|
||||
});
|
||||
|
||||
let randRange = getRandValueByMinMax(0 - FIX_ATTRIBUTES_RAN, FIX_ATTRIBUTES_RAN, 0);
|
||||
|
||||
let holes = new Array<Holes>();
|
||||
for(let i = 0; i < hole; i++) {
|
||||
holes.push({id: i+1, isOpen: false, jewel: 0})
|
||||
|
||||
@@ -293,6 +293,19 @@ export function getRandValue(base: number, ratio: number, decimal = 2): number {
|
||||
return parseFloat((base * (1 - ratio + Math.random() * ratio * 2)).toFixed(decimal));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 在给定最大最小值中随机一个值
|
||||
* @param min 最小
|
||||
* @param max 最大
|
||||
* @param decimal 返回值保留的小数位数
|
||||
*/
|
||||
export function getRandValueByMinMax(min: number, max: number, decimal = 2): number {
|
||||
return parseFloat((min + (max - min) * Math.random()).toFixed(decimal));
|
||||
|
||||
}
|
||||
|
||||
|
||||
export function resResult(status: {code: number, simStr: string}, data = null, customMsg = '') {
|
||||
const { code, simStr } = status;
|
||||
if (code !== STATUS.SUCCESS.code) {
|
||||
|
||||
Reference in New Issue
Block a user