From f8822fc6be4aa85093238f5b55345561c4cd9d05 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Mon, 13 Nov 2023 14:53:24 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=8D=89=E8=99=AB?= =?UTF-8?q?=E5=AD=90=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 ( From 232dc9d0518eee776b053123ee6e3b6b16baf8bb Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Mon, 13 Nov 2023 14:58:08 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/catchbugs/room.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/catchbugs/room.go b/modules/catchbugs/room.go index b025a8120..fdc55a95b 100644 --- a/modules/catchbugs/room.go +++ b/modules/catchbugs/room.go @@ -294,8 +294,10 @@ func (this *Room) AiHanle(stype string) { this.AiHandleByOpenCard() break case "opencard": - time.Sleep(time.Second) - this.AiHandleByOpenCard() + if this.aihandlenumber < int32(len(this.aihandlecards)) { + time.Sleep(time.Second) + this.AiHandleByOpenCard() + } } } From a28d16b1b9a524643f59ae9324bb57f68570a84e Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Mon, 13 Nov 2023 16:03:55 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=88=BF=E9=97=B4?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/catchbugs/room.go | 140 +++++++++++++++++++++----------------- 1 file changed, 76 insertions(+), 64 deletions(-) diff --git a/modules/catchbugs/room.go b/modules/catchbugs/room.go index fdc55a95b..85eb3fcec 100644 --- a/modules/catchbugs/room.go +++ b/modules/catchbugs/room.go @@ -133,7 +133,7 @@ func (this *Room) PlayerHandleEnd(uid string, handle *pb.CatchbugsHandleEndReq) card []*pb.DBCatchBugsCard ) this.handleplayers++ - if this.data.Red.Info.Uid == uid { + if uid == this.data.Red.Info.Uid { this.handleplayer = this.data.Blue.Info.Uid } else { this.handleplayer = this.data.Red.Info.Uid @@ -141,35 +141,7 @@ func (this *Room) PlayerHandleEnd(uid string, handle *pb.CatchbugsHandleEndReq) state := this.checkGameOver() if state == 3 { - winuid := "" - if len(this.data.Red.Cards) > len(this.data.Blue.Cards) { - winuid = this.data.Red.Info.Uid - this.data.Red.Score = int32(len(this.data.Red.Cards) * 4) - this.data.Blue.Score = int32(len(this.data.Blue.Cards)) - - } else if len(this.data.Red.Cards) < len(this.data.Blue.Cards) { - winuid = this.data.Blue.Info.Uid - this.data.Blue.Score = int32(len(this.data.Blue.Cards) * 4) - this.data.Red.Score = int32(len(this.data.Red.Cards)) - } else { - this.data.Red.Score = int32(len(this.data.Red.Cards) * 2) - this.data.Blue.Score = int32(len(this.data.Blue.Cards) * 2) - } - this.data.Red.Integral += this.data.Red.Score - this.data.Blue.Integral += this.data.Blue.Score - this.module.model.Change(this.data.Red.Info.Uid, map[string]interface{}{ - "integral": this.data.Red.Integral, - }) - if !this.data.Blue.Isai { - this.module.model.Change(this.data.Blue.Info.Uid, map[string]interface{}{ - "integral": this.data.Blue.Integral, - }) - } - this.SendAllSessions("gameover", &pb.CatchbugsGameOverPush{ - Winuid: winuid, - Redintegral: this.data.Red.Integral, - Blueintegral: this.data.Blue.Integral, - }, true) + this.gameover() } else { if state == 2 { //需要补拍 this.ReplenishCard() @@ -182,55 +154,62 @@ func (this *Room) PlayerHandleEnd(uid string, handle *pb.CatchbugsHandleEndReq) } else { if this.handleplayers == 2 { this.round++ - if this.round == 3 { - this.ReplenishCard() - card = this.data.Card - this.SendAllSessions("tableschange", &pb.CatchbugsTablesChangePush{ - Changetype: 1, - Card: card, - }, false) - } - if this.round%this.conf.Round == 0 { //触发技能 - switch this.data.Rules.Skill { - case 1: - this.data.Card = Skill1Effect(this.data.Card) + this.handleplayers = 0 + if this.round < 6 { + if this.round == 3 { + this.ReplenishCard() card = this.data.Card this.SendAllSessions("tableschange", &pb.CatchbugsTablesChangePush{ - Changetype: 0, + Changetype: 1, Card: card, }, false) - break - case 2: - this.data.Card = Skill2Effect(this.data.Card) - card = this.data.Card - this.SendAllSessions("tableschange", &pb.CatchbugsTablesChangePush{ - Changetype: 0, - Card: card, - }, false) - break - case 4: - this.data.Card = Skill4Effect(this.data.Card) - card = this.data.Card - this.SendAllSessions("tableschange", &pb.CatchbugsTablesChangePush{ - Changetype: 0, - Card: card, - }, false) - break } + if this.round%this.conf.Round == 0 { //触发技能 + switch this.data.Rules.Skill { + case 1: + this.data.Card = Skill1Effect(this.data.Card) + card = this.data.Card + this.SendAllSessions("tableschange", &pb.CatchbugsTablesChangePush{ + Changetype: 0, + Card: card, + }, false) + break + case 2: + this.data.Card = Skill2Effect(this.data.Card) + card = this.data.Card + this.SendAllSessions("tableschange", &pb.CatchbugsTablesChangePush{ + Changetype: 0, + Card: card, + }, false) + break + case 4: + this.data.Card = Skill4Effect(this.data.Card) + card = this.data.Card + this.SendAllSessions("tableschange", &pb.CatchbugsTablesChangePush{ + Changetype: 0, + Card: card, + }, false) + break + } + } + this.SendAllSessions("roundend", &pb.CatchbugsRoundEndPush{}, true) + } else { + this.gameover() } - this.SendAllSessions("roundend", &pb.CatchbugsRoundEndPush{}, true) } else { this.SendAllSessions("roundend", &pb.CatchbugsRoundEndPush{}, true) } } - } - return } -//检测游戏是否结束 +//检测游戏是否结束 1 正常 2 补拍 3结束 func (this *Room) checkGameOver() (state int32) { + if this.round >= 6 { + state = 3 + return + } for _, v := range this.data.Card { if !v.Isopen { state = 1 @@ -323,6 +302,7 @@ func (this *Room) AiHandleByOpenCard() { }) this.aihandlenumber++ if this.aihandlenumber >= int32(len(this.aihandlecards)) { + time.Sleep(time.Second) this.PlayerHandleEnd(this.data.Blue.Info.Uid, &pb.CatchbugsHandleEndReq{ Roomid: this.data.Rid, }) @@ -330,6 +310,38 @@ func (this *Room) AiHandleByOpenCard() { } +func (this *Room) gameover() { + winuid := "" + if len(this.data.Red.Cards) > len(this.data.Blue.Cards) { + winuid = this.data.Red.Info.Uid + this.data.Red.Score = int32(len(this.data.Red.Cards) * 4) + this.data.Blue.Score = int32(len(this.data.Blue.Cards)) + + } else if len(this.data.Red.Cards) < len(this.data.Blue.Cards) { + winuid = this.data.Blue.Info.Uid + this.data.Blue.Score = int32(len(this.data.Blue.Cards) * 4) + this.data.Red.Score = int32(len(this.data.Red.Cards)) + } else { + this.data.Red.Score = int32(len(this.data.Red.Cards) * 2) + this.data.Blue.Score = int32(len(this.data.Blue.Cards) * 2) + } + this.data.Red.Integral += this.data.Red.Score + this.data.Blue.Integral += this.data.Blue.Score + this.module.model.Change(this.data.Red.Info.Uid, map[string]interface{}{ + "integral": this.data.Red.Integral, + }) + if !this.data.Blue.Isai { + this.module.model.Change(this.data.Blue.Info.Uid, map[string]interface{}{ + "integral": this.data.Blue.Integral, + }) + } + this.SendAllSessions("gameover", &pb.CatchbugsGameOverPush{ + Winuid: winuid, + Redintegral: this.data.Red.Integral, + Blueintegral: this.data.Blue.Integral, + }, true) +} + //技能效果1 随机2x2的区域 旋转 func Skill1Effect(cards []*pb.DBCatchBugsCard) (cardsTemp []*pb.DBCatchBugsCard) { var (