1
This commit is contained in:
parent
6fb616dc61
commit
42d39118ac
@ -45,14 +45,13 @@ type Team interface {
|
||||
Started() bool
|
||||
CanStartGame(Player) bool
|
||||
StartGame()
|
||||
GetMemberNum() int32
|
||||
|
||||
Leave(Player)
|
||||
Disband()
|
||||
KickOut(Player, string)
|
||||
HandoverLeader(Player, string)
|
||||
CancelMatch()
|
||||
SetReady(Player)
|
||||
GrantInvitePermission(Player, string)
|
||||
}
|
||||
|
||||
type TeamMgr interface {
|
||||
|
@ -167,11 +167,15 @@ func (this *player) CMLeaveTeam(hdr *f5.MsgHdr, msg *cs.CMLeaveTeam) {
|
||||
if this.GetTeam().Started() {
|
||||
rspMsg.Errcode = proto.Int32(1)
|
||||
rspMsg.Errmsg = proto.String("team already started")
|
||||
this.SendMsg(rspMsg)
|
||||
return
|
||||
} else {
|
||||
this.GetTeam().Leave(this)
|
||||
}
|
||||
this.SendMsg(rspMsg)
|
||||
team.SendStateNotify()
|
||||
if team.GetMemberNum() > 0 {
|
||||
team.SendUpdateNotify()
|
||||
}
|
||||
}
|
||||
|
||||
func (this *player) CMDisbandTeam(hdr *f5.MsgHdr, msg *cs.CMDisbandTeam) {
|
||||
@ -241,10 +245,10 @@ func (this *player) CMSetReady(hdr *f5.MsgHdr, msg *cs.CMSetReady) {
|
||||
rspMsg.Errcode = proto.Int32(1)
|
||||
rspMsg.Errmsg = proto.String("team already started")
|
||||
} else {
|
||||
this.GetTeam().SetReady(this)
|
||||
this.isReady = 1
|
||||
}
|
||||
this.SendMsg(rspMsg)
|
||||
this.GetTeam().SendStateNotify()
|
||||
this.GetTeam().SendUpdateNotify()
|
||||
}
|
||||
|
||||
func (this *player) CMGrantInvitePermission(hdr *f5.MsgHdr, msg *cs.CMGrantInvitePermission) {
|
||||
@ -253,7 +257,10 @@ func (this *player) CMGrantInvitePermission(hdr *f5.MsgHdr, msg *cs.CMGrantInvit
|
||||
rspMsg.Errcode = proto.Int32(1)
|
||||
rspMsg.Errmsg = proto.String("team already started")
|
||||
} else {
|
||||
this.GetTeam().GrantInvitePermission(this, msg.GetTargetId())
|
||||
target := this.GetTeam().GetMemberByAccountId(msg.GetTargetId())
|
||||
if target != nil {
|
||||
target.(*player).permission = 1
|
||||
}
|
||||
}
|
||||
this.SendMsg(rspMsg)
|
||||
this.GetTeam().SendStateNotify()
|
||||
|
@ -36,4 +36,6 @@ enum SMMessageId_e
|
||||
|
||||
_SMTeamUpdateNotify = 1001;
|
||||
_SMTeamStateNotify = 1002;
|
||||
_SMTeamDisbandNotify = 1003;
|
||||
_SMTeamKickoutNotify = 1004;
|
||||
}
|
||||
|
@ -290,3 +290,14 @@ message SMTeamStateNotify
|
||||
optional int32 state = 1; //0:已取消 1:已开始 2:正在匹配(moba模式)
|
||||
optional MFJoinMsg join_msg = 2; //进入房间传的字段(只有一开始才生效)
|
||||
}
|
||||
|
||||
//队伍解散通知
|
||||
message SMTeamDisbandNotify
|
||||
{
|
||||
}
|
||||
|
||||
//队伍被踢通知
|
||||
message SMTeamKickoutNotify
|
||||
{
|
||||
optional string account_id = 1; //账号id
|
||||
}
|
||||
|
@ -126,26 +126,60 @@ func (this *team) StartGame() {
|
||||
}
|
||||
}
|
||||
|
||||
func (this *team) GetMemberNum() int32 {
|
||||
return int32(len(this.accountIdHash))
|
||||
}
|
||||
|
||||
func (this *team) chooseNextLeader() {
|
||||
nextLeader := this.owner
|
||||
for _, m := range this.accountIdHash {
|
||||
if nextLeader == nil {
|
||||
nextLeader = m
|
||||
} else if m.GetSortIdx() < nextLeader.GetSortIdx() {
|
||||
nextLeader = m
|
||||
}
|
||||
}
|
||||
this.owner = nextLeader
|
||||
}
|
||||
|
||||
func (this *team) Leave(hum common.Player) {
|
||||
if !this.Started() {
|
||||
if this.IsLeader(hum) {
|
||||
|
||||
delete(this.accountIdHash, hum.GetAccountId())
|
||||
if this.GetMemberNum() > 0 {
|
||||
this.chooseNextLeader()
|
||||
}
|
||||
} else {
|
||||
|
||||
delete(this.accountIdHash, hum.GetAccountId())
|
||||
}
|
||||
if this.GetMemberNum() < 0 {
|
||||
this.Disband()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (this *team) Disband() {
|
||||
if !this.Started() {
|
||||
if this.GetMemberNum() < 0 {
|
||||
|
||||
} else {
|
||||
notifyMsg := &cs.SMTeamDisbandNotify{}
|
||||
this.broadcastMsg(notifyMsg)
|
||||
}
|
||||
_teamMgr.removeTeam(this.GetTeamUuid())
|
||||
}
|
||||
}
|
||||
|
||||
func (this *team) KickOut(hum common.Player, targetId string) {
|
||||
if !this.Started() {
|
||||
if this.IsLeader(hum) {
|
||||
|
||||
target := this.GetMemberByAccountId(targetId)
|
||||
if target != nil && target != hum {
|
||||
notifyMsg := &cs.SMTeamKickoutNotify{}
|
||||
notifyMsg.AccountId = proto.String(target.GetAccountId())
|
||||
target.SendMsg(notifyMsg)
|
||||
delete(this.accountIdHash, target.GetAccountId())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -153,7 +187,10 @@ func (this *team) KickOut(hum common.Player, targetId string) {
|
||||
func (this *team) HandoverLeader(hum common.Player, targetId string) {
|
||||
if !this.Started() {
|
||||
if this.IsLeader(hum) {
|
||||
|
||||
target := this.GetMemberByAccountId(targetId)
|
||||
if target != nil && target != hum {
|
||||
this.owner = target
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -163,20 +200,6 @@ func (this *team) CancelMatch() {
|
||||
}
|
||||
}
|
||||
|
||||
func (this *team) SetReady(hum common.Player) {
|
||||
if !this.Started() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func (this *team) GrantInvitePermission(hum common.Player, targetId string) {
|
||||
if !this.Started() {
|
||||
if this.IsLeader(hum) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (this *team) rearrangementSortIdx() {
|
||||
members := []common.Player{}
|
||||
q5.NewSlice(&members, 0, 4)
|
||||
|
@ -61,3 +61,7 @@ func (this *teamMgr) GetTeamByUuid(teamUuid string) common.Team {
|
||||
func (this *teamMgr) OnEnterNewUser(hum common.Player) {
|
||||
|
||||
}
|
||||
|
||||
func (this *teamMgr) removeTeam(teamUuid string) {
|
||||
delete(this.teamUuidHash, teamUuid)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user