装备:洗练

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

@@ -28,6 +28,7 @@ export enum HERO_SYSTEM_TYPE {
EQUIP_JEWEL = 25, // 装备装上or卸下天晶石
EQUIP_STONE = 26, // 装备装上or卸下地玉石
JEWEL_RESET_RANDSE = 27, // 天晶石洗练
JEWEL_QUENCH = 28, // 天晶石淬炼
};
// 武将上限

View File

@@ -325,6 +325,9 @@ export const STATUS = {
JEWEL_HAVE_NO_RANDSE: { code: 30529, simStr: '天晶石上无随机属性' },
JEWEL_DUPLICATE_LOCK: { code: 30530, simStr: '随机属性不可重复锁定' },
JEWEL_NOT_PREVIEW: { code: 30531, simStr: '该天晶石未预览洗练值' },
JEWEL_HAS_CHOOSEN_QUENCH: { code: 30532, simStr: '每个天晶石只能选择一个词条淬炼' },
JEWEL_NOT_CHOOSEN_QUENCH: { code: 30533, simStr: '请选择一个可淬炼的词条' },
JEWEL_HAVE_NO_CUR_RANDSE: { code: 30534, simStr: '该天晶石上未找到该属性' },
//全局养成30600-30699
ROLE_REACH_MAX_TITLE_LEVEL: { code: 30600, simStr: '玩家已达到最高的爵位' },

View File

@@ -20,6 +20,8 @@ export class RandSe {
@prop({ required: false, default: false })
quenched: boolean = false; // 是否淬炼了
@prop({ required: false, default: 0 })
quenchCnt: number = 0; // 淬炼次数
constructor(id: number, seid: number, rand: number) {
this.id = id;
@@ -101,10 +103,25 @@ export default class Jewel extends BaseModel {
}
public static async lock(seqId: number, id: number, lock: boolean) {
let result: JewelType = await JewelModel.findOneAndUpdate({ seqId, 'randSe.id': id }, { $set: { 'randSe.$.locked': lock } }, { new: true, upsert: false }).select('seqId id randSe').lean();
let result: JewelType = await JewelModel.findOneAndUpdate({ seqId, 'randSe.id': id }, { $set: { 'randSe.$.locked': lock } }, { new: true }).select('seqId id randSe').lean();
return result;
}
public static async chooseQuench(seqId: number, id: number) {
let result: JewelType = await JewelModel.findOneAndUpdate({ seqId, 'randSe.id': id }, { $set: { 'randSe.$.quenched': true } }, { new: true }).lean();
return result;
}
public static async quench(seqId: number, isSuccess: boolean, rand: number) {
if(isSuccess) {
let result: JewelType = await JewelModel.findOneAndUpdate({ seqId, 'randSe.quenched': true }, { $set: { 'randSe.$.rand': rand } }, { new: true }).lean();
return result;
} else {
let result: JewelType = await JewelModel.findOneAndUpdate({ seqId, 'randSe.quenched': true }, { $inc: { 'randSe.$.quenchCnt': 1 } }, { new: true }).lean();
return result;
}
}
public static async updateInfo(seqId: number, update: jewelUpdate) {
let result: JewelType = await JewelModel.findOneAndUpdate({ seqId }, { $set: update }, {new: true}).lean();
return result;

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

File diff suppressed because it is too large Load Diff