增加匹配分的获取

This commit is contained in:
zhl 2021-01-15 17:49:40 +08:00
parent 024e03b3c4
commit 4a0a1959e5
15 changed files with 208 additions and 29 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
[{"id":30012,"herounit_id":52012,"ex_skill":0,"follower1id":51072,"follower2id":51082,"follower3id":51032,"follower4id":51052},{"id":30022,"herounit_id":52022,"ex_skill":0,"follower1id":51372,"follower2id":51162,"follower3id":51382,"follower4id":51332},{"id":30032,"herounit_id":52032,"ex_skill":0,"follower1id":51352,"follower2id":51042,"follower3id":51142,"follower4id":51062},{"id":30042,"herounit_id":52042,"ex_skill":0,"follower1id":51062,"follower2id":51122,"follower3id":51112,"follower4id":51042},{"id":30052,"herounit_id":52052,"ex_skill":0,"follower1id":51132,"follower2id":51082,"follower3id":51402,"follower4id":51112},{"id":30062,"herounit_id":52062,"ex_skill":0,"follower1id":51222,"follower2id":51272,"follower3id":51412,"follower4id":51042},{"id":30072,"herounit_id":52072,"ex_skill":0,"follower1id":51012,"follower2id":51082,"follower3id":51402,"follower4id":51152},{"id":30082,"herounit_id":52082,"ex_skill":0,"follower1id":51062,"follower2id":51272,"follower3id":51072,"follower4id":51052},{"id":30092,"herounit_id":52092,"ex_skill":0,"follower1id":51102,"follower2id":51372,"follower3id":51232,"follower4id":51292},{"id":30102,"herounit_id":52102,"ex_skill":0,"follower1id":51022,"follower2id":51092,"follower3id":51192,"follower4id":51392},{"id":30112,"herounit_id":52112,"ex_skill":0,"follower1id":51372,"follower2id":51162,"follower3id":51382,"follower4id":51332},{"id":30122,"herounit_id":52122,"ex_skill":0,"follower1id":51252,"follower2id":51052,"follower3id":51402,"follower4id":51132},{"id":30132,"herounit_id":52132,"ex_skill":0,"follower1id":51032,"follower2id":51342,"follower3id":51412,"follower4id":51252},{"id":30142,"herounit_id":52142,"ex_skill":0,"follower1id":51402,"follower2id":51202,"follower3id":51212,"follower4id":51342}]
[{"id":30012,"herounit_id":52012,"org_gift":"1","ex_skill":0,"follower1id":51072,"follower2id":51082,"follower3id":51032,"follower4id":51152},{"id":30022,"herounit_id":52022,"org_gift":"","ex_skill":0,"follower1id":51372,"follower2id":51162,"follower3id":51382,"follower4id":51332},{"id":30032,"herounit_id":52032,"org_gift":"1","ex_skill":0,"follower1id":51052,"follower2id":51042,"follower3id":51122,"follower4id":51062},{"id":30042,"herounit_id":52042,"org_gift":"1","ex_skill":0,"follower1id":51062,"follower2id":51122,"follower3id":51072,"follower4id":51042},{"id":30052,"herounit_id":52052,"org_gift":"","ex_skill":0,"follower1id":51132,"follower2id":51082,"follower3id":51402,"follower4id":51112},{"id":30062,"herounit_id":52062,"org_gift":"","ex_skill":0,"follower1id":51222,"follower2id":51272,"follower3id":51412,"follower4id":51042},{"id":30072,"herounit_id":52072,"org_gift":"1","ex_skill":0,"follower1id":51012,"follower2id":51082,"follower3id":51032,"follower4id":51152},{"id":30082,"herounit_id":52082,"org_gift":"1","ex_skill":0,"follower1id":51062,"follower2id":51082,"follower3id":51072,"follower4id":51052},{"id":30092,"herounit_id":52092,"org_gift":"","ex_skill":0,"follower1id":51102,"follower2id":51372,"follower3id":51232,"follower4id":51292},{"id":30102,"herounit_id":52102,"org_gift":"","ex_skill":0,"follower1id":51022,"follower2id":51092,"follower3id":51192,"follower4id":51392},{"id":30112,"herounit_id":52112,"org_gift":"","ex_skill":0,"follower1id":51372,"follower2id":51162,"follower3id":51382,"follower4id":51332},{"id":30122,"herounit_id":52122,"org_gift":"","ex_skill":0,"follower1id":51252,"follower2id":51352,"follower3id":51402,"follower4id":51132},{"id":30132,"herounit_id":52132,"org_gift":"","ex_skill":0,"follower1id":51032,"follower2id":51342,"follower3id":51412,"follower4id":51252},{"id":30142,"herounit_id":52142,"org_gift":"","ex_skill":0,"follower1id":51402,"follower2id":51202,"follower3id":51212,"follower4id":51342}]

File diff suppressed because one or more lines are too long

View File

@ -52,6 +52,8 @@
normal_stat: [0, 0, 0, 0] //匹配: 胜利场数, 失败场数, 平局场数, 掉线场数
season_stat: [0, 0, 0, 0] // 当前赛季状态
season_rank: 1 // 当前赛季排名
match_score: 1000 //当前匹配分, 用于匹配时上传
season_score: 1000 // 排位分, 用于显示
}
```
@ -299,4 +301,4 @@
```
```
```

38
package-lock.json generated
View File

@ -73,6 +73,15 @@
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.20.tgz",
"integrity": "sha512-Y93R97Ouif9JEOWPIUyU+eyIdyRqQR0I8Ez1dzku4hDx34NWh4HbtIc3WNzwB1Y9ULvNGeu5B8h8bVL5cAk4/A=="
},
"@types/redis": {
"version": "2.8.28",
"resolved": "https://registry.npmjs.org/@types/redis/-/redis-2.8.28.tgz",
"integrity": "sha512-8l2gr2OQ969ypa7hFOeKqtFoY70XkHxISV0pAwmQ2nm6CSPb1brmTmqJCGGrekCo+pAZyWlNXr+Kvo6L/1wijA==",
"dev": true,
"requires": {
"@types/node": "*"
}
},
"abstract-logging": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/abstract-logging/-/abstract-logging-2.0.1.tgz",
@ -936,6 +945,35 @@
"util-deprecate": "^1.0.1"
}
},
"redis": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/redis/-/redis-3.0.2.tgz",
"integrity": "sha512-PNhLCrjU6vKVuMOyFu7oSP296mwBkcE6lrAjruBYG5LgdSqtRBoVQIylrMyVZD/lkF24RSNNatzvYag6HRBHjQ==",
"requires": {
"denque": "^1.4.1",
"redis-commands": "^1.5.0",
"redis-errors": "^1.2.0",
"redis-parser": "^3.0.0"
}
},
"redis-commands": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/redis-commands/-/redis-commands-1.6.0.tgz",
"integrity": "sha512-2jnZ0IkjZxvguITjFTrGiLyzQZcTvaw8DAaCXxZq/dsHXz7KfMQ3OUJy7Tz9vnRtZRVz6VRCPDvruvU8Ts44wQ=="
},
"redis-errors": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/redis-errors/-/redis-errors-1.2.0.tgz",
"integrity": "sha1-62LSrbFeTq9GEMBK/hUpOEJQq60="
},
"redis-parser": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/redis-parser/-/redis-parser-3.0.0.tgz",
"integrity": "sha1-tm2CjNyv5rS4pCin3vTGvKwxyLQ=",
"requires": {
"redis-errors": "^1.0.0"
}
},
"reflect-metadata": {
"version": "0.1.13",
"resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.1.13.tgz",

View File

@ -0,0 +1,33 @@
import {Cfg} from "../../common/DataParser";
export class FormulaCfg implements Cfg{
name: "FormulaCfg";
public id: number;
public parname: number;
public code: number;
public number: number;
public numtypeid: number;
public prerequisite1id: number;
public prerequisite2id: number;
public decode(data: any) {
this.id = data.id;
this.parname = data.parname;
this.code = data.code;
this.number = data.number;
this.numtypeid = data.numtypeid;
this.prerequisite1id = data.prerequisite1id;
this.prerequisite2id = data.prerequisite2id;
};
public isOK (uniqueID: number, param1: any, param2: any): boolean {
if((param1 == undefined || param1 == null) && (param2 == undefined || param2 == null)){
return this.id == uniqueID;
}
if(param2 == undefined || param2 == null){
return this.id == uniqueID && this.id == param1;
}
return this.id == uniqueID && this.id == param1 && this.id == param2;
};
};

View File

@ -5,6 +5,7 @@ export class HeroCfg implements Cfg{
public id: number;
public herounit_id: number;
public org_gift: number;
public ex_skill: number;
public follower1id: number;
public follower2id: number;
@ -14,6 +15,7 @@ export class HeroCfg implements Cfg{
public decode(data: any) {
this.id = data.id;
this.herounit_id = data.herounit_id;
this.org_gift = data.org_gift;
this.ex_skill = data.ex_skill;
this.follower1id = data.follower1id;
this.follower2id = data.follower2id;

View File

@ -2,12 +2,14 @@ import {DataParser} from "./DataParser";
import {HeroCfg} from "../cfg/parsers/HeroCfg";
import {UnitCfg} from "../cfg/parsers/UnitCfg";
import {BaseConst} from "../constants/BaseConst";
import {FormulaCfg} from "../cfg/parsers/FormulaCfg";
export function initData() {
const rP = DataParser.regCommonParser.bind(DataParser);
rP(BaseConst.HERO, HeroCfg);
rP(BaseConst.UNIT, UnitCfg);
rP(BaseConst.FORMULA, FormulaCfg);
DataParser.loadAll();
}

View File

@ -66,5 +66,6 @@ export class BaseConst {
public static readonly HERO = "hero";
public static readonly SKILL = "skill";
public static readonly SYSTEMCARD = "systemcard";
public static readonly FORMULA = "formula";
public static readonly UNIT = "unit";
}

View File

@ -17,6 +17,10 @@ export default class AccountController extends BaseController {
if (account.locked) {
throw new ZError(4, 'account locked');
}
const formulaCfg = global.$cfg.get(BaseConst.FORMULA);
if (account.season_score == -1) {
account.season_score = formulaCfg.get(70003).number;
}
let cardSet = new Set(account.cards);
for (let [,cfg] of global.$cfg.get(BaseConst.HERO)) {
if (cfg.id <= 30100) {
@ -62,7 +66,8 @@ export default class AccountController extends BaseController {
result.normal_stat= account.normal_stat;
result.season_stat = account.season_stat;
result.extinfo = account.extinfo;
result.rank = 0;
result.season_score = account.season_score;
result.match_score = account.getMatchScore();
return result;
}

View File

@ -1,26 +1,62 @@
import {GameRecord} from "../models/GameRecord";
import BaseController from "../common/base.controller";
import {role, router} from "../decorators/router";
import {RecordInfo, User} from "../models/User";
import {error} from "../common/Debug";
import {timeBeforeDay} from "../utils/time.util";
import {BaseConst} from "../constants/BaseConst";
export default class RecordController extends BaseController {
@role('anon')
@router('post /api/:accountid/records')
async recordList(req: any) {
let {accountid} = req.params;
let records = await GameRecord.find({'players.accountid': accountid});
let results: any = [];
for (let record of records) {
results.push(record.toJSON());
}
return results;
@role('anon')
@router('post /api/:accountid/records')
async recordList(req: any) {
let {accountid} = req.params;
let records = await GameRecord.find({'players.accountid': accountid});
let results: any = [];
for (let record of records) {
results.push(record.toJSON());
}
return results;
}
@role('anon')
@router('post /svr/record/save')
async upload(req: any) {
let record = new GameRecord(req.params);
await record.save();
return {};
@role('anon')
@router('post /svr/record/save')
async upload(req: any) {
let record = new GameRecord(req.params);
await record.save();
const fc = global.$cfg.get(BaseConst.FORMULA);
for (let player of record.players) {
if (player.accountid.startsWith('robot')) {
continue;
}
let user = await User.findById(player.accountid);
if (!user) {
error(`save game record, account not found: ${player.accountid}`);
continue;
}
let data = new RecordInfo();
data.time = Date.now();
if (player.team == record.winner) {
data.status = 2;
} else if (record.winner == -1) {
data.status = 1;
} else {
data.status = 0;
}
user.season_records.push(data);
let records = user.season_records;
while (records.length > 10) {
records.pop();
}
let smallTime = timeBeforeDay(30);
for (let r of records) {
if (r.time < smallTime) {
records.remove(r);
}
}
await user.save();
}
return {};
}
}

View File

@ -10,7 +10,9 @@ import {Base, TimeStamps} from "@typegoose/typegoose/lib/defaultClasses";
interface GameRecordClass extends TimeStamps {
}
@modelOptions({
options: {allowMixed: Severity.ALLOW}
})
class GamePlayer {
@prop()
public playerid: string;
@ -24,10 +26,10 @@ class GamePlayer {
public heroid: number;
@prop()
public cardgroup: string;
@prop()
@prop({ type: () => [Number] })
public cards: [number];
@prop({type: mongoose.Schema.Types.Mixed})
public statdata: any;
public statdata: NewableFunction;
}
/**
*

View File

@ -4,7 +4,7 @@ import {
modelOptions,
index,
plugin,
mongoose
mongoose, Severity
} from '@typegoose/typegoose';
import {dbconn} from '../decorators/dbconn';
// @ts-ignore
@ -18,13 +18,27 @@ import {Card} from "./subdoc/Card";
import {Hero} from "./subdoc/Hero";
import {ZError} from "../common/ZError";
import {MoneyTypeConst} from "../constants/MoneyTypeConst";
import {timeBeforeDay} from "../utils/time.util";
import {BaseConst} from "../constants/BaseConst";
export class RecordInfo {
@prop()
public time: number;
/**
*
* @type {number} 1: 平局, 2: 0:
*/
@prop()
public status: number;
}
interface AccountClass extends Base<string>, TimeStamps {}
@dbconn()
// @index({ _id: 1}, { unique: true })
@plugin(findOrCreate)
@modelOptions({schemaOptions:
{collection: "account", timestamps: true}
{collection: "account", timestamps: true},
options: {allowMixed: Severity.ALLOW}
})
class UserClass extends FindOrCreate{
@prop()
@ -73,11 +87,17 @@ class UserClass extends FindOrCreate{
*/
@prop({type: Number, default: [0,0,0,0]})
public season_stat: number[];
/**
* 10
* @type {RecordInfo[]}
*/
@prop({_id: false, type: () => [RecordInfo]})
public season_records: RecordInfo[];
/**
*
*/
@prop({type: Number, default: 1000})
@prop({type: Number, default: -1})
public season_score: number;
/**
* ,
@ -91,6 +111,35 @@ class UserClass extends FindOrCreate{
}
}
/**
*
* @return {number}
*/
public getMatchScore() {
//twp=ten_wp*ten_wn-ten_lp*ten_ln-ten_ap*ten_an
const fc = global.$cfg.get(BaseConst.FORMULA);
let smallTime = timeBeforeDay(30);
let records = this.season_records || [];
for (let r of records) {
if (r.time < smallTime) {
records.remove(r);
}
}
let win = 0;
let lost = 0;
let total = records.length;
for(let record of records) {
if (record.status == 2) {
win ++;
} else if (record.status == 0) {
lost ++;
}
}
let twp = win * fc.get(70016).number / 100 - lost * fc.get(70017).number / 100 - (10 - total) * fc.get(70018).number / 100;
// mp=bm_mp+cp*(bm_twp+twp)
return fc.get(70021).number + this.season_score * (fc.get(70020).number / 100 + twp);
}
public async unlockHero(heroid: number, useMoney: boolean) {
if (this.heros.has(heroid + '')) {
if (!this.heros.get(heroid + '').trial) {

9
src/utils/time.util.ts Normal file
View File

@ -0,0 +1,9 @@
/**
* n天前的time
* @param {number} day
* @return {number}
*/
export function timeBeforeDay(day: number): number {
let time = Date.now();
return time - day * 1000 * 24 * 24;
}