From f8822fc6be4aa85093238f5b55345561c4cd9d05 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Mon, 13 Nov 2023 14:53:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=8D=89=E8=99=AB=E5=AD=90?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/catchbugs/room.go | 52 +++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/modules/catchbugs/room.go b/modules/catchbugs/room.go index 5fa141b9f..b025a8120 100644 --- a/modules/catchbugs/room.go +++ b/modules/catchbugs/room.go @@ -12,15 +12,17 @@ import ( ) type Room struct { - module *CatchBugs - data *pb.DBCatchBugsRoom - conf *cfg.GameCatchbugSkillData - sessions []comm.IUserSession - starttime time.Time - round int32 - isReplenish bool - handleplayer string - handleplayers int32 + module *CatchBugs + data *pb.DBCatchBugsRoom + conf *cfg.GameCatchbugSkillData + sessions []comm.IUserSession + starttime time.Time + round int32 + isReplenish bool + handleplayer string + handleplayers int32 + aihandlecards []int32 + aihandlenumber int32 } func (this *Room) GameStart() (err error) { @@ -284,17 +286,16 @@ func (this *Room) AiHanle(stype string) { random = int32(len(cardsSlice)) } indexs := comm.RandShuffle(len(cardsSlice)) - for i, v := range indexs[0:random] { - this.PlayerHandle(this.data.Blue.Info.Uid, &pb.CatchbugsHandleReq{ - Roomid: this.data.Rid, - Index: cardsSlice[v], - Number: int32(i % 2), - }) + this.aihandlecards = make([]int32, 0) + this.aihandlenumber = 0 + for _, v := range indexs[0:random] { + this.aihandlecards = append(this.aihandlecards, cardsSlice[v]) } - this.PlayerHandleEnd(this.data.Blue.Info.Uid, &pb.CatchbugsHandleEndReq{ - Roomid: this.data.Rid, - }) + this.AiHandleByOpenCard() break + case "opencard": + time.Sleep(time.Second) + this.AiHandleByOpenCard() } } @@ -312,6 +313,21 @@ func (this *Room) SendAllSessions(stype string, msg proto.Message, ispush bool) } } +func (this *Room) AiHandleByOpenCard() { + this.PlayerHandle(this.data.Blue.Info.Uid, &pb.CatchbugsHandleReq{ + Roomid: this.data.Rid, + Index: this.aihandlecards[this.aihandlenumber], + Number: int32(this.aihandlenumber % 2), + }) + this.aihandlenumber++ + if this.aihandlenumber >= int32(len(this.aihandlecards)) { + this.PlayerHandleEnd(this.data.Blue.Info.Uid, &pb.CatchbugsHandleEndReq{ + Roomid: this.data.Rid, + }) + } + +} + //技能效果1 随机2x2的区域 旋转 func Skill1Effect(cards []*pb.DBCatchBugsCard) (cardsTemp []*pb.DBCatchBugsCard) { var (