diff --git a/docs/api.md b/docs/api.md index bedfa5b..b6a67b3 100644 --- a/docs/api.md +++ b/docs/api.md @@ -50,7 +50,6 @@ 'card_scroll': 0, //抽卡卷轴 }, normal_stat: [0, 0, 0, 0] //匹配: 胜利场数, 失败场数, 平局场数, 掉线场数 - season_stat: [0, 0, 0, 0] // 当前赛季状态 season_rank: 1 // 当前赛季排名 match_score: 1000 //当前匹配分, 用于匹配时上传 season_score: 1000 // 排位分, 用于显示 diff --git a/src/controllers/AccountController.ts b/src/controllers/AccountController.ts index a008698..1e92a2e 100644 --- a/src/controllers/AccountController.ts +++ b/src/controllers/AccountController.ts @@ -64,7 +64,6 @@ export default class AccountController extends BaseController { await account.save(); result.moneys = account.moneys; result.normal_stat= account.normal_stat; - result.season_stat = account.season_stat; result.extinfo = account.extinfo; result.season_score = account.season_score; result.match_score = account.getMatchScore(); diff --git a/src/controllers/RecordController.ts b/src/controllers/RecordController.ts index 2d42a0e..384b607 100644 --- a/src/controllers/RecordController.ts +++ b/src/controllers/RecordController.ts @@ -24,7 +24,19 @@ export default class RecordController extends BaseController { async upload(req: any) { let record = new GameRecord(req.params); await record.save(); + if (!record.season) { + return; + } const fc = global.$cfg.get(BaseConst.FORMULA); + const scores = [ + fc.get(70043).number, + fc.get(70046).number, + fc.get(70044).number, + fc.get(70045).number, + fc.get(70047).number, + fc.get(70048).number + ]; + let seasonData = {}; for (let player of record.players) { if (player.accountid.startsWith('robot')) { continue; @@ -34,6 +46,13 @@ export default class RecordController extends BaseController { error(`save game record, account not found: ${player.accountid}`); continue; } + user.season_score += player.scoreChange; + if (!user.season_data) { + user.season_data = new Map(); + } + /** + * begin of 将赛季排位记录放入season_records, 方便计算10胜 + */ let data = new RecordInfo(); data.time = Date.now(); if (player.team == record.winner) { @@ -55,8 +74,44 @@ export default class RecordController extends BaseController { records.remove(r); } } + /** + * end of 将赛季排位记录放入season_records, 方便计算10胜 + */ + /** + * begin of 处理比赛统计信息 + */ + if (record.winner == player.team) { + user.season_data.inc('win', 1); + } else { + user.season_data.inc('loss', 1); + } + let statData = player.statdata; + let honorp = 0; + for(let key in statData) { + let numKey = +key; + + if (numKey >= scores.length) { + continue; + } + // @ts-ignore + let val = Number(statData[key]); + honorp += val * scores[numKey]; + user.season_data.inc(key + '_total', val * scores[numKey]); + if (user.season_data.has(key + '')) { + user.season_data.set(key + '', Math.max(user.season_data.get(key + ''), val)) + } else { + user.season_data.set(key + '', val); + } + } + user.season_data.inc('honor_ap', honorp); + user.season_data.inc('mvp_ap', player.mvpscore); + /** + * end of 处理比赛统计信息 + */ await user.save(); + // @ts-ignore + seasonData[player.playerid] = user.season_data; } - return {}; + return seasonData; } } diff --git a/src/models/GameRecord.ts b/src/models/GameRecord.ts index 8a6fc52..93567c4 100644 --- a/src/models/GameRecord.ts +++ b/src/models/GameRecord.ts @@ -25,11 +25,17 @@ class GamePlayer { @prop() public heroid: number; @prop() + public mvpscore: number; + @prop() public cardgroup: string; @prop({ type: () => [Number] }) public cards: [number]; @prop({type: mongoose.Schema.Types.Mixed}) - public statdata: NewableFunction; + public statdata: {}; + @prop() + public score: number; + @prop() + public scoreChange: number; } /** * 对战记录 @@ -48,6 +54,8 @@ class GameRecordClass extends Base{ public round: number; @prop() public winner: number; + @prop() + public mvp: string; /** * 赛季 * @type {number} 0: 匹配, 1: 对应赛季 @@ -55,6 +63,7 @@ class GameRecordClass extends Base{ @prop() public season: number; + @prop({_id: false, type: () => [GamePlayer]}) public players: GamePlayer[]; diff --git a/src/models/User.ts b/src/models/User.ts index bd31e7e..c8954b2 100644 --- a/src/models/User.ts +++ b/src/models/User.ts @@ -83,10 +83,10 @@ class UserClass extends FindOrCreate{ @prop({type: Number, default: [0,0,0,0]}) public normal_stat: number[]; /** - * 当前赛季: 胜利场数, 失败场数, 平局场数, 掉线场数 + * 赛季数据 */ - @prop({type: Number, default: [0,0,0,0]}) - public season_stat: number[]; + @prop({ type: Number, default: new Map() }) + public season_data: Map; /** * 一个月内10场记录 * @type {RecordInfo[]}