主线:添加warType

This commit is contained in:
luying
2022-03-14 17:08:36 +08:00
parent 992885674e
commit 7b4f500979
4 changed files with 53 additions and 48 deletions

View File

@@ -436,8 +436,8 @@ export class NormalBattleHandler {
}
// 关卡列表
async receiveChapterBox(msg: { chapter: number, id: number }, session: BackendSession) {
const { id, chapter } = msg;
async receiveChapterBox(msg: { chapter: number, id: number, warType: number }, session: BackendSession) {
const { id, chapter, warType } = msg;
if(!isNumber(id)) return resResult(STATUS.WRONG_PARMS);
let roleId = session.get('roleId');
@@ -447,14 +447,13 @@ export class NormalBattleHandler {
let role = await RoleModel.findByRoleId(roleId, 'warStar receivedBox');
let ids: number[] = [];
let rewards: RewardInter[] = [];
let starOfChapter = getStarOfChapter(role.warStar);
let star = getStarOfChapter(role.warStar, warType, chapter);
let boxIds = id == 0? gameData.mainBoxByChapter.get(chapter): [id];
let boxIds = id == 0? gameData.mainBoxByChapter.get(`${warType}_${chapter}`): [id];
for(let id of boxIds) {
let dicBox = gameData.mainBox.get(id);
if(dicBox && dicBox.chapter == chapter) {
let star = starOfChapter.get(chapter)
if(dicBox && dicBox.chapter == chapter && dicBox.warType == warType) {
if(star >= dicBox.star) {
rewards.push(...dicBox.reward);
ids.push(id);

View File

@@ -195,28 +195,31 @@ export async function getBattleList(role: RoleType, type: number) {
return result;
}
export function getStarOfChapter(warStar: WarStar[]) {
let map = new Map<number, number>();
export function getStarOfChapter(warStar: WarStar[], warTye: number, chapter: number) {
let starOfChapter = 0
for(let { id, star } of warStar ) {
let dicWar = gameData.war.get(id);
if(dicWar.warType == WAR_TYPE.NORMAL && star > 0) {
if(!map.has(dicWar.chapter)) {
map.set(dicWar.chapter, star);
} else {
map.set(dicWar.chapter, map.get(dicWar.chapter) + star);
}
if(dicWar.warType == warTye && star > 0) {
starOfChapter += star;
}
}
return map;
return starOfChapter;
}
export function getMainChapter(role: RoleType) {
let chapterMap = getStarOfChapter(role.warStar);
let chapterArr: { chapter: number, star: number }[] = [];
for(let [ chapter, star ] of chapterMap) {
chapterArr.push({ chapter, star });
let chapterArr: { chapter: number, star: number, warType: number }[] = [];
for(let { id, star } of role.warStar ) {
let dicWar = gameData.war.get(id);
if((dicWar.warType == WAR_TYPE.NORMAL || dicWar.warType == WAR_TYPE.MAIN_ELITE) && star > 0) {
let curChapter = chapterArr.find(cur => cur.warType == dicWar.warType && cur.chapter == dicWar.chapter);
if(!curChapter) {
chapterArr.push({ chapter: dicWar.chapter, star, warType: dicWar.warType });
} else {
curChapter.star += star;
}
}
}
return {
star: chapterArr,
receivedBox: role.receivedBox||[],

View File

@@ -12,10 +12,12 @@ export interface DicMainStarBox {
readonly star: number;
// 奖励
readonly reward: RewardInter[];
// 主线类型
readonly warType: number;
}
export const dicMainStarBox = new Map<number, DicMainStarBox>();
export const dicMainStarBoxByChapter = new Map<number, number[]>(); // chapter => ids;
export const dicMainStarBoxByChapter = new Map<string, number[]>(); // chapter => ids;
export function loadMainStarBox() {
dicMainStarBox.clear();
dicMainStarBoxByChapter.clear();
@@ -24,11 +26,12 @@ export function loadMainStarBox() {
arr.forEach(o => {
o.reward = parseGoodStr(o.reward);
o.warType = o.maintype;
dicMainStarBox.set(o.id, o);
if(!dicMainStarBoxByChapter.has(o.chapter)) {
dicMainStarBoxByChapter.set(o.chapter, []);
if(!dicMainStarBoxByChapter.has(`${o.warType}_${o.chapter}`)) {
dicMainStarBoxByChapter.set(`${o.warType}_${o.chapter}`, []);
}
dicMainStarBoxByChapter.get(o.chapter).push(o.id);
dicMainStarBoxByChapter.get(`${o.warType}_${o.chapter}`).push(o.id);
});
arr = undefined;
}

View File

@@ -172,167 +172,167 @@
"chapter": 1,
"star": 6,
"reward": "31002&500",
"maintype": 2
"maintype": 12
},
{
"id": 26,
"chapter": 1,
"star": 12,
"reward": "31002&500",
"maintype": 2
"maintype": 12
},
{
"id": 27,
"chapter": 1,
"star": 18,
"reward": "22001&30",
"maintype": 2
"maintype": 12
},
{
"id": 28,
"chapter": 2,
"star": 6,
"reward": "31002&500",
"maintype": 2
"maintype": 12
},
{
"id": 29,
"chapter": 2,
"star": 12,
"reward": "31002&500",
"maintype": 2
"maintype": 12
},
{
"id": 30,
"chapter": 2,
"star": 18,
"reward": "22001&30",
"maintype": 2
"maintype": 12
},
{
"id": 31,
"chapter": 3,
"star": 6,
"reward": "31002&500",
"maintype": 2
"maintype": 12
},
{
"id": 32,
"chapter": 3,
"star": 12,
"reward": "31002&500",
"maintype": 2
"maintype": 12
},
{
"id": 33,
"chapter": 3,
"star": 18,
"reward": "22001&30",
"maintype": 2
"maintype": 12
},
{
"id": 34,
"chapter": 4,
"star": 6,
"reward": "31002&500",
"maintype": 2
"maintype": 12
},
{
"id": 35,
"chapter": 4,
"star": 12,
"reward": "31002&500",
"maintype": 2
"maintype": 12
},
{
"id": 36,
"chapter": 4,
"star": 18,
"reward": "22001&30",
"maintype": 2
"maintype": 12
},
{
"id": 37,
"chapter": 5,
"star": 7,
"reward": "31002&500",
"maintype": 2
"maintype": 12
},
{
"id": 38,
"chapter": 5,
"star": 14,
"reward": "31002&500",
"maintype": 2
"maintype": 12
},
{
"id": 39,
"chapter": 5,
"star": 21,
"reward": "31002&500",
"maintype": 2
"maintype": 12
},
{
"id": 40,
"chapter": 5,
"star": 28,
"reward": "22001&30",
"maintype": 2
"maintype": 12
},
{
"id": 41,
"chapter": 6,
"star": 7,
"reward": "31002&500",
"maintype": 2
"maintype": 12
},
{
"id": 42,
"chapter": 6,
"star": 14,
"reward": "31002&500",
"maintype": 2
"maintype": 12
},
{
"id": 43,
"chapter": 6,
"star": 21,
"reward": "31002&500",
"maintype": 2
"maintype": 12
},
{
"id": 44,
"chapter": 6,
"star": 28,
"reward": "22001&30",
"maintype": 2
"maintype": 12
},
{
"id": 45,
"chapter": 7,
"star": 7,
"reward": "31002&500",
"maintype": 2
"maintype": 12
},
{
"id": 46,
"chapter": 7,
"star": 14,
"reward": "31002&500",
"maintype": 2
"maintype": 12
},
{
"id": 47,
"chapter": 7,
"star": 21,
"reward": "31002&500",
"maintype": 2
"maintype": 12
},
{
"id": 48,
"chapter": 7,
"star": 28,
"reward": "22001&30",
"maintype": 2
"maintype": 12
}
]