寻宝:roleStatus.heroes格式修改
This commit is contained in:
@@ -11,7 +11,7 @@ import Role, { RoleModel } from '../../../db/Role';
|
||||
import { STATUS } from '../../../consts/statusCode';
|
||||
import { Application, BackendSession } from 'pinus';
|
||||
import { resResult, getRandSingleEelm } from '../../../pubUtils/util';
|
||||
import { RoleStatus, ComBattleTeamModel, ComBattleTeamType, BossHp } from '../../../db/ComBattleTeam';
|
||||
import { RoleStatus, ComBattleTeamModel, ComBattleTeamType, BossHp, ComRoleStatusHero } from '../../../db/ComBattleTeam';
|
||||
import { ItemModel, ItemType } from '../../../db/Item';
|
||||
import { addItems, handleCost } from '../../../services/rewardService';
|
||||
import { checkRoleInQueue, rmRoleFromQueue, setTeamSearchReq } from '../../../services/redisService';
|
||||
@@ -26,6 +26,7 @@ import { getZeroPointD, getTimeFunD } from '../../../pubUtils/timeUtil';
|
||||
import { FriendParams } from '../../../domain/roleField/friend';
|
||||
import { checkTask, checkTaskWithGoods } from '../../../services/taskService';
|
||||
import { gameData, getWarByBlueprtId } from '../../../pubUtils/data';
|
||||
import { HeroModel } from '../../../db/Hero';
|
||||
|
||||
export default function(app: Application) {
|
||||
return new ComBattleHandler(app);
|
||||
@@ -263,10 +264,15 @@ export class ComBattleHandler {
|
||||
*/
|
||||
async teammateReady(msg: {teamCode: string, heroes: number[]}, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
let { teamCode, heroes } = msg;
|
||||
let { teamCode, heroes: hids } = msg;
|
||||
let teamStatus = this.teamMap.get(teamCode);
|
||||
if (!teamStatus || !teamStatus.roleIds || teamStatus.roleIds.indexOf(roleId) === -1) return resResult(STATUS.COM_BATTLE_TEAM_INVALID);
|
||||
|
||||
const heroDBs = await HeroModel.findByHidRange(hids, roleId);
|
||||
const heroes = heroDBs.map(hero => {
|
||||
return new ComRoleStatusHero(hero);
|
||||
});
|
||||
|
||||
let team = await ComBattleTeamModel.updateHeroes(teamCode, roleId, heroes);
|
||||
if (!team) return resResult(STATUS.COM_BATTLE_UPDATE_HEROES_ERR);
|
||||
|
||||
@@ -291,11 +297,16 @@ export class ComBattleHandler {
|
||||
*/
|
||||
async setupHeroes(msg: {teamCode: string, heroes: number[], battleCode: string}, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
let { teamCode, heroes, battleCode = 'default' } = msg;
|
||||
if (!heroes || heroes.length === 0) return resResult(STATUS.COM_BATTLE_HEROES_ERR);
|
||||
let { teamCode, heroes: hids, battleCode = 'default' } = msg;
|
||||
if (!hids || hids.length === 0) return resResult(STATUS.COM_BATTLE_HEROES_ERR);
|
||||
let teamStatus = this.teamMap.get(teamCode);
|
||||
if (!teamStatus || !teamStatus.roleIds || teamStatus.roleIds.indexOf(roleId) === -1) return resResult(STATUS.COM_BATTLE_TEAM_INVALID);
|
||||
|
||||
const heroDBs = await HeroModel.findByHidRange(hids, roleId);
|
||||
const heroes = heroDBs.map(hero => {
|
||||
return new ComRoleStatusHero(hero);
|
||||
});
|
||||
|
||||
let team = await ComBattleTeamModel.setupBattleInfo(teamCode, roleId, heroes, battleCode);
|
||||
if (!team) return resResult(STATUS.COM_BATTLE_UPDATE_HEROES_ERR);
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import { checkActivityTask, checkTask } from './taskService';
|
||||
import { getRandExpedition, gameData } from '../pubUtils/data';
|
||||
import { ItemInter, RewardInter } from '../pubUtils/interface';
|
||||
import { getTimeFunM } from '../pubUtils/timeUtil';
|
||||
import { ComRoleStatusHero } from '../db/ComBattleTeam';
|
||||
|
||||
/**
|
||||
* 获取当前镇念塔状态
|
||||
@@ -461,10 +462,17 @@ export function getRandRobot(cnt = 1, withAttr = false) {
|
||||
const warInfo = gameData.warJson.get(info.warId);
|
||||
if (!warInfo || !warInfo.length) continue;
|
||||
|
||||
let heroes = [];
|
||||
let heroes: ComRoleStatusHero[] = [];
|
||||
for (let hero of warInfo) {
|
||||
if (hero && hero.relation === 2 && hero.actorId) {
|
||||
heroes.push(hero.actorId);
|
||||
let dicHero = gameData.hero.get(hero.actorId);
|
||||
heroes.push({
|
||||
id: hero.actorId,
|
||||
star: hero.star,
|
||||
colorStar: 0,
|
||||
lv: hero.lv,
|
||||
quality: dicHero.quality
|
||||
});
|
||||
}
|
||||
}
|
||||
robots.push(heroes);
|
||||
|
||||
@@ -230,7 +230,9 @@ function updateRobotKilled(bossHp: number, roleSt: RoleStatus) {
|
||||
const dmgProgress = Math.floor(roleSt.totalDmg / (robotTotalHurt / roleSt.heroes.length));
|
||||
if (dmgProgress > roleSt.killed.length && dmgProgress <= roleSt.heroes.length) {
|
||||
const newKilledCnt = dmgProgress - roleSt.killed.length;
|
||||
const aliveHeroes = difference(roleSt.heroes, roleSt.killed);
|
||||
const aliveHeroes = roleSt.heroes.filter(hero => {
|
||||
return roleSt.killed.indexOf(hero.id) == -1;
|
||||
}).map(cur => cur.id);
|
||||
const newKilledHeroes = getRandEelm(aliveHeroes, newKilledCnt);
|
||||
roleSt.killed = roleSt.killed.concat(newKilledHeroes);
|
||||
}
|
||||
@@ -358,7 +360,7 @@ export function comBtlLvInvalid(lv: number, lvRange: number) {
|
||||
const range = gameData.comBtlLvRange.get(lvRange);
|
||||
if (!range) return true;
|
||||
let { min, max } = range;
|
||||
return lv >= min && lv <= max;
|
||||
return lv < min || lv > max;
|
||||
}
|
||||
|
||||
export async function dismissTeam(teamStatus: MemComBtlTeam, teamMap: Map<string, MemComBtlTeam>, roleId: string, teamDisTimer: Map<string, NodeJS.Timer>, channel) {
|
||||
|
||||
@@ -2,6 +2,27 @@ import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
import { EXTERIOR } from '../pubUtils/dicParam';
|
||||
import { ItemReward } from '../domain/dbGeneral';
|
||||
import { HeroType } from './Hero';
|
||||
|
||||
export class ComRoleStatusHero {
|
||||
@prop({ required: true })
|
||||
id: number;
|
||||
@prop({ required: true })
|
||||
quality: number;
|
||||
@prop({ required: true })
|
||||
star: number;
|
||||
@prop({ required: true })
|
||||
colorStar: number;
|
||||
@prop({ required: true })
|
||||
lv: number;
|
||||
constructor(hero: HeroType) {
|
||||
this.id = hero.hid;
|
||||
this.quality = hero.quality;
|
||||
this.star = hero.star;
|
||||
this.colorStar = hero.colorStar;
|
||||
this.lv = hero.lv;
|
||||
}
|
||||
}
|
||||
|
||||
export class RoleStatus {
|
||||
@prop({ required: true })
|
||||
@@ -19,8 +40,8 @@ export class RoleStatus {
|
||||
@prop({ required: false, default: '' })
|
||||
battleCode: string;
|
||||
// 玩家所用阵容
|
||||
@prop({ required: false, type: Number, default: [] })
|
||||
heroes: number[];
|
||||
@prop({ required: false, type: ComRoleStatusHero, default: [], _id: false })
|
||||
heroes: ComRoleStatusHero[];
|
||||
// 阵亡武将
|
||||
@prop({ required: false, type: Number, default: [] })
|
||||
killed: number[];
|
||||
@@ -58,7 +79,7 @@ export class RoleStatus {
|
||||
@prop({ required: true, default: 0 })
|
||||
frdRatio: number = 0;
|
||||
|
||||
constructor(roleId: string, roleName: string, isCap: boolean, isFrd: boolean, head: number, frame: number, spine: number, topLineupCe: number, lv: number, heroes = [], isRobot = false) {
|
||||
constructor(roleId: string, roleName: string, isCap: boolean, isFrd: boolean, head: number, frame: number, spine: number, topLineupCe: number, lv: number, heroes: ComRoleStatusHero[] = [], isRobot = false) {
|
||||
this.roleId = roleId;
|
||||
this.roleName = roleName;
|
||||
this.isCap = isCap;
|
||||
@@ -178,12 +199,12 @@ export default class ComBattleTeam extends BaseModel {
|
||||
return team;
|
||||
}
|
||||
|
||||
public static async updateHeroes(teamCode: string, roleId: string, heroes: number[], lean = true) {
|
||||
public static async updateHeroes(teamCode: string, roleId: string, heroes: ComRoleStatusHero[], lean = true) {
|
||||
const team: ComBattleTeamType = await ComBattleTeamModel.findOneAndUpdate({ teamCode, 'roleStatus.roleId': roleId}, {$set: {'roleStatus.$.heroes': heroes}}, {new: true}).lean(lean);
|
||||
return team;
|
||||
}
|
||||
|
||||
public static async setupBattleInfo(teamCode: string, roleId: string, heroes: number[], battleCode: string, lean = true) {
|
||||
public static async setupBattleInfo(teamCode: string, roleId: string, heroes: ComRoleStatusHero[], battleCode: string, lean = true) {
|
||||
const team: ComBattleTeamType = await ComBattleTeamModel.findOneAndUpdate({ teamCode, 'roleStatus.roleId': roleId}, {$set: {'roleStatus.$.heroes': heroes, 'roleStatus.$.battleCode': battleCode}}, {new: true}).lean(lean);
|
||||
return team;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user