Merge branch 'master' of http://git.kingsome.cn/node/card_info_svr
This commit is contained in:
commit
07b7f2ed0b
83
docs/api.md
83
docs/api.md
@ -40,15 +40,12 @@
|
|||||||
trial: false, // 是否是试用
|
trial: false, // 是否是试用
|
||||||
trial_expire: 1609919293, // 试用到期时间, 0: 说明是永久
|
trial_expire: 1609919293, // 试用到期时间, 0: 说明是永久
|
||||||
}],
|
}],
|
||||||
moneys: {
|
moneys: [
|
||||||
'coin': 0, // 金币
|
{
|
||||||
'diamond': 0, // 钻石
|
"itemid": 80012, //代币的id
|
||||||
'hero_shard': 0, // 通用英雄碎片
|
"itemnum": 140 // 数量
|
||||||
'hero_exp': 0, // 通用英雄经验
|
}
|
||||||
'hero_shard_heroid': 0, // 英雄专用碎片
|
],
|
||||||
'hero_exp_heroid': 0, // 英雄专用经验
|
|
||||||
'card_scroll': 0, //抽卡卷轴
|
|
||||||
},
|
|
||||||
normal_stat: [0, 0, 0, 0] //匹配: 胜利场数, 失败场数, 平局场数, 掉线场数
|
normal_stat: [0, 0, 0, 0] //匹配: 胜利场数, 失败场数, 平局场数, 掉线场数
|
||||||
season_rank: 1 // 当前赛季排名
|
season_rank: 1 // 当前赛季排名
|
||||||
match_score: 1000 //当前匹配分, 用于匹配时上传
|
match_score: 1000 //当前匹配分, 用于匹配时上传
|
||||||
@ -341,8 +338,9 @@
|
|||||||
```js
|
```js
|
||||||
[ //附件列表
|
[ //附件列表
|
||||||
{
|
{
|
||||||
"itemid": 0, //道具id
|
"id": 0, //道具id
|
||||||
"itemnum": 0, //道具数量
|
"count": 0, //道具数量
|
||||||
|
"type": 1 //道具类型
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -368,9 +366,10 @@
|
|||||||
```js
|
```js
|
||||||
[ //物品列表
|
[ //物品列表
|
||||||
{
|
{
|
||||||
"itemid": 0, //道具id
|
"id": 0, //道具id
|
||||||
"itemnum": 0, //道具数量
|
"count": 0, //道具数量
|
||||||
},
|
"type": 1 //道具类型
|
||||||
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
```
|
```
|
||||||
@ -395,8 +394,9 @@
|
|||||||
```js
|
```js
|
||||||
[ //物品列表
|
[ //物品列表
|
||||||
{
|
{
|
||||||
"itemid": 0, //道具id
|
"id": 0, //道具id
|
||||||
"itemnum": 0, //道具数量
|
"count": 0, //道具数量
|
||||||
|
"type": 1 //道具类型
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -471,37 +471,14 @@
|
|||||||
```js
|
```js
|
||||||
[ //物品列表
|
[ //物品列表
|
||||||
{
|
{
|
||||||
"itemid": 0, //道具id
|
"id": 0, //道具id
|
||||||
"itemnum": 0, //道具数量
|
"count": 0, //道具数量
|
||||||
|
"type": 1 //道具类型
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### 18. 开始比赛
|
|
||||||
1. Method: POST
|
|
||||||
2. URI: /api/:accountid/beginmatch
|
|
||||||
|
|
||||||
| 字段 | 说明 |
|
|
||||||
| -------- | -------------------------------------- |
|
|
||||||
| accountid | 帐号id |
|
|
||||||
|
|
||||||
> POST参数
|
|
||||||
|
|
||||||
|
|
||||||
| 字段 | 说明 |
|
|
||||||
| -------- | -------------------------------------- |
|
|
||||||
| matchid |10_match.xlsx里的id |
|
|
||||||
|
|
||||||
|
|
||||||
3. Response: JSON
|
|
||||||
|
|
||||||
```js
|
|
||||||
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -522,6 +499,28 @@
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 2. 开始比赛
|
||||||
|
1. Method: POST
|
||||||
|
2. URI: /svr/:accountid/beginmatch
|
||||||
|
|
||||||
|
| 字段 | 说明 |
|
||||||
|
| -------- | -------------------------------------- |
|
||||||
|
| accountid | 帐号id |
|
||||||
|
|
||||||
|
> POST参数
|
||||||
|
|
||||||
|
|
||||||
|
| 字段 | 说明 |
|
||||||
|
| -------- | -------------------------------------- |
|
||||||
|
| matchid |10_match.xlsx里的id |
|
||||||
|
|
||||||
|
|
||||||
|
3. Response: JSON
|
||||||
|
|
||||||
|
```js
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@ import { BaseConst } from '../constants/BaseConst'
|
|||||||
import { Hero } from '../models/subdoc/Hero'
|
import { Hero } from '../models/subdoc/Hero'
|
||||||
import { CardGroup } from '../models/CardGroup'
|
import { CardGroup } from '../models/CardGroup'
|
||||||
import { BagItem, ItemType } from '../models/BagItem'
|
import { BagItem, ItemType } from '../models/BagItem'
|
||||||
import ItemCtrl from '../logic/ItemCtrl'
|
|
||||||
|
|
||||||
export default class AccountController extends BaseController {
|
export default class AccountController extends BaseController {
|
||||||
@role('anon')
|
@role('anon')
|
||||||
@ -71,7 +70,8 @@ export default class AccountController extends BaseController {
|
|||||||
|
|
||||||
result.heros = heros
|
result.heros = heros
|
||||||
await account.save()
|
await account.save()
|
||||||
result.moneys = account.moneys
|
const moneyList = await BagItem.find({accountid, itemtype: ItemType.MONEY})
|
||||||
|
result.moneys = moneyList.map(o => o.toJson())
|
||||||
result.normal_stat = account.normal_stat
|
result.normal_stat = account.normal_stat
|
||||||
result.extinfo = account.extinfo
|
result.extinfo = account.extinfo
|
||||||
result.season_score = account.season_score
|
result.season_score = account.season_score
|
||||||
@ -100,89 +100,6 @@ export default class AccountController extends BaseController {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
@router('post /api/:accountid/items')
|
|
||||||
async itemList(req: any) {
|
|
||||||
let { accountid, type } = req.params
|
|
||||||
let queryData: any = { accountid }
|
|
||||||
if (type != undefined) {
|
|
||||||
queryData.itemtype = type << 0
|
|
||||||
}
|
|
||||||
let items = await BagItem.find(queryData)
|
|
||||||
return items.map(o => o.toJson())
|
|
||||||
}
|
|
||||||
|
|
||||||
@router('post /svr/:accountid/useitem')
|
|
||||||
@router('post /api/:accountid/useitem')
|
|
||||||
async userItem(req: any) {
|
|
||||||
let { accountid, itemid, count } = req.params
|
|
||||||
let record = await BagItem.findOne({
|
|
||||||
accountid,
|
|
||||||
itemid,
|
|
||||||
})
|
|
||||||
if (!record) {
|
|
||||||
throw new ZError(11, 'item not found')
|
|
||||||
}
|
|
||||||
if (record.count < count) {
|
|
||||||
throw new ZError(12, 'not enough item')
|
|
||||||
}
|
|
||||||
record.count -= count
|
|
||||||
let data = ItemCtrl.useItem(itemid, count)
|
|
||||||
// let data = [{ itemid: 10001, itemnum: 1 }]
|
|
||||||
for (let obj of data) {
|
|
||||||
let item = (await BagItem.findOrCreate({
|
|
||||||
accountid,
|
|
||||||
itemid: obj.id,
|
|
||||||
itemtype: obj.type
|
|
||||||
})).doc
|
|
||||||
item.count += obj.count
|
|
||||||
await item.save()
|
|
||||||
}
|
|
||||||
await record.save()
|
|
||||||
return data
|
|
||||||
}
|
|
||||||
|
|
||||||
@router('post /api/:accountid/buyitem')
|
|
||||||
async buyItem(req: any) {
|
|
||||||
let { itemid, count, accountid } = req.params
|
|
||||||
let pinfo = ItemCtrl.getItemPrice(itemid << 0)
|
|
||||||
if (pinfo.id == 0) {
|
|
||||||
throw new ZError(10, 'item can`t buy')
|
|
||||||
}
|
|
||||||
let record = await BagItem.findOne({
|
|
||||||
accountid,
|
|
||||||
itemid: pinfo.id
|
|
||||||
})
|
|
||||||
if (!record || record.count < pinfo.count * count) {
|
|
||||||
throw new ZError(11, 'not enough money')
|
|
||||||
}
|
|
||||||
record.count -= pinfo.count * count
|
|
||||||
let newItem = (await BagItem.findOrCreate({ accountid, itemid }))
|
|
||||||
.doc
|
|
||||||
newItem.count += count
|
|
||||||
await newItem.save()
|
|
||||||
await record.save()
|
|
||||||
return {
|
|
||||||
itemid,
|
|
||||||
buynum: count,
|
|
||||||
totalnum: newItem.count,
|
|
||||||
priceid: pinfo.id,
|
|
||||||
pricenum: pinfo.count
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@router('post /svr/:accountid/additem')
|
|
||||||
async addItem(req: any) {
|
|
||||||
let { itemid, count, accountid } = req.params
|
|
||||||
let itemInfo = ItemCtrl.findItem(itemid)
|
|
||||||
if (!itemInfo) {
|
|
||||||
throw new ZError(10, 'no item found')
|
|
||||||
}
|
|
||||||
let record = (await BagItem.findOrCreate({ accountid, itemid }))
|
|
||||||
.doc
|
|
||||||
record.count += count
|
|
||||||
record.itemtype = itemInfo._type
|
|
||||||
await record.save()
|
|
||||||
return record.toJson()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
84
src/controllers/ItemController.ts
Normal file
84
src/controllers/ItemController.ts
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
import BaseController from '../common/base.controller'
|
||||||
|
import { router } from '../decorators/router'
|
||||||
|
import { BagItem } from '../models/BagItem'
|
||||||
|
import { ZError } from '../common/ZError'
|
||||||
|
import { ItemInfo } from '../logic/ItemDef'
|
||||||
|
import ItemCtrl from '../logic/ItemCtrl'
|
||||||
|
|
||||||
|
export default class ItemController extends BaseController {
|
||||||
|
@router('post /api/:accountid/items')
|
||||||
|
async itemList(req: any) {
|
||||||
|
let { accountid, type } = req.params
|
||||||
|
let queryData: any = { accountid }
|
||||||
|
if (type != undefined) {
|
||||||
|
queryData.itemtype = type << 0
|
||||||
|
}
|
||||||
|
let items = await BagItem.find(queryData)
|
||||||
|
return items.map(o => o.toJson())
|
||||||
|
}
|
||||||
|
|
||||||
|
@router('post /svr/:accountid/useitem')
|
||||||
|
@router('post /api/:accountid/useitem')
|
||||||
|
async userItem(req: any) {
|
||||||
|
let { accountid, itemid, count } = req.params
|
||||||
|
let record = await BagItem.findOne({
|
||||||
|
accountid,
|
||||||
|
itemid,
|
||||||
|
})
|
||||||
|
if (!record) {
|
||||||
|
throw new ZError(11, 'item not found')
|
||||||
|
}
|
||||||
|
if (record.count < count) {
|
||||||
|
throw new ZError(12, 'not enough item')
|
||||||
|
}
|
||||||
|
record.count -= count
|
||||||
|
let data: ItemInfo[] = ItemCtrl.useItem(itemid, count)
|
||||||
|
await BagItem.addItems(accountid, data)
|
||||||
|
await record.save()
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
@router('post /api/:accountid/buyitem')
|
||||||
|
async buyItem(req: any) {
|
||||||
|
let { itemid, count, accountid } = req.params
|
||||||
|
let pinfo = ItemCtrl.getItemPrice(itemid << 0)
|
||||||
|
if (pinfo.id == 0) {
|
||||||
|
throw new ZError(10, 'item can`t buy')
|
||||||
|
}
|
||||||
|
let record = await BagItem.findOne({
|
||||||
|
accountid,
|
||||||
|
itemid: pinfo.id
|
||||||
|
})
|
||||||
|
if (!record || record.count < pinfo.count * count) {
|
||||||
|
throw new ZError(11, 'not enough money')
|
||||||
|
}
|
||||||
|
record.count -= pinfo.count * count
|
||||||
|
let newItem = (await BagItem.findOrCreate({ accountid, itemid }))
|
||||||
|
.doc
|
||||||
|
newItem.count += count
|
||||||
|
await newItem.save()
|
||||||
|
await record.save()
|
||||||
|
return {
|
||||||
|
itemid,
|
||||||
|
buynum: count,
|
||||||
|
totalnum: newItem.count,
|
||||||
|
priceid: pinfo.id,
|
||||||
|
pricenum: pinfo.count
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@router('post /svr/:accountid/additem')
|
||||||
|
async addItem(req: any) {
|
||||||
|
let { itemid, count, accountid } = req.params
|
||||||
|
let itemInfo = ItemCtrl.findItem(itemid)
|
||||||
|
if (!itemInfo) {
|
||||||
|
throw new ZError(10, 'no item found')
|
||||||
|
}
|
||||||
|
let record = (await BagItem.findOrCreate({ accountid, itemid }))
|
||||||
|
.doc
|
||||||
|
record.count += count
|
||||||
|
record.itemtype = itemInfo._type
|
||||||
|
await record.save()
|
||||||
|
return record.toJson()
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,8 @@ import { router } from '../decorators/router'
|
|||||||
import { getAttachment } from '../service/mail'
|
import { getAttachment } from '../service/mail'
|
||||||
import { ZError } from '../common/ZError'
|
import { ZError } from '../common/ZError'
|
||||||
import { BagItem, getItemType } from '../models/BagItem'
|
import { BagItem, getItemType } from '../models/BagItem'
|
||||||
|
import ItemCtrl from '../logic/ItemCtrl'
|
||||||
|
import { ItemInfo } from '../logic/ItemDef'
|
||||||
|
|
||||||
export default class MailController extends BaseController {
|
export default class MailController extends BaseController {
|
||||||
|
|
||||||
@ -13,19 +15,18 @@ export default class MailController extends BaseController {
|
|||||||
if (data.errcode) {
|
if (data.errcode) {
|
||||||
throw new ZError(data.errcode, data.errmsg)
|
throw new ZError(data.errcode, data.errmsg)
|
||||||
}
|
}
|
||||||
|
let items: ItemInfo[] = []
|
||||||
if (data.attachments && data.attachments.length > 0) {
|
if (data.attachments && data.attachments.length > 0) {
|
||||||
for (let obj of data.attachments) {
|
let itemStr = ''
|
||||||
let itemType = getItemType(obj.itemid << 0)
|
for (let i = 0; i < data.attachments.length; i++) {
|
||||||
let item = (await BagItem.findOrCreate({
|
const obj = data.attachments[i]
|
||||||
accountid,
|
if (i > 0) itemStr += '|'
|
||||||
itemid: obj.itemid,
|
itemStr += `${obj.itemid}:${obj.itemnum}`
|
||||||
itemtype: itemType
|
|
||||||
})).doc
|
|
||||||
item.count += obj.itemnum
|
|
||||||
await item.save()
|
|
||||||
}
|
}
|
||||||
|
items = ItemCtrl.getItemsByInfo(itemStr)
|
||||||
|
await BagItem.addItems(accountid, items)
|
||||||
}
|
}
|
||||||
return data.attachments
|
return items
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import { BagItem } from '../models/BagItem'
|
|||||||
|
|
||||||
export default class MatchController extends BaseController {
|
export default class MatchController extends BaseController {
|
||||||
|
|
||||||
@router('post /api/:accountid/beginmatch')
|
@router('post /svr/:accountid/beginmatch')
|
||||||
async beginMatch(req: any) {
|
async beginMatch(req: any) {
|
||||||
let {accountid, matchid} = req.params
|
let {accountid, matchid} = req.params
|
||||||
let cfg: MatchCfg = global.$cfg.get(BaseConst.MATCH).get(matchid << 0)
|
let cfg: MatchCfg = global.$cfg.get(BaseConst.MATCH).get(matchid << 0)
|
||||||
|
@ -5,6 +5,10 @@ import { RecordInfo, User } from '../models/User'
|
|||||||
import { error } from '../common/Debug'
|
import { error } from '../common/Debug'
|
||||||
import { timeBeforeDay } from '../utils/time.util'
|
import { timeBeforeDay } from '../utils/time.util'
|
||||||
import { BaseConst } from '../constants/BaseConst'
|
import { BaseConst } from '../constants/BaseConst'
|
||||||
|
import { MatchCfg } from '../cfg/parsers/MatchCfg'
|
||||||
|
import ItemCtrl from '../logic/ItemCtrl'
|
||||||
|
import { ItemInfo } from '../logic/ItemDef'
|
||||||
|
import { BagItem } from '../models/BagItem'
|
||||||
|
|
||||||
export default class RecordController extends BaseController {
|
export default class RecordController extends BaseController {
|
||||||
@role('anon')
|
@role('anon')
|
||||||
@ -24,9 +28,13 @@ export default class RecordController extends BaseController {
|
|||||||
async upload(req: any) {
|
async upload(req: any) {
|
||||||
let record = new GameRecord(req.params)
|
let record = new GameRecord(req.params)
|
||||||
await record.save()
|
await record.save()
|
||||||
if (!record.season) {
|
if (!record.matchid) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
let cfg: MatchCfg = global.$cfg.get(BaseConst.MATCH).get(parseInt(record.matchid))
|
||||||
|
if (cfg) {
|
||||||
|
error(`match cfg not found: ${record.matchid}`)
|
||||||
|
}
|
||||||
const fc = global.$cfg.get(BaseConst.FORMULA)
|
const fc = global.$cfg.get(BaseConst.FORMULA)
|
||||||
const scores = [
|
const scores = [
|
||||||
fc.get(70043).number,
|
fc.get(70043).number,
|
||||||
@ -36,7 +44,8 @@ export default class RecordController extends BaseController {
|
|||||||
fc.get(70047).number,
|
fc.get(70047).number,
|
||||||
fc.get(70048).number
|
fc.get(70048).number
|
||||||
]
|
]
|
||||||
let seasonData = {}
|
let seasonData: any = {}
|
||||||
|
let itemData: any = {}
|
||||||
for (let player of record.players) {
|
for (let player of record.players) {
|
||||||
if (player.accountid.startsWith('robot')) {
|
if (player.accountid.startsWith('robot')) {
|
||||||
continue
|
continue
|
||||||
@ -115,9 +124,21 @@ export default class RecordController extends BaseController {
|
|||||||
* end of 处理比赛统计信息
|
* end of 处理比赛统计信息
|
||||||
*/
|
*/
|
||||||
await user.save()
|
await user.save()
|
||||||
// @ts-ignore
|
|
||||||
seasonData[player.playerid] = user.season_data
|
seasonData[player.playerid] = user.season_data
|
||||||
|
/**
|
||||||
|
* 获取胜利失败的物品
|
||||||
|
*/
|
||||||
|
let items: ItemInfo[] = []
|
||||||
|
if (cfg) {
|
||||||
|
if (record.winner == player.team && cfg.winget) {
|
||||||
|
items = ItemCtrl.getItemsByInfo(cfg.winget);
|
||||||
|
} else if (record.winner !== player.team && cfg.failget) {
|
||||||
|
items = ItemCtrl.getItemsByInfo(cfg.failget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
itemData[player.playerid] = items
|
||||||
|
await BagItem.addItems(player.accountid, items)
|
||||||
}
|
}
|
||||||
return seasonData
|
return {seasonData, itemData}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,8 @@ import { dbconn } from '../decorators/dbconn'
|
|||||||
import {
|
import {
|
||||||
getModelForClass,
|
getModelForClass,
|
||||||
index,
|
index,
|
||||||
modelOptions, plugin,
|
modelOptions,
|
||||||
|
plugin,
|
||||||
prop,
|
prop,
|
||||||
Severity
|
Severity
|
||||||
} from '@typegoose/typegoose'
|
} from '@typegoose/typegoose'
|
||||||
@ -16,6 +17,7 @@ import findOrCreate from 'mongoose-findorcreate'
|
|||||||
import { BaseConst } from '../constants/BaseConst'
|
import { BaseConst } from '../constants/BaseConst'
|
||||||
import { DropItemCfg } from '../cfg/parsers/DropItemCfg'
|
import { DropItemCfg } from '../cfg/parsers/DropItemCfg'
|
||||||
import { ItemCardCfg } from '../cfg/parsers/ItemCardCfg'
|
import { ItemCardCfg } from '../cfg/parsers/ItemCardCfg'
|
||||||
|
import { ItemInfo } from '../logic/ItemDef'
|
||||||
|
|
||||||
export enum ItemType {
|
export enum ItemType {
|
||||||
UNKNOW = 0, // 未知
|
UNKNOW = 0, // 未知
|
||||||
@ -71,12 +73,25 @@ class BagItemClass extends FindOrCreate {
|
|||||||
public position: number
|
public position: number
|
||||||
|
|
||||||
@prop()
|
@prop()
|
||||||
public souce?: string
|
public source?: string
|
||||||
|
|
||||||
|
public static async addItems(accountid: string, items: ItemInfo[]) {
|
||||||
|
for (const item of items) {
|
||||||
|
let record = (await BagItem.findOrCreate({
|
||||||
|
accountid,
|
||||||
|
itemid: item.id,
|
||||||
|
itemtype: item.type
|
||||||
|
})).doc
|
||||||
|
record.count += item.count
|
||||||
|
await record.save()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public toJson() {
|
public toJson() {
|
||||||
return {
|
return {
|
||||||
itemid: this.itemid,
|
id: this.itemid,
|
||||||
itemnum: this.count
|
count: this.count,
|
||||||
|
type: this.itemtype
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,9 @@ class GameRecordClass extends Base<string>{
|
|||||||
@prop()
|
@prop()
|
||||||
public season: number;
|
public season: number;
|
||||||
|
|
||||||
|
@prop()
|
||||||
|
public matchid: string;
|
||||||
|
|
||||||
|
|
||||||
@prop({_id: false, type: () => [GamePlayer]})
|
@prop({_id: false, type: () => [GamePlayer]})
|
||||||
public players: GamePlayer[];
|
public players: GamePlayer[];
|
||||||
@ -73,6 +76,7 @@ class GameRecordClass extends Base<string>{
|
|||||||
round: this.round,
|
round: this.round,
|
||||||
winner: this.winner,
|
winner: this.winner,
|
||||||
season: this.season,
|
season: this.season,
|
||||||
|
match: this.matchid,
|
||||||
players: '',
|
players: '',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user