增加新的配置

This commit is contained in:
zhl 2021-01-21 15:16:40 +08:00
parent d628879431
commit 3cc20295f6
6 changed files with 142 additions and 80 deletions

View File

@ -77,7 +77,8 @@
ban: false, // 是否被禁用
usetype: 1, // 赛季专属, 0: 通用, 1: 赛季排位专用, 2: 匹配专用
free: false, // 是否免费
free_expire: 1609919293 // 免费到期时间
free_expire: 1609919293 // 免费到期时间
time:1609919293 // 该卡第一次解锁时间
}]
```
@ -111,6 +112,8 @@
trial_expire: 1609919293 // 试用到期时间, 0: 说明是永久
level: 1, // 等级
exp: 0, // 当前的经验值
time: 1609919293 // 该英雄解锁时间
slot: 1, // 已解锁卡槽数量
}]
```
@ -364,6 +367,23 @@
},
]
```
### 14. 解锁英雄卡槽
1. Method: POST
2. URI: /api/:accountid/hero/unlockslot/:heroid
| 字段 | 说明 |
| -------- | -------------------------------------- |
| accountid | 帐号id |
| heroid | 英雄id |
3. Response: JSON
```js
```

View File

@ -3,6 +3,10 @@ import {HeroCfg} from "../cfg/parsers/HeroCfg";
import {UnitCfg} from "../cfg/parsers/UnitCfg";
import {BaseConst} from "../constants/BaseConst";
import {FormulaCfg} from "../cfg/parsers/FormulaCfg";
import { DropItemCfg } from '../cfg/parsers/DropItemCfg'
import { ItemCardCfg } from '../cfg/parsers/ItemCardCfg'
import { MatchCfg } from '../cfg/parsers/MatchCfg'
import { ItemFuncCfg } from '../cfg/parsers/ItemFuncCfg'
export function initData() {
@ -10,6 +14,10 @@ export function initData() {
rP(BaseConst.HERO, HeroCfg);
rP(BaseConst.UNIT, UnitCfg);
rP(BaseConst.FORMULA, FormulaCfg);
rP(BaseConst.DROPITEM, DropItemCfg);
rP(BaseConst.ITEMCARD, ItemCardCfg);
rP(BaseConst.MATCH, MatchCfg);
rP(BaseConst.ITEMFUNC, ItemFuncCfg);
DataParser.loadAll();
}

View File

@ -68,4 +68,8 @@ export class BaseConst {
public static readonly SYSTEMCARD = "systemcard";
public static readonly FORMULA = "formula";
public static readonly UNIT = "unit";
public static readonly DROPITEM = "dropitem";
public static readonly ITEMCARD = "itemcard";
public static readonly MATCH = "match";
public static readonly ITEMFUNC = "itemfunc";
}

View File

@ -1,88 +1,99 @@
import BaseController from "../common/base.controller";
import {router} from "../decorators/router";
import {ZError} from "../common/ZError";
import {BaseConst} from "../constants/BaseConst";
import {CardGroup} from "../models/CardGroup";
import {Card} from "../models/subdoc/Card";
import BaseController from '../common/base.controller'
import { router } from '../decorators/router'
import { ZError } from '../common/ZError'
import { BaseConst } from '../constants/BaseConst'
import { CardGroup } from '../models/CardGroup'
import { Card } from '../models/subdoc/Card'
export default class HeroController extends BaseController {
@router('post /api/:accountid/heros')
async herolist(req: any) {
let account = req.user;
let heros: any[] = [];
for(let [, hero] of account.heros) {
heros.push(hero.toJson());
}
//TODO:: 添加限免英雄和免费英雄
return heros;
@router('post /api/:accountid/heros')
async herolist(req: any) {
let account = req.user
let heros: any[] = []
for (let [, hero] of account.heros) {
heros.push(hero.toJson())
}
//TODO:: 添加限免英雄和免费英雄
return heros
}
@router('post /api/:accountid/hero/unlock/:heroid')
@router('post /svr/:accountid/hero/unlock/:heroid')
async unlockHero(req: any) {
let account = req.user;
let {heroid, type} = req.params;
if (!heroid) {
throw new ZError(101, '未指定heroid');
@router('post /api/:accountid/hero/unlock/:heroid')
@router('post /svr/:accountid/hero/unlock/:heroid')
async unlockHero(req: any) {
let account = req.user
let { heroid, type } = req.params
if (!heroid) {
throw new ZError(101, '未指定heroid')
}
let hero
if (!type) {
let userMoney = !req.url.startsWith('/svr')
hero = await account.unlockHero(heroid, userMoney)
// 将该英雄的默认卡组添加到玩家的卡组中,
// 将默认卡组里的卡添加到玩家可用卡牌中
let cardSet = new Set(account.cards)
let cfg = global.$cfg.get(BaseConst.HERO).get(parseInt(hero.heroid))
let cardgroup = new CardGroup({})
let cards: Card[] = []
for (let i = 1; i < 10; i++) {
if (!cfg[`follower${ i }id`]) {
break
}
let hero;
if (!type) {
let userMoney = !req.url.startsWith('/svr');
hero = await account.unlockHero(heroid, userMoney);
// 将该英雄的默认卡组添加到玩家的卡组中,
// 将默认卡组里的卡添加到玩家可用卡牌中
let cardSet = new Set(account.cards);
let cfg = global.$cfg.get(BaseConst.HERO).get(parseInt(hero.heroid));
let cardgroup = new CardGroup({});
let cards: Card[] = [];
for (let i = 1; i < 10; i++) {
if (!cfg[`follower${i}id`]) {
break;
}
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 = hero.heroid;
cardgroup.selected = false;
cardgroup.isdefault = true;
cardgroup.cards = cards;
await cardgroup.save();
account.cards = [...cardSet];
await account.save();
} else {
hero = await account.tryHero(heroid);
await account.save();
}
return hero.toJson();
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 = hero.heroid
cardgroup.selected = false
cardgroup.isdefault = true
cardgroup.cards = cards
await cardgroup.save()
account.cards = [...cardSet]
await account.save()
} else {
hero = await account.tryHero(heroid)
await account.save()
}
return hero.toJson()
@router('post /api/:accountid/hero/update/:heroid')
async updateHero(req: any) {
let account = req.user;
let {heroid, items} = req.params;
if (!heroid || !items) {
throw new ZError(101, '参数不足');
}
if (!account.heros.has(heroid + '')) {
throw new ZError(102, '你未解锁该英雄');
}
let hero = account.heros.get(heroid + '');
if (hero.trial) {
throw new ZError(103, '不能升级试用英雄');
}
let data = await account.updateHero(heroid, items);
await account.save();
return data;
}
@router('post /api/:accountid/hero/update/:heroid')
async updateHero(req: any) {
let account = req.user
let { heroid, items } = req.params
if (!heroid || !items) {
throw new ZError(101, '参数不足')
}
if (!account.heros.has(heroid + '')) {
throw new ZError(102, '你未解锁该英雄')
}
let hero = account.heros.get(heroid + '')
if (hero.trial) {
throw new ZError(103, '不能升级试用英雄')
}
let data = await account.updateHero(heroid, items)
await account.save()
return data
}
/**
*
* @param req
* @return {Promise<void>}
*/
@router('post /api/:accountid/hero/unlockslot/:heroid')
async unlockCardSlot(req: any) {
let account = req.user
let { heroid } = req.params
}
}

View File

@ -26,6 +26,11 @@ export class Hero {
*/
@prop({ default: 0 })
public exp: number
/**
*
*/
@prop({default: 1})
public slot: number
@prop()
public time: number
@ -39,6 +44,8 @@ export class Hero {
free: this.free,
trial: this.trial,
trial_expire: this.trial_expire,
slot: this.slot,
time: this.time,
ban: false
}
data.owned = !this.trial

View File

@ -1,5 +1,17 @@
const BASE_URL = ''
import { generateKeyValStr } from '../utils/string.util'
import axios from 'axios'
export function getGameConfig(session_id: string, account_id: string) {
const CONFIG_URL = 'https://cloud.kingsome.cn/webapp/index.php?c=Config&a=read'
/**
* jcfw中该游戏的配置
* @param {string} gameid
* @param {string} channel
* @return {Promise<AxiosResponse<any>>}
*/
export function getGameConfig(gameid: string, channel: string) {
let data = { gameid, channel }
let paramStr = generateKeyValStr(data)
let url = `${ CONFIG_URL }&${ paramStr }`
return axios.get(url)
}