装备:洗练

This commit is contained in:
luying
2022-02-17 12:41:40 +08:00
parent 82b15e5792
commit 2bfc27356f
10 changed files with 1295 additions and 1992 deletions

View File

@@ -1,5 +1,5 @@
// 武将特技表
import { readFileAndParse, parseNumberList } from '../util'
import { readFileAndParse, decodeArrayListStr } from '../util'
import { FILENAME } from '../../consts'
export interface DicRandomEffectPool {
@@ -16,6 +16,10 @@ export interface DicRandomEffectPool {
readonly Min: number;
// 随机最大值
readonly Max: number;
// 分割
readonly gap: number;
// 分割
readonly rate: {min: number, max: number, weight: number}[];
}
@@ -26,8 +30,22 @@ export function loadRandomEffectPool() {
let arr = readFileAndParse(FILENAME.DIC_RANDOM_EFFECT_POOL);
arr.forEach(o => {
o.gainValueArr = parseNumberList(o.gainValue)
o.rate = parseRate(o.count)
dicRandomEffectPool.set(o.id, o);
});
arr = undefined;
}
function parseRate(str: string) {
let result: {min: number, max: number, weight: number}[] = [];
if(!str) return result;
let decodeArr = decodeArrayListStr(str);
for(let [min, max, weight] of decodeArr) {
if(isNaN(parseInt(min)) || isNaN(parseInt(max)) || isNaN(parseInt(weight))) {
throw new Error('data table format wrong');
}
result.push({min: parseInt(min), max: parseInt(max), weight: parseInt(weight) });
}
return result
}

View File

@@ -4,7 +4,7 @@ import { HeroModel, HeroType, } from '../db/Hero';
import { ItemModel } from '../db/Item';
import { gameData } from './data';
import { ITID, CURRENCY_BY_TYPE, CURRENCY_TYPE, ROLE_SELECT, FIGURE_UNLOCK_CONDITION, CONSUME_TYPE, HERO_SYSTEM_TYPE, ITEM_CHANGE_REASON } from '../consts';
import { getRandValueByMinMax, getRandEelm } from './util';
import { getRandValueByMinMax, getRandEelm, getRandEelmWithWeight, getDecimalCnt } from './util';
import { findWhere } from 'underscore';
import { RoleModel, RoleType, } from '../db/Role';
@@ -111,15 +111,30 @@ export async function getAddJewelInfo(roleId: string, roleName: string, jewel: {
let randomResult: number[] = getRandEelm(randomEffect, effectCount);
let randSe: Array<RandSe> = randomResult.map((id: number, index: number) => {
let random = gameData.randomEffectPool.get(id)
let rand = 0;
if (random.id > 0) rand = getRandValueByMinMax(random.Min, random.Max, 0);
return new RandSe(index + 1, random.id, rand);
return getJewelRandSe(index + 1, id);
});
return { roleId, roleName, id, name, randSe };
}
/**
* 天晶石已知词条随机值
* @param id 词条位置,第几条
* @param seid 词条id
* @returns
*/
export function getJewelRandSe(id: number, seid: number) {
let dicRandom = gameData.randomEffectPool.get(seid)
let rand = 0;
if (dicRandom.id > 0) {
let randRange = getRandEelmWithWeight(dicRandom.rate);
let randResult = getRandValueByMinMax(randRange.dic.min, randRange.dic.max, getDecimalCnt(dicRandom.gap));
let n = Math.floor((randResult - dicRandom.Min)/dicRandom.gap);
rand = dicRandom.Min + n * dicRandom.gap;
}
return new RandSe(id, dicRandom.id, rand);
}
/**
* @description 获取元宝物品 { id, count }
* @param count 元宝数量

View File

@@ -184,7 +184,8 @@ export async function calPlayerCe(hero: HeroType, update: HeroUpdate, type: numb
heroAttrs = calEquipPutOnOrOffStoneIncAttr(hero, update, args, params, addSeidList, removeSeidList);
break;
case HERO_SYSTEM_TYPE.JEWEL_RESET_RANDSE:
heroAttrs = calJewelResetRandSe(hero, args, params, addSeidList, removeSeidList);
case HERO_SYSTEM_TYPE.JEWEL_QUENCH:
heroAttrs = calJewelResetRandSeIncAttr(hero, args, params, addSeidList, removeSeidList);
break;
case HERO_SYSTEM_TYPE.EQUIP: //
heroAttrs = calEquipPutOnOffIncAttr(hero, args, addSeidList, removeSeidList);
@@ -784,7 +785,7 @@ function updateHeroAttrOfStone(heroAttrs: CeAttrData[], equip: EPlace, ratio: nu
}
export function calJewelResetRandSe(hero: HeroType, eplaceIds: number[], params: { oldJewel: JewelType, newJewel: JewelType }, addSeidList: number[], removeSeidList: number[]) {
export function calJewelResetRandSeIncAttr(hero: HeroType, eplaceIds: number[], params: { oldJewel: JewelType, newJewel: JewelType }, addSeidList: number[], removeSeidList: number[]) {
let { attr: heroAttrs, ePlace } = hero;
for(let eplaceId of eplaceIds) {
let equip = ePlace.find(cur => cur.id == eplaceId);

View File

@@ -180,7 +180,7 @@ export function shouldRefreshWeek(preTime: Date, now: Date, day: number = 1, hou
*/
export function getRandEelm<T>(source: Array<T> = [], cnt = 1): Array<T> {
if (cnt == 0) return [];
if (cnt >= source.length) return source;
if (cnt >= source.length) return sortArrRandom(source);
let idxs = new Set();
while (1) {
@@ -337,6 +337,11 @@ export const cal = {
}
};
export function getDecimalCnt(num: number) {
let str = num.toString();
return str.split('.')[1]? str.split('.')[1].length: 0;
}
//计算公式
// export function calculateNum(ratio: { A: number, B: number }, params: { num: number }, defaultVal = 0) {
// // result = a * num + b