名将擂台:奖励及扫荡
This commit is contained in:
@@ -22,24 +22,26 @@ 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 fixReward: Array<{id: number, count: number}>;
|
||||
private conditionReward: Array<{id: number, count: number, condition: number}>;
|
||||
private randomReward: Array<{id: number, count: number, frequency: 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}> = [];
|
||||
private ladderReward: Array<{id: number, count: number, weight: number, isSuccess: boolean}> = [];
|
||||
private costAp: number;
|
||||
|
||||
constructor(roleId: string, roleName: string, sid: string, battleId: number, isSuccess: boolean) {
|
||||
this.roleId = roleId;
|
||||
this.roleName = roleName;
|
||||
this.sid = sid;
|
||||
this.battleId = battleId;
|
||||
if(battleId) {
|
||||
this.battleId = battleId;
|
||||
this.warInfo = gameData.war.get(battleId);
|
||||
let { fixReward, conditionReward, randomReward } = this.warInfo;
|
||||
this.fixReward = fixReward;
|
||||
this.conditionReward = conditionReward;
|
||||
this.randomReward = randomReward;
|
||||
}
|
||||
this.condition = new Map();
|
||||
this.warInfo = gameData.war.get(battleId);
|
||||
|
||||
let { fixReward, conditionReward, randomReward } = this.warInfo;
|
||||
this.fixReward = fixReward;
|
||||
this.conditionReward = conditionReward;
|
||||
this.randomReward = randomReward;
|
||||
|
||||
this.isSuccess = isSuccess;
|
||||
this.costAp = this.warInfo.cost;
|
||||
@@ -71,16 +73,24 @@ export class WarReward {
|
||||
}
|
||||
}
|
||||
|
||||
private handleFixReward(num: number, fixReward: RewardInter[]) {
|
||||
public setLadderReward(reward: {id: number, count: number, weight: number}[], isSuccess: boolean) {
|
||||
for(let r of reward) {
|
||||
this.ladderReward.push({...r, isSuccess});
|
||||
}
|
||||
}
|
||||
|
||||
private handleFixReward(num: number) {
|
||||
if(!this.fixReward) return
|
||||
for(let i = 0; i < num; i++) {
|
||||
for(let obj of fixReward) {
|
||||
for(let obj of this.fixReward) {
|
||||
this.rewards.push({type: BATTLE_REWARD_TYPE.FIX_REWARD, times: i +1, ...obj, count: obj.count });
|
||||
}
|
||||
}
|
||||
}
|
||||
private handleConditionReward(num: number, conditionReward: {id: number, count: number, condition: number}[]) {
|
||||
private handleConditionReward(num: number) {
|
||||
if(!this.conditionReward) return
|
||||
for(let i = 0; i < num; i++) {
|
||||
for(let obj of conditionReward) {
|
||||
for(let obj of this.conditionReward) {
|
||||
if(this.condition.get(obj.condition)) {
|
||||
this.rewards.push({type: BATTLE_REWARD_TYPE.CONDITION_REWARD, times: i +1, ...obj, count: obj.count});
|
||||
}
|
||||
@@ -88,9 +98,9 @@ export class WarReward {
|
||||
}
|
||||
}
|
||||
|
||||
private async handleRandomReward(num: number, randomReward: {id: number, count: number, frequency: number}[]) {
|
||||
|
||||
for(let obj of randomReward) {
|
||||
private async handleRandomReward(num: number) {
|
||||
if(!this.randomReward) return
|
||||
for(let obj of this.randomReward) {
|
||||
let { id, frequency } = obj;
|
||||
let dropHistory = await BattleDropModel.findByGid(this.roleId, this.battleId, id);
|
||||
let { getNum = 0, allNum = 0, getSum = 0, allSum = 0 } = dropHistory;
|
||||
@@ -117,18 +127,30 @@ export class WarReward {
|
||||
}
|
||||
}
|
||||
|
||||
private async handleLadderReward(num: number, isSuccess: boolean) {
|
||||
if(!this.ladderReward) return;
|
||||
for(let i = 0; i < num; i++) {
|
||||
let arr = this.ladderReward.filter(cur => cur.isSuccess == isSuccess);
|
||||
let { dic: reward } = getRandEelmWithWeight(arr);
|
||||
if(reward) {
|
||||
this.rewards.push({type: BATTLE_REWARD_TYPE.RANDOM_REWARD, times: i +1, id: reward.id, count: reward.count });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async saveReward(num: number, combine: boolean = false) {
|
||||
this.rewards = new Array();
|
||||
// let warType = this.warInfo.warType;
|
||||
|
||||
if(this.isSuccess) { // 成功了才给固定奖励
|
||||
console.log(this.fixReward)
|
||||
if(this.fixReward) this.handleFixReward(num, this.fixReward);
|
||||
if(this.conditionReward) this.handleConditionReward(num, this.conditionReward);
|
||||
if(this.randomReward) await this.handleRandomReward(num, this.randomReward);
|
||||
if(this.fixReward) this.handleFixReward(num);
|
||||
if(this.conditionReward) this.handleConditionReward(num);
|
||||
if(this.randomReward) await this.handleRandomReward(num);
|
||||
|
||||
// if(this.costAp > 0) await this.handlerBlueprtReward(num);
|
||||
}
|
||||
if(this.ladderReward) this.handleLadderReward(num, this.isSuccess);
|
||||
|
||||
let rewards = this.rewards;
|
||||
if(combine) {
|
||||
|
||||
Reference in New Issue
Block a user