85 lines
1.4 KiB
Go
85 lines
1.4 KiB
Go
package team
|
|
|
|
import (
|
|
"cs"
|
|
"main/common"
|
|
)
|
|
|
|
type team struct {
|
|
cs.MsgHandlerImpl
|
|
teamUuid string
|
|
isCopy bool
|
|
zoneId 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 {
|
|
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 {
|
|
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
|
|
}
|