添加刷新武将和拼藏宝图的接口
This commit is contained in:
parent
b0a1344495
commit
6b1b9f7f58
36
docs/api.md
36
docs/api.md
@ -448,6 +448,42 @@
|
|||||||
]
|
]
|
||||||
|
|
||||||
```
|
```
|
||||||
|
### 18. 刷新随机到的武将
|
||||||
|
1. Method: POST
|
||||||
|
2. URI: /api/:accountid/randomhero
|
||||||
|
|
||||||
|
| 字段 | 说明 |
|
||||||
|
| -------- | -------------------------------------- |
|
||||||
|
| accountid | 帐号id |
|
||||||
|
|
||||||
|
|
||||||
|
3. Response: JSON
|
||||||
|
|
||||||
|
```js
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### 19. 拼藏宝图
|
||||||
|
1. Method: POST
|
||||||
|
2. URI: /api/:accountid/puzzle
|
||||||
|
|
||||||
|
| 字段 | 说明 |
|
||||||
|
| -------- | -------------------------------------- |
|
||||||
|
| accountid | 帐号id |
|
||||||
|
|
||||||
|
|
||||||
|
3. Response: JSON
|
||||||
|
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
"id": 0, //道具id
|
||||||
|
"count": 0, //道具数量
|
||||||
|
"type": 1 //道具类型
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,6 +4,8 @@ import { BagItem } from '../models/BagItem'
|
|||||||
import { ZError } from '../common/ZError'
|
import { ZError } from '../common/ZError'
|
||||||
import { ItemInfo } from '../logic/ItemDef'
|
import { ItemInfo } from '../logic/ItemDef'
|
||||||
import ItemCtrl from '../logic/ItemCtrl'
|
import ItemCtrl from '../logic/ItemCtrl'
|
||||||
|
import { BaseConst } from '../constants/BaseConst'
|
||||||
|
import { error } from '../common/Debug'
|
||||||
|
|
||||||
export default class ItemController extends BaseController {
|
export default class ItemController extends BaseController {
|
||||||
@router('post /api/:accountid/items')
|
@router('post /api/:accountid/items')
|
||||||
@ -23,7 +25,7 @@ export default class ItemController extends BaseController {
|
|||||||
let { accountid, itemid, count } = req.params
|
let { accountid, itemid, count } = req.params
|
||||||
let record = await BagItem.findOne({
|
let record = await BagItem.findOne({
|
||||||
accountid,
|
accountid,
|
||||||
itemid,
|
itemid
|
||||||
})
|
})
|
||||||
if (!record) {
|
if (!record) {
|
||||||
throw new ZError(11, 'item not found')
|
throw new ZError(11, 'item not found')
|
||||||
@ -82,8 +84,45 @@ export default class ItemController extends BaseController {
|
|||||||
return record.toJson()
|
return record.toJson()
|
||||||
}
|
}
|
||||||
|
|
||||||
@router('post /svr/:accountid/randomhero')
|
@router('post /api/:accountid/randomhero')
|
||||||
async randomHero(req: any) {
|
async randomHero(req: any) {
|
||||||
|
let { accountid } = req.params
|
||||||
|
const cfg = global.$cfg.get(BaseConst.ITEMFUNC).get(90003)
|
||||||
|
const itemInfos: ItemInfo[] = ItemCtrl.getItemsByInfo(cfg.consume1)
|
||||||
|
for (let item of itemInfos) {
|
||||||
|
let record = await BagItem.findOne({ accountid, itemid: item.id })
|
||||||
|
if (!record || record.count < item.count) {
|
||||||
|
throw new ZError(10, 'not enough item' + item.id)
|
||||||
|
}
|
||||||
|
record.count -= item.count
|
||||||
|
await record.save()
|
||||||
|
}
|
||||||
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@router('post /api/:accountid/puzzle')
|
||||||
|
async puzzleMap(req: any) {
|
||||||
|
let { accountid } = req.params
|
||||||
|
const cfg = global.$cfg.get(BaseConst.ITEMFUNC).get(90004)
|
||||||
|
const itemInfos: ItemInfo[] = ItemCtrl.getItemsByInfo(cfg.consume1)
|
||||||
|
for (let item of itemInfos) {
|
||||||
|
let record = await BagItem.findOne({ accountid, itemid: item.id })
|
||||||
|
if (!record || record.count < item.count) {
|
||||||
|
throw new ZError(10, 'not enough item' + item.id)
|
||||||
|
}
|
||||||
|
record.count -= item.count
|
||||||
|
await record.save()
|
||||||
|
}
|
||||||
|
const resultItems = ItemCtrl.getItemsByInfo(cfg.get)
|
||||||
|
if (!resultItems || resultItems.length == 0) {
|
||||||
|
error(`拼藏宝图, 未获取到正确的目标物品配置`)
|
||||||
|
throw new ZError(11, 'no target item found')
|
||||||
|
}
|
||||||
|
let resultItem = resultItems[0]
|
||||||
|
let newItem = (await BagItem.findOrCreate({ accountid, itemid: resultItem.id, itemtype: resultItem.type })).doc
|
||||||
|
newItem.count += resultItem.count
|
||||||
|
await newItem.save()
|
||||||
|
return newItem.toJson()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user