名将擂台:奖励及扫荡
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { LADDER_OPP_STATUS, LADDER_STATUS, PUSH_ROUTE, REDIS_KEY } from "../consts";
|
||||
import { ITEM_CHANGE_REASON, LADDER_OPP_STATUS, LADDER_STATUS, PUSH_ROUTE, REDIS_KEY } from "../consts";
|
||||
import { HeroType } from "../db/Hero";
|
||||
import { LadderMatchModel, LadderMatchType, LadderUpdateInter } from "../db/LadderMatch";
|
||||
import { LadderMatchRecModel } from "../db/LadderMatchRec";
|
||||
@@ -10,7 +10,9 @@ import { ItemInter } from "../pubUtils/interface";
|
||||
import { getRandValueByMinMax, shouldRefresh } from "../pubUtils/util";
|
||||
import { sendMessageToUserWithSuc } from "./pushService";
|
||||
import { Rank } from "./rankService";
|
||||
import { addItems } from "./role/rewardService";
|
||||
import { combineItems } from "./role/util";
|
||||
import { WarReward } from "./warRewardService";
|
||||
|
||||
export function refreshLadderDaily(ladderData: LadderMatchType) {
|
||||
|
||||
@@ -272,7 +274,6 @@ export async function battleEndWhenChange(ladderMatch: LadderMatchType) {
|
||||
|
||||
// 更新redis
|
||||
let r = new Rank(REDIS_KEY.LADDER, { serverId: ladderMatch.serverId });
|
||||
console.log('##### ladderMatch.roleId', ladderMatch.roleId)
|
||||
r.setRankWithRoleInfo(ladderMatch.roleId, ladderMatch.rank, 0);
|
||||
|
||||
// 刷新对手
|
||||
@@ -283,4 +284,15 @@ export async function battleEndWhenChange(ladderMatch: LadderMatchType) {
|
||||
oppPlayers
|
||||
});
|
||||
return oppPlayers
|
||||
}
|
||||
|
||||
export async function ladderBattleEndReward(roleId: string, roleName: string, sid: string, rank: number, isSuccess: boolean, isBreak: boolean, num: number) {
|
||||
let dicLadderDifficultRatio = gameData.ladderDifficultRatio.get(rank);
|
||||
if(!dicLadderDifficultRatio) return null;
|
||||
let warReward = new WarReward(roleId, roleName, sid, dicLadderDifficultRatio.gkId, isSuccess);
|
||||
warReward.setLadderReward(dicLadderDifficultRatio.randomFailReward, true);
|
||||
warReward.setLadderReward(dicLadderDifficultRatio.randomWinReward, false);
|
||||
let battleGoods = await warReward.saveReward(num);
|
||||
let breakGoods = isBreak? await addItems(roleId, roleName, sid, dicLadderDifficultRatio?.onceReward||[], ITEM_CHANGE_REASON.LADDER_BATTLE_REWARD): [];
|
||||
return { battleGoods, breakGoods };
|
||||
}
|
||||
@@ -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