pvp:修改接口

This commit is contained in:
luying
2021-10-29 16:36:23 +08:00
parent e39b120af4
commit 7fb13da627
10 changed files with 359 additions and 214 deletions
+94 -10
View File
@@ -1,8 +1,9 @@
import { prop, Ref, mongoose } from '@typegoose/typegoose';
import Hero, { } from '../../db/Hero';
import Hero, { HeroType } from '../../db/Hero';
import { PvpDefenseType } from '../../db/PvpDefense';
import PvpHistoryOpp from '../../db/PvpHistoryOpp';
import { PvpSeasonResultType } from '../../db/PvpSeasonResult';
import { getPLvByScore } from '../../pubUtils/data';
import { RewardInter } from '../../pubUtils/interface';
@@ -18,6 +19,14 @@ export class DefenseHero {
order: number;
@prop({ ref: 'Hero', type: mongoose.Schema.Types.ObjectId })
hero: Ref<Hero>;
constructor(param: { actorId: number, ai: number, dataId: number, order: number }, heroId: string) {
this.actorId = param.actorId;
this.ai = param.ai;
this.dataId = param.dataId;
this.order = param.order;
this.hero = heroId;
}
}
// 防守阵容
@@ -32,6 +41,14 @@ export class Defense {
score: number; // 防守阵容的总军功
@prop({ required: true })
pLv: number; // 防守阵容的等级
constructor(heroes: DefenseHero[], score: number, warId: number, buff: number) {
this.heroes = heroes;
this.score = score;
this.pLv = getPLvByScore(score);
this.warId = warId;
this.buff = buff;
}
}
// 挑战阵容武将
@@ -50,6 +67,12 @@ export class Attack {
score: number; // 防守阵容的总军功
@prop({ required: true })
pLv: number; // 防守阵容的等级
constructor(heroes: AttackHero[], score: number) {
this.heroes = heroes;
this.score = score;
this.pLv = getPLvByScore(score);
}
}
// 两个阵容中的武将的分别的战力
@@ -63,7 +86,7 @@ export class LineupCe {
export class OppPlayer {
@prop({ required: true })
roleId: string;
@prop({ ref: 'PvpHistoryOpp', type: mongoose.Schema.Types.ObjectId })
@prop({ ref: () => PvpHistoryOpp, type: mongoose.Schema.Types.ObjectId })
oppDef: Ref<PvpHistoryOpp>;
@prop({ required: true })
pos: number;
@@ -115,6 +138,13 @@ export class DefenseHeroReturn {
ai: number; // ai逻辑,1-进攻型 2-防守型
dataId: number;
order: number;
constructor(defenseHero: DefenseHero) {
this.actorId = defenseHero.actorId;
this.ai = defenseHero.ai;
this.dataId = defenseHero.dataId;
this.order = defenseHero.order;
}
}
export class DefenseLineupReturn {
@@ -124,19 +154,44 @@ export class DefenseLineupReturn {
score: number;
pLv: number;
ce: number;
constructor(defense: Defense, defenseCe: number) {
this.warId = defense.warId;
this.buff = defense.buff;
this.heroes = defense.heroes.map(cur => new DefenseHeroReturn(cur));
this.score = defense.score;
this.pLv = defense.pLv;
this.ce = defenseCe;
}
}
export class AttackLineupReturn {
warId: number;
buff: number;
heroes: AttackHero[];
score: number;
pLv: number;
ce: number;
constructor(attack: Attack, attackCe: number) {
this.heroes = attack.heroes;
this.score = attack.score;
this.pLv = attack.pLv;
this.ce = attackCe;
}
}
export class heroScoreReturn extends HeroScore {
isDefense: boolean;
export class HeroScoreReturn extends HeroScore {
isDefense: boolean = false;
constructor(heroScore: HeroScore, defense: Defense) {
super();
this.hid = heroScore.hid;
this.score = heroScore.score;
if(defense && defense.heroes) {
let index = defense.heroes.findIndex(cur => cur.actorId == this.hid);
if(index != -1) {
this.isDefense = true;
}
}
}
}
export class SeasonDataReturn {
@@ -181,18 +236,47 @@ export class PvpDataReturn {
challengeRefTime: number;
receiveBox: number[] = [];
hisScore: number = 0;
heroScores: heroScoreReturn[] = [];
heroScores: HeroScoreReturn[] = [];
isFirstEntry: boolean = false;
resultRecord: PvpSeasonResultRecord;
constructor(pvpDefense: PvpDefenseType) {
setPvpDefense(pvpDefense: PvpDefenseType) {
this.score = pvpDefense.score;
this.winStreakNum = pvpDefense.winStreakNum;
this.receiveBox = pvpDefense.receivedBox;
this.hisScore = pvpDefense.hisScore;
// this.oppPlayers
// this.heroScores
this.refOppCnt = pvpDefense.refOppCnt;
this.setAttackCnt = pvpDefense.setAttackCnt;
this.challengeCnt = pvpDefense.challengeCnt;
this.challengeRefTime = pvpDefense.challengeRefTime;
let { attackCe, defenseCe } = PvpDataReturn.getAttackAndDefenseCe(pvpDefense);
if(pvpDefense.attack) this.attack = new AttackLineupReturn(pvpDefense.attack, attackCe);
if(pvpDefense.defense) this.defense = new DefenseLineupReturn(pvpDefense.defense, defenseCe);
this.heroScores = pvpDefense.heroScores.map(cur => new HeroScoreReturn(cur, pvpDefense.defense));
}
static getAttackAndDefenseCe(pvpDefense: PvpDefenseType) {
let { lineupCe, attack, defense } = pvpDefense;
let attackCe = 0, defenseCe = 0;
for(let { hid, ce } of lineupCe) {
if(attack && attack.heroes) {
let hero = attack.heroes.find(cur => cur.actorId == hid);
if(hero) attackCe += ce;
}
if(defense && defense.heroes) {
let hero = defense.heroes.find(cur => cur.actorId == hid);
if(hero) defenseCe += ce;
}
}
return { attackCe, defenseCe };
}
setIsFirstEntry(isFirstEntry: boolean) {
this.isFirstEntry = isFirstEntry;
}
setOppPlayers(oppPlayers: OppPlayerReturn[]) {
+8 -5
View File
@@ -2,6 +2,8 @@ import { prop, mongoose, Ref } from '@typegoose/typegoose';
import { DicWarJson } from '../pubUtils/dictionary/DicWarJson';
import Hero, { HeroType } from '../db/Hero';
import { nowSeconds } from '../pubUtils/timeUtil';
import { DicHero } from '../pubUtils/dictionary/DicHero';
import { gameData } from '../pubUtils/data';
// 从玩家数据中覆盖warjson的部分字段
export class PvpHeroInfo {
@@ -41,13 +43,14 @@ export class PvpHeroInfo {
this.quality = hero.quality;
}
setRobotInfo(warjson: DicWarJson, actorId: number, lv: number, initialStar: number, quality: number) {
setRobotInfo(actorId: number, lv: number) {
let dicHero = gameData.hero.get(actorId);
this.actorId = actorId;
this.skinId = warjson.actorId;
this.actorName = warjson.actorName;
this.star = initialStar;
this.skinId = actorId;
this.actorName = dicHero.name;
this.star = dicHero.initialStars;
this.lv = lv;
this.quality = quality;
this.quality = dicHero.quality;
}
setAttribute(attribute: string) {