增加对玩家逃跑的处理
This commit is contained in:
parent
d596c95a5c
commit
c133707c21
@ -4,7 +4,11 @@ import { BaseConst } from '../constants/BaseConst'
|
|||||||
import { ZError } from '../common/ZError'
|
import { ZError } from '../common/ZError'
|
||||||
import { MatchCfg } from '../cfg/parsers/MatchCfg'
|
import { MatchCfg } from '../cfg/parsers/MatchCfg'
|
||||||
import { BagItem } from '../models/BagItem'
|
import { BagItem } from '../models/BagItem'
|
||||||
import { checkGameing, setGameEnd } from '../service/rank'
|
import { checkGameing, setGameEnd, updateRank } from '../service/rank'
|
||||||
|
import { error } from '../common/Debug'
|
||||||
|
import { ItemInfo } from '../logic/ItemDef'
|
||||||
|
import ItemCtrl from '../logic/ItemCtrl'
|
||||||
|
import { User } from '../models/User'
|
||||||
|
|
||||||
export default class MatchController extends BaseController {
|
export default class MatchController extends BaseController {
|
||||||
|
|
||||||
@ -35,9 +39,33 @@ export default class MatchController extends BaseController {
|
|||||||
|
|
||||||
@router('post /svr/:accountid/leftgame')
|
@router('post /svr/:accountid/leftgame')
|
||||||
async userLeft(req: any) {
|
async userLeft(req: any) {
|
||||||
let { accountid, roomid } = req.params
|
let { accountid, roomid, dead, matchid, scoreChange } = req.params
|
||||||
console.log(`${roomid} player ${accountid} left game manul`)
|
console.log(`${roomid} player ${accountid} left game manul, isdead: ${dead}`)
|
||||||
await setGameEnd(accountid)
|
await setGameEnd(accountid)
|
||||||
|
if (!dead && matchid) {
|
||||||
|
let cfg: MatchCfg = global.$cfg.get(BaseConst.MATCH).get(parseInt(matchid))
|
||||||
|
if (!cfg) {
|
||||||
|
error(`match cfg not found: ${matchid}`)
|
||||||
|
}
|
||||||
|
let user = await User.findById(accountid)
|
||||||
|
if (!user) {
|
||||||
|
error(`save game record, account not found: ${ accountid }`)
|
||||||
|
}
|
||||||
|
let items: ItemInfo[] = []
|
||||||
|
if (cfg.escapeget) {
|
||||||
|
items = ItemCtrl.getItemsByInfo(cfg.escapeget);
|
||||||
|
}
|
||||||
|
await BagItem.addItems(accountid, items, 'game_left', roomid)
|
||||||
|
// 更新逃跑次数
|
||||||
|
user.season_data.inc('escape', 1)
|
||||||
|
user.season_data.inc('loss', 1)
|
||||||
|
const fc = global.$cfg.get(BaseConst.FORMULA)
|
||||||
|
let oldScore = user.season_score
|
||||||
|
user.season_score = Math.max((user.season_score + scoreChange) | 0, fc.get(70002).number)
|
||||||
|
await updateRank(user._id, user.season_score)
|
||||||
|
await user.save()
|
||||||
|
return {scoreChange: user.season_score - oldScore, score: user.season_score, items}
|
||||||
|
}
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,35 +59,41 @@ export default class RecordController extends BaseController {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
await setGameEnd(player.accountid)
|
await setGameEnd(player.accountid)
|
||||||
user.season_score = Math.max((user.season_score + player.scoreChange) | 0, fc.get(70002).number)
|
if (!player.escape) {
|
||||||
await updateRank(user._id, user.season_score)
|
user.season_score = Math.max((user.season_score + player.scoreChange) | 0, fc.get(70002).number)
|
||||||
|
await updateRank(user._id, user.season_score)
|
||||||
|
}
|
||||||
|
|
||||||
if (!user.season_data) {
|
if (!user.season_data) {
|
||||||
user.season_data = new Map()
|
user.season_data = new Map()
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* begin of 将赛季排位记录放入season_records, 方便计算10胜
|
* begin of 将赛季排位记录放入season_records, 方便计算10胜
|
||||||
*/
|
*/
|
||||||
let data = new RecordInfo()
|
if (!player.escape) {
|
||||||
data.time = Date.now()
|
let data = new RecordInfo()
|
||||||
if (player.team == record.winner) {
|
data.time = Date.now()
|
||||||
data.status = 2
|
if (player.team == record.winner) {
|
||||||
} else if (record.winner == -1) {
|
data.status = 2
|
||||||
data.status = 1
|
} else if (record.winner == -1) {
|
||||||
} else {
|
data.status = 1
|
||||||
data.status = 0
|
} else {
|
||||||
}
|
data.status = 0
|
||||||
user.season_records.push(data)
|
}
|
||||||
|
user.season_records.push(data)
|
||||||
|
|
||||||
let records = user.season_records
|
let records = user.season_records
|
||||||
while (records.length > 10) {
|
while (records.length > 10) {
|
||||||
records.pop()
|
records.pop()
|
||||||
}
|
}
|
||||||
let smallTime = timeBeforeDay(30)
|
let smallTime = timeBeforeDay(30)
|
||||||
for (let r of records) {
|
for (let r of records) {
|
||||||
if (r.time < smallTime) {
|
if (r.time < smallTime) {
|
||||||
records.removeEx(r)
|
records.removeEx(r)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* end of 将赛季排位记录放入season_records, 方便计算10胜
|
* end of 将赛季排位记录放入season_records, 方便计算10胜
|
||||||
*/
|
*/
|
||||||
@ -95,38 +101,41 @@ export default class RecordController extends BaseController {
|
|||||||
* begin of 处理比赛统计信息
|
* begin of 处理比赛统计信息
|
||||||
*/
|
*/
|
||||||
let subType = ''
|
let subType = ''
|
||||||
if (record.winner == player.team) {
|
|
||||||
user.season_data.inc('win', 1)
|
|
||||||
subType += 'win'
|
|
||||||
} else {
|
|
||||||
user.season_data.inc('loss', 1)
|
|
||||||
subType += 'loss'
|
|
||||||
}
|
|
||||||
let statData = player.statdata
|
|
||||||
let honorp = 0
|
|
||||||
for (let key in statData) {
|
|
||||||
let numKey = +key
|
|
||||||
|
|
||||||
if (numKey >= scores.length) {
|
if (!player.escape) {
|
||||||
continue
|
if (record.winner == player.team) {
|
||||||
}
|
user.season_data.inc('win', 1)
|
||||||
// @ts-ignore
|
subType += 'win'
|
||||||
let val = Number(statData[key])
|
|
||||||
honorp += val * scores[numKey]
|
|
||||||
if (numKey == 4 || numKey == 5) {
|
|
||||||
user.season_data.inc(key + '_total', val)
|
|
||||||
} else {
|
} else {
|
||||||
user.season_data.inc(key + '_total', val * scores[numKey])
|
user.season_data.inc('loss', 1)
|
||||||
|
subType += 'loss'
|
||||||
}
|
}
|
||||||
|
let statData = player.statdata
|
||||||
|
let honorp = 0
|
||||||
|
for (let key in statData) {
|
||||||
|
let numKey = +key
|
||||||
|
|
||||||
if (user.season_data.has(key + '')) {
|
if (numKey >= scores.length) {
|
||||||
user.season_data.set(key + '', Math.max(user.season_data.get(key + ''), val))
|
continue
|
||||||
} else {
|
}
|
||||||
user.season_data.set(key + '', val)
|
// @ts-ignore
|
||||||
|
let val = Number(statData[key])
|
||||||
|
honorp += val * scores[numKey]
|
||||||
|
if (numKey == 4 || numKey == 5) {
|
||||||
|
user.season_data.inc(key + '_total', val)
|
||||||
|
} else {
|
||||||
|
user.season_data.inc(key + '_total', val * scores[numKey])
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user.season_data.has(key + '')) {
|
||||||
|
user.season_data.set(key + '', Math.max(user.season_data.get(key + ''), val))
|
||||||
|
} else {
|
||||||
|
user.season_data.set(key + '', val)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
user.season_data.inc('honor_ap', honorp)
|
||||||
|
user.season_data.inc('mvp_ap', player.mvpscore)
|
||||||
}
|
}
|
||||||
user.season_data.inc('honor_ap', honorp)
|
|
||||||
user.season_data.inc('mvp_ap', player.mvpscore)
|
|
||||||
/**
|
/**
|
||||||
* end of 处理比赛统计信息
|
* end of 处理比赛统计信息
|
||||||
*/
|
*/
|
||||||
@ -136,15 +145,15 @@ export default class RecordController extends BaseController {
|
|||||||
* 获取胜利失败的物品
|
* 获取胜利失败的物品
|
||||||
*/
|
*/
|
||||||
let items: ItemInfo[] = []
|
let items: ItemInfo[] = []
|
||||||
if (cfg) {
|
if (cfg && !player.escape) {
|
||||||
if (record.winner == player.team && cfg.winget) {
|
if (record.winner == player.team && cfg.winget) {
|
||||||
items = ItemCtrl.getItemsByInfo(cfg.winget);
|
items = ItemCtrl.getItemsByInfo(cfg.winget);
|
||||||
} else if (record.winner !== player.team && cfg.failget) {
|
} else if (record.winner !== player.team && cfg.failget) {
|
||||||
items = ItemCtrl.getItemsByInfo(cfg.failget);
|
items = ItemCtrl.getItemsByInfo(cfg.failget);
|
||||||
}
|
}
|
||||||
|
await BagItem.addItems(player.accountid, items, 'game_' + subType, record.id)
|
||||||
}
|
}
|
||||||
itemData[player.playerid] = items
|
itemData[player.playerid] = items
|
||||||
await BagItem.addItems(player.accountid, items, 'game_' + subType, record.id)
|
|
||||||
}
|
}
|
||||||
return {seasonData, itemData}
|
return {seasonData, itemData}
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,8 @@ class GamePlayer {
|
|||||||
public score: number;
|
public score: number;
|
||||||
@prop()
|
@prop()
|
||||||
public scoreChange: number;
|
public scoreChange: number;
|
||||||
|
@prop()
|
||||||
|
public escape: boolean;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 对战记录
|
* 对战记录
|
||||||
@ -68,7 +70,6 @@ class GameRecordClass extends Base<string>{
|
|||||||
@prop()
|
@prop()
|
||||||
public mode: number;
|
public mode: number;
|
||||||
|
|
||||||
|
|
||||||
@prop({_id: false, type: () => [GamePlayer]})
|
@prop({_id: false, type: () => [GamePlayer]})
|
||||||
public players: GamePlayer[];
|
public players: GamePlayer[];
|
||||||
|
|
||||||
|
@ -82,7 +82,8 @@ class UserClass extends FindOrCreate {
|
|||||||
@prop({ type: Hero, default: new Map() })
|
@prop({ type: Hero, default: new Map() })
|
||||||
public heros: Map<string, Hero>
|
public heros: Map<string, Hero>
|
||||||
/**
|
/**
|
||||||
* 货币信息
|
* 货币信息, Deprecated
|
||||||
|
* 具体的货币从BagItem中查找ItemType.MONEY的记录
|
||||||
* coin: 金币
|
* coin: 金币
|
||||||
* diamond: 钻石
|
* diamond: 钻石
|
||||||
* hero_shard: 通用英雄碎片
|
* hero_shard: 通用英雄碎片
|
||||||
|
Loading…
x
Reference in New Issue
Block a user