战场:扫荡奖励

This commit is contained in:
luying
2021-11-12 16:57:07 +08:00
parent c62cd91a10
commit bcdfe1ac15
4 changed files with 30 additions and 8 deletions

View File

@@ -318,7 +318,7 @@ export class NormalBattleHandler {
// 发奖励
let warReward = new WarReward(roleId, roleName, sid, battleId, true);
let result = await warReward.saveReward(count);
let result = await warReward.saveReward(count, true);
let actordata = await roleLevelup(KING_EXP_RATIO_TYPE.BATTLE, roleId, warInfo.kingExp * count, session)// 主公升级经验
@@ -339,7 +339,7 @@ export class NormalBattleHandler {
return resResult(STATUS.SUCCESS, {
battleId, count,
battleGoods: result,
battleGoods: result,
dailyNum, dungeonNum,
...actordata
});

View File

@@ -293,6 +293,25 @@ export function combineItems(items: { id?: number, count?: number }[]) {
return result;
}
export function combineItemAndEquips(items: { id?: number, count?: number }[]) {
let result: { id: number, count: number }[] = [];
for(let { id, count = 1 } of items) {
let dicGoods = gameData.goods.get(id);
let dicItid = ITID.get(dicGoods.itid);
if(dicItid.table != 'equip') {
let index = result.findIndex(cur => cur.id == id);
if(index == -1) {
result.push({ id, count });
} else {
result[index].count += count;
}
} else {
result.push({ id, count });
}
}
return result;
}
function sortItems(goods: ItemInter[], handleType: HANDLE_REWARD_TYPE) {
let items: { id: number, count: number }[] = []; // 可叠加道具
let equips: { seqId?: number, id?: number, hid?: number }[] = []; // 不可叠加装备

View File

@@ -6,7 +6,7 @@
import { BattleDropModel } from '../db/BattleDrop';
import { getRandEelmWithWeight, getRandSingleEelm } from '../pubUtils/util';
import { BATTLE_REWARD_TYPE, BLUEPRT_CONST } from '../consts';
import { addItems } from './rewardService';
import { addItems, combineItemAndEquips } from './rewardService';
import { BattleBlueprtDropModel } from '../db/BattleBlueprtDrop'
import { RoleModel } from '../db/Role';
import { gameData } from '../pubUtils/data';
@@ -22,7 +22,7 @@ export class WarReward {
private condition: Map<number, boolean>;
private warInfo: DicWar;
private isSuccess: boolean;
private rewards: Array<{type: number, id: number, count: number, times: number}>;
private rewards: Array<{type?: number, id: number, count: number, times?: number}>;
private fixReward: Array<{id: number, count: number}>;
private conditionReward: Array<{id: number, count: number, condition: number}>;
private randomReward: Array<{id: number, count: number, frequency: number}>;
@@ -169,7 +169,7 @@ export class WarReward {
}
}
public async saveReward(num: number) {
public async saveReward(num: number, combine: boolean = false) {
this.rewards = new Array();
// let warType = this.warInfo.warType;
@@ -179,10 +179,13 @@ export class WarReward {
if(this.conditionReward) this.handleConditionReward(num, this.conditionReward);
if(this.randomReward) await this.handleRandomReward(num, this.randomReward);
if(this.costAp > 0) await this.handlerBlueprtReward(num);
// if(this.costAp > 0) await this.handlerBlueprtReward(num);
}
let rewards = this.rewards.sort((a, b) => a.times - b.times)
let rewards = this.rewards;
if(combine) {
rewards = combineItemAndEquips(rewards);
}
await addItems(this.roleId, this.roleName, this.sid, rewards);
return rewards;
}

View File

@@ -59,7 +59,7 @@ export function loadWar() {
arr.forEach(o => {
o.fixReward = parseFixReward(o.fixReward);
o.conditionReward = parseConditionReward(o.conditionReward);
o.parseRandomReward = parseRandomReward(o.RandomReward||o.randomReward);
o.randomReward = parseRandomReward(o.RandomReward||o.randomReward);
o.detailUIBg = parseDetailUIBg(o.detailUIBg);
o.jackpotReward = parseJackpotReward(o.jackpotReward);
o.teammateReward = parseFixReward(o.teammateReward);