diff --git a/src/controllers/AccountController.ts b/src/controllers/AccountController.ts index 426ac26..19a46a1 100644 --- a/src/controllers/AccountController.ts +++ b/src/controllers/AccountController.ts @@ -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) { diff --git a/src/controllers/HeroController.ts b/src/controllers/HeroController.ts index 29bcb1f..fa225b6 100644 --- a/src/controllers/HeroController.ts +++ b/src/controllers/HeroController.ts @@ -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:: 添加限免英雄和免费英雄