修改hero相关返回数据, 增加trial字段

This commit is contained in:
zhl 2021-01-08 12:06:36 +08:00
parent 0e80dc5bf1
commit 2390751a0f
5 changed files with 51 additions and 25 deletions

View File

@ -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 @@
```
```

View File

@ -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}`;
}
}

View File

@ -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')

View File

@ -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;

View File

@ -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;
}
}