From 3cc20295f6a71461e2ee4dba6bb1a70679acf5fe Mon Sep 17 00:00:00 2001 From: zhl Date: Thu, 21 Jan 2021 15:16:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=B0=E7=9A=84=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/api.md | 22 +++- src/common/GConfig.ts | 8 ++ src/constants/BaseConst.ts | 4 + src/controllers/HeroController.ts | 165 ++++++++++++++++-------------- src/models/subdoc/Hero.ts | 7 ++ src/service/jcfw.ts | 16 ++- 6 files changed, 142 insertions(+), 80 deletions(-) diff --git a/docs/api.md b/docs/api.md index ee3c58b..dfa7a43 100644 --- a/docs/api.md +++ b/docs/api.md @@ -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 + + ``` diff --git a/src/common/GConfig.ts b/src/common/GConfig.ts index 8084217..ce749ec 100644 --- a/src/common/GConfig.ts +++ b/src/common/GConfig.ts @@ -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(); } diff --git a/src/constants/BaseConst.ts b/src/constants/BaseConst.ts index 1cdbfac..27d418d 100644 --- a/src/constants/BaseConst.ts +++ b/src/constants/BaseConst.ts @@ -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"; } diff --git a/src/controllers/HeroController.ts b/src/controllers/HeroController.ts index c0cc0ff..edf1e22 100644 --- a/src/controllers/HeroController.ts +++ b/src/controllers/HeroController.ts @@ -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} + */ + @router('post /api/:accountid/hero/unlockslot/:heroid') + async unlockCardSlot(req: any) { + let account = req.user + let { heroid } = req.params + } } diff --git a/src/models/subdoc/Hero.ts b/src/models/subdoc/Hero.ts index c9a8ba5..79db1ba 100644 --- a/src/models/subdoc/Hero.ts +++ b/src/models/subdoc/Hero.ts @@ -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 diff --git a/src/service/jcfw.ts b/src/service/jcfw.ts index 354021f..381f745 100644 --- a/src/service/jcfw.ts +++ b/src/service/jcfw.ts @@ -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>} + */ +export function getGameConfig(gameid: string, channel: string) { + let data = { gameid, channel } + let paramStr = generateKeyValStr(data) + let url = `${ CONFIG_URL }&${ paramStr }` + return axios.get(url) }