ActorModel学习(四)--房间节点设计
框架中的房间节点的设计的宗旨是全,做所有功能的全量,让用户自行选择使用什么功能,从而提高框架的可适配性,不会出现独特的必要的房间功能导致房间节点不可用。
首先设计的对象是通用房间接口,由通用房间结构实现这个接口。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
type IGameRoom interface {
Init()
GetId() string
GetAllUsers() []string
GetAllPlayers() []string
CheckIsPlayer(uid string) bool //是否已加入游戏
CheckGameIsStart() bool // 游戏是否已经开始
GetRoomUser(uid string) (*gamepb.GamePlayer, *errors.Error)
DeletePlayer(uid string)
GetGamePlayer(uid string) (IGamePlayer, *errors.Error)
JoinGameCheck(uid string) *errors.Error
QuitGameCheck(uid string) *errors.Error
KickPlayerCheck(operUid, targetuid string) *errors.Error
JoinRoom(uid string, req *gamepb.JoinRoomReq) *errors.Error
QuitRoom(uid string) *errors.Error
GameOver()
CheckEnd() bool
AddDisConnectPlayer(uid string, tid uint64)
ReConnectPlayer(uid string)
ClearDisConnectPlayer(uid string)
CheckConnectPlayer(uid string) bool
OnGameEnd()
GetStateBroad() proto.Message
OnJoinGame(uid string, req *gamepb.JoinGameReq, isReady bool, autoStartNum int32) (*gamepb.PushRes, *errors.Error)
OnQuitGame(uid string) (*gamepb.PushRes, *errors.Error)
OnStartGame(uid string, force bool) (*gamepb.PushRes, *errors.Error)
OnGameSetting(uid string, json string) (*gamepb.PushRes, *errors.Error)
OnCloseGame(uid string, clearSeat bool) (*gamepb.PushRes, *errors.Error)
OnKickPlayer(operUid, targetuid string) (*gamepb.PushRes, *errors.Error)
OnJoinRoom(uid string, req *gamepb.JoinRoomReq) (*gamepb.PushRes, *errors.Error)
OnQuitRoom(uid string) (*gamepb.PushRes, *errors.Error)
OnReloadRoom(uid string) (*gamepb.PushRes, *errors.Error)
OnAutoGame(uid string) (bool, *errors.Error)
}
房间最重要的能力就是维护房间内用户的信息,房间只维护基本的用户信息,当用户进入游戏时,会产生游戏状态,身份也就进化为玩家,玩家信息维护在逻辑节点而不是房间节点。玩家信息是用户的超集,在逻辑节点产生用户快照的时候,需要向房间申请玩家的基本信息。
1
2
3
4
5
6
7
8
9
type User struct {
Uid string
Status int64
MemberType int64
Name string
Avatar string
// ... 代补充
}
This post is licensed under CC BY 4.0 by the author.