增加新的配置

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, // 是否被禁用 ban: false, // 是否被禁用
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
``` ```

View File

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

View File

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

View File

@ -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:: 添加限免英雄和免费英雄
return heros;
} }
//TODO:: 添加限免英雄和免费英雄
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
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; let card = new Card()
if (!type) { card.cardid = cfg[`follower${ i }id`]
let userMoney = !req.url.startsWith('/svr'); card.owned = false
hero = await account.unlockHero(heroid, userMoney); card.ban = false
// 将该英雄的默认卡组添加到玩家的卡组中, card.usetype = 0
// 将默认卡组里的卡添加到玩家可用卡牌中 card.free = true
let cardSet = new Set(account.cards); card.free_expire = 0
let cfg = global.$cfg.get(BaseConst.HERO).get(parseInt(hero.heroid)); cards.push(card)
let cardgroup = new CardGroup({}); cardSet.add(card.cardid)
let cards: Card[] = []; }
for (let i = 1; i < 10; i++) { cardgroup.accountid = account.id
if (!cfg[`follower${i}id`]) { cardgroup.heroid = hero.heroid
break; cardgroup.selected = false
} cardgroup.isdefault = true
let card = new Card(); cardgroup.cards = cards
card.cardid = cfg[`follower${i}id`]; await cardgroup.save()
card.owned = false; account.cards = [...cardSet]
card.ban = false; await account.save()
card.usetype = 0; } else {
card.free = true; hero = await account.tryHero(heroid)
card.free_expire = 0; await account.save()
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();
} }
return hero.toJson()
@router('post /api/:accountid/hero/update/:heroid') }
async updateHero(req: any) {
let account = req.user; @router('post /api/:accountid/hero/update/:heroid')
let {heroid, items} = req.params; async updateHero(req: any) {
if (!heroid || !items) { let account = req.user
throw new ZError(101, '参数不足'); let { heroid, items } = req.params
} if (!heroid || !items) {
if (!account.heros.has(heroid + '')) { throw new ZError(101, '参数不足')
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;
} }
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 }) @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

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)
} }