增加新的配置
This commit is contained in:
parent
d628879431
commit
3cc20295f6
20
docs/api.md
20
docs/api.md
@ -78,6 +78,7 @@
|
|||||||
usetype: 1, // 赛季专属, 0: 通用, 1: 赛季排位专用, 2: 匹配专用
|
usetype: 1, // 赛季专属, 0: 通用, 1: 赛季排位专用, 2: 匹配专用
|
||||||
free: false, // 是否免费
|
free: false, // 是否免费
|
||||||
free_expire: 1609919293 // 免费到期时间
|
free_expire: 1609919293 // 免费到期时间
|
||||||
|
time:1609919293 // 该卡第一次解锁时间
|
||||||
}]
|
}]
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -111,6 +112,8 @@
|
|||||||
trial_expire: 1609919293 // 试用到期时间, 0: 说明是永久
|
trial_expire: 1609919293 // 试用到期时间, 0: 说明是永久
|
||||||
level: 1, // 等级
|
level: 1, // 等级
|
||||||
exp: 0, // 当前的经验值
|
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
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,6 +3,10 @@ import {HeroCfg} from "../cfg/parsers/HeroCfg";
|
|||||||
import {UnitCfg} from "../cfg/parsers/UnitCfg";
|
import {UnitCfg} from "../cfg/parsers/UnitCfg";
|
||||||
import {BaseConst} from "../constants/BaseConst";
|
import {BaseConst} from "../constants/BaseConst";
|
||||||
import {FormulaCfg} from "../cfg/parsers/FormulaCfg";
|
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() {
|
export function initData() {
|
||||||
@ -10,6 +14,10 @@ export function initData() {
|
|||||||
rP(BaseConst.HERO, HeroCfg);
|
rP(BaseConst.HERO, HeroCfg);
|
||||||
rP(BaseConst.UNIT, UnitCfg);
|
rP(BaseConst.UNIT, UnitCfg);
|
||||||
rP(BaseConst.FORMULA, FormulaCfg);
|
rP(BaseConst.FORMULA, FormulaCfg);
|
||||||
|
rP(BaseConst.DROPITEM, DropItemCfg);
|
||||||
|
rP(BaseConst.ITEMCARD, ItemCardCfg);
|
||||||
|
rP(BaseConst.MATCH, MatchCfg);
|
||||||
|
rP(BaseConst.ITEMFUNC, ItemFuncCfg);
|
||||||
DataParser.loadAll();
|
DataParser.loadAll();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -68,4 +68,8 @@ export class BaseConst {
|
|||||||
public static readonly SYSTEMCARD = "systemcard";
|
public static readonly SYSTEMCARD = "systemcard";
|
||||||
public static readonly FORMULA = "formula";
|
public static readonly FORMULA = "formula";
|
||||||
public static readonly UNIT = "unit";
|
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";
|
||||||
}
|
}
|
||||||
|
@ -1,88 +1,99 @@
|
|||||||
import BaseController from "../common/base.controller";
|
import BaseController from '../common/base.controller'
|
||||||
import {router} from "../decorators/router";
|
import { router } from '../decorators/router'
|
||||||
import {ZError} from "../common/ZError";
|
import { ZError } from '../common/ZError'
|
||||||
import {BaseConst} from "../constants/BaseConst";
|
import { BaseConst } from '../constants/BaseConst'
|
||||||
import {CardGroup} from "../models/CardGroup";
|
import { CardGroup } from '../models/CardGroup'
|
||||||
import {Card} from "../models/subdoc/Card";
|
import { Card } from '../models/subdoc/Card'
|
||||||
|
|
||||||
export default class HeroController extends BaseController {
|
export default class HeroController extends BaseController {
|
||||||
@router('post /api/:accountid/heros')
|
@router('post /api/:accountid/heros')
|
||||||
async herolist(req: any) {
|
async herolist(req: any) {
|
||||||
let account = req.user;
|
let account = req.user
|
||||||
let heros: any[] = [];
|
let heros: any[] = []
|
||||||
for (let [, hero] of account.heros) {
|
for (let [, hero] of account.heros) {
|
||||||
heros.push(hero.toJson());
|
heros.push(hero.toJson())
|
||||||
}
|
}
|
||||||
//TODO:: 添加限免英雄和免费英雄
|
//TODO:: 添加限免英雄和免费英雄
|
||||||
return heros;
|
return heros
|
||||||
}
|
}
|
||||||
|
|
||||||
@router('post /api/:accountid/hero/unlock/:heroid')
|
@router('post /api/:accountid/hero/unlock/:heroid')
|
||||||
@router('post /svr/:accountid/hero/unlock/:heroid')
|
@router('post /svr/:accountid/hero/unlock/:heroid')
|
||||||
async unlockHero(req: any) {
|
async unlockHero(req: any) {
|
||||||
let account = req.user;
|
let account = req.user
|
||||||
let {heroid, type} = req.params;
|
let { heroid, type } = req.params
|
||||||
if (!heroid) {
|
if (!heroid) {
|
||||||
throw new ZError(101, '未指定heroid');
|
throw new ZError(101, '未指定heroid')
|
||||||
}
|
}
|
||||||
let hero;
|
let hero
|
||||||
if (!type) {
|
if (!type) {
|
||||||
let userMoney = !req.url.startsWith('/svr');
|
let userMoney = !req.url.startsWith('/svr')
|
||||||
hero = await account.unlockHero(heroid, userMoney);
|
hero = await account.unlockHero(heroid, userMoney)
|
||||||
// 将该英雄的默认卡组添加到玩家的卡组中,
|
// 将该英雄的默认卡组添加到玩家的卡组中,
|
||||||
// 将默认卡组里的卡添加到玩家可用卡牌中
|
// 将默认卡组里的卡添加到玩家可用卡牌中
|
||||||
let cardSet = new Set(account.cards);
|
let cardSet = new Set(account.cards)
|
||||||
let cfg = global.$cfg.get(BaseConst.HERO).get(parseInt(hero.heroid));
|
let cfg = global.$cfg.get(BaseConst.HERO).get(parseInt(hero.heroid))
|
||||||
let cardgroup = new CardGroup({});
|
let cardgroup = new CardGroup({})
|
||||||
let cards: Card[] = [];
|
let cards: Card[] = []
|
||||||
for (let i = 1; i < 10; i++) {
|
for (let i = 1; i < 10; i++) {
|
||||||
if (!cfg[`follower${ i }id`]) {
|
if (!cfg[`follower${ i }id`]) {
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
let card = new Card();
|
let card = new Card()
|
||||||
card.cardid = cfg[`follower${i}id`];
|
card.cardid = cfg[`follower${ i }id`]
|
||||||
card.owned = false;
|
card.owned = false
|
||||||
card.ban = false;
|
card.ban = false
|
||||||
card.usetype = 0;
|
card.usetype = 0
|
||||||
card.free = true;
|
card.free = true
|
||||||
card.free_expire = 0;
|
card.free_expire = 0
|
||||||
cards.push(card);
|
cards.push(card)
|
||||||
cardSet.add(card.cardid);
|
cardSet.add(card.cardid)
|
||||||
}
|
}
|
||||||
cardgroup.accountid = account.id;
|
cardgroup.accountid = account.id
|
||||||
cardgroup.heroid = hero.heroid;
|
cardgroup.heroid = hero.heroid
|
||||||
cardgroup.selected = false;
|
cardgroup.selected = false
|
||||||
cardgroup.isdefault = true;
|
cardgroup.isdefault = true
|
||||||
cardgroup.cards = cards;
|
cardgroup.cards = cards
|
||||||
await cardgroup.save();
|
await cardgroup.save()
|
||||||
account.cards = [...cardSet];
|
account.cards = [...cardSet]
|
||||||
await account.save();
|
await account.save()
|
||||||
} else {
|
} else {
|
||||||
hero = await account.tryHero(heroid);
|
hero = await account.tryHero(heroid)
|
||||||
await account.save();
|
await account.save()
|
||||||
|
|
||||||
}
|
}
|
||||||
return hero.toJson();
|
return hero.toJson()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@router('post /api/:accountid/hero/update/:heroid')
|
@router('post /api/:accountid/hero/update/:heroid')
|
||||||
async updateHero(req: any) {
|
async updateHero(req: any) {
|
||||||
let account = req.user;
|
let account = req.user
|
||||||
let {heroid, items} = req.params;
|
let { heroid, items } = req.params
|
||||||
if (!heroid || !items) {
|
if (!heroid || !items) {
|
||||||
throw new ZError(101, '参数不足');
|
throw new ZError(101, '参数不足')
|
||||||
}
|
}
|
||||||
if (!account.heros.has(heroid + '')) {
|
if (!account.heros.has(heroid + '')) {
|
||||||
throw new ZError(102, '你未解锁该英雄');
|
throw new ZError(102, '你未解锁该英雄')
|
||||||
}
|
}
|
||||||
let hero = account.heros.get(heroid + '');
|
let hero = account.heros.get(heroid + '')
|
||||||
if (hero.trial) {
|
if (hero.trial) {
|
||||||
throw new ZError(103, '不能升级试用英雄');
|
throw new ZError(103, '不能升级试用英雄')
|
||||||
}
|
}
|
||||||
let data = await account.updateHero(heroid, items);
|
let data = await account.updateHero(heroid, items)
|
||||||
await account.save();
|
await account.save()
|
||||||
return data;
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,11 @@ export class Hero {
|
|||||||
*/
|
*/
|
||||||
@prop({ default: 0 })
|
@prop({ default: 0 })
|
||||||
public exp: number
|
public exp: number
|
||||||
|
/**
|
||||||
|
* 英雄已解锁卡槽数量
|
||||||
|
*/
|
||||||
|
@prop({default: 1})
|
||||||
|
public slot: number
|
||||||
|
|
||||||
@prop()
|
@prop()
|
||||||
public time: number
|
public time: number
|
||||||
@ -39,6 +44,8 @@ export class Hero {
|
|||||||
free: this.free,
|
free: this.free,
|
||||||
trial: this.trial,
|
trial: this.trial,
|
||||||
trial_expire: this.trial_expire,
|
trial_expire: this.trial_expire,
|
||||||
|
slot: this.slot,
|
||||||
|
time: this.time,
|
||||||
ban: false
|
ban: false
|
||||||
}
|
}
|
||||||
data.owned = !this.trial
|
data.owned = !this.trial
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user