添加藏宝图按体力掉落

This commit is contained in:
luying
2020-11-24 15:44:10 +08:00
parent f362c5505f
commit 991d193eab
5 changed files with 170 additions and 19 deletions
+72 -14
View File
@@ -4,22 +4,25 @@
*/
import { BattleDropModel } from '../db/BattleDrop';
import { getWarById } from '../pubUtils/gamedata';
import { decodeStr } from '../pubUtils/util';
import { BATTLE_REWARD_TYPE } from '../consts/consts';
import { getWarById, getBluePrtByQuality } from '../pubUtils/gamedata';
import { decodeStr, getRefTime, getRandomWithWeight, getRandomByLen } from '../pubUtils/util';
import { BATTLE_REWARD_TYPE, BLUEPRT_CONST, BLUEPRT_CHANCE } from '../consts/consts';
import { handleReward } from './rewardService';
import { BattleBlueprtDropModel } from '../db/BattleBlueprtDrop'
import { RoleModel } from '../db/Role';
export class WarReward {
roleId: string;
roleName: string;
battleId: number;
condition: Map<number, boolean>;
warInfo: any;
isSuccess: boolean;
rewards: Array<{type: number, gid: number, count: number, times: number}>;
fixReward: string;
conditionReward: string;
randomReward: string;
private roleId: string;
private roleName: string;
private battleId: number;
private condition: Map<number, boolean>;
private warInfo: any;
private isSuccess: boolean;
private rewards: Array<{type: number, gid: number, count: number, times: number}>;
private fixReward: string;
private conditionReward: string;
private randomReward: string;
private costAp: number;
constructor(roleId: string, roleName: string, battleId: number, isSuccess: boolean) {
this.roleId = roleId;
@@ -34,6 +37,7 @@ export class WarReward {
this.randomReward = RandomReward;
this.isSuccess = isSuccess;
this.costAp = this.warInfo.cost;
}
public setCondition(id: number, isOk: boolean) {
@@ -101,7 +105,7 @@ export class WarReward {
let { getNum = 0, allNum = 0, getSum = 0, allSum = 0 } = dropHistory;
for(let i = 0; i < num; i ++) {
let flag = false; // 是否可以获得
if(allNum + 1 > frequency) {
if(allNum >= frequency) {
allNum = 0; getNum = 0;
}
allNum++; allSum++;
@@ -122,6 +126,58 @@ export class WarReward {
}
}
private async handlerBlueprtReward(num: number) {
const refTime = getRefTime(new Date(), BLUEPRT_CONST.REFRESH_TIME);
const battleBlueprtDrop = await BattleBlueprtDropModel.findByTime(this.roleId, refTime);
if(battleBlueprtDrop) {
let { getNum = 0, curCostAp = 0, getSum = 0, costAp = 0 } = battleBlueprtDrop;
for(let i = 0; i < num; i ++) {
let flag = false; // 是否可以获得
if( curCostAp >= BLUEPRT_CONST.PER_AP) {
curCostAp = curCostAp - BLUEPRT_CONST.PER_AP; getNum = 0;
}
costAp += this.costAp; curCostAp += this.costAp;
if(getNum == 0) {
let r = Math.random();
console.log(r, 1/BLUEPRT_CONST.PER_AP*curCostAp);
if(r <= 1/BLUEPRT_CONST.PER_AP*curCostAp || (curCostAp >= BLUEPRT_CONST.PER_AP) ) {
flag = true; // 独立概率随机
}
}
if(getSum >= BLUEPRT_CONST.DAILY_CNT) {
flag = false;
}
if(flag) {
getNum ++; getSum++;
const obj = await this.randomBlueprt();
if(obj) {
this.rewards.push({type: BATTLE_REWARD_TYPE.RANDOM_REWARD, times: i +1, ...obj});
}
}
}
await BattleBlueprtDropModel.updateByTime(this.roleId, refTime, {
getNum, curCostAp, getSum, costAp
});
}
}
private async randomBlueprt() {
const { lv } = await RoleModel.findByRoleId(this.roleId);
const result = BLUEPRT_CHANCE.find(cur => {return cur.min <= lv && cur.max >= lv});
console.log('****', lv, result)
if(result) {
const dicOdds = decodeStr('possibility', result.chance);
const {dic: {id}} = getRandomWithWeight(dicOdds);
const blueprtList = getBluePrtByQuality(id);
const gid = getRandomByLen(blueprtList);
return {gid, count:1}
} else {
return null
}
}
public async saveReward(num: number) {
this.rewards = new Array();
// let warType = this.warInfo.warType;
@@ -131,6 +187,8 @@ export class WarReward {
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.costAp > 0) await this.handlerBlueprtReward(num);
}
let returnGoods = await handleReward(this.roleId, this.roleName, this.rewards);