增加玩家死亡后退出游戏解锁game locker的功能
This commit is contained in:
parent
26ab203cc6
commit
70b286f59e
@ -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)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,10 +19,11 @@ import { GameStateConst } from '../constants/GameStateConst'
|
|||||||
import { GameRestartCommand } from './commands/GameRestartCommand'
|
import { GameRestartCommand } from './commands/GameRestartCommand'
|
||||||
import { RobotClient } from '../robot/RobotClient'
|
import { RobotClient } from '../robot/RobotClient'
|
||||||
import { ChangePetCommand } from './commands/ChangePetCommand'
|
import { ChangePetCommand } from './commands/ChangePetCommand'
|
||||||
import { createRobot } from '../common/WebApi'
|
import { createRobot, leftGame } from '../common/WebApi'
|
||||||
import { Service } from '../service/Service'
|
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'
|
||||||
|
|
||||||
export class GeneralRoom extends Room {
|
export class GeneralRoom extends Room {
|
||||||
dispatcher = new Dispatcher(this)
|
dispatcher = new Dispatcher(this)
|
||||||
@ -186,17 +187,21 @@ export class GeneralRoom extends Room {
|
|||||||
}
|
}
|
||||||
this.bUserLeft(client.sessionId)
|
this.bUserLeft(client.sessionId)
|
||||||
} else {
|
} 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)
|
let assistClient = this.getAssistClient(client.sessionId)
|
||||||
assistClient.active = true
|
assistClient.active = true
|
||||||
try {
|
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')
|
throw new Error('consented leave')
|
||||||
} else {
|
} else {
|
||||||
await this.allowReconnection(client, 10 * 60)
|
await this.allowReconnection(client, 10 * 60)
|
||||||
debugRoom(`${ client.sessionId } 重连`)
|
debugRoom(`${ client.sessionId } 重连`)
|
||||||
assistClient.active = false
|
assistClient.active = false
|
||||||
this.state.players.get(client.sessionId).online = true
|
player.online = true
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugRoom(`player realy level :${ client.sessionId }, try add robot`)
|
debugRoom(`player realy level :${ client.sessionId }, try add robot`)
|
||||||
@ -371,6 +376,7 @@ export class GeneralRoom extends Room {
|
|||||||
getAssistClient(sessionId: string): RobotClient {
|
getAssistClient(sessionId: string): RobotClient {
|
||||||
return this.assistMap.get(sessionId)
|
return this.assistMap.get(sessionId)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据指定的座次号获取玩家信息
|
* 根据指定的座次号获取玩家信息
|
||||||
*/
|
*/
|
||||||
@ -400,10 +406,11 @@ export class GeneralRoom extends Room {
|
|||||||
let opposIdx = ((this.maxClients / 2 | 0) + idx) % this.maxClients
|
let opposIdx = ((this.maxClients / 2 | 0) + idx) % this.maxClients
|
||||||
return this.getPlayerByIdx(opposIdx)
|
return this.getPlayerByIdx(opposIdx)
|
||||||
}
|
}
|
||||||
|
|
||||||
getOtherTeamPlayers(srcPlayer: string, exPlayer?: string): Player[] {
|
getOtherTeamPlayers(srcPlayer: string, exPlayer?: string): Player[] {
|
||||||
let team = this.state.players.get(srcPlayer).team
|
let team = this.state.players.get(srcPlayer).team
|
||||||
let results:Player[] = []
|
let results: Player[] = []
|
||||||
for (let [,player] of this.state.players) {
|
for (let [, player] of this.state.players) {
|
||||||
if (player.team !== team) {
|
if (player.team !== team) {
|
||||||
if (exPlayer && player.id != exPlayer) {
|
if (exPlayer && player.id != exPlayer) {
|
||||||
results.push(player)
|
results.push(player)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user