战力计算,远征战力筛选

This commit is contained in:
luying
2020-11-12 18:21:05 +08:00
parent 40c16587b3
commit b0a0bbc71b
34 changed files with 22812 additions and 15964 deletions
+53 -24
View File
@@ -17,6 +17,9 @@ export class WarReward {
warInfo: any;
isSuccess: boolean;
rewards: Array<{type: number, gid: number, count: number, times: number}>;
fixReward: string;
conditionReward: string;
randomReward: string;
constructor(roleId: string, roleName: string, battleId: number, isSuccess: boolean) {
this.roleId = roleId;
@@ -24,6 +27,12 @@ export class WarReward {
this.battleId = battleId;
this.condition = new Map();
this.warInfo = getWarById(battleId);
let {fixReward = '', conditionReward = '', RandomReward = ''} = this.warInfo;
this.fixReward = fixReward;
this.conditionReward = conditionReward;
this.randomReward = RandomReward;
this.isSuccess = isSuccess;
}
@@ -31,34 +40,53 @@ export class WarReward {
this.condition.set(id, isOk);
}
private handleFixReward(num: number) {
if(this.isSuccess) { // 成功了才给固定奖励
let {fixReward = ''} = this.warInfo;
let reward = decodeStr('fixReward', fixReward);
for(let i = 0; i < num; i++) {
for(let obj of reward) {
this.rewards.push({type: BATTLE_REWARD_TYPE.FIX_REWARD, times: i +1, ...obj, count: obj.count });
}
public setFixReward(reward: string) {
let last = this.fixReward.substr(this.fixReward.length - 1, 1);
if(this.fixReward.length && last == '&') {
this.fixReward += reward;
} else {
this.fixReward += '&' + reward;
}
}
public setConditionReward(reward: string) {
let last = this.conditionReward.substr(this.fixReward.length - 1, 1);
if(last == '&') {
this.conditionReward += reward;
} else {
this.conditionReward += '&' + reward;
}
}
public setRandomReward(reward: string) {
let last = this.randomReward.substr(this.fixReward.length - 1, 1);
if(last == '&') {
this.randomReward += reward;
} else {
this.randomReward += '&' + reward;
}
}
private handleFixReward(num: number, fixReward: string) {
let reward = decodeStr('fixReward', fixReward);
for(let i = 0; i < num; i++) {
for(let obj of reward) {
this.rewards.push({type: BATTLE_REWARD_TYPE.FIX_REWARD, times: i +1, ...obj, count: obj.count });
}
}
}
private handleConditionReward(num: number) {
if(this.isSuccess) {
let {conditionReward = ''} = this.warInfo;
let reward = decodeStr('conditionReward', conditionReward);
for(let i = 0; i < num; i++) {
for(let obj of reward) {
if(this.condition.get(obj.condition)) {
this.rewards.push({type: BATTLE_REWARD_TYPE.CONDITION_REWARD, times: i +1, ...obj, count: obj.count});
}
private handleConditionReward(num: number, conditionReward: string) {
let reward = decodeStr('conditionReward', conditionReward);
for(let i = 0; i < num; i++) {
for(let obj of reward) {
if(this.condition.get(obj.condition)) {
this.rewards.push({type: BATTLE_REWARD_TYPE.CONDITION_REWARD, times: i +1, ...obj, count: obj.count});
}
}
}
}
private async handleRandomReward(num: number) {
if(this.isSuccess) {
let {RandomReward:randomReward = ''} = this.warInfo;
private async handleRandomReward(num: number, randomReward: string) {
let reward = decodeStr('randomReward', randomReward);
for(let obj of reward) {
@@ -86,16 +114,17 @@ export class WarReward {
getNum, allNum, getSum, allSum
});
}
}
}
public async saveReward(num: number) {
this.rewards = new Array();
// let warType = this.warInfo.warType;
this.handleFixReward(num);
this.handleConditionReward(num);
await this.handleRandomReward(num);
if(this.isSuccess) { // 成功了才给固定奖励
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);
}
let returnGoods = await handleReward(this.roleId, this.roleName, this.rewards);
return returnGoods;