-
Notifications
You must be signed in to change notification settings - Fork 4
/
guild.go
57 lines (49 loc) · 1.41 KB
/
guild.go
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package game
import (
"github.com/fish-tennis/gentity"
"github.com/fish-tennis/gnet"
"github.com/fish-tennis/gserver/logger"
"github.com/fish-tennis/gserver/pb"
)
const (
// 组件名
ComponentNameGuild = "Guild"
)
// 利用go的init进行组件的自动注册
func init() {
RegisterPlayerComponentCtor(ComponentNameGuild, 100, func(player *Player, playerData *pb.PlayerData) gentity.Component {
component := &Guild{
PlayerDataComponent: *NewPlayerDataComponent(player, ComponentNameGuild),
Data: &pb.PlayerGuildData{
GuildId: 0,
},
}
gentity.LoadData(component, playerData.GetGuild())
return component
})
}
// 玩家的公会模块
type Guild struct {
PlayerDataComponent
Data *pb.PlayerGuildData `db:"Guild"`
}
func (this *Player) GetGuild() *Guild {
return this.GetComponentByName(ComponentNameGuild).(*Guild)
}
func (this *Guild) GetGuildData() *pb.PlayerGuildData {
return this.Data
}
func (this *Guild) SetGuildId(guildId int64) {
this.Data.GuildId = guildId
this.SetDirty()
logger.Debug("%v SetGuildId %v", this.GetPlayerId(), guildId)
}
// 玩家进游戏服成功,非客户端消息
// 这种格式写的函数可以自动注册非客户端的消息回调
func (this *Guild) HandleGuildJoinAgreeRes(cmd gnet.PacketCommand, msg *pb.GuildJoinAgreeRes) {
logger.Debug("HandleGuildJoinAgreeRes:%v", msg)
if msg.IsAgree {
this.SetGuildId(msg.GuildId)
}
this.GetPlayer().Send(cmd, msg)
}