增加一个游戏结束双倍领取的接口
This commit is contained in:
parent
2fe2efa6d9
commit
0c934eb85c
25
docs/api.md
25
docs/api.md
@ -685,7 +685,32 @@
|
||||
|
||||
```
|
||||
|
||||
### 26.游戏结束双倍领取
|
||||
|
||||
1. Method: POST
|
||||
2. URI: /api/:accountid/gamereward
|
||||
|
||||
| 字段 | 说明 |
|
||||
| -------- | -------------------------------------- |
|
||||
| accountid | 帐号id |
|
||||
> POST参数
|
||||
|
||||
|
||||
| 字段 |说明 |
|
||||
| -------- | -------------------------------------- |
|
||||
|roomid | 游戏房间id |
|
||||
|
||||
3. Response: JSON
|
||||
|
||||
```js
|
||||
[ //物品列表
|
||||
{
|
||||
"id": 0, //道具id
|
||||
"count": 0, //道具数量
|
||||
},
|
||||
]
|
||||
|
||||
```
|
||||
|
||||
## 三. 服务端接口列表
|
||||
|
||||
|
@ -10,6 +10,8 @@ import ItemCtrl from '../logic/ItemCtrl'
|
||||
import { ItemInfo } from '../logic/ItemDef'
|
||||
import { BagItem } from '../models/BagItem'
|
||||
import { setGameEnd, updateRank } from '../service/rank'
|
||||
import { ZError } from '../common/ZError'
|
||||
import { ActRecord } from '../models/ActRecord'
|
||||
|
||||
export default class RecordController extends BaseController {
|
||||
@role('anon')
|
||||
@ -146,4 +148,52 @@ export default class RecordController extends BaseController {
|
||||
}
|
||||
return {seasonData, itemData}
|
||||
}
|
||||
|
||||
@router('post /api/:accountid/gamereward')
|
||||
async doubleReward(req: any) {
|
||||
let { accountid, roomid } = req.params
|
||||
let day = (new Date(0)).format('yyyy-MM-dd', true)
|
||||
let arecord = (await ActRecord.findOrCreate({
|
||||
accountid,
|
||||
actid: roomid,
|
||||
day
|
||||
})).doc
|
||||
if (arecord.count > 0) {
|
||||
throw new ZError(12, 'already goted')
|
||||
}
|
||||
arecord.count += 1
|
||||
let records = await GameRecord.find({'players.accountid': accountid, roomid})
|
||||
if (!records || records.length == 0) {
|
||||
throw new ZError(10, 'record not found')
|
||||
}
|
||||
let record = records[0]
|
||||
if (!record.matchid) {
|
||||
throw new ZError(11, 'current game mode has no double reward')
|
||||
}
|
||||
let isWin = false
|
||||
for (let pdata of record.players) {
|
||||
if (pdata.accountid == accountid) {
|
||||
if (pdata.team == record.winner) {
|
||||
isWin = true
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
let cfg: MatchCfg = global.$cfg.get(BaseConst.MATCH).get(parseInt(record.matchid))
|
||||
if (!cfg) {
|
||||
error(`match cfg not found: ${record.matchid}`)
|
||||
}
|
||||
/**
|
||||
* 获取胜利失败的物品
|
||||
*/
|
||||
let items: ItemInfo[] = []
|
||||
if (isWin) {
|
||||
items = ItemCtrl.getItemsByInfo(cfg.winget);
|
||||
} else {
|
||||
items = ItemCtrl.getItemsByInfo(cfg.failget);
|
||||
}
|
||||
await BagItem.addItems(accountid, items, 'double_reward', roomid)
|
||||
await arecord.save()
|
||||
return items
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user