增加对玩家逃跑的处理
This commit is contained in:
parent
e8ed483eb4
commit
0b3df16bf5
@ -87,6 +87,15 @@ export class GameEnv {
|
||||
// 等待玩家确认的最长时间
|
||||
public maxWaitingTime: number
|
||||
|
||||
// pve模式是否允许中途退出
|
||||
public allowLeftPve: boolean
|
||||
|
||||
// 休闲模式是否允许中途退出
|
||||
public allowLeftCasual: boolean
|
||||
|
||||
// 匹配模式是否允许中途退出
|
||||
public allowLeftMatch: boolean
|
||||
|
||||
public init(data: Map<number, BaseCfg>) {
|
||||
this.initCardNum = parseInt(data.get(BaseConst.INIT_CARD_NUM).value)
|
||||
this.cardChangeNum = parseInt(data.get(BaseConst.CARD_CHANGE_NUM).value)
|
||||
@ -146,6 +155,9 @@ export class GameEnv {
|
||||
+(data.get(99060)?.value || 0),
|
||||
]
|
||||
this.maxWaitingTime = 60
|
||||
this.allowLeftPve = !!data.get(99062)?.value
|
||||
this.allowLeftCasual = !!data.get(99063)?.value
|
||||
this.allowLeftMatch = !!data.get(99064)?.value
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -155,7 +155,7 @@ export async function createRobot(data: any) {
|
||||
axios.get(`${robotHost}/robot/create`, {
|
||||
params: data
|
||||
}).then((res) => {
|
||||
debugRoom(`caeate robot result: `, res.data)
|
||||
debugRoom(`create robot result: `, res.data)
|
||||
}).catch((err) => {
|
||||
error(err)
|
||||
})
|
||||
@ -165,11 +165,14 @@ export async function createRobot(data: any) {
|
||||
* 用户主动离开游戏
|
||||
* @param {string} accountid
|
||||
* @param {string} roomid
|
||||
* @param matchid
|
||||
* @param dead
|
||||
* @param scoreChange
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
export async function leftGame(accountid: string, roomid: string) {
|
||||
export async function leftGame(accountid: string, roomid: string, matchid: string, dead: number, scoreChange: number = 0) {
|
||||
debugRoom(`player dead and left game: ${roomid}, ${accountid}`)
|
||||
const data = { roomid, token: SERVER_TOKEN }
|
||||
const data = { roomid, token: SERVER_TOKEN, dead, matchid, scoreChange }
|
||||
let dataStr = JSON.stringify(data)
|
||||
const infoHost = await new Service().getInfoSvr()
|
||||
if (!infoHost) {
|
||||
|
@ -24,6 +24,7 @@ import { Service } from '../service/Service'
|
||||
import { ManualTurnEndCommand } from './commands/ManualTurnEndCommand'
|
||||
import { RoomOptions } from '../cfg/RoomOptions'
|
||||
import { PlayerStateConst } from '../constants/PlayerStateConst'
|
||||
import { PlayLeftCommand } from './commands/PlayLeftCommand'
|
||||
|
||||
export class GeneralRoom extends Room {
|
||||
dispatcher = new Dispatcher(this)
|
||||
@ -157,6 +158,11 @@ export class GeneralRoom extends Room {
|
||||
this.dispatcher.dispatch(new ManualTurnEndCommand(), { client })
|
||||
})
|
||||
|
||||
this.onMessage('player_left_c2s', (client) => {
|
||||
msgLog('player_left_c2s from ', client.sessionId)
|
||||
this.dispatcher.dispatch(new PlayLeftCommand(), { client })
|
||||
})
|
||||
|
||||
this.onMessage('*', (client, type, message) => {
|
||||
//
|
||||
// Triggers when any other type of message is sent,
|
||||
@ -194,7 +200,7 @@ export class GeneralRoom extends Room {
|
||||
try {
|
||||
// 20210310 添加, 如果该玩家已死亡, 则上报下, 清除redis中的锁定键
|
||||
if (this.state.mode == 1 && !player.robot && player.state == PlayerStateConst.PLAYER_DEAD) {
|
||||
await leftGame(player.accountId, this.roomId)
|
||||
await leftGame(player.accountId, this.roomId, this.match, 1)
|
||||
} else if (consented) {
|
||||
throw new Error('consented leave')
|
||||
} else {
|
||||
|
@ -84,8 +84,7 @@ export class GameResultCommand extends Command<CardGameState, {}> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const scores = [
|
||||
const scoresCfg = [
|
||||
fc.get(70043).number,
|
||||
fc.get(70046).number,
|
||||
fc.get(70044).number,
|
||||
@ -97,7 +96,8 @@ export class GameResultCommand extends Command<CardGameState, {}> {
|
||||
let scoreMap: Map<Player, number> = new Map()
|
||||
for (let [, player] of this.state.players) {
|
||||
let result = results.get(player)
|
||||
if (winner == player.team) {
|
||||
// 计算赛季排位分的改变
|
||||
if (winner == player.team && !player.escape) {
|
||||
if (score[player.team] == Math.max.apply(this, score)) {
|
||||
result.scoreChange = 100 / (1 + Math.pow(10, ((score[player.team] - Math.min.apply(this, score)) / 2500)))
|
||||
} else {
|
||||
@ -112,11 +112,11 @@ export class GameResultCommand extends Command<CardGameState, {}> {
|
||||
}
|
||||
let s = 0
|
||||
for (let [type, val] of player.statData) {
|
||||
if (type >= scores.length) {
|
||||
if (type >= scoresCfg.length) {
|
||||
continue
|
||||
}
|
||||
result.stat[type] = val
|
||||
val = val * scores[type]
|
||||
val = val * scoresCfg[type]
|
||||
s += val
|
||||
if (resultMap.has(type)) {
|
||||
let current = resultMap.get(type)
|
||||
@ -132,7 +132,7 @@ export class GameResultCommand extends Command<CardGameState, {}> {
|
||||
let statics: any = []
|
||||
|
||||
for (let [type, val] of resultMap) {
|
||||
if (type < scores.length) {
|
||||
if (type < scoresCfg.length) {
|
||||
statics.push({
|
||||
type,
|
||||
player: val[0],
|
||||
@ -293,6 +293,7 @@ export class GameResultCommand extends Command<CardGameState, {}> {
|
||||
heroid: player.heroId,
|
||||
statdata: dataObj,
|
||||
score: player.score,
|
||||
escape: player.escape,
|
||||
cards: cards,
|
||||
scoreChange: results.get(player).scoreChange,
|
||||
mvpscore: player.id == mvp ? mvpScore : 0
|
||||
|
49
src/rooms/commands/PlayLeftCommand.ts
Normal file
49
src/rooms/commands/PlayLeftCommand.ts
Normal file
@ -0,0 +1,49 @@
|
||||
import { Command } from '@colyseus/command'
|
||||
import { CardGameState } from '../schema/CardGameState'
|
||||
import { PlayerStateConst } from '../../constants/PlayerStateConst'
|
||||
import { Client } from 'colyseus'
|
||||
import { leftGame } from '../../common/WebApi'
|
||||
import { GameEnv } from '../../cfg/GameEnv'
|
||||
|
||||
/**
|
||||
* 玩家主动离开游戏
|
||||
*/
|
||||
export class PlayLeftCommand extends Command<CardGameState, { client: Client }> {
|
||||
|
||||
async execute({ client } = this.payload) {
|
||||
const player = this.state.players.get(client.sessionId)
|
||||
if (this.state.mode === 1) {
|
||||
if (!new GameEnv().allowLeftMatch) {
|
||||
client.send('player_left_s2c', {errcode: 11, errmsg: '当前配置不允许逃跑'})
|
||||
return
|
||||
}
|
||||
const dead = player.state === PlayerStateConst.PLAYER_DEAD ? 1 : 0
|
||||
if (!dead) {
|
||||
player.escape = true
|
||||
}
|
||||
let teamSet = new Set()
|
||||
for (let [, player] of this.state.players) {
|
||||
teamSet.add(player.team)
|
||||
}
|
||||
const teamCount = teamSet.size
|
||||
let score: number[] = new Array(teamCount).fill(0)
|
||||
for (let [, player] of this.state.players) {
|
||||
score[player.team] += player.score
|
||||
}
|
||||
let scoreChange
|
||||
if (score[player.team] == Math.max.apply(this, score)) {
|
||||
scoreChange = -(80 - 80 / (1 + Math.pow(10, ((score[player.team] - Math.min.apply(this, score)) / 2500))))
|
||||
} else {
|
||||
scoreChange = -(80 / (1 + Math.pow(10, ((Math.max.apply(this, score) - score[player.team]) / 2500))))
|
||||
}
|
||||
const res: any = await leftGame(player.accountId, this.room.roomId, this.room.match, dead, scoreChange)
|
||||
let result = res.data
|
||||
client.send('player_left_s2c', {errcode: result.errcode,
|
||||
errmsg: result.errmsg,
|
||||
scoreChange:
|
||||
result?.data?.scoreChange,
|
||||
score: result?.data?.score,
|
||||
items: result?.data?.items})
|
||||
}
|
||||
}
|
||||
}
|
@ -45,7 +45,7 @@ export class PlayReadyCommand extends Command<CardGameState, {
|
||||
}
|
||||
if (robotCount === self.room.clientCount) {
|
||||
for (let player of humans) {
|
||||
await leftGame(player.accountId, self.room.roomId)
|
||||
await leftGame(player.accountId, self.room.roomId, self.room.match, 1)
|
||||
}
|
||||
await self.room.disconnect()
|
||||
} else {
|
||||
|
@ -70,6 +70,10 @@ export class Player extends Schema {
|
||||
state: number
|
||||
|
||||
online: boolean = true
|
||||
/**
|
||||
* 是否是逃跑的, 逃跑的玩家最后结算的时候特殊处理
|
||||
*/
|
||||
escape: boolean = false
|
||||
/**
|
||||
* 随从
|
||||
*/
|
||||
@ -136,6 +140,7 @@ export class Player extends Schema {
|
||||
this.countTotal = 0
|
||||
this.countPresent = 0
|
||||
this.online = true
|
||||
this.escape = false
|
||||
for (let i = 0; i < new GameEnv().maxPlayerPetCount + 1; i++) {
|
||||
let pet = new Pet(i)
|
||||
pet.state = 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user