fix:游戏房补充退出房间逻辑
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.chwl.app.game.core.engine
|
||||
|
||||
import android.os.Build
|
||||
import com.chwl.app.BuildConfig
|
||||
import com.chwl.app.game.core.GameQueueAbility
|
||||
import com.chwl.app.game.core.GameStateAbility
|
||||
import com.chwl.core.bean.game.GameResultBean
|
||||
@@ -7,6 +9,7 @@ import com.chwl.core.bean.game.SudGameConfigBean
|
||||
import com.chwl.core.sud.model.GameViewInfoModel
|
||||
import com.chwl.core.sud.state.SudMGPMGState
|
||||
import com.chwl.core.support.room.RoomContext
|
||||
import com.chwl.library.utils.SingleToastUtil
|
||||
import com.chwl.library.utils.json.JsonUtils
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
@@ -59,6 +62,7 @@ class GameEngineAbility : SudEngineAbility() {
|
||||
loadGame(activity, roomId.toString(), gameId)
|
||||
} else {
|
||||
logD("checkRunning() destroyGame")
|
||||
exitGame()
|
||||
destroyGame()
|
||||
}
|
||||
}
|
||||
@@ -94,6 +98,9 @@ class GameEngineAbility : SudEngineAbility() {
|
||||
jsonObject.put("value0", roundId)
|
||||
val extras = jsonObject.toString()
|
||||
logD("autoPlayGame roundId:${roundId}")
|
||||
if (BuildConfig.DEBUG) {
|
||||
SingleToastUtil.showToast("value0:${roundId}")
|
||||
}
|
||||
sudFSTAPP.notifyAPPCommonSelfPlaying(true, extras, "value0")
|
||||
}
|
||||
}
|
||||
|
@@ -10,7 +10,6 @@ import com.chwl.app.R
|
||||
import com.chwl.app.avroom.game.AppConfig
|
||||
import com.chwl.core.auth.AuthModel
|
||||
import com.chwl.core.room.game.GameModel
|
||||
import com.chwl.core.room.game.bean.GameCfg
|
||||
import com.chwl.core.sud.decorator.SudFSMMGDecorator
|
||||
import com.chwl.core.sud.decorator.SudFSMMGListener
|
||||
import com.chwl.core.sud.decorator.SudFSTAPPDecorator
|
||||
@@ -51,6 +50,7 @@ open class SudEngineAbility : RoomAbility(), SudFSMMGListener, ILog {
|
||||
logD("loadGame() activity 状态异常")
|
||||
return
|
||||
}
|
||||
exitGame()
|
||||
destroyGame()
|
||||
this.isRunning = true
|
||||
this.roomId = roomId
|
||||
@@ -62,6 +62,44 @@ open class SudEngineAbility : RoomAbility(), SudFSMMGListener, ILog {
|
||||
})
|
||||
}
|
||||
|
||||
// 该用户是否在游戏中
|
||||
fun playerIsPlaying(userId: Long): Boolean {
|
||||
return sudFSMMG.playerIsPlaying(userId.toString())
|
||||
}
|
||||
|
||||
// 返回该玩家是否已加入了游戏
|
||||
fun playerIsIn(userId: Long): Boolean {
|
||||
return sudFSMMG.playerIsIn(userId.toString())
|
||||
}
|
||||
|
||||
// 自己是否已加入了游戏
|
||||
fun isSelfInGame(): Boolean {
|
||||
return playerIsIn(getUserId())
|
||||
}
|
||||
|
||||
fun exitGame() {
|
||||
if (!isRunning) {
|
||||
return
|
||||
}
|
||||
val userId = getUserId()
|
||||
if (playerIsPlaying(userId)) {
|
||||
logD("exitGame() 1")
|
||||
// 用户正在游戏中,先退出本局游戏,再退出游戏
|
||||
sudFSTAPP.notifyAPPCommonSelfPlaying(false, null, null)
|
||||
sudFSTAPP.notifyAPPCommonSelfReady(false)
|
||||
sudFSTAPP.notifyAPPCommonSelfIn(false, -1, true, 1)
|
||||
} else if (sudFSMMG.playerIsReady(userId.toString())) {
|
||||
logD("exitGame() 2")
|
||||
// 用户已加入并且已经准备,先取消准备,再退出游戏
|
||||
sudFSTAPP.notifyAPPCommonSelfReady(false)
|
||||
sudFSTAPP.notifyAPPCommonSelfIn(false, -1, true, 1)
|
||||
} else if (isSelfInGame()) {
|
||||
logD("exitGame() 3")
|
||||
// 用户已加入游戏 退出游戏
|
||||
sudFSTAPP.notifyAPPCommonSelfIn(false, -1, true, 1)
|
||||
}
|
||||
}
|
||||
|
||||
fun destroyGame() {
|
||||
if (!isRunning) {
|
||||
return
|
||||
@@ -97,10 +135,9 @@ open class SudEngineAbility : RoomAbility(), SudFSMMGListener, ILog {
|
||||
if (!isRunning) {
|
||||
return
|
||||
}
|
||||
val userId = AuthModel.get().currentUid.toString()
|
||||
sudFSTAPP.destroyMG()
|
||||
val iSudFSTAPP =
|
||||
SudMGP.loadMG(activity, userId, getRoomId(), code, gameId, getGameLanguage(), sudFSMMG)
|
||||
SudMGP.loadMG(activity, getUserId().toString(), getRoomId(), code, gameId, getGameLanguage(), sudFSMMG)
|
||||
sudFSTAPP.setISudFSTAPP(iSudFSTAPP)
|
||||
gameViewFlow.value = iSudFSTAPP.gameView
|
||||
}
|
||||
@@ -217,6 +254,8 @@ open class SudEngineAbility : RoomAbility(), SudFSMMGListener, ILog {
|
||||
|
||||
private fun getGameId() = gameId
|
||||
|
||||
protected open fun getUserId(): Long = AuthModel.get().currentUid
|
||||
|
||||
protected open fun getAppId() = AppConfig.APP_ID
|
||||
|
||||
protected open fun getAppKey() = AppConfig.APP_KEY
|
||||
|
Reference in New Issue
Block a user