创建武将
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
import { HERO_SYSTEM_TYPE, ABI_TYPE, HERO_CE_RATIO, LINEUP_NUM, TALENT_RELATION_TYPE } from '../consts';
|
||||
|
||||
import { cal, deepCopy, getAllAttrStage, reduceCe } from './util';
|
||||
import { cal, calculatetopLineup, deepCopy, getAllAttrStage, reduceCe } from './util';
|
||||
import { HeroModel, HeroType, HeroUpdate, CeAttrData, EPlace, Stone, Talent } from '../db/Hero';
|
||||
import { RoleModel, RoleType, RoleUpdate, CeAttrDataRole } from '../db/Role';
|
||||
import { AttributeCal } from '../domain/roleField/attribute';
|
||||
@@ -209,53 +209,6 @@ export async function calPlayerCe(hero: HeroType, update: HeroUpdate, type: numb
|
||||
return heroAttrs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算最强阵容战力
|
||||
* @param role
|
||||
* @param hid
|
||||
* @param ce
|
||||
* @param heroId
|
||||
*/
|
||||
export async function calculatetopLineup(role: RoleType, hid?: number, ce?: number, heroId?: string) {
|
||||
let topLineup = role?.topLineup || new Array();
|
||||
if(!hid) { // 直接重新排
|
||||
let heroes = await HeroModel.getTopHero(role.roleId, LINEUP_NUM);
|
||||
topLineup = heroes.map(cur => { return { hid: cur.hid, ce: cur.ce, hero: cur._id } });
|
||||
} else {
|
||||
topLineup.sort((a, b) => { return b.ce - a.ce }); // 0-6,最大-最小
|
||||
let index = topLineup.findIndex(cur => cur.hid == hid);
|
||||
if(index != -1 && !heroId) {
|
||||
let heroes = await HeroModel.getTopHero(role.roleId, LINEUP_NUM);
|
||||
topLineup = heroes.map(cur => { return { hid: cur.hid, ce: cur.ce, hero: cur._id } });
|
||||
} else {
|
||||
if (index == -1) { // 不在最强列表
|
||||
if (topLineup.length < LINEUP_NUM) { // 不满6人
|
||||
topLineup.push({ hid, ce, hero: heroId });
|
||||
} else if (topLineup.length == LINEUP_NUM) {
|
||||
if (ce > topLineup[topLineup.length - 1].ce) { // 跻身最强6人
|
||||
topLineup.pop();
|
||||
topLineup.push({ hid, ce, hero: heroId });
|
||||
}
|
||||
} else {
|
||||
topLineup.splice(LINEUP_NUM, topLineup.length - LINEUP_NUM);
|
||||
}
|
||||
} else { // 原来就是最强6人
|
||||
if (ce < topLineup[topLineup.length - 1].ce) { // 滑出最强
|
||||
let heroes = await HeroModel.getTopHero(role.roleId, LINEUP_NUM);
|
||||
topLineup = heroes.map(cur => { return { hid: cur.hid, ce: cur.ce, hero: cur._id } });
|
||||
} else {
|
||||
topLineup[index].ce = ce;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let topLineupCe = topLineup.reduce((pre, cur) => {
|
||||
return pre + cur.ce
|
||||
}, 0);
|
||||
|
||||
return { topLineup, topLineupCe };
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加皮肤全局加成
|
||||
|
||||
+58
-1
@@ -6,13 +6,14 @@ import { isNumber } from 'underscore';
|
||||
const csprng = require('csprng');
|
||||
import fs = require('fs');
|
||||
import path = require('path');
|
||||
import { HERO_CE_RATIO, ABI_STAGE, GACHA_TO_FLOOR, REFRESH_TIME, ROBOT_SYS_TYPE, ITEM_CHANGE_REASON, WAR_TYPE } from '../consts';
|
||||
import { HERO_CE_RATIO, ABI_STAGE, GACHA_TO_FLOOR, REFRESH_TIME, ROBOT_SYS_TYPE, ITEM_CHANGE_REASON, WAR_TYPE, LINEUP_NUM } from '../consts';
|
||||
|
||||
import { findIndex } from 'underscore';
|
||||
import { getTimeFunM } from './timeUtil';
|
||||
import { Floor } from '../domain/activityField/gachaField';
|
||||
import { WhiteListModel } from '../db/RegionWhiteList';
|
||||
import { RewardInter } from './interface';
|
||||
import { RoleType } from '../db/Role';
|
||||
const randomName = require("chinese-random-name");
|
||||
const moment = require('moment');
|
||||
const crypto = require('crypto');
|
||||
@@ -788,3 +789,59 @@ export function stringToRewardInter(rewardStr: string): Array<RewardInter> {
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
export function addToMap<T>(map: Map<T, number>, id: T, value: number) {
|
||||
if(!map.has(id)) {
|
||||
map.set(id, value);
|
||||
} else {
|
||||
map.set(id, map.get(id) + value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算最强阵容战力
|
||||
* @param role
|
||||
* @param hid
|
||||
* @param ce
|
||||
* @param heroId
|
||||
*/
|
||||
export async function calculatetopLineup(role: RoleType, hid?: number, ce?: number, heroId?: string) {
|
||||
let topLineup = role?.topLineup || new Array();
|
||||
if(!hid) { // 直接重新排
|
||||
let heroes = await HeroModel.getTopHero(role.roleId, LINEUP_NUM);
|
||||
topLineup = heroes.map(cur => { return { hid: cur.hid, ce: cur.ce, hero: cur._id } });
|
||||
} else {
|
||||
topLineup.sort((a, b) => { return b.ce - a.ce }); // 0-6,最大-最小
|
||||
let index = topLineup.findIndex(cur => cur.hid == hid);
|
||||
if(index != -1 && !heroId) {
|
||||
let heroes = await HeroModel.getTopHero(role.roleId, LINEUP_NUM);
|
||||
topLineup = heroes.map(cur => { return { hid: cur.hid, ce: cur.ce, hero: cur._id } });
|
||||
} else {
|
||||
if (index == -1) { // 不在最强列表
|
||||
if (topLineup.length < LINEUP_NUM) { // 不满6人
|
||||
topLineup.push({ hid, ce, hero: heroId });
|
||||
} else if (topLineup.length == LINEUP_NUM) {
|
||||
if (ce > topLineup[topLineup.length - 1].ce) { // 跻身最强6人
|
||||
topLineup.pop();
|
||||
topLineup.push({ hid, ce, hero: heroId });
|
||||
}
|
||||
} else {
|
||||
topLineup.splice(LINEUP_NUM, topLineup.length - LINEUP_NUM);
|
||||
}
|
||||
} else { // 原来就是最强6人
|
||||
if (ce < topLineup[topLineup.length - 1].ce) { // 滑出最强
|
||||
let heroes = await HeroModel.getTopHero(role.roleId, LINEUP_NUM);
|
||||
topLineup = heroes.map(cur => { return { hid: cur.hid, ce: cur.ce, hero: cur._id } });
|
||||
} else {
|
||||
topLineup[index].ce = ce;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let topLineupCe = topLineup.reduce((pre, cur) => {
|
||||
return pre + cur.ce
|
||||
}, 0);
|
||||
|
||||
return { topLineup, topLineupCe };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user