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 = 0 this.PushMessage("startselecthero", &pb.RealArenaStartSelectHeroPush{ Uid: this.members[0].User.Uid, Num: 2, Countdown: 10, }) return } //选择英雄 func (this *Room) selectheros(uid string, heros []string, herocid []string) (err error) { var ( num int32 ) if uid != this.handle { err = fmt.Errorf("cant handle!") return } for _, v := range this.members { if v.User.Uid == uid { v.Heros = heros v.Heroscid = herocid } else { this.handle = v.User.Uid } } switch this.step { case 1, 6: num = 1 break case 2, 3, 4, 5: num = 2 break default: num = 1 break } this.PushMessage("startselecthero", &pb.RealArenaSelectHeroPush{ Uid: this.members[0].User.Uid, Heroscids: herocid, }) this.step++ if this.step == 7 { //选完了 this.PushMessage("startdisableHero", &pb.RealArenaStartDisableHeroPush{ Uid: this.members[0].User.Uid, Countdown: 10, }) } else { this.PushMessage("startselecthero", &pb.RealArenaStartSelectHeroPush{ Uid: this.handle, Num: num, Countdown: 10, }) } return } //禁用英雄 func (this *Room) disableheros(uid string, index int32) (err error) { var finish bool finish = true for _, v := range this.members { if v.User.Uid == uid { v.Disable = index } if v.Disable == -1 { finish = false } } this.PushMessage("selecthero", &pb.RealArenaDisableHeroPush{ Uid: uid, Index: index, }) if finish { 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 finish bool finish = true for _, v := range this.members { if v.User.Uid == uid { v.Leader = index } if v.Leader == -1 { finish = false } } this.PushMessage("selectleader", &pb.RealArenaSelectLeaderPush{ Uid: uid, Index: index, }) if finish { 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...) }