This commit is contained in:
aozhiwei 2024-03-11 21:27:12 +08:00
parent ba90357060
commit 6079f8bd6f
3 changed files with 49 additions and 2 deletions

View File

@ -17,6 +17,7 @@ type Team interface {
GetMemberByAccountId(string) Player GetMemberByAccountId(string) Player
OnPlayerOffline(Player) OnPlayerOffline(Player)
OnPlayerOnline(Player) OnPlayerOnline(Player)
IsCopy() bool
} }
type TeamMgr interface { type TeamMgr interface {
@ -29,6 +30,8 @@ type Player interface {
GetSocket() f5.WspCliConn GetSocket() f5.WspCliConn
GetAccountId() string GetAccountId() string
GetSessionId() string GetSessionId() string
GetZoneId() int32
GetNodeId() int32
GetName() string GetName() string
GetAvatarUrl() string GetAvatarUrl() string
GetHeroId() string GetHeroId() string

View File

@ -8,8 +8,19 @@ import (
type team struct { type team struct {
cs.MsgHandlerImpl cs.MsgHandlerImpl
teamUuid string teamUuid string
isCopy bool
zoneId int32 zoneId int32
nodeId int32 nodeId int32
owner common.Player
accountIdHash map[string]common.Player
}
func (this *team) init(teamUuid string, owner common.Player) {
this.teamUuid = teamUuid
this.zoneId = owner.GetZoneId()
this.nodeId = owner.GetNodeId()
this.owner = owner
this.accountIdHash[owner.GetAccountId()] = owner
} }
func (this *team) GetZoneId() int32 { func (this *team) GetZoneId() int32 {
@ -29,6 +40,10 @@ func (this *team) CanJoin(accountId string) bool {
} }
func (this *team) GetMemberByAccountId(accountId string) common.Player { func (this *team) GetMemberByAccountId(accountId string) common.Player {
hum, ok := this.accountIdHash[accountId]
if ok {
return hum
}
return nil return nil
} }
@ -41,5 +56,20 @@ func (this *team) OnPlayerOnline(hum common.Player) {
} }
func (this *team) Join(hum common.Player) bool { func (this *team) Join(hum common.Player) bool {
return false this.accountIdHash[hum.GetAccountId()] = hum
return true
}
func (this *team) isFull() bool {
return len(this.accountIdHash) >= 4
}
func (this *team) IsCopy() bool {
return this.isCopy
}
func newTeam() *team {
t := new(team)
t.accountIdHash = map[string]common.Player{}
return t
} }

View File

@ -23,10 +23,24 @@ func (this *teamMgr) UnInit() {
} }
func (this *teamMgr) CreateTeam(hum common.Player, msg *cs.CMLogin) { func (this *teamMgr) CreateTeam(hum common.Player, msg *cs.CMLogin) {
teamUuid := this.genTeamUuid(hum.GetZoneId(), hum.GetNodeId())
team := newTeam()
team.init(teamUuid, hum)
this.teamUuidHash[team.teamUuid] = team
} }
func (this *teamMgr) genTeamUuid(zoneId int32, nodeId int32) string { func (this *teamMgr) genTeamUuid(zoneId int32, nodeId int32) string {
teamUuid := ""
for true {
teamUuid = this.internalGenTeamUuid(zoneId, nodeId)
if this.GetTeamByUuid(teamUuid) == nil {
return teamUuid
}
}
panic("genTeamUuid error")
}
func (this *teamMgr) internalGenTeamUuid(zoneId int32, nodeId int32) string {
this.curIdx++ this.curIdx++
teamUuid := q5.ToString(zoneId) + "_" + q5.ToString(nodeId) + "_" + teamUuid := q5.ToString(zoneId) + "_" + q5.ToString(nodeId) + "_" +
q5.Md5Str(q5.ToString(f5.GetApp().NewUuid()) + q5.ToString(f5.GetApp().GetPid()) + q5.Md5Str(q5.ToString(f5.GetApp().NewUuid()) + q5.ToString(f5.GetApp().GetPid()) +