增加玩家死亡后退出游戏解锁game locker的功能

This commit is contained in:
zhl 2021-03-10 14:55:06 +08:00
parent 26ab203cc6
commit 70b286f59e
2 changed files with 40 additions and 6 deletions

View File

@ -161,4 +161,31 @@ export async function createRobot(data: any) {
})
}
/**
*
* @param {string} accountid
* @param {string} roomid
* @return {Promise<any>}
*/
export async function leftGame(accountid: string, roomid: string) {
debugRoom(`player dead and left game: ${roomid}, ${accountid}`)
const data = { roomid }
let dataStr = JSON.stringify(data)
const infoHost = await new Service().getInfoSvr()
if (!infoHost) {
error('no info host found!!!')
}
let reqConfig = {
method: 'post',
url: `${ infoHost }/${ accountid }/leftgame`,
headers: {
'Content-Type': 'application/json'
},
data: dataStr
}
// @ts-ignore
return axios(reqConfig)
}

View File

@ -19,10 +19,11 @@ import { GameStateConst } from '../constants/GameStateConst'
import { GameRestartCommand } from './commands/GameRestartCommand'
import { RobotClient } from '../robot/RobotClient'
import { ChangePetCommand } from './commands/ChangePetCommand'
import { createRobot } from '../common/WebApi'
import { createRobot, leftGame } from '../common/WebApi'
import { Service } from '../service/Service'
import { ManualTurnEndCommand } from './commands/ManualTurnEndCommand'
import { RoomOptions } from '../cfg/RoomOptions'
import { PlayerStateConst } from '../constants/PlayerStateConst'
export class GeneralRoom extends Room {
dispatcher = new Dispatcher(this)
@ -186,17 +187,21 @@ export class GeneralRoom extends Room {
}
this.bUserLeft(client.sessionId)
} else {
this.state.players.get(client.sessionId).online = false
let player = this.state.players.get(client.sessionId)
player.online = false
let assistClient = this.getAssistClient(client.sessionId)
assistClient.active = true
try {
if (consented) {
// 20210310 添加, 如果该玩家已死亡, 则上报下, 清除redis中的锁定键
if (this.state.mode == 1 && !player.robot && player.state == PlayerStateConst.PLAYER_DEAD) {
await leftGame(player.id, this.roomId)
} else if (consented) {
throw new Error('consented leave')
} else {
await this.allowReconnection(client, 10 * 60)
debugRoom(`${ client.sessionId } 重连`)
assistClient.active = false
this.state.players.get(client.sessionId).online = true
player.online = true
}
} catch (e) {
debugRoom(`player realy level :${ client.sessionId }, try add robot`)
@ -371,6 +376,7 @@ export class GeneralRoom extends Room {
getAssistClient(sessionId: string): RobotClient {
return this.assistMap.get(sessionId)
}
/**
*
*/
@ -400,10 +406,11 @@ export class GeneralRoom extends Room {
let opposIdx = ((this.maxClients / 2 | 0) + idx) % this.maxClients
return this.getPlayerByIdx(opposIdx)
}
getOtherTeamPlayers(srcPlayer: string, exPlayer?: string): Player[] {
let team = this.state.players.get(srcPlayer).team
let results:Player[] = []
for (let [,player] of this.state.players) {
let results: Player[] = []
for (let [, player] of this.state.players) {
if (player.team !== team) {
if (exPlayer && player.id != exPlayer) {
results.push(player)