新建武将时计算初始战力

This commit is contained in:
luying
2020-12-23 18:37:59 +08:00
parent 5cbeaa83e9
commit 3732c536d2
5 changed files with 67 additions and 10 deletions
+58 -3
View File
@@ -27,7 +27,9 @@ export function calPlayerCe(globalCeAttr: CeAttr, hero: HeroType, type: number,
let addSeidList = new Array<number>();
let removeSeidList = new Array<number>();
if (type == HERO_SYSTEM_TYPE.STAR) {
if (type == HERO_SYSTEM_TYPE.INIT) {
reIncAttr = calHeroInitIncAttr(hero, addSeidList, removeSeidList); // args: 升的星盘
} else if (type == HERO_SYSTEM_TYPE.STAR) {
reIncAttr = calHeroStarIncAttr(hero, args, addSeidList); // args: 升的星盘
} else if (type == HERO_SYSTEM_TYPE.TRAIN) {
reIncAttr = calHeroTrainIncAttr(hero);
@@ -49,6 +51,8 @@ export function calPlayerCe(globalCeAttr: CeAttr, hero: HeroType, type: number,
reIncAttr = calHeroCeWhenJewelOn(hero, args);
} else if (type == HERO_SYSTEM_TYPE.JEWEL_OFF) {//宝石卸下
reIncAttr = calHeroCeWhenJewelOff(hero, args);
} else {
reIncAttr = hero.ceAttr;
}
addSeidEffect(reIncAttr, hero.ceAttr, addSeidList, removeSeidList); // 处理加值
@@ -71,9 +75,24 @@ export function calPlayerCe(globalCeAttr: CeAttr, hero: HeroType, type: number,
//修改并下发战力
export async function calPlayerCeAndSave(roleId: string, heros: Array<HeroType>, type?: number, args?: Array<number>) {
if(!heros.length) heros = await HeroModel.findByRole(roleId);
let incPlayerCe = 0;
let pushHeros = new Array<{hid: number, ce: number, incHeroCe: number}>();
let role = await RoleModel.findByRoleId(roleId);
if(!role.globalCeAttr) role.globalCeAttr = new CeAttr();
let reIncAttr: CeAttr = {}; // role表属性增量
if (type == HERO_SYSTEM_TYPE.INIT) {
reIncAttr = calRoleInitIncAttr(heros, role.globalCeAttr); // 全局变量增
}
for (let attrName in reIncAttr) {
role.globalCeAttr[attrName].fixUp = reIncAttr[attrName].fixUp;
role.globalCeAttr[attrName].ratioUp = reIncAttr[attrName].ratioUp;
}
for (let hero of heros) {
let incHeroCe = calPlayerCe(role.globalCeAttr, hero, type, args);
incPlayerCe += incHeroCe;
@@ -85,10 +104,46 @@ export async function calPlayerCeAndSave(roleId: string, heros: Array<HeroType>,
});
}
role.ce += incPlayerCe;
await RoleModel.updateRoleInfo(roleId, role);
await RoleModel.updateRoleInfo(roleId, {globalCeAttr: role.globalCeAttr, ce: role.ce});
return {pushHeros, role}
}
// 初始战力
export function calHeroInitIncAttr(hero: HeroType, addSeidList: Array<number>, removeSeidList: Array<number>) {
let res1 = calHeroStarIncAttr(hero, getAllAttrStage(), addSeidList);
let hero1 = combineHeroCeAttr(hero, res1)
calHeroJobStageUpIncAttr(hero1, [0], addSeidList, removeSeidList);
console.log(JSON.stringify(res1));
return res1
}
export function calRoleInitIncAttr(heros: HeroType[], globalCeAttr: CeAttr) {
let args = new Array<number>();
for(let hero of heros) {
for(let skin of hero.skins) {
args.push(skin.id);
}
}
let res = calHeroAddSkin(args, globalCeAttr);
return res;
}
// 将hero的ceAttr暂时更新,不更新在originalHero本体上
function combineHeroCeAttr(originalHero: HeroType, result: CeAttr) {
let hero = deepCopy(originalHero);
if(!hero.ceAttr) hero.ceAttr = new CeAttr();
for (let attrName in result) {
if(!result[attrName]) continue;
if(!hero.ceAttr[attrName]) hero.ceAttr[attrName] = new CeAttrData();
for (let attrKey in result[attrName]) {
hero.ceAttr[attrName][attrKey] = parseInt(result[attrName][attrKey]||0);
}
}
delete hero._id;
return hero;
}
export function calHeroStarIncAttr (hero: HeroType, args: Array<number>, addSeidList: Array<number>) {
let {star, starStage, quality, colorStar, colorStarStage, ceAttr} = hero;
let res: CeAttr = {};
@@ -165,7 +220,7 @@ export function calHeroTrainIncAttr(hero: HeroType) {
//进阶
export function calHeroJobStageUpIncAttr(hero: HeroType, args: Array<number>, addSeidList: Array<number>, removeSeidList: Array<number>) {
let res: CeAttr = {};
let lastJob = gameData.job.get(args[0]);
let lastJob = gameData.job.get(args[0])||{seid:[]};
let currentJob = gameData.job.get(hero.job);
for (let seid of currentJob.seid) {
let index = _.findIndex(lastJob.seid, seid);
+1 -1
View File
@@ -269,7 +269,7 @@ export function getRefTime(now = new Date(), hour: number, day = 0) {
* @param cnt 返回随机元素个数
*/
export function getRandEelm(source: Array<any> = [], cnt = 1): Array<any> {
if (cnt > source.length) return [];
if (cnt > source.length || cnt == 0 ) return [];
if (cnt === source.length) return source;
let idxs = new Set();