diff --git a/docs/api.md b/docs/api.md index 86bd89f..6804d07 100644 --- a/docs/api.md +++ b/docs/api.md @@ -35,8 +35,10 @@ usetype: 1, // 赛季专属, 0: 通用, 1: 赛季排位专用, 2: 匹配专用 level: number, // 等级 exp: number, // 当前的经验值 + ban: false, // 是否被禁用 free: false, // 是否免费 - free_expire: 1609919293, // 免费到期时间, 0: 说明是永久免费 + trial: false, // 是否是试用 + trial_expire: 1609919293, // 试用到期时间, 0: 说明是永久 }], moneys: { 'coin': 0, // 金币 @@ -101,8 +103,10 @@ owned: true, // 是否已拥有 ban: false, // 是否被禁用 usetype: 1, // 赛季专属, 0: 通用, 1: 赛季排位专用, 2: 匹配专用 + ban: false, // 是否被禁用 free: false, // 是否免费 - free_expire: 1609919293 // 免费到期时间, 0: 说明是永久免费 + trial: false, // 是否试用 + trial_expire: 1609919293 // 试用到期时间, 0: 说明是永久 level: 1, // 等级 exp: 0, // 当前的经验值 }] @@ -203,7 +207,8 @@ ban: false, // 是否被禁用 usetype: 1, // 赛季专属, 0: 通用, 1: 赛季排位专用, 2: 匹配专用 free: false, // 是否免费 - free_expire: 1609919293 // 免费到期时间, 0: 说明是永久免费 + trial: false, // 是否是试用 + trial_expire: 1609919293 // 试用到期时间, 0: 说明是永久 level: 1, // 等级 exp: 0, // 当前的经验值 }] @@ -311,4 +316,6 @@ +``` + ``` \ No newline at end of file diff --git a/src/constants/MoneyTypeConst.ts b/src/constants/MoneyTypeConst.ts index 9f9fac1..e0650f1 100644 --- a/src/constants/MoneyTypeConst.ts +++ b/src/constants/MoneyTypeConst.ts @@ -19,15 +19,13 @@ export class MoneyTypeConst { * card_scroll: 抽卡卷轴 */ public static readonly CARD_SCROLL = 'card_scroll'; - private static readonly HERO_SHARD_HEROID = 'hero_shard_'; - private static readonly HERO_EXP_HEROID = 'hero_exp_'; /** * 英雄专用碎片 * @param heroId */ public static getHeroShard(heroId: number): string { - return `${this.HERO_SHARD_HEROID}_${heroId}`; + return `${this.HERO_SHARD}_${heroId}`; } /** @@ -35,6 +33,6 @@ export class MoneyTypeConst { * @param heroId */ public static getHeroExp(heroId: number): string { - return `${this.HERO_EXP_HEROID}_${heroId}`; + return `${this.HERO_EXP}_${heroId}`; } } diff --git a/src/controllers/HeroController.ts b/src/controllers/HeroController.ts index 349a88d..0bffed9 100644 --- a/src/controllers/HeroController.ts +++ b/src/controllers/HeroController.ts @@ -11,15 +11,7 @@ export default class HeroController extends BaseController { let account = req.user; let heros: any[] = []; for(let [key, hero] of account.heros) { - heros.push({ - heroid: hero.heroid, - owned: true, - usetype: 0, - level: hero.level, - exp: hero.exp, - free: hero.free, - free_expire: 0 - }); + heros.push(hero.toJson()); } //TODO:: 添加限免英雄和免费英雄 return heros; @@ -37,18 +29,12 @@ export default class HeroController extends BaseController { if (!type) { hero = await account.unlockHero(heroid); await account.save(); - hero.owned = true; - hero.ban = false; - hero.usetype = 0; } else { hero = await account.tryHero(heroid); await account.save(); - hero.owned = false; - hero.ban = false; - hero.usetype = 0; - hero.free_expire = 0; + } - return hero; + return hero.toJson(); } catch (err) { throw err; } @@ -66,6 +52,8 @@ export default class HeroController extends BaseController { if (!account.heros.has(heroid + '')) { throw new ZError(102, '你未解锁该英雄'); } + let hero = account.heros.get(heroid + ''); + } @router('post /api/:accountid/hero/toexp/:heroid') diff --git a/src/models/User.ts b/src/models/User.ts index 8fbdf9e..37a2b5b 100644 --- a/src/models/User.ts +++ b/src/models/User.ts @@ -119,7 +119,9 @@ class UserClass extends FindOrCreate{ let hero = new Hero(); hero.heroid = heroid; hero.free = false; + hero.trial = false; hero.level = 1; + hero.trial_expire = 0; hero.exp = 0; this.heros.set(heroid + '', hero); return hero; @@ -132,8 +134,10 @@ class UserClass extends FindOrCreate{ //TODO:: 根据配置查看该英雄是否可使用 let hero = new Hero(); hero.heroid = heroid; - hero.free = true; + hero.free = false; + hero.trial = true; hero.level = 1; + hero.trial_expire = 0; hero.exp = 0; this.heros.set(heroid+'', hero); return hero; diff --git a/src/models/subdoc/Hero.ts b/src/models/subdoc/Hero.ts index 61615db..13d92e5 100644 --- a/src/models/subdoc/Hero.ts +++ b/src/models/subdoc/Hero.ts @@ -8,8 +8,37 @@ export class Hero { */ @prop({default: false}) public free: boolean; + /** + * 是否是试用 + */ + @prop({default: false}) + public trial: boolean; + + @prop({default: 0}) + public trial_expire: number; + /** + * 等级 + */ @prop({default: 1}) public level: number; + /** + * 该等级下的经验值 + */ @prop({default: 0}) public exp: number; + + public toJson() { + let data: any = { + heroid: this.heroid, + usetype: 0, + level: this.level, + exp: this.exp, + free: this.free, + trial: this.trial, + trial_expire: this.trial_expire, + ban: false, + }; + data.owned = !this.trial; + return data; + } }