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