战力计算,远征战力筛选

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
@@ -212,6 +212,7 @@ export class NormalBattleHandler {
let condition2 = await BattleRecordModel.getBattleRecordByIdAndStar(roleId, battleId, 3);
if(!condition2) warReward.setCondition(1, true);
}
if(towerReward) warReward.setFixReward(towerReward);
await updateWarStar(roleId, battleId, warInfo.warType, star);
}
@@ -235,7 +236,7 @@ export class NormalBattleHandler {
// towerStatus: false-本层未通过, true-本层已通过
return resResult(STATUS.SUCCESS, {
battleCode, battleId, status, towerStatus,
...reward, towerReward,
...reward,
apJson,
dailyNum,
heroes: curHeroes,
@@ -1,6 +1,7 @@
import { ChatRemote } from '../remote/chatRemote';
import {Application, BackendSession} from 'pinus';
import { FrontendSession } from 'pinus';
import { HeroModel } from '../../../db/Hero';
import Actor from '../../../pubUtils/actor';
import { updateCe } from '../../../pubUtils/util';
export default function(app: Application) {
return new ChatHandler(app);
@@ -10,8 +11,15 @@ export class ChatHandler {
constructor(private app: Application) {
}
async test(msg: {content: string , target: string}, session: BackendSession) {
console.log('test')
async test(msg: {}, session: BackendSession) {
let roleId = session.get('roleId')
let hero = await HeroModel.find().limit(1000);
for(let h of hero) {
let actor = new Actor(h);
let ce = actor.calculateCE();
await updateCe(roleId, h);
}
return 'success'
}
/**
* Send messages to users
@@ -10,6 +10,7 @@ import { resResult } from '../../../pubUtils/util';
import { startEvent } from '../../../services/eventSercive';
import { EVENT_START_LV } from '../../../consts/consts';
import { getAp } from '../../../services/actionPointService';
import Actor from '../../../pubUtils/actor';
export default function (app: Application) {
return new EntryHandler(app);
@@ -64,6 +65,7 @@ export class EntryHandler {
session.on('closed', this.onUserLeave.bind(this));
if(role.lv >= EVENT_START_LV && !role.eventStatus) {
startEvent(self.app, session);
}
@@ -79,6 +81,12 @@ export class EntryHandler {
// let users = await self.app.rpc.chat.chatRemote.add.route(session)(role.roleId, self.app.get('serverId'), rid, true);
let heros = await HeroModel.findByRole(role.roleId);
let equips = await EquipModel.findbyRole(role.roleId);
for(let hero of heros) {
let actor = new Actor(hero);
actor.calculateCE();
}
role['heros'] = heros;
role['equips'] = equips;
let apJson = await getAp(Date.now(), role.roleId);
@@ -29,12 +29,14 @@ export class RoleHandler {
async initHeros(roleId: string, roleName: string) {
const seqId = await CounterModel.getNewCounter('hid');
let ce = calculateCE({hid: 1, lv: 1});
const heroInfo = {
roleId,
roleName,
hid: 1,
hName: '曹操',
seqId,
star: 0,
ce
}
await HeroModel.createHero(heroInfo);
+1 -4
View File
@@ -77,10 +77,7 @@ export async function towerBattleEnd(channelService: ChannelService, sid: string
}
const { reward } = getTowerDataByLv(towerLv);
if (reward) {
let result = await handleFixedReward(roleId, roleName, reward, 1);
towerReward = result.goods;
}
if (reward) towerReward = reward;
if (towerLv + 1 == HANG_UP_CONSTS.ENABLE_LV) {
await startHangUp(roleId, roleName);
channelService.pushMessageByUids('hangUpEnable', {code: 200, data: {enable: true}}, [{uid: roleId, sid}]);
+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;