全局:加载json方法全部改为最新

This commit is contained in:
luying
2021-05-06 20:25:05 +08:00
parent 2ef00e8179
commit 0315269387
36 changed files with 401 additions and 920 deletions
+51 -68
View File
@@ -4,13 +4,14 @@
*/
import { BattleDropModel } from '../db/BattleDrop';
import { getWarById, getBluePrtByQuality, getGamedata } from '../pubUtils/gamedata';
import { decodeStr, getRefTime, getRandomWithWeight, getRandomByLen } from '../pubUtils/util';
import { getRefTime, getRandEelmWithWeight, getRandSingleEelm } from '../pubUtils/util';
import { BATTLE_REWARD_TYPE, BLUEPRT_CONST } from '../consts';
import { addItems } from './rewardService';
import { BattleBlueprtDropModel } from '../db/BattleBlueprtDrop'
import { RoleModel } from '../db/Role';
import { gameData } from '../pubUtils/data';
import { DicWar } from '../pubUtils/dictionary/DicWar';
import { RewardInter } from '../pubUtils/interface';
export class WarReward {
private roleId: string;
@@ -18,12 +19,12 @@ export class WarReward {
private sid: string;
private battleId: number;
private condition: Map<number, boolean>;
private warInfo: any;
private warInfo: DicWar;
private isSuccess: boolean;
private rewards: Array<{type: number, id: number, count: number, times: number}>;
private fixReward: string;
private conditionReward: string;
private randomReward: string;
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 costAp: number;
constructor(roleId: string, roleName: string, sid: string, battleId: number, isSuccess: boolean) {
@@ -32,12 +33,12 @@ export class WarReward {
this.sid = sid;
this.battleId = battleId;
this.condition = new Map();
this.warInfo = getWarById(battleId);
this.warInfo = gameData.war.get(battleId);
let {fixReward = '', conditionReward = '', RandomReward = ''} = this.warInfo;
let { fixReward, conditionReward, randomReward } = this.warInfo;
this.fixReward = fixReward;
this.conditionReward = conditionReward;
this.randomReward = RandomReward;
this.randomReward = randomReward;
this.isSuccess = isSuccess;
this.costAp = this.warInfo.cost;
@@ -47,55 +48,38 @@ export class WarReward {
this.condition.set(id, isOk);
}
public setFixReward(reward: string) {
let str = this.fixReward;
let last = str.substr(str.length-1, 1);
if(last == '&') str = str.substr(0, str.length - 1);
if(str.length) {
this.fixReward = str + '|' + reward;
} else {
this.fixReward = str + reward;
public setFixReward(reward: RewardInter[]) {
for(let r of reward) {
this.fixReward.push(r);
}
}
public resetFixReward(reward: string) {
public resetFixReward(reward: RewardInter[]) {
this.fixReward = reward;
}
public setConditionReward(reward: string) {
let str = this.conditionReward;
let last = str.substr(str.length-1, 1);
if(last == '&') str = str.substr(0, str.length - 1);
if(str.length) {
this.conditionReward = str + '|' + reward;
} else {
this.conditionReward = str + reward;
public setConditionReward(reward: {id: number, count: number, condition: number}[]) {
for(let r of reward) {
this.conditionReward.push(r);
}
}
public setRandomReward(reward: string) {
let str = this.randomReward;
let last = str.substr(str.length-1, 1);
if(last == '&') str = str.substr(0, str.length - 1);
if(str.length) {
this.randomReward = str + '|' + reward;
} else {
this.randomReward = str + reward;
public setRandomReward(reward: {id: number, count: number, frequency: number}[]) {
for(let r of reward) {
this.randomReward.push(r);
}
}
private handleFixReward(num: number, fixReward: string) {
let reward = decodeStr('fixReward', fixReward);
private handleFixReward(num: number, fixReward: RewardInter[]) {
for(let i = 0; i < num; i++) {
for(let obj of reward) {
for(let obj of fixReward) {
this.rewards.push({type: BATTLE_REWARD_TYPE.FIX_REWARD, times: i +1, ...obj, count: obj.count });
}
}
}
private handleConditionReward(num: number, conditionReward: string) {
let reward = decodeStr('conditionReward', conditionReward);
private handleConditionReward(num: number, conditionReward: {id: number, count: number, condition: number}[]) {
for(let i = 0; i < num; i++) {
for(let obj of reward) {
for(let obj of conditionReward) {
if(this.condition.get(obj.condition)) {
this.rewards.push({type: BATTLE_REWARD_TYPE.CONDITION_REWARD, times: i +1, ...obj, count: obj.count});
}
@@ -103,34 +87,33 @@ export class WarReward {
}
}
private async handleRandomReward(num: number, randomReward: string) {
private async handleRandomReward(num: number, randomReward: {id: number, count: number, frequency: number}[]) {
let reward = decodeStr('randomReward', randomReward);
for(let obj of reward) {
let { id, frequency } = obj;
let dropHistory = await BattleDropModel.findByGid(this.roleId, this.battleId, id);
let { getNum = 0, allNum = 0, getSum = 0, allSum = 0 } = dropHistory;
for(let i = 0; i < num; i ++) {
let flag = false; // 是否可以获得
if(allNum >= frequency) {
allNum = 0; getNum = 0;
}
allNum++; allSum++;
if(getNum == 0) {
let r = Math.random();
if(r <= 1/frequency*allNum || (allNum >= frequency) ) {
flag = true; // 独立概率随机
}
}
if(flag) {
getNum ++; getSum++;
this.rewards.push({type: BATTLE_REWARD_TYPE.RANDOM_REWARD, times: i +1, ...obj});
for(let obj of 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;
for(let i = 0; i < num; i ++) {
let flag = false; // 是否可以获得
if(allNum >= frequency) {
allNum = 0; getNum = 0;
}
allNum++; allSum++;
if(getNum == 0) {
let r = Math.random();
if(r <= 1/frequency*allNum || (allNum >= frequency) ) {
flag = true; // 独立概率随机
}
}
await BattleDropModel.updateByGid(this.roleId, this.battleId, id, {
getNum, allNum, getSum, allSum
});
if(flag) {
getNum ++; getSum++;
this.rewards.push({type: BATTLE_REWARD_TYPE.RANDOM_REWARD, times: i +1, ...obj});
}
}
await BattleDropModel.updateByGid(this.roleId, this.battleId, id, {
getNum, allNum, getSum, allSum
});
}
}
private async handlerBlueprtReward(num: number) {
@@ -175,10 +158,10 @@ export class WarReward {
const result = dicPossibility.find(cur => {return cur.min <= lv && cur.max >= lv});
if(result) {
const {dic: {id}} = getRandomWithWeight(result.possibility);
const {dic: {id}} = getRandEelmWithWeight(result.possibility);
const blueprtList = getBluePrtByQuality(id);
const gid = getRandomByLen(blueprtList);
const blueprtList = gameData.blueprt.get(id);
const gid = getRandSingleEelm(blueprtList);
return {id: gid, count:1}
} else {
return null
@@ -190,7 +173,7 @@ export class WarReward {
// let warType = this.warInfo.warType;
if(this.isSuccess) { // 成功了才给固定奖励
// console.log(this.fixReward)
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);