武将重生:添加消耗记录

This commit is contained in:
luying
2022-02-26 17:41:39 +08:00
parent 0e14ea0440
commit cf920c0c80
3 changed files with 104 additions and 42 deletions

View File

@@ -7,7 +7,7 @@ import { Teraph, RoleModel, RoleType, RoleUpdate } from '../db/Role';
import { SCHOOL } from '../pubUtils/dicParam';
import { gameData } from '../pubUtils/data';
import { SchoolModel } from '../db/School';
import { SclResultInter, SclPosInter, RewardInter } from '../pubUtils/interface';
import { SclResultInter, SclPosInter, RewardInter, ItemInter } from '../pubUtils/interface';
import { CheckMeterial } from './rewardService';
import { HeroUpdate } from '../db/Hero';
import { SkinUpdate } from '../db/Skin';
@@ -153,9 +153,22 @@ export function getInitHeroById(hid: number) {
}
}
export function addConsumeToHero(oldConsume: Reward[], consumes: RewardInter[]) {
export function addConsumeToHero(oldConsume: Reward[] = [], consumes: ItemInter[] = []) {
let consumeMap = new Map<number, number>();
for(let { id, count = 1 } of consumes) {
consumeMap.set(id, count);
}
let newConsume: Reward[] = [];
for(let {id, count} of oldConsume) {
if(consumeMap.has(id)) {
newConsume.push({ id, count: count + consumeMap.get(id)});
consumeMap.delete(id);
} else {
newConsume.push({ id, count });
}
}
for(let [id, count] of consumeMap) {
newConsume.push({ id, count });
}
return newConsume;
}