获取英雄信息时, 将免费英雄和卡牌等信息存入库

This commit is contained in:
zhl 2021-01-12 17:19:28 +08:00
parent 400d09dc5c
commit 933f458b04
2 changed files with 38 additions and 1 deletions

View File

@ -3,6 +3,9 @@ import {role, router} from "../decorators/router";
import {User} from "../models/User";
import {ZError} from "../common/ZError";
import {Card} from "../models/subdoc/Card";
import {BaseConst} from "../constants/BaseConst";
import {Hero} from "../models/subdoc/Hero";
import {CardGroup} from "../models/CardGroup";
export default class AccountController extends BaseController {
@role('anon')
@ -14,6 +17,40 @@ export default class AccountController extends BaseController {
if (account.locked) {
throw new ZError(4, 'account locked');
}
let cardSet = new Set(account.cards);
for (let [,cfg] of global.$cfg.get(BaseConst.HERO)) {
if (cfg.id <= 30100) {
let hero = new Hero();
hero.heroid = cfg.id;
hero.free = true;
hero.trial = false;
hero.level = 1;
hero.exp = 0;
if (!account.heros.has(cfg.id + '')) {
account.heros.set(cfg.id + '', hero);
let cardgroup = new CardGroup({});
let cards: Card[] = [];
for (let i = 1; i <= 4; i++) {
let card = new Card();
card.cardid = cfg[`follower${i}id`];
card.owned = false;
card.ban = false;
card.usetype = 0;
card.free = true;
card.free_expire = 0;
cards.push(card);
cardSet.add(card.cardid);
}
cardgroup.accountid = account.id;
cardgroup.heroid = cfg.id;
cardgroup.selected = false;
cardgroup.isdefault = true;
cardgroup.cards = cards;
await cardgroup.save();
}
}
}
account.cards = [...cardSet];
result.cards = account.cards;
let heros: any[] = [];
for(let [key, hero] of account.heros) {

View File

@ -7,7 +7,7 @@ export default class HeroController extends BaseController {
async herolist(req: any) {
let account = req.user;
let heros: any[] = [];
for(let [key, hero] of account.heros) {
for(let [, hero] of account.heros) {
heros.push(hero.toJson());
}
//TODO:: 添加限免英雄和免费英雄