增加解锁卡槽的接口
This commit is contained in:
parent
880811235c
commit
72a0d6502d
@ -1,5 +1,5 @@
|
||||
{
|
||||
"redis": "redis://127.0.0.1:6379/15",
|
||||
"db_main": "mongodb://192.168.100.24/card-development",
|
||||
"db_main": "mongodb://127.0.0.1/card-development",
|
||||
"port": 2987
|
||||
}
|
||||
|
29
docs/api.md
29
docs/api.md
@ -368,8 +368,35 @@
|
||||
]
|
||||
|
||||
```
|
||||
### 14. 使用物品
|
||||
1. Method: POST
|
||||
2. URI: /api/:accountid/useitem
|
||||
|
||||
### 14. 解锁英雄卡槽
|
||||
| 字段 | 说明 |
|
||||
| -------- | -------------------------------------- |
|
||||
| accountid | 帐号id |
|
||||
|
||||
> POST参数
|
||||
|
||||
|
||||
| 字段 | 说明 |
|
||||
| -------- | -------------------------------------- |
|
||||
| itemid |物品id |
|
||||
| count |使用数量 |
|
||||
|
||||
3. Response: JSON
|
||||
|
||||
```js
|
||||
[ //物品列表
|
||||
{
|
||||
"itemid": 0, //道具id
|
||||
"itemnum": 0, //道具数量
|
||||
},
|
||||
]
|
||||
|
||||
```
|
||||
|
||||
### 15. 解锁英雄卡槽
|
||||
1. Method: POST
|
||||
2. URI: /api/:accountid/hero/unlockslot/:heroid
|
||||
|
||||
|
39
package-lock.json
generated
39
package-lock.json
generated
@ -40,6 +40,12 @@
|
||||
"integrity": "sha512-Q1y515GcOdTHgagaVFhHnIFQ38ygs/kmxdNpvpou+raI9UO3YZcHDngBSYKQklcKlvA7iuQlmIKbzvmxcOE9CQ==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/json5": {
|
||||
"version": "0.0.29",
|
||||
"resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz",
|
||||
"integrity": "sha1-7ihweulOEdK4J7y+UnC86n8+ce4=",
|
||||
"dev": true
|
||||
},
|
||||
"@types/jsonwebtoken": {
|
||||
"version": "8.5.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/jsonwebtoken/-/jsonwebtoken-8.5.0.tgz",
|
||||
@ -616,6 +622,15 @@
|
||||
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz",
|
||||
"integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg=="
|
||||
},
|
||||
"json5": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/json5/-/json5-1.0.1.tgz",
|
||||
"integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"minimist": "^1.2.0"
|
||||
}
|
||||
},
|
||||
"jsonwebtoken": {
|
||||
"version": "8.5.1",
|
||||
"resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-8.5.1.tgz",
|
||||
@ -772,6 +787,12 @@
|
||||
"brace-expansion": "^1.1.7"
|
||||
}
|
||||
},
|
||||
"minimist": {
|
||||
"version": "1.2.5",
|
||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
|
||||
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
|
||||
"dev": true
|
||||
},
|
||||
"mkdirp": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz",
|
||||
@ -1137,6 +1158,12 @@
|
||||
"safe-buffer": "~5.2.0"
|
||||
}
|
||||
},
|
||||
"strip-bom": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz",
|
||||
"integrity": "sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=",
|
||||
"dev": true
|
||||
},
|
||||
"tiny-lru": {
|
||||
"version": "7.0.6",
|
||||
"resolved": "https://registry.npmjs.org/tiny-lru/-/tiny-lru-7.0.6.tgz",
|
||||
@ -1177,6 +1204,18 @@
|
||||
"yn": "3.1.1"
|
||||
}
|
||||
},
|
||||
"tsconfig-paths": {
|
||||
"version": "3.9.0",
|
||||
"resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.9.0.tgz",
|
||||
"integrity": "sha512-dRcuzokWhajtZWkQsDVKbWyY+jgcLC5sqJhg2PSgf4ZkH2aHPvaOY8YWGhmjb68b5qqTfasSsDO9k7RUiEmZAw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/json5": "^0.0.29",
|
||||
"json5": "^1.0.1",
|
||||
"minimist": "^1.2.0",
|
||||
"strip-bom": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"tslib": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.1.0.tgz",
|
||||
|
@ -4,7 +4,7 @@
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"dev:api": "DEBUG=colyseus:*,jc:* node --require ts-node/register --inspect src/api.ts",
|
||||
"dev:api": "DEBUG=colyseus:*,jc:* ts-node -r tsconfig-paths/register src/api.ts",
|
||||
"win": "$env:DEBUG='jc:*';node --require ts-node/register --inspect src/api.ts",
|
||||
"debug": "node --require ts-node/register --inspect src/api.ts"
|
||||
},
|
||||
@ -36,6 +36,7 @@
|
||||
"@types/mongoose": "5.10.3",
|
||||
"@types/node": "^14.14.20",
|
||||
"ts-node": "^9.1.1",
|
||||
"tsconfig-paths": "^3.9.0",
|
||||
"typescript": "^4.1.3"
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,8 @@ export default class AccountController extends BaseController {
|
||||
hero.free = true
|
||||
hero.trial = false
|
||||
hero.level = 1
|
||||
hero.slot = 1
|
||||
hero.time = Date.now()
|
||||
hero.exp = 0
|
||||
if (!account.heros.has(cfg.id + '')) {
|
||||
account.heros.set(cfg.id + '', hero)
|
||||
|
@ -4,6 +4,9 @@ import { ZError } from '../common/ZError'
|
||||
import { BaseConst } from '../constants/BaseConst'
|
||||
import { CardGroup } from '../models/CardGroup'
|
||||
import { Card } from '../models/subdoc/Card'
|
||||
import { HeroCfg } from '../cfg/parsers/HeroCfg'
|
||||
import { Hero } from '../models/subdoc/Hero'
|
||||
import { BagItem, ItemType } from '../models/BagItem'
|
||||
|
||||
export default class HeroController extends BaseController {
|
||||
@router('post /api/:accountid/heros')
|
||||
@ -93,7 +96,32 @@ export default class HeroController extends BaseController {
|
||||
@router('post /api/:accountid/hero/unlockslot/:heroid')
|
||||
async unlockCardSlot(req: any) {
|
||||
let account = req.user
|
||||
let { heroid } = req.params
|
||||
let { accountid, heroid } = req.params
|
||||
let cfg: HeroCfg = global.$cfg.get(BaseConst.HERO).get(heroid << 0)
|
||||
if (!cfg) {
|
||||
throw new ZError(10, 'hero not found')
|
||||
}
|
||||
if (!account.heros.has(heroid + '')) {
|
||||
throw new ZError(11, 'hero not unlock')
|
||||
}
|
||||
let hero: Hero = account.heros.get(heroid + '')
|
||||
if (hero.slot >= cfg.groupmax) {
|
||||
throw new ZError(12, 'hero slot reach max')
|
||||
}
|
||||
let needSlot = hero.slot + 1
|
||||
// @ts-ignore
|
||||
let needItem = cfg[`Unlockgroup${needSlot}id`]
|
||||
// @ts-ignore
|
||||
let needCount = cfg[`Unlockgroup${needSlot}num`]
|
||||
let item = await BagItem.findOne({accountid, itemid: needItem, itemtype: ItemType.UNKNOW})
|
||||
if (!item || item.count < needCount) {
|
||||
throw new ZError(13, 'not enough unlock item')
|
||||
}
|
||||
item.count -= needCount
|
||||
await item.save()
|
||||
hero.slot += 1;
|
||||
await account.save()
|
||||
return {slot: hero.slot}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -187,6 +187,8 @@ class UserClass extends FindOrCreate {
|
||||
hero.level = 1
|
||||
hero.trial_expire = 0
|
||||
hero.exp = 0
|
||||
hero.slot = 1
|
||||
hero.time = Date.now()
|
||||
this.heros.set(heroid + '', hero)
|
||||
return hero
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user