修改远征创建记录逻辑

This commit is contained in:
luying
2020-11-17 10:07:59 +08:00
parent d5a5cfc270
commit 0e2f043f93
26 changed files with 2147 additions and 1150 deletions

View File

@@ -1,8 +1,7 @@
import { Application, BackendSession } from 'pinus';
import { DailyRecordModel } from '../../../db/DailyRecord';
import { BattleRecordModel } from '../../../db/BattleRecord';
import { getGamedata } from '../../../pubUtils/gamedata';
import { WAR_TYPE, GOLD_COST_RATIO } from '../../../consts/consts';
import { GOLD_COST_RATIO } from '../../../consts/consts';
import { STATUS } from '../../../consts/statusCode';
import { resResult, calculateNum } from '../../../pubUtils/util';
import { RoleModel } from '../../../db/Role';
@@ -20,8 +19,7 @@ export class DailyBattleHandler {
async getData(msg: { }, session: BackendSession) {
let roleId = session.get('roleId');
const BattleRecord = await BattleRecordModel.getBattleList(roleId, WAR_TYPE.DAILY);
let {warStar} = await RoleModel.findByRoleId(roleId);
let dicDaily = getGamedata('dic_zyz_daily');
let dicDailyWar = getGamedata('dic_zyz_gk_daily');
@@ -32,13 +30,13 @@ export class DailyBattleHandler {
for(let {war_id, dailyType, cost, gk_name, previousGk } of dicDailyWar) {
if(dailyType == type) {
let status = 0, star = 0;
let curBattle = BattleRecord.find(cur => cur.battleId == war_id);
let curBattle = warStar.find(cur => cur.id == war_id);
if(curBattle) {
status = 2;
star = curBattle.star;
} else {
if (previousGk) {
let preBattleRecord = BattleRecord.find(cur => cur.battleId == previousGk);
let preBattleRecord = warStar.find(cur => cur.id == previousGk);
if(preBattleRecord) {
status = 1;
} else {
@@ -54,6 +52,7 @@ export class DailyBattleHandler {
}
}
let checkDailyResult = await getDailyNum(refreshResult, timesPerDay, timesCanBuy);
checkDailyResult['count'] = checkDailyResult.battleCount;
result.push({
type, name, ...checkDailyResult,
wars
@@ -94,6 +93,7 @@ export class DailyBattleHandler {
let newDailyRecord = await DailyRecordModel.increseBuyCount(roleId, type, count);
let checkDailyResult = await getDailyNum(newDailyRecord, timesPerDay, timesCanBuy);
checkDailyResult['count'] = checkDailyResult.battleCount;
return resResult(STATUS.SUCCESS, { type, ...checkDailyResult, buyCost});
}
}

View File

@@ -6,7 +6,7 @@ import { ExpeditionWarRecordModel } from '../../../db/ExpeditionWarRecord';
import { ExpeditionPointModel } from '../../../db/ExpeditionPoint';
import { RoleModel } from '../../../db/Role';
import { calculateSumCE, genCode } from '../../../pubUtils/util';
import { matchPlayers, matchRobots, getPointRewardStatus, getCEScaleAndRange, getResetRemainCnt } from '../../../services/expeditionService';
import { getPointRewardStatus, getResetRemainCnt, findOrCreateEnemies } from '../../../services/expeditionService';
import { EXPEDITION_CONST } from '../../../consts/consts';
import { WarReward } from '../../../services/warRewardService';
import { handleFixedReward } from '../../../services/rewardService';
@@ -34,11 +34,12 @@ export class ExpeditionBattleHandler {
// 获取远征关卡状态
let expeditionRecord = await ExpeditionRecordModel.getCurRecord(roleId);
if(!expeditionRecord) { // 首次新建一条记录
// 我方战力(暂定)
// 我方战力
let myCe = await calculateSumCE(roleId, 1, { num: 5 });
expeditionRecord = await ExpeditionRecordModel.createRecord({
roleId, roleName, heroes: [], myCe
});
await findOrCreateEnemies(roleId, myCe, expeditionRecord.expeditionCode, 1);
}
// 每一关的挑战状态
@@ -89,12 +90,18 @@ export class ExpeditionBattleHandler {
let { expeditionCode, heroes } = await ExpeditionRecordModel.createRecord({
roleId, roleName, heroes: [], myCe
});
await findOrCreateEnemies(roleId, myCe, expeditionCode, 1);
await RoleModel.increaseExpeditionResetCnt(roleId, needRefresh, curTime);
let expeditionWarRecord = await ExpeditionWarRecordModel.getRecordByCode(expeditionCode);
let curLv = 0;
if(expeditionWarRecord.length > 0) {
curLv = expeditionWarRecord[expeditionWarRecord.length - 1].expeditionId;
}
return resResult(STATUS.SUCCESS, {
expeditionCode,
curLv: 0,
expeditionWarRecord: [],
curLv,
expeditionWarRecord,
heroes,
resetCnt: resetCnt - 1
});
@@ -112,40 +119,22 @@ export class ExpeditionBattleHandler {
let { myCe } = await ExpeditionRecordModel.getExpeditionRecordByCode(expeditionCode);
let expeditionWarRecord = await ExpeditionWarRecordModel.getRecordByCodeAndId(expeditionCode, expeditionId);
if(!expeditionWarRecord) { // 如果没有信息
let enemyObj = {
enemyFrom: 0,
enemyId: '',
enemies: new Array()
};
let dicExpedition = getGamedata('dic_expedition');
let curDicExpedition = dicExpedition.find(cur => cur.id == expeditionId);
// 获取系数和步长
let {scale, range, lv} = await getCEScaleAndRange(roleId, curDicExpedition);
// 优先匹配其他玩家
let flag = await matchPlayers(roleId, scale, range, myCe, curDicExpedition.json, enemyObj);
// 当数量不够时使用机器人匹配
if(!flag) {
flag = await matchRobots(scale, myCe, curDicExpedition.ce, curDicExpedition.json, lv, enemyObj);
}
if(!flag) {
return resResult(STATUS.EXPEDITION_MATCH_NO_PLAYER);
}
// 保存
let {warId} = curDicExpedition;
expeditionWarRecord = await ExpeditionWarRecordModel.saveRecord(expeditionCode, expeditionId, {
roleId, battleId: warId, ...enemyObj
});
let curExpeditionWarRecord = await findOrCreateEnemies(roleId, myCe, expeditionCode, expeditionId);
if(!curExpeditionWarRecord) {
return resResult(STATUS.EXPEDITION_MATCH_NO_PLAYER);
}
let { battleId, enemyFrom, enemies, battleStatus, ce: curCe } = curExpeditionWarRecord;
let nextCe = 0; // 下一关战力
let nextExpeditionWarRecord = await findOrCreateEnemies(roleId, myCe, expeditionCode, expeditionId + 1);
if(nextExpeditionWarRecord) nextCe = nextExpeditionWarRecord.ce;
let { battleId, enemyFrom, enemies, battleStatus } = expeditionWarRecord;
return resResult(STATUS.SUCCESS, {
expeditionCode, expeditionId, battleId,
battleStatus,
enemyFrom,
enemies
enemies,
curCe,
nextCe
});
}
@@ -282,51 +271,11 @@ export class ExpeditionBattleHandler {
});
}
/**
* 领取战斗宝箱
* 领取宝箱,更新远征状态
*/
async battleReward(msg: { expeditionCode: string, expeditionId: number }, session: BackendSession) {
const { expeditionCode, expeditionId } = msg;
let roleId = session.get('roleId');
let roleName = session.get('roleName');
// 检查expeditionWarRecord的battleStatus
let expeditionWarRecord = await ExpeditionWarRecordModel.getRecordByCodeAndId(expeditionCode, expeditionId);
if(!expeditionWarRecord) {
return resResult(STATUS.EXPEDITION_MISS_WAR_RECORD);
}
if(expeditionWarRecord.battleStatus != 1) {
return resResult(STATUS.EXPEDITION_WRONG_STATUS_WHEN_RECEIVE);
}
if(expeditionWarRecord.received) {
return resResult(STATUS.EXPEDITION_WRONG_RECEIVE_STATUS);
}
// 设置expeditionWarRecord的received和rewards
let dicExpedition = getGamedata('dic_expedition');
let curDicExpedition = dicExpedition.find(cur => cur.id == expeditionId);
if(!curDicExpedition) {
return resResult(STATUS.EXPEDITION_MISS_INFO);
}
let result = await ExpeditionWarRecordModel.updateBoxStatus(expeditionCode, expeditionId, true, curDicExpedition.reward);
let { battleId, battleCode, battleStatus, received } = result;
// 获取东西
let goods = await handleFixedReward(roleId, roleName, curDicExpedition.reward, 1);
return resResult(STATUS.SUCCESS, {
expeditionCode, expeditionId,
battleId, battleCode, battleStatus, received,
...goods
});
}
/**
* 领取点数宝箱
* 领取点数宝箱,不扣除点数,那么就需要记录领取状态并且有返回
*/
async pointReward(msg: { point }, session: BackendSession) {
async pointReward(msg: { point: number }, session: BackendSession) {
const { point } = msg;
let roleId = session.get('roleId');
@@ -353,51 +302,28 @@ export class ExpeditionBattleHandler {
}
// 标记状态
await ExpeditionPointModel.updatePointStatus(roleId, point, curDicExpeditionPoint.reward);
let {rewards: resultRewards} = await ExpeditionPointModel.updatePointStatus(roleId, point, curDicExpeditionPoint.reward);
let hasReceivedAll = true, maxPoint = 0;
for(let dic of dicExpeditionPoint) {
let curReward = resultRewards.find(cur => cur.point == dic.point);
if(!curReward || !curReward.received) {
hasReceivedAll = false;
}
if(dic.point > maxPoint) maxPoint = dic.point;
}
if(hasReceivedAll) { // 全部领取了,刷新
await ExpeditionPointModel.completeStatus(roleId);
await RoleModel.increaseExpeditionPoint(roleId, maxPoint * -1);
}
let pointRewards = await getPointRewardStatus(roleId);
let goods = await handleFixedReward(roleId, roleName, curDicExpeditionPoint.reward, 1);
return resResult(STATUS.SUCCESS, {
costPoint: hasReceivedAll?maxPoint: 0,
pointRewards,
...goods
})
}
/**
* 刷新点数宝箱
* 扣除远征点数,并刷新箱子状态
*/
async resetPointReward(msg: { }, session: BackendSession) {
let roleId = session.get('roleId');
// let roleName = session.get('roleName');
let pointStatusInDatabase = await ExpeditionPointModel.getExpeditionPoint(roleId);
if(!pointStatusInDatabase) {
return resResult(STATUS.EXPEDITION_POINT_RECORD_NOT_FOUND);
}
let { rewards } = pointStatusInDatabase;
let dicExpeditionPoint = getGamedata('dic_expedition_point');
let flag = true, maxPoint = 0;
for(let dic of dicExpeditionPoint) {
let curReward = rewards.find(cur => cur.point == dic.point);
if(!curReward || !curReward.received) {
flag = false;
}
if(dic.point > maxPoint) maxPoint = dic.point;
}
if(!flag) {
return resResult(STATUS.EXPEDITION_POINT_NEED_ALL_RECEIVED);
}
// 刷新
await ExpeditionPointModel.completeStatus(roleId);
await RoleModel.increaseExpeditionPoint(roleId, maxPoint * -1);
let pointRewards = await getPointRewardStatus(roleId);
return resResult(STATUS.SUCCESS, {
pointRewards
});
}
}

View File

@@ -15,9 +15,7 @@ export class ChatHandler {
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);
await updateCe(h.roleId, h);
}
return 'success'
}

View File

@@ -83,7 +83,8 @@ export class EntryHandler {
let equips = await EquipModel.findbyRole(role.roleId);
for(let hero of heros) {
let actor = new Actor(hero);
let actor = new Actor();
actor.initHero(hero);
actor.calculateCE();
}

View File

@@ -3,13 +3,48 @@ import { ExpeditionPointModel } from '../db/ExpeditionPoint';
import Role, { RoleModel } from '../db/Role';
import { PvpDefenseModel } from '../db/PvpDefense';
import { getWarJsons, getGamedata } from '../pubUtils/gamedata';
import { getWarJsons, getGamedata, getExpeditionById } from '../pubUtils/gamedata';
import { decodeStr, resResult, setLocalHours, shouldRefresh } from '../pubUtils/util';
import { WAR_JSON_ATTRIBUTE_TYPE, EXPEDITION_CONST } from '../consts/consts';
import Actor from '../pubUtils/actor';
import { ExpeditionWarRecordModel } from '../db/ExpeditionWarRecord';
export async function findOrCreateEnemies(roleId: string, myCe: number, expeditionCode: string, expeditionId: number) {
let expeditionWarRecord = await ExpeditionWarRecordModel.getRecordByCodeAndId(expeditionCode, expeditionId);
if(!expeditionWarRecord) { // 如果没有信息
let curDicExpedition = getExpeditionById(expeditionId);
if(curDicExpedition) {
let enemyObj = {
enemyFrom: 0,
enemyId: '',
enemies: new Array(),
ce: 0
};
// 获取系数和步长
let {scale, range, lv} = await getCEScaleAndRange(roleId, curDicExpedition);
// 优先匹配其他玩家
let flag = await matchPlayers(roleId, scale, range, myCe, curDicExpedition.json, enemyObj);
// 当数量不够时使用机器人匹配
if(!flag) {
flag = await matchRobots(scale, myCe, curDicExpedition.ce, curDicExpedition.json, lv, enemyObj);
}
if(flag) {
// 保存
let {warId} = curDicExpedition;
expeditionWarRecord = await ExpeditionWarRecordModel.saveRecord(expeditionCode, expeditionId, {
roleId, battleId: warId, ...enemyObj
});
}
}
}
return expeditionWarRecord;
}
// 匹配玩家
export async function matchPlayers(roleId: string, scale: number, range: number, myCe: number, warJsonIndex:any, enemyObj: {enemyFrom: number, enemyId: string, enemies: Array<any> }) {
export async function matchPlayers(roleId: string, scale: number, range: number, myCe: number, warJsonIndex:any, enemyObj: {enemyFrom: number, enemyId: string, enemies: Array<any>, ce: number }) {
let {json: dicWarJson } = getWarJsons(warJsonIndex);
let min = myCe * scale * (1 - range/100);
@@ -19,10 +54,11 @@ export async function matchPlayers(roleId: string, scale: number, range: number,
if(resultRange.length > 0) {
let index = Math.floor(Math.random() * resultRange.length);
let result = resultRange[index];
let {roleId, heroes } = result;
let {roleId, heroes, ce } = result;
enemyObj.enemyFrom = 1;
enemyObj.enemyId = roleId;
enemyObj.ce = ce;
let heroIndex = 0;
for(let enemy of dicWarJson) {
@@ -42,12 +78,13 @@ export async function matchPlayers(roleId: string, scale: number, range: number,
}
// 匹配机器人
export async function matchRobots(scale: number, myCe: number, robotCe: number, warJsonIndex:any, lv: number, enemyObj: {enemyFrom: number, enemyId: string, enemies: Array<any> }) {
export async function matchRobots(scale: number, myCe: number, robotCe: number, warJsonIndex:any, lv: number, enemyObj: {enemyFrom: number, enemyId: string, enemies: Array<any>, ce: number }) {
let {json: dicWarJson, fileName } = getWarJsons(warJsonIndex);
if(dicWarJson) {
enemyObj.enemyFrom = 2;
enemyObj.enemyId = fileName;
enemyObj.enemyId = fileName + '';
let allCe = 0;
let ratio = myCe / robotCe * scale; // 玩家战力/机器人初始战力*系数
for(let enemy of dicWarJson) {
if(enemy.relation == 2) {
@@ -56,9 +93,14 @@ export async function matchRobots(scale: number, myCe: number, robotCe: number,
attribute[value] *= ratio;
attribute[value] = Math.round(attribute[value]);
}
let actor = new Actor();
let ce = actor.calculateCEByExpression(attribute);
enemyObj.enemies.push({...enemy, attribute, lv});
allCe += ce;
}
}
console.log(JSON.stringify(enemyObj.enemies))
enemyObj.ce = Math.floor(allCe);
return true
} else {
@@ -79,12 +121,11 @@ export async function getCEScaleAndRange(roleId: string, curDicExpedition: any)
}
// 远征表属性解码
export function decodeWarJsonAttribute(attribute) {
export function decodeWarJsonAttribute(attribute: string) {
let arr = decodeStr('attribute', attribute);
let obj = {}
for(let key in WAR_JSON_ATTRIBUTE_TYPE) {
obj[WAR_JSON_ATTRIBUTE_TYPE[key]] = 0; // 初始化
}
// 初始化
let obj = {hp: 0, atk: 0, matk: 0, def: 0, mdef: 0, speed: 0, agi: 0, luk: 0, hit: 0, cri: 0, flee: 0, antCri: 0, damageIncrease: 0, damageDecrease: 0, defIngnore: 0, bloodSuck: 0}
for(let {id, value} of arr) {
let field = WAR_JSON_ATTRIBUTE_TYPE[id];
if(field) {