From a8ff5bf5450dd3ecbcc1346a16d5e01ea964fc40 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 19 Mar 2024 20:00:28 +0800 Subject: [PATCH] 1 --- server/matchserver/team/team.go | 25 +++++++++++++++++++++++-- server/matchserver/team/teammgr.go | 7 ++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/server/matchserver/team/team.go b/server/matchserver/team/team.go index f5d65f50..57fbb4c0 100644 --- a/server/matchserver/team/team.go +++ b/server/matchserver/team/team.go @@ -8,6 +8,7 @@ import ( "main/constant" "sort" + "strings" "github.com/golang/protobuf/proto" ) @@ -29,8 +30,7 @@ type team struct { matchTick int64 } -func (this *team) init(copyIdx int32, teamUuid string, - owner common.Player, msg *cs.CMLogin, mapInfo* common.MapInfoRsp) { +func (this *team) init(copyIdx int32, teamUuid string, owner common.Player, mapInfo* common.MapInfoRsp) { this.sortIdx++ this.teamUuid = teamUuid this.copyIdx = copyIdx @@ -375,6 +375,27 @@ func (this *team) genStartGameInfo() { } func (this *team) genNextCopyTeam() { + nextCopyIdx := this.copyIdx + 1 + oldId := q5.ToString(this.zoneId) + "_" + + q5.ToString(this.nodeId) + "_" + + q5.ToString(this.copyIdx) + "_"; + newId := q5.ToString(this.zoneId) + "_" + + q5.ToString(this.nodeId) + "_" + + q5.ToString(nextCopyIdx) + "_"; + this.nextTeamUuid = strings.Replace(this.GetTeamUuid(), oldId, newId, 0) + if this.nextTeamUuid == this.GetTeamUuid() { + panic("genNextCopyTeam error1") + return + } + if _teamMgr.GetTeamByUuid(this.nextTeamUuid) != nil { + panic("genNextCopyTeam error2") + return + } + nextMapInfo := &common.MapInfoRsp{} + *nextMapInfo = *this.mapInfo + nextTeam := newTeam() + nextTeam.init(nextCopyIdx, this.nextTeamUuid, this.owner, nextMapInfo) + _teamMgr.addTeam(nextTeam) } func (this *team) broadcastMsg(msg proto.Message) { diff --git a/server/matchserver/team/teammgr.go b/server/matchserver/team/teammgr.go index 7753a093..5b8ba93f 100644 --- a/server/matchserver/team/teammgr.go +++ b/server/matchserver/team/teammgr.go @@ -26,11 +26,16 @@ func (this *teamMgr) CreateTeam(hum common.Player, msg *cs.CMLogin, mapInfo* com var copyIdx int32 = 0 teamUuid := this.genTeamUuid(copyIdx, hum.GetZoneId(), hum.GetNodeId()) team := newTeam() - team.init(copyIdx, teamUuid, hum, msg, mapInfo) + team.init(copyIdx, teamUuid, hum, mapInfo) this.teamUuidHash[team.teamUuid] = team + this.addTeam(team) return team } +func (this *teamMgr) addTeam(team *team) { + this.teamUuidHash[team.teamUuid] = team +} + func (this *teamMgr) genTeamUuid(zoneId int32, nodeId int32, copyIdx int32) string { teamUuid := "" for true {