aozhiwei 15ca5cc7c0 1
2024-03-12 17:00:02 +08:00

117 lines
2.3 KiB
Go

package team
import (
"q5"
"cs"
"main/common"
"github.com/golang/protobuf/proto"
)
type team struct {
cs.MsgHandlerImpl
teamUuid string
nextTeamUuid string
isCopy bool
zoneId int32
nodeId int32
mapId 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
owner.SetTeam(this)
this.accountIdHash[owner.GetAccountId()] = owner
}
func (this *team) GetZoneId() int32 {
return this.zoneId
}
func (this *team) GetNodeId() int32 {
return this.nodeId
}
func (this *team) GetTeamUuid() string {
return this.teamUuid
}
func (this *team) CanJoin(accountId string) bool {
if this.IsCopy() {
if !this.isFull() {
return true
} else if this.GetMemberByAccountId(accountId) != nil {
return true
}
} else {
return !this.isFull()
}
return false
}
func (this *team) GetMemberByAccountId(accountId string) common.Player {
hum, ok := this.accountIdHash[accountId]
if ok {
return hum
}
return nil
}
func (this *team) OnPlayerOffline(hum common.Player) {
}
func (this *team) OnPlayerOnline(hum common.Player) {
}
func (this *team) Join(hum common.Player) bool {
hum.SetTeam(this)
this.accountIdHash[hum.GetAccountId()] = hum
return true
}
func (this *team) IsLeader(hum common.Player) bool {
return hum == this.owner
}
func (this *team) isFull() bool {
return len(this.accountIdHash) >= 4
}
func (this *team) IsCopy() bool {
return this.isCopy
}
func (this *team) broadcastMsg(msg proto.Message) {
for _, m := range this.accountIdHash {
m.SendMsg(msg)
}
}
func (this *team) SendUpdateNotify() {
notifyMsg := &cs.SMTeamUpdateNotify{}
notifyMsg.TeamInfo = &cs.MFTeam{}
notifyMsg.TeamInfo.TeamUuid = proto.String(this.teamUuid)
notifyMsg.TeamInfo.NextTeamUuid = proto.String(this.nextTeamUuid)
notifyMsg.TeamInfo.MapId = proto.Int32(this.mapId)
q5.NewSlice(&notifyMsg.TeamInfo.Members, 0, 1)
for _, m := range this.accountIdHash {
m_pb := &cs.MFTeamMember{}
q5.AppendSlice(&notifyMsg.TeamInfo.Members, m_pb)
m.FillMFTeamMember(m_pb)
}
this.broadcastMsg(notifyMsg)
}
func newTeam() *team {
t := new(team)
t.accountIdHash = map[string]common.Player{}
return t
}