✨ feat(好友切磋): a7befab5f到f5146b93d
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import { Application, BackendSession, pinus, HandlerService, } from 'pinus';
|
||||
import { LadderMatchModel } from '../../../db/LadderMatch';
|
||||
import { HeroModel, HeroType } from '../../../db/Hero';
|
||||
import { ArtifactModel } from '../../../db/Artifact';
|
||||
import { getHeroesAttributes } from '../../../services/playerCeService';
|
||||
import { gameData } from '../../../pubUtils/data';
|
||||
import { LadderOppDetailHeroReturn } from '../../../domain/battleField/ladder';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { STATUS } from '../../../consts/statusCode';
|
||||
import { RoleType } from '../../../db/Role';
|
||||
import { FRIEND_BATTLE_DISPATCH_JSONID } from '../../../consts';
|
||||
|
||||
export default function (app: Application) {
|
||||
new HandlerService(app, {});
|
||||
return new FriendBattleHandler(app);
|
||||
}
|
||||
|
||||
export class FriendBattleHandler {
|
||||
constructor(private app: Application) {
|
||||
}
|
||||
|
||||
async getFriendOpp(msg: { roleId: string }, session: BackendSession) {
|
||||
const { roleId: targetRoleId, } = msg;
|
||||
|
||||
let hisLadderData = await LadderMatchModel.findByRoleIdAndInclude(targetRoleId);
|
||||
if (!hisLadderData || !hisLadderData.defense || !hisLadderData.defense.heroes) return resResult(STATUS.LADDER_NOT_OPEN);
|
||||
|
||||
let artifactSeids = [], subHids: number[] = [];
|
||||
for (let { hero, subHid } of hisLadderData.defense.heroes) {
|
||||
let dbHero = <HeroType>hero;
|
||||
if (dbHero) artifactSeids.push(dbHero.artifact);
|
||||
if (subHid) subHids.push(subHid);
|
||||
}
|
||||
|
||||
let artifacts = await ArtifactModel.findbySeqIds(targetRoleId, artifactSeids);
|
||||
let subHeroes = await HeroModel.findByHidRange(subHids, targetRoleId, 'hid skinId');
|
||||
let attrByHid = await getHeroesAttributes(targetRoleId);
|
||||
let dicWarJson = gameData.warJson.get(FRIEND_BATTLE_DISPATCH_JSONID);
|
||||
let result: LadderOppDetailHeroReturn[] = [];
|
||||
for (let obj of hisLadderData.defense.heroes) {
|
||||
const { dataId, subHid, actorId } = obj;
|
||||
let warJson = dicWarJson.find(cur => cur.dataId == dataId);
|
||||
if (warJson) {
|
||||
let subHero = subHeroes.find(sub => sub.hid == subHid);
|
||||
let rec = new LadderOppDetailHeroReturn(warJson, obj, artifacts, subHero);
|
||||
let attr = attrByHid.get(actorId);
|
||||
if (attr) {
|
||||
rec.setAttribute(attr.getAttributesToString());
|
||||
}
|
||||
result.push(rec);
|
||||
}
|
||||
}
|
||||
const role = <RoleType>hisLadderData.role;
|
||||
const title = role?.title || 1;
|
||||
const combo = hisLadderData.defense.combo || [];
|
||||
|
||||
return resResult(STATUS.SUCCESS, { title, combo, heroes: result })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user