fix bug 远征显示下一关等

This commit is contained in:
luying
2020-11-17 17:37:05 +08:00
parent 0e2f043f93
commit 80b8f1bac7
13 changed files with 73 additions and 49 deletions

View File

@@ -39,7 +39,7 @@ export class ExpeditionBattleHandler {
expeditionRecord = await ExpeditionRecordModel.createRecord({
roleId, roleName, heroes: [], myCe
});
await findOrCreateEnemies(roleId, myCe, expeditionRecord.expeditionCode, 1);
await findOrCreateEnemies(roleId, myCe, expeditionRecord.expeditionCode, 1, 0);
}
// 每一关的挑战状态
@@ -63,7 +63,7 @@ export class ExpeditionBattleHandler {
curLv,
expeditionWarRecord,
pointRewards,
heroes,
heroes: heroes.map(cur => {return {"dataId": cur.seqId, "hp": cur.hp, "ap": cur.ap}}),
resetCnt
});
}
@@ -90,7 +90,7 @@ export class ExpeditionBattleHandler {
let { expeditionCode, heroes } = await ExpeditionRecordModel.createRecord({
roleId, roleName, heroes: [], myCe
});
await findOrCreateEnemies(roleId, myCe, expeditionCode, 1);
await findOrCreateEnemies(roleId, myCe, expeditionCode, 1, 0);
await RoleModel.increaseExpeditionResetCnt(roleId, needRefresh, curTime);
let expeditionWarRecord = await ExpeditionWarRecordModel.getRecordByCode(expeditionCode);
let curLv = 0;
@@ -119,13 +119,13 @@ export class ExpeditionBattleHandler {
let { myCe } = await ExpeditionRecordModel.getExpeditionRecordByCode(expeditionCode);
let curExpeditionWarRecord = await findOrCreateEnemies(roleId, myCe, expeditionCode, expeditionId);
let curExpeditionWarRecord = await findOrCreateEnemies(roleId, myCe, expeditionCode, expeditionId, 0);
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);
let nextExpeditionWarRecord = await findOrCreateEnemies(roleId, myCe, expeditionCode, expeditionId + 1, -1);
if(nextExpeditionWarRecord) nextCe = nextExpeditionWarRecord.ce;
return resResult(STATUS.SUCCESS, {
@@ -186,7 +186,7 @@ export class ExpeditionBattleHandler {
}
}, true);
let result = await ExpeditionWarRecordModel.updateStatus(expeditionCode, expeditionId, 0, battleCode);
let result = await ExpeditionWarRecordModel.updateBattleCode(expeditionCode, expeditionId, 0, battleCode);
return resResult(STATUS.SUCCESS, {
expeditionCode,
@@ -259,6 +259,8 @@ export class ExpeditionBattleHandler {
let reward = await warReward.saveReward(1);
let actordata = await roleLevelup(roleId, isSuccess?warInfo.kingExp:0);// 主公升级经验
// 更新下一关状态
await ExpeditionWarRecordModel.updateStatus(expeditionCode, expeditionId + 1, 0);
return resResult(STATUS.SUCCESS, {
expeditionCode, expeditionId,

View File

@@ -158,6 +158,7 @@ export class TowerBattleHandler {
let curTasks = await TowerTaskRecModel.getCurTasks(roleId); // 当前显示中的任务
const needRefresh = shouldRefresh(towerTaskRefTime, curTime, TOWER_TASK_CONST.REFRESH_TIME);
if(needRefresh) {
const batchCode = genCode(8);
await RoleModel.resetTowerCnt(roleId, curTime); // 重置派遣次数
@@ -230,7 +231,7 @@ export class TowerBattleHandler {
return resResult(STATUS.TOWER_TASK_CODE_NOT_FOUND);
}
if (usedHeroes.length > 0) { // 是否在其他任务重使用了武将
let hasHero = await checkBattleHeroes(roleId, usedHeroes);
let hasHero = await checkBattleHeroes(roleId, task.heroes);
if(!hasHero) return resResult(STATUS.BATTLE_HERO_NOT_FOUND);
let used = !!task.heroes.find(seqId => usedHeroes.indexOf(seqId) !== -1);
if (used) {
@@ -276,7 +277,7 @@ export class TowerBattleHandler {
const rewardGoods = await handleFixedReward(roleId, roleName, reward, 1);
goods = goods.concat(rewardGoods.goods);
if(termsForAdd) {
const result = checkTaskConditions(roleId, task.heroes, termsForAdd);
const result = await checkTaskConditions(roleId, task.heroes, termsForAdd);
const bonusGoods = await handleFixedReward(roleId, roleName, result?additionalReward:'', 1);
goods = goods.concat(bonusGoods.goods);
}

View File

@@ -26,7 +26,11 @@ export async function checkTowerWar(roleId: string, battleId: number, heroes: Ar
return { status: -1, resResult: resResult(STATUS.TOWER_WRONG_BATTLE_ID) };
}
let { heroes: recHeroes = [], warStatus = [] } = await TowerRecordModel.getRecordByLv(roleId, towerLv);
const tower = await TowerRecordModel.getRecordByLv(roleId, towerLv);
if(!tower) {
return { status: -1, resResult: resResult(STATUS.TOWER_NOT_FOUND) };
}
let { heroes: recHeroes = [], warStatus = [] } = tower;
for (let hid of heroes) {
if (recHeroes.indexOf(hid) !== -1) {
return { status: -1, resResult: resResult(STATUS.TOWER_DUPLICATE_HERO) };
@@ -194,8 +198,8 @@ async function checkCond(roleId: string, heroes, type: number, param: number, cn
switch (type) {
case 1:
for(let seqId of heroes) {
const rec = await HeroModel.findBySeqIdAndRole(seqId, roleId);
if (rec.star >= param) {
const {star, fire} = await HeroModel.findBySeqIdAndRole(seqId, roleId);
if (star + fire >= param) {
heroCnt++;
}
}
@@ -253,7 +257,7 @@ export async function createCurTasks(towerLv: number, batchCode: string, roleId:
let dicTask = getGamedata('dic_zyz_search');
for(let task of dicTask) {
let {suitFloor} = task;
let {min, max} = decodeStrSingle('suitLevel', suitFloor);
let {min, max} = decodeStrSingle('suitLevelSingle', suitFloor);
let flag = max?(towerLv >= min && towerLv <= max): (towerLv >= min);
if(flag) {
randomList.push(task);

View File

@@ -8,8 +8,9 @@ import { decodeStr, resResult, setLocalHours, shouldRefresh } from '../pubUtils/
import { WAR_JSON_ATTRIBUTE_TYPE, EXPEDITION_CONST } from '../consts/consts';
import Actor from '../pubUtils/actor';
import { ExpeditionWarRecordModel } from '../db/ExpeditionWarRecord';
import { stat } from 'fs';
export async function findOrCreateEnemies(roleId: string, myCe: number, expeditionCode: string, expeditionId: number) {
export async function findOrCreateEnemies(roleId: string, myCe: number, expeditionCode: string, expeditionId: number, battleStatus: number) {
let expeditionWarRecord = await ExpeditionWarRecordModel.getRecordByCodeAndId(expeditionCode, expeditionId);
if(!expeditionWarRecord) { // 如果没有信息
@@ -35,7 +36,7 @@ export async function findOrCreateEnemies(roleId: string, myCe: number, expediti
// 保存
let {warId} = curDicExpedition;
expeditionWarRecord = await ExpeditionWarRecordModel.saveRecord(expeditionCode, expeditionId, {
roleId, battleId: warId, ...enemyObj
roleId, battleId: warId, ...enemyObj, battleStatus
});
}
}

View File

@@ -30,8 +30,12 @@ export async function roleLevelup(roleId: string, kingExp: number) {
export async function checkBattleHeroes(roleId: string, heroes: Array<number>) {
let flag = true;
if(heroes.length <= 0) flag = false;
const findHeroes = await HeroModel.findBySeqIdRange(heroes, roleId);
if(findHeroes.length != heroes.length) flag = false;
for(let seqId of heroes) {
let hero = await HeroModel.findBySeqIdAndRole(seqId||0, roleId);
let hero = findHeroes.find(cur => cur.seqId == seqId);
if(!hero) flag = false;
}
return flag;

View File

@@ -45,9 +45,9 @@ export class WarReward {
let last = str.substr(str.length-1, 1);
if(last == '&') str = str.substr(0, str.length - 1);
if(str.length) {
this.fixReward += reward;
} else {
this.fixReward += '|' + reward;
} else {
this.fixReward += reward;
}
}

View File

@@ -24,6 +24,7 @@ import Counter from '@db/Counter';
import { STATUS } from '@consts/statusCode';
import { getGoodById } from '@pubUtils/gamedata';
import { ITID } from '@consts/consts';
import Actor from '@pubUtils/actor';
/**
* Test Service
@@ -342,32 +343,15 @@ export default class GMUsers extends Service {
let { lv } = hero;
let dicHero = ctx.service.utils.getHeroById(hid);
let { hp, hp_up, atk, atk_up, matk, matk_up, def, def_up, mdef, mdef_up } = dicHero;
let ce = ctx.service.utils.calculateCE({hid, lv});
let actor = new Actor();
actor.initHero(hero);
let ce = actor.calculateCE();
let attribute = actor.getAttributeJson();
let heroInfo = {
actorId: dicHero.heroId,
actorName: dicHero.name,
attribute: {
hp: hp + lv * hp_up,
atk: atk + lv * atk_up,
matk: matk + lv * matk_up,
def: def + lv * def_up,
mdef: mdef + lv * mdef_up,
agi: 0,
luk: 0,
speed: 0,
hit: 0,
cri: 0,
flee: 0,
antCri: 0,
damageIncrease: 0,
damageDecrease: 0,
defIgnore: 0,
bloodSuck: 0,
ap: 0
},
lv,
attribute, lv,
ce
};

View File

@@ -67,7 +67,7 @@ export default class ExpeditionWarRecord extends BaseModel {
ce: number; // 敌军战力
public static async getRecordByCode(expeditionCode: string, lean = true) {
const result = await ExpeditionWarRecordModel.find({ expeditionCode }).select('expeditionId battleId battleCode battleStatus ce').sort({expeditionId: 1}).lean(lean);
const result = await ExpeditionWarRecordModel.find({ expeditionCode, battleStatus: {$gte: 0} }).select('expeditionId battleId battleCode battleStatus ce').sort({expeditionId: 1}).lean(lean);
return result;
}
@@ -76,14 +76,19 @@ export default class ExpeditionWarRecord extends BaseModel {
return result;
}
public static async saveRecord(expeditionCode: string, expeditionId: number, params: {roleId: string, battleId: number, enemyFrom: number, enemyId: string, enemies: Array<any>}, lean = true) {
public static async saveRecord(expeditionCode: string, expeditionId: number, params: {roleId: string, battleId: number, enemyFrom: number, enemyId: string, enemies: Array<any>, battleStatus: number}, lean = true) {
const doc = new ExpeditionWarRecordModel();
const update = Object.assign(doc.toJSON(), params, {expeditionCode, expeditionId});
const result = await ExpeditionWarRecordModel.findOneAndUpdate({ expeditionCode, expeditionId }, update, {new: true, upsert: true}).select('expeditionId battleId battleCode battleStatus enemyFrom enemies ce').lean(lean);
return result;
}
public static async updateStatus(expeditionCode: string, expeditionId: number, battleStatus: number, battleCode: string, lean = true) {
public static async updateStatus(expeditionCode: string, expeditionId: number, battleStatus: number, lean = true) {
const result = await ExpeditionWarRecordModel.findOneAndUpdate({ expeditionCode, expeditionId }, {battleStatus}, {new: true}).lean(lean);
return result;
}
public static async updateBattleCode(expeditionCode: string, expeditionId: number, battleStatus: number, battleCode: string, lean = true) {
const result = await ExpeditionWarRecordModel.findOneAndUpdate({ expeditionCode, expeditionId }, {battleStatus, battleCode}, {new: true}).lean(lean);
return result;
}

View File

@@ -41,7 +41,7 @@ export default class HangUpRecord extends BaseModel {
public static async initRecord(roleId: string, roleName: string, lean = true) {
const curTime = new Date();
const recDoc = new HangUpRecordModel();
const update = Object.assign(recDoc.toJSON(), {roleId, roleName, startTime: curTime});
const update = Object.assign(recDoc.toJSON(), {roleId, roleName, startTime: curTime, startLv: HANG_UP_CONSTS.ENABLE_LV});
const rec = await HangUpRecordModel.findOneAndUpdate({roleId, startLv: HANG_UP_CONSTS.ENABLE_LV}, update, {upsert: true, new: true}).lean(lean);
return rec;
}
@@ -59,7 +59,7 @@ export default class HangUpRecord extends BaseModel {
public static async updateRec(roleId: string, roleName: string, endLv: number, endTime: Date, needReceiveGoods: Array<{gid:number, count: number}>, lean = true) {
await HangUpRecordModel.findOneAndUpdate({roleId, received: false}, {endLv, endTime, received: true, notReceivedGoods: needReceiveGoods}).lean(lean);
const recDoc = new HangUpRecordModel();
const update = Object.assign(recDoc.toJSON(), {roleId, roleName, startTime: endTime});
const update = Object.assign(recDoc.toJSON(), {roleId, roleName, startTime: endTime, startLv: endLv});
delete update._id;
const newRec = await HangUpRecordModel.findOneAndUpdate({roleId, startLv: endLv, received: false}, update, {upsert: true, new: true}).lean(lean);
return newRec;

View File

@@ -7,6 +7,7 @@ import { updateCe } from '../pubUtils/util';
* 英雄表
*/
@index({ roleId: 1, hid: 1 })
@index({ roleId: 1, seqId: 1 })
export default class Hero extends BaseModel {
@prop({ required: true })
@@ -60,6 +61,10 @@ export default class Hero extends BaseModel {
return heros || [];
}
public static async findBySeqIdRange(seqIds: Array<number>, roleId: string, lean = true) {
const hero = await HeroModel.find({ seqId: {$in: seqIds}, roleId }).lean(lean);
return hero;
}
public static async findBySeqIdAndRole(seqId: number, roleId: string, lean = true) {
const hero = await HeroModel.findOne({ seqId, roleId }).lean(lean);
return hero;

View File

@@ -123,7 +123,7 @@ export default class Role extends BaseModel {
@prop({ required: true, default: 0})
towerTaskCnt: number; // 刷新派遣任务的次数向上累加每天8个
@prop({ required: true, default: new Date()})
@prop({ required: false})
towerTaskRefTime: Date; // 刷新派遣任务的时间
// 奇遇事件相关

View File

@@ -256,14 +256,19 @@ export default class Actor {
return baseAbility
}
calculateCE() {
// 武将
getAttributeJson() {
let json = {hp: 0, atk: 0, matk: 0, def: 0, mdef: 0, agi: 0, speed: 0, luk: 0, hit: 0, cri: 0, flee: 0, antCri: 0, damageIncrease: 0, damageDecrease: 0, defIngnore: 0, bloodSuck: 0};
for(let i = ABI_TYPE.ABI_HP;i < ABI_TYPE.ABI_MAX;i++){
let field = WAR_JSON_ATTRIBUTE_TYPE[i];
json[field] = this.getRealAbility(i);
}
return json
}
calculateCE() {
// 武将
let json = this.getAttributeJson();
let ce = this.calculateCEByExpression(json);
// 装备

View File

@@ -61,6 +61,19 @@ const moment = require('moment');
result = { min: parseInt(min), max: parseInt(max) };
break;
}
case 'suitLevelSingle': {
let [min, max] = arr;
console.log(min, max)
if(max) {
if(isNaN(min) || isNaN(max)) throw new Error('data table format wrong');
result = { min: parseInt(min), max: parseInt(max) };
break;
} else {
if(isNaN(min)) throw new Error('data table format wrong');
result = { min: parseInt(min) };
break;
}
}
case 'attribute': {
let [id, value] = arr;
if(isNaN(id) || isNaN(value)) throw new Error('data table format wrong');
@@ -187,7 +200,7 @@ export function shouldRefresh(preTime: Date, now: Date, hour: number, deltaDay =
if(!preTime) return true;
let curTime = new Date(now.getTime());
let refeshTime = setLocalHours(hour, curTime);
console.log(refeshTime - preTime.getTime())
console.log(refeshTime - preTime.getTime(), (deltaDay>=1?deltaDay-1:0) * 24 * 60 * 60 * 1000, curTime.getTime(), refeshTime)
if (refeshTime - preTime.getTime() > (deltaDay>=1?deltaDay-1:0) * 24 * 60 * 60 * 1000 && curTime.getTime() >= refeshTime) {
return true;
}
@@ -324,7 +337,7 @@ export function setLocalHours(hour: number, curTime = new Date()) {
let offset = curTime.getTimezoneOffset(); // 格林威治时间和本地时间之间的时差(分)
let localTime = new Date(curTime.getTime() + offset * 60 * 1000 + 8 * 60 * 60 * 1000); // 中国时间
localTime.setUTCHours(hour, 0, 0, 0); // 中国的几点
return localTime.getTime() - offset * 60 * 1000 - 8 * 60 * 60 * 1000; // 回到格林威治时间
return localTime.getTime() - 8 * 60 * 60 * 1000; // 回到格林威治时间
}
export async function updateCe(roleId: string, hero: any ) {