Basic Review
In the previous section, we introduced the basic callback function for Mahjong event login. However, in real game scenarios, when this is invoked, it is not certain whether the player has already entered the game lobby. Further checks are needed to determine whether the player has entered the game and if the game has started.
How to Determine
The lobbymgr library provides game status information that can help you determine the current state of the game.
Example Code
package main
import (
"github.com/moxcomic/Archer/mgr/lobbymgr"
)
func onLogin() {
if lobbymgr.Inst.Enable() {
// 在游戏大厅页面
// On the game lobby page
} else {
// 不在游戏大厅页面
// Not on the game lobby page
}
}
Advanced Code
- The code above only checks once whether the player is on the lobby page, but entering the lobby is not instantaneous. Therefore, we need to use a loop to continuously check.
package main
import (
"github.com/moxcomic/Archer/mgr/lobbymgr"
)
func onLogin() {
for range time.Tick(time.Second) {
if !lobbymgr.Inst().Enable() {
fmt.Println("Waiting to enter the lobby...")
continue
}
break
}
}
- Of course, this is just an example. The specific game logic needs to be determined based on the actual situation.