diff --git a/modules/entertainment/room.go b/modules/entertainment/room.go index 302d00759..3dc8522ba 100644 --- a/modules/entertainment/room.go +++ b/modules/entertainment/room.go @@ -175,7 +175,8 @@ func (this *Room) AiOperator() { } this.curPower = this.NexPower if this.RoomType == 2 && this.curPower == this.player2.Userinfo.Uid { - this.AiOperator() + //this.AiOperator() + this.AutoOperator(this.player2) } } @@ -204,85 +205,8 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr color = 2 } if req.Itype == 1 { //释放技能 - // 能量校验 - if color == 1 { // 玩家1 放技能 - conf, err := this.module.configure.GetGameConsumeHero(this.player1.Cardid) - if err != nil { - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_EntertainNoHeroSkill, - Title: pb.ErrorCode_EntertainNoHeroSkill.ToString(), - } - return - } - if this.player1.Energy >= conf.Skillload { - this.player1.Energy = 0 // 清零 - if _, m := this.chessboard.SkillUp(req.Curid, color, conf.Skilleffect, conf.Skillvalue, true); len(m) > 0 { - szMap = append(szMap, m...) - } else { - szMap = append(szMap, &pb.MapData{ - Data: this.chessboard.GetPalatData(), - }) - } - for _, v := range szMap { - curScore += v.CurSocre - this.player1.Score += v.CurSocre - v.CurSocre = this.player1.Score - } - - } else { - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_EntertainNoEnergy, - Title: pb.ErrorCode_EntertainNoEnergy.ToString(), - } - return - } - this.NexPower = this.curPower - } else { - conf, err := this.module.configure.GetGameConsumeHero(this.player2.Cardid) - if err != nil { - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_EntertainNoHeroSkill, - Title: pb.ErrorCode_EntertainNoHeroSkill.ToString(), - } - return - } - if this.player2.Energy >= conf.Skillload { - this.player2.Energy = 0 // 清零 - if _, m := this.chessboard.SkillUp(0, color, conf.Skilleffect, conf.Skillvalue, true); len(m) > 0 { - szMap = append(szMap, m...) - } else { - szMap = append(szMap, &pb.MapData{ - Data: this.chessboard.GetPalatData(), - }) - } - for _, v := range szMap { - curScore += v.CurSocre - this.player2.Score += v.CurSocre - v.CurSocre = this.player2.Score - } - - } else { - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_EntertainNoEnergy, - Title: pb.ErrorCode_EntertainNoEnergy.ToString(), - } - return - } - this.NexPower = this.curPower - } - if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{ - Mpadata: szMap, - Power: this.NexPower, - Curpower: this.curPower, - Score: curScore, - Round: this.round, - User1: this.player1, - User2: this.player2, - Itype: req.Itype, - Curid: oid1, - Targetid: oid2, - }, this.szSession...); err != nil { - this.module.Errorln(err) + if errdata = this.UserSkillUp(color, req.Curid); errdata != nil { + return } return } @@ -519,7 +443,8 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr this.module.Errorln(err) } if this.curPower == this.player2.Userinfo.Uid { - this.AiOperator() + //this.AiOperator() + this.AutoOperator(this.player2) } } else { @@ -743,14 +668,7 @@ func (this *Room) AutoOperator(p *pb.PlayerData) { szMap, oid1, oid2, bAddPs = this.chessboard.AiSwapGirde() p.Ps-- if p.Ps <= 0 { // 权限给下一个人 - if p == this.player2 { - this.NexPower = this.player1.Userinfo.Uid - this.player1.Ps = MaxPs - } else { - this.NexPower = this.player2.Userinfo.Uid - this.player2.Ps = MaxPs - } - + this.ChangePower() this.round++ } if bAddPs { @@ -800,7 +718,112 @@ func (this *Room) AutoOperator(p *pb.PlayerData) { return } this.curPower = this.NexPower - if this.RoomType == 2 && this.curPower == this.player2.Userinfo.Uid { - this.AutoOperator(this.player2) + if this.RoomType == 2 && this.curPower == p.Userinfo.Uid { + this.AutoOperator(p) + } +} + +// 玩家释放技能 +func (this *Room) UserSkillUp(color int32, curid int32) (errdata *pb.ErrorData) { + var ( + curScore int32 // 该次操作的得分 + oid1 int32 // 唯一id + oid2 int32 + ) + var szMap []*pb.MapData + // 能量校验 + if color == 1 { // 玩家1 放技能 + conf, err := this.module.configure.GetGameConsumeHero(this.player1.Cardid) + if err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_EntertainNoHeroSkill, + Title: pb.ErrorCode_EntertainNoHeroSkill.ToString(), + } + return + } + if this.player1.Energy >= conf.Skillload { + this.player1.Energy = 0 // 清零 + if _, m := this.chessboard.SkillUp(curid, color, conf.Skilleffect, conf.Skillvalue, true); len(m) > 0 { + szMap = append(szMap, m...) + } else { + szMap = append(szMap, &pb.MapData{ + Data: this.chessboard.GetPalatData(), + }) + } + for _, v := range szMap { + curScore += v.CurSocre + this.player1.Score += v.CurSocre + v.CurSocre = this.player1.Score + } + + } else { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_EntertainNoEnergy, + Title: pb.ErrorCode_EntertainNoEnergy.ToString(), + } + return + } + this.NexPower = this.curPower + } else { + conf, err := this.module.configure.GetGameConsumeHero(this.player2.Cardid) + if err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_EntertainNoHeroSkill, + Title: pb.ErrorCode_EntertainNoHeroSkill.ToString(), + } + return + } + if this.player2.Energy >= conf.Skillload { + this.player2.Energy = 0 // 清零 + if _, m := this.chessboard.SkillUp(curid, color, conf.Skilleffect, conf.Skillvalue, true); len(m) > 0 { + szMap = append(szMap, m...) + } else { + szMap = append(szMap, &pb.MapData{ + Data: this.chessboard.GetPalatData(), + }) + } + for _, v := range szMap { + curScore += v.CurSocre + this.player2.Score += v.CurSocre + v.CurSocre = this.player2.Score + } + + } else { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_EntertainNoEnergy, + Title: pb.ErrorCode_EntertainNoEnergy.ToString(), + } + return + } + this.NexPower = this.curPower + } + if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{ + Mpadata: szMap, + Power: this.NexPower, + Curpower: this.curPower, + Score: curScore, + Round: this.round, + User1: this.player1, + User2: this.player2, + Itype: 1, + Curid: oid1, + Targetid: oid2, + }, this.szSession...); err != nil { + this.module.Errorln(err) + } + return +} + +// 交换玩家权限 +func (this *Room) ChangePower() { + if this.curPower == this.player1.Userinfo.Uid { + this.NexPower = this.player2.Userinfo.Uid + this.player2.Ps = MaxPs + this.player1.Ps = 0 + } + if this.curPower == this.player2.Userinfo.Uid { + this.NexPower = this.player1.Userinfo.Uid + this.player1.Ps = MaxPs + this.player2.Ps = 0 } } diff --git a/modules/entertainment/xxlPlat.go b/modules/entertainment/xxlPlat.go index 9e0ecd301..87010a403 100644 --- a/modules/entertainment/xxlPlat.go +++ b/modules/entertainment/xxlPlat.go @@ -65,8 +65,7 @@ func (this *MapData) CreateGride(count int) (girdes []*pb.GirdeData) { Special: 0, } id = this.GetRandType() - conf, err = this.module.configure.GetGameBlockByKey(id) - if err == nil { + if conf, err = this.module.configure.GetGameBlockByKey(id); err == nil { girde.Color = conf.Color girde.Cid = conf.Key girde.Special = conf.Type @@ -124,19 +123,20 @@ func (this *MapData) InitMap(module *Entertainment, iType int32) { var mp map[int32]struct{} mp = make(map[int32]struct{}, 0) for { - n1, _ := rand.Int(rand.Reader, big.NewInt(Total-1)) + n1, _ := rand.Int(rand.Reader, big.NewInt(Total)) mp[int32(n1.Int64())] = struct{}{} if len(mp) >= 2 { break } } - if iType == 3 { - sp = 4 - } else if iType == 4 { - n1, _ := rand.Int(rand.Reader, big.NewInt(4)) // 随机一个消除类型 - sp = int32(n1.Int64()) + 5 - } + for key := range mp { + if iType == 3 { + sp = 4 + } else if iType == 4 { + n1, _ := rand.Int(rand.Reader, big.NewInt(4)) // 随机一个消除类型 + sp = int32(n1.Int64()) + 5 + } if conf, err := this.module.configure.GetGameBlock(this.Plat[key].Color, sp); err == nil { this.Plat[key].Cid = conf.Key this.Plat[key].Special = conf.Type @@ -548,6 +548,9 @@ func (this *MapData) DropGirde() bool { } } } + if len(fill) == 0 { + return bDrop + } sz := this.CreateGride(len(fill)) for pos, id := range fill { this.Plat[id] = sz[pos] @@ -586,13 +589,14 @@ func (this *MapData) DropGirde() bool { mp[fill[n1.Int64()]] = struct{}{} } - if this.iType == 3 { - sp = 4 - } else if this.iType == 4 { - n1, _ := rand.Int(rand.Reader, big.NewInt(4)) // 随机一个消除类型 - sp = int32(n1.Int64()) + 5 - } + for key := range mp { + if this.iType == 3 { + sp = 4 + } else if this.iType == 4 { + n1, _ := rand.Int(rand.Reader, big.NewInt(4)) // 随机一个消除类型 + sp = int32(n1.Int64()) + 5 + } if conf, err := this.module.configure.GetGameBlock(this.Plat[key].Color, sp); err == nil { this.Plat[key].Cid = conf.Key this.Plat[key].Special = conf.Type