From 933f458b044663fc0e286cf43ccc049c78fdd8a3 Mon Sep 17 00:00:00 2001 From: zhl Date: Tue, 12 Jan 2021 17:19:28 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E8=8B=B1=E9=9B=84=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=97=B6,=20=E5=B0=86=E5=85=8D=E8=B4=B9=E8=8B=B1?= =?UTF-8?q?=E9=9B=84=E5=92=8C=E5=8D=A1=E7=89=8C=E7=AD=89=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E5=AD=98=E5=85=A5=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/AccountController.ts | 37 ++++++++++++++++++++++++++++ src/controllers/HeroController.ts | 2 +- 2 files changed, 38 insertions(+), 1 deletion(-) 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:: 添加限免英雄和免费英雄