1
This commit is contained in:
parent
c1488ddac4
commit
3f8ef69198
@ -25,7 +25,7 @@ type team struct {
|
|||||||
state int32
|
state int32
|
||||||
startTime int64
|
startTime int64
|
||||||
stateNotifyMsg *cs.SMTeamStateNotify
|
stateNotifyMsg *cs.SMTeamStateNotify
|
||||||
accountIdHash map[string]common.Player
|
memberIdHash map[string]common.Player
|
||||||
matchOk *team
|
matchOk *team
|
||||||
matchTick int64
|
matchTick int64
|
||||||
}
|
}
|
||||||
@ -43,7 +43,7 @@ func (this *team) init(copyIdx int32, zoneId int32, nodeId int32,
|
|||||||
this.stateNotifyMsg.JoinMsg.TeamUuid = proto.String(this.teamUuid)
|
this.stateNotifyMsg.JoinMsg.TeamUuid = proto.String(this.teamUuid)
|
||||||
owner.SetTeam(this)
|
owner.SetTeam(this)
|
||||||
owner.SetSortIdx(this.sortIdx)
|
owner.SetSortIdx(this.sortIdx)
|
||||||
this.accountIdHash[owner.GetAccountId()] = owner
|
this.memberIdHash[owner.GetAccountId()] = owner
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *team) GetZoneId() int32 {
|
func (this *team) GetZoneId() int32 {
|
||||||
@ -76,7 +76,7 @@ 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]
|
hum, ok := this.memberIdHash[accountId]
|
||||||
if ok {
|
if ok {
|
||||||
return hum
|
return hum
|
||||||
}
|
}
|
||||||
@ -95,7 +95,7 @@ func (this *team) Join(hum common.Player) bool {
|
|||||||
this.sortIdx++
|
this.sortIdx++
|
||||||
hum.SetTeam(this)
|
hum.SetTeam(this)
|
||||||
hum.SetSortIdx(this.sortIdx)
|
hum.SetSortIdx(this.sortIdx)
|
||||||
this.accountIdHash[hum.GetAccountId()] = hum
|
this.memberIdHash[hum.GetAccountId()] = hum
|
||||||
this.rearrangementSortIdx()
|
this.rearrangementSortIdx()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -105,7 +105,7 @@ func (this *team) IsLeader(hum common.Player) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *team) isFull() bool {
|
func (this *team) isFull() bool {
|
||||||
return len(this.accountIdHash) >= 4
|
return len(this.memberIdHash) >= 4
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *team) IsCopy() bool {
|
func (this *team) IsCopy() bool {
|
||||||
@ -165,7 +165,7 @@ func (this *team) CanStartGame(hum common.Player) bool {
|
|||||||
if !this.IsLock() {
|
if !this.IsLock() {
|
||||||
if this.GetMemberNum() > 0 {
|
if this.GetMemberNum() > 0 {
|
||||||
allReady := true
|
allReady := true
|
||||||
for _, m := range this.accountIdHash {
|
for _, m := range this.memberIdHash {
|
||||||
if m != this.owner && !m.IsReady() {
|
if m != this.owner && !m.IsReady() {
|
||||||
allReady = false
|
allReady = false
|
||||||
break
|
break
|
||||||
@ -199,12 +199,12 @@ func (this *team) StartGame() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *team) GetMemberNum() int32 {
|
func (this *team) GetMemberNum() int32 {
|
||||||
return int32(len(this.accountIdHash))
|
return int32(len(this.memberIdHash))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *team) chooseNextLeader() {
|
func (this *team) chooseNextLeader() {
|
||||||
nextLeader := this.owner
|
nextLeader := this.owner
|
||||||
for _, m := range this.accountIdHash {
|
for _, m := range this.memberIdHash {
|
||||||
if nextLeader == nil {
|
if nextLeader == nil {
|
||||||
nextLeader = m
|
nextLeader = m
|
||||||
} else if m.GetSortIdx() < nextLeader.GetSortIdx() {
|
} else if m.GetSortIdx() < nextLeader.GetSortIdx() {
|
||||||
@ -218,12 +218,12 @@ func (this *team) chooseNextLeader() {
|
|||||||
func (this *team) Leave(hum common.Player) {
|
func (this *team) Leave(hum common.Player) {
|
||||||
if !this.Started() {
|
if !this.Started() {
|
||||||
if this.IsLeader(hum) {
|
if this.IsLeader(hum) {
|
||||||
delete(this.accountIdHash, hum.GetAccountId())
|
delete(this.memberIdHash, hum.GetAccountId())
|
||||||
if this.GetMemberNum() > 0 {
|
if this.GetMemberNum() > 0 {
|
||||||
this.chooseNextLeader()
|
this.chooseNextLeader()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
delete(this.accountIdHash, hum.GetAccountId())
|
delete(this.memberIdHash, hum.GetAccountId())
|
||||||
}
|
}
|
||||||
if this.GetMemberNum() < 0 {
|
if this.GetMemberNum() < 0 {
|
||||||
this.Disband()
|
this.Disband()
|
||||||
@ -251,7 +251,7 @@ func (this *team) KickOut(hum common.Player, targetId string) {
|
|||||||
notifyMsg := &cs.SMTeamKickoutNotify{}
|
notifyMsg := &cs.SMTeamKickoutNotify{}
|
||||||
notifyMsg.AccountId = proto.String(target.GetAccountId())
|
notifyMsg.AccountId = proto.String(target.GetAccountId())
|
||||||
target.SendMsg(notifyMsg)
|
target.SendMsg(notifyMsg)
|
||||||
delete(this.accountIdHash, target.GetAccountId())
|
delete(this.memberIdHash, target.GetAccountId())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -291,7 +291,7 @@ func (this* team) IsMobaMode() bool {
|
|||||||
func (this *team) rearrangementSortIdx() {
|
func (this *team) rearrangementSortIdx() {
|
||||||
members := []common.Player{}
|
members := []common.Player{}
|
||||||
q5.NewSlice(&members, 0, 4)
|
q5.NewSlice(&members, 0, 4)
|
||||||
for _, m := range this.accountIdHash {
|
for _, m := range this.memberIdHash {
|
||||||
q5.AppendSlice(&members, m)
|
q5.AppendSlice(&members, m)
|
||||||
}
|
}
|
||||||
sort.Slice(members, func(i, j int) bool {
|
sort.Slice(members, func(i, j int) bool {
|
||||||
@ -359,7 +359,7 @@ func (this *team) genStartGameInfo() {
|
|||||||
for _, t := range teamList {
|
for _, t := range teamList {
|
||||||
ele := q5.NewSliceElement(&startInfo.TeamList)
|
ele := q5.NewSliceElement(&startInfo.TeamList)
|
||||||
ele.TeamUuid = t.GetTeamUuid()
|
ele.TeamUuid = t.GetTeamUuid()
|
||||||
for _, m := range t.accountIdHash {
|
for _, m := range t.memberIdHash {
|
||||||
ele2 := q5.NewSliceElement(&ele.Members)
|
ele2 := q5.NewSliceElement(&ele.Members)
|
||||||
ele2.AccountId = m.GetAccountId()
|
ele2.AccountId = m.GetAccountId()
|
||||||
ele2.SpecSkill = m.GetSpecSkill()
|
ele2.SpecSkill = m.GetSpecSkill()
|
||||||
@ -397,7 +397,7 @@ func (this *team) genNextCopyTeam() {
|
|||||||
nextTeam := newTeam()
|
nextTeam := newTeam()
|
||||||
nextTeam.init(nextCopyIdx, this.zoneId, this.nodeId,
|
nextTeam.init(nextCopyIdx, this.zoneId, this.nodeId,
|
||||||
this.nextTeamUuid, this.owner.GenNextCopy(), nextMapInfo)
|
this.nextTeamUuid, this.owner.GenNextCopy(), nextMapInfo)
|
||||||
for _, m := range this.accountIdHash {
|
for _, m := range this.memberIdHash {
|
||||||
if m != this.owner {
|
if m != this.owner {
|
||||||
nextTeam.Join(m.GenNextCopy())
|
nextTeam.Join(m.GenNextCopy())
|
||||||
}
|
}
|
||||||
@ -406,7 +406,7 @@ func (this *team) genNextCopyTeam() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *team) broadcastMsg(msg proto.Message) {
|
func (this *team) broadcastMsg(msg proto.Message) {
|
||||||
for _, m := range this.accountIdHash {
|
for _, m := range this.memberIdHash {
|
||||||
m.SendMsg(msg)
|
m.SendMsg(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -417,7 +417,7 @@ func (this *team) SendUpdateNotify() {
|
|||||||
notifyMsg.TeamInfo.TeamUuid = proto.String(this.teamUuid)
|
notifyMsg.TeamInfo.TeamUuid = proto.String(this.teamUuid)
|
||||||
notifyMsg.TeamInfo.MapId = proto.Int32(this.mapInfo.MapId)
|
notifyMsg.TeamInfo.MapId = proto.Int32(this.mapInfo.MapId)
|
||||||
q5.NewSlice(¬ifyMsg.TeamInfo.Members, 0, 1)
|
q5.NewSlice(¬ifyMsg.TeamInfo.Members, 0, 1)
|
||||||
for _, m := range this.accountIdHash {
|
for _, m := range this.memberIdHash {
|
||||||
m_pb := &cs.MFTeamMember{}
|
m_pb := &cs.MFTeamMember{}
|
||||||
q5.AppendSlice(¬ifyMsg.TeamInfo.Members, m_pb)
|
q5.AppendSlice(¬ifyMsg.TeamInfo.Members, m_pb)
|
||||||
m.FillMFTeamMember(m_pb)
|
m.FillMFTeamMember(m_pb)
|
||||||
@ -439,7 +439,7 @@ func (this *team) canMatch(targetT *team) bool {
|
|||||||
if this.GetMemberNum() <= 0 || targetT.GetMemberNum() <= 0 {
|
if this.GetMemberNum() <= 0 || targetT.GetMemberNum() <= 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
for _, m := range this.accountIdHash {
|
for _, m := range this.memberIdHash {
|
||||||
if targetT.GetMemberByAccountId(m.GetAccountId()) != nil {
|
if targetT.GetMemberByAccountId(m.GetAccountId()) != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -452,6 +452,6 @@ func newTeam() *team {
|
|||||||
t.state = constant.TEAM_STATE_INIT
|
t.state = constant.TEAM_STATE_INIT
|
||||||
t.stateNotifyMsg = &cs.SMTeamStateNotify{}
|
t.stateNotifyMsg = &cs.SMTeamStateNotify{}
|
||||||
t.stateNotifyMsg.JoinMsg = &cs.MFJoinMsg{}
|
t.stateNotifyMsg.JoinMsg = &cs.MFJoinMsg{}
|
||||||
t.accountIdHash = map[string]common.Player{}
|
t.memberIdHash = map[string]common.Player{}
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user