主线:添加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
@@ -436,8 +436,8 @@ export class NormalBattleHandler {
} }
// 关卡列表 // 关卡列表
async receiveChapterBox(msg: { chapter: number, id: number }, session: BackendSession) { async receiveChapterBox(msg: { chapter: number, id: number, warType: number }, session: BackendSession) {
const { id, chapter } = msg; const { id, chapter, warType } = msg;
if(!isNumber(id)) return resResult(STATUS.WRONG_PARMS); if(!isNumber(id)) return resResult(STATUS.WRONG_PARMS);
let roleId = session.get('roleId'); let roleId = session.get('roleId');
@@ -447,14 +447,13 @@ export class NormalBattleHandler {
let role = await RoleModel.findByRoleId(roleId, 'warStar receivedBox'); let role = await RoleModel.findByRoleId(roleId, 'warStar receivedBox');
let ids: number[] = []; let ids: number[] = [];
let rewards: RewardInter[] = []; 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) { for(let id of boxIds) {
let dicBox = gameData.mainBox.get(id); let dicBox = gameData.mainBox.get(id);
if(dicBox && dicBox.chapter == chapter) { if(dicBox && dicBox.chapter == chapter && dicBox.warType == warType) {
let star = starOfChapter.get(chapter)
if(star >= dicBox.star) { if(star >= dicBox.star) {
rewards.push(...dicBox.reward); rewards.push(...dicBox.reward);
ids.push(id); ids.push(id);
+17 -14
View File
@@ -195,28 +195,31 @@ export async function getBattleList(role: RoleType, type: number) {
return result; return result;
} }
export function getStarOfChapter(warStar: WarStar[]) { export function getStarOfChapter(warStar: WarStar[], warTye: number, chapter: number) {
let map = new Map<number, number>(); let starOfChapter = 0
for(let { id, star } of warStar ) { for(let { id, star } of warStar ) {
let dicWar = gameData.war.get(id); let dicWar = gameData.war.get(id);
if(dicWar.warType == WAR_TYPE.NORMAL && star > 0) { if(dicWar.warType == warTye && star > 0) {
if(!map.has(dicWar.chapter)) { starOfChapter += star;
map.set(dicWar.chapter, star);
} else {
map.set(dicWar.chapter, map.get(dicWar.chapter) + star);
}
} }
} }
return map; return starOfChapter;
} }
export function getMainChapter(role: RoleType) { export function getMainChapter(role: RoleType) {
let chapterMap = getStarOfChapter(role.warStar); let chapterArr: { chapter: number, star: number, warType: number }[] = [];
let chapterArr: { chapter: number, star: number }[] = []; for(let { id, star } of role.warStar ) {
for(let [ chapter, star ] of chapterMap) { let dicWar = gameData.war.get(id);
chapterArr.push({ chapter, star }); 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 { return {
star: chapterArr, star: chapterArr,
receivedBox: role.receivedBox||[], receivedBox: role.receivedBox||[],
+7 -4
View File
@@ -12,10 +12,12 @@ export interface DicMainStarBox {
readonly star: number; readonly star: number;
// 奖励 // 奖励
readonly reward: RewardInter[]; readonly reward: RewardInter[];
// 主线类型
readonly warType: number;
} }
export const dicMainStarBox = new Map<number, DicMainStarBox>(); 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() { export function loadMainStarBox() {
dicMainStarBox.clear(); dicMainStarBox.clear();
dicMainStarBoxByChapter.clear(); dicMainStarBoxByChapter.clear();
@@ -24,11 +26,12 @@ export function loadMainStarBox() {
arr.forEach(o => { arr.forEach(o => {
o.reward = parseGoodStr(o.reward); o.reward = parseGoodStr(o.reward);
o.warType = o.maintype;
dicMainStarBox.set(o.id, o); dicMainStarBox.set(o.id, o);
if(!dicMainStarBoxByChapter.has(o.chapter)) { if(!dicMainStarBoxByChapter.has(`${o.warType}_${o.chapter}`)) {
dicMainStarBoxByChapter.set(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; arr = undefined;
} }
@@ -172,167 +172,167 @@
"chapter": 1, "chapter": 1,
"star": 6, "star": 6,
"reward": "31002&500", "reward": "31002&500",
"maintype": 2 "maintype": 12
}, },
{ {
"id": 26, "id": 26,
"chapter": 1, "chapter": 1,
"star": 12, "star": 12,
"reward": "31002&500", "reward": "31002&500",
"maintype": 2 "maintype": 12
}, },
{ {
"id": 27, "id": 27,
"chapter": 1, "chapter": 1,
"star": 18, "star": 18,
"reward": "22001&30", "reward": "22001&30",
"maintype": 2 "maintype": 12
}, },
{ {
"id": 28, "id": 28,
"chapter": 2, "chapter": 2,
"star": 6, "star": 6,
"reward": "31002&500", "reward": "31002&500",
"maintype": 2 "maintype": 12
}, },
{ {
"id": 29, "id": 29,
"chapter": 2, "chapter": 2,
"star": 12, "star": 12,
"reward": "31002&500", "reward": "31002&500",
"maintype": 2 "maintype": 12
}, },
{ {
"id": 30, "id": 30,
"chapter": 2, "chapter": 2,
"star": 18, "star": 18,
"reward": "22001&30", "reward": "22001&30",
"maintype": 2 "maintype": 12
}, },
{ {
"id": 31, "id": 31,
"chapter": 3, "chapter": 3,
"star": 6, "star": 6,
"reward": "31002&500", "reward": "31002&500",
"maintype": 2 "maintype": 12
}, },
{ {
"id": 32, "id": 32,
"chapter": 3, "chapter": 3,
"star": 12, "star": 12,
"reward": "31002&500", "reward": "31002&500",
"maintype": 2 "maintype": 12
}, },
{ {
"id": 33, "id": 33,
"chapter": 3, "chapter": 3,
"star": 18, "star": 18,
"reward": "22001&30", "reward": "22001&30",
"maintype": 2 "maintype": 12
}, },
{ {
"id": 34, "id": 34,
"chapter": 4, "chapter": 4,
"star": 6, "star": 6,
"reward": "31002&500", "reward": "31002&500",
"maintype": 2 "maintype": 12
}, },
{ {
"id": 35, "id": 35,
"chapter": 4, "chapter": 4,
"star": 12, "star": 12,
"reward": "31002&500", "reward": "31002&500",
"maintype": 2 "maintype": 12
}, },
{ {
"id": 36, "id": 36,
"chapter": 4, "chapter": 4,
"star": 18, "star": 18,
"reward": "22001&30", "reward": "22001&30",
"maintype": 2 "maintype": 12
}, },
{ {
"id": 37, "id": 37,
"chapter": 5, "chapter": 5,
"star": 7, "star": 7,
"reward": "31002&500", "reward": "31002&500",
"maintype": 2 "maintype": 12
}, },
{ {
"id": 38, "id": 38,
"chapter": 5, "chapter": 5,
"star": 14, "star": 14,
"reward": "31002&500", "reward": "31002&500",
"maintype": 2 "maintype": 12
}, },
{ {
"id": 39, "id": 39,
"chapter": 5, "chapter": 5,
"star": 21, "star": 21,
"reward": "31002&500", "reward": "31002&500",
"maintype": 2 "maintype": 12
}, },
{ {
"id": 40, "id": 40,
"chapter": 5, "chapter": 5,
"star": 28, "star": 28,
"reward": "22001&30", "reward": "22001&30",
"maintype": 2 "maintype": 12
}, },
{ {
"id": 41, "id": 41,
"chapter": 6, "chapter": 6,
"star": 7, "star": 7,
"reward": "31002&500", "reward": "31002&500",
"maintype": 2 "maintype": 12
}, },
{ {
"id": 42, "id": 42,
"chapter": 6, "chapter": 6,
"star": 14, "star": 14,
"reward": "31002&500", "reward": "31002&500",
"maintype": 2 "maintype": 12
}, },
{ {
"id": 43, "id": 43,
"chapter": 6, "chapter": 6,
"star": 21, "star": 21,
"reward": "31002&500", "reward": "31002&500",
"maintype": 2 "maintype": 12
}, },
{ {
"id": 44, "id": 44,
"chapter": 6, "chapter": 6,
"star": 28, "star": 28,
"reward": "22001&30", "reward": "22001&30",
"maintype": 2 "maintype": 12
}, },
{ {
"id": 45, "id": 45,
"chapter": 7, "chapter": 7,
"star": 7, "star": 7,
"reward": "31002&500", "reward": "31002&500",
"maintype": 2 "maintype": 12
}, },
{ {
"id": 46, "id": 46,
"chapter": 7, "chapter": 7,
"star": 14, "star": 14,
"reward": "31002&500", "reward": "31002&500",
"maintype": 2 "maintype": 12
}, },
{ {
"id": 47, "id": 47,
"chapter": 7, "chapter": 7,
"star": 21, "star": 21,
"reward": "31002&500", "reward": "31002&500",
"maintype": 2 "maintype": 12
}, },
{ {
"id": 48, "id": 48,
"chapter": 7, "chapter": 7,
"star": 28, "star": 28,
"reward": "22001&30", "reward": "22001&30",
"maintype": 2 "maintype": 12
} }
] ]