126 lines
2.9 KiB
Go
126 lines
2.9 KiB
Go
package realarena
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
// /装备 数据组件
|
|
type Room struct {
|
|
Id string
|
|
module *RealArena
|
|
sessions []comm.IUserSession
|
|
members []*pb.DBRealArenaMember
|
|
state int //0 无状态 1选择英雄阶段 2禁用英雄阶段 3选择队长阶段 4战斗中
|
|
step int //阶段
|
|
handle string // 操作玩家
|
|
}
|
|
|
|
func (this *Room) init() (err error) {
|
|
this.PushMessage("matchsucc", &pb.RealArenaMatchSuccPush{
|
|
Race: &pb.DBRealArenaRace{
|
|
Id: this.Id,
|
|
ServicePath: fmt.Sprintf("%s", this.module.service.GetId()),
|
|
Red: this.members[0],
|
|
Bule: this.members[1],
|
|
},
|
|
})
|
|
this.handle = this.members[0].User.Uid
|
|
this.step = 1
|
|
this.PushMessage("startselecthero", &pb.RealArenaStartSelectHeroPush{
|
|
Uid: this.members[0].User.Uid,
|
|
Num: 2,
|
|
Countdown: 10,
|
|
})
|
|
return
|
|
}
|
|
|
|
//选择英雄
|
|
func (this *Room) selectheros(uid string, heros []string) (err error) {
|
|
if uid != this.handle {
|
|
err = fmt.Errorf("cant handle!")
|
|
return
|
|
}
|
|
if uid == this.members[1].User.Uid {
|
|
this.step++
|
|
}
|
|
for _, v := range this.members {
|
|
if v.User.Uid == uid {
|
|
v.Heros = heros
|
|
} else {
|
|
this.handle = v.User.Uid
|
|
}
|
|
}
|
|
this.PushMessage("startselecthero", &pb.RealArenaSelectHeroPush{
|
|
Uid: this.members[0].User.Uid,
|
|
Heros: heros,
|
|
})
|
|
this.PushMessage("startselecthero", &pb.RealArenaStartSelectHeroPush{
|
|
Uid: this.handle,
|
|
Num: 2,
|
|
Countdown: 10,
|
|
})
|
|
if this.step == 4 { //选完了
|
|
this.PushMessage("startdisableHero", &pb.RealArenaStartDisableHeroPush{
|
|
Uid: this.members[0].User.Uid,
|
|
Countdown: 10,
|
|
})
|
|
}
|
|
return
|
|
}
|
|
|
|
//禁用英雄
|
|
func (this *Room) disableheros(uid string, index int32) (err error) {
|
|
var isend bool
|
|
for _, v := range this.members {
|
|
if v.User.Uid == uid {
|
|
v.Disable = index
|
|
}
|
|
if v.Disable == -1 {
|
|
isend = false
|
|
}
|
|
}
|
|
this.PushMessage("selecthero", &pb.RealArenaDisableHeroPush{
|
|
Uid: uid,
|
|
Index: index,
|
|
})
|
|
if isend {
|
|
this.PushMessage("startselectleader", &pb.RealArenaStartSelectLeaderPush{
|
|
Uid: this.members[0].User.Uid,
|
|
Countdown: 10,
|
|
})
|
|
}
|
|
return
|
|
}
|
|
|
|
//选择队长
|
|
func (this *Room) selectleader(uid string, index int32) (err error) {
|
|
var isend bool
|
|
for _, v := range this.members {
|
|
if v.User.Uid == uid {
|
|
v.Leader = index
|
|
}
|
|
if v.Leader == -1 {
|
|
isend = false
|
|
}
|
|
}
|
|
this.PushMessage("selectleader", &pb.RealArenaSelectLeaderPush{
|
|
Uid: uid,
|
|
Index: index,
|
|
})
|
|
if isend {
|
|
var uinfos []*pb.BaseUserInfo = make([]*pb.BaseUserInfo, 0)
|
|
uinfos = append(uinfos, this.members[0].User, this.members[1].User)
|
|
err = this.module.pvp.CreateRoomById(this.Id, pb.PvpType_realarena, this.sessions, uinfos)
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (this *Room) PushMessage(stype string, msg proto.Message) {
|
|
this.module.SendMsgToSession(string(this.module.GetType()), stype, msg, this.sessions...)
|
|
}
|