This commit is contained in:
meixiongfeng 2023-11-13 17:20:39 +08:00
commit e992bce862

View File

@ -12,15 +12,17 @@ import (
) )
type Room struct { type Room struct {
module *CatchBugs module *CatchBugs
data *pb.DBCatchBugsRoom data *pb.DBCatchBugsRoom
conf *cfg.GameCatchbugSkillData conf *cfg.GameCatchbugSkillData
sessions []comm.IUserSession sessions []comm.IUserSession
starttime time.Time starttime time.Time
round int32 round int32
isReplenish bool isReplenish bool
handleplayer string handleplayer string
handleplayers int32 handleplayers int32
aihandlecards []int32
aihandlenumber int32
} }
func (this *Room) GameStart() (err error) { func (this *Room) GameStart() (err error) {
@ -131,7 +133,7 @@ func (this *Room) PlayerHandleEnd(uid string, handle *pb.CatchbugsHandleEndReq)
card []*pb.DBCatchBugsCard card []*pb.DBCatchBugsCard
) )
this.handleplayers++ this.handleplayers++
if this.data.Red.Info.Uid == uid { if uid == this.data.Red.Info.Uid {
this.handleplayer = this.data.Blue.Info.Uid this.handleplayer = this.data.Blue.Info.Uid
} else { } else {
this.handleplayer = this.data.Red.Info.Uid this.handleplayer = this.data.Red.Info.Uid
@ -139,35 +141,7 @@ func (this *Room) PlayerHandleEnd(uid string, handle *pb.CatchbugsHandleEndReq)
state := this.checkGameOver() state := this.checkGameOver()
if state == 3 { if state == 3 {
winuid := "" this.gameover()
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)
} else { } else {
if state == 2 { //需要补拍 if state == 2 { //需要补拍
this.ReplenishCard() this.ReplenishCard()
@ -180,55 +154,62 @@ func (this *Room) PlayerHandleEnd(uid string, handle *pb.CatchbugsHandleEndReq)
} else { } else {
if this.handleplayers == 2 { if this.handleplayers == 2 {
this.round++ this.round++
if this.round == 3 { this.handleplayers = 0
this.ReplenishCard() if this.round < 6 {
card = this.data.Card if this.round == 3 {
this.SendAllSessions("tableschange", &pb.CatchbugsTablesChangePush{ this.ReplenishCard()
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)
card = this.data.Card card = this.data.Card
this.SendAllSessions("tableschange", &pb.CatchbugsTablesChangePush{ this.SendAllSessions("tableschange", &pb.CatchbugsTablesChangePush{
Changetype: 0, Changetype: 1,
Card: card, Card: card,
}, false) }, 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 { } else {
this.SendAllSessions("roundend", &pb.CatchbugsRoundEndPush{}, true) this.SendAllSessions("roundend", &pb.CatchbugsRoundEndPush{}, true)
} }
} }
} }
return return
} }
//检测游戏是否结束 //检测游戏是否结束 1 正常 2 补拍 3结束
func (this *Room) checkGameOver() (state int32) { func (this *Room) checkGameOver() (state int32) {
if this.round >= 6 {
state = 3
return
}
for _, v := range this.data.Card { for _, v := range this.data.Card {
if !v.Isopen { if !v.Isopen {
state = 1 state = 1
@ -284,17 +265,18 @@ func (this *Room) AiHanle(stype string) {
random = int32(len(cardsSlice)) random = int32(len(cardsSlice))
} }
indexs := comm.RandShuffle(len(cardsSlice)) indexs := comm.RandShuffle(len(cardsSlice))
for i, v := range indexs[0:random] { this.aihandlecards = make([]int32, 0)
this.PlayerHandle(this.data.Blue.Info.Uid, &pb.CatchbugsHandleReq{ this.aihandlenumber = 0
Roomid: this.data.Rid, for _, v := range indexs[0:random] {
Index: cardsSlice[v], this.aihandlecards = append(this.aihandlecards, cardsSlice[v])
Number: int32(i % 2),
})
} }
this.PlayerHandleEnd(this.data.Blue.Info.Uid, &pb.CatchbugsHandleEndReq{ this.AiHandleByOpenCard()
Roomid: this.data.Rid,
})
break break
case "opencard":
if this.aihandlenumber < int32(len(this.aihandlecards)) {
time.Sleep(time.Second)
this.AiHandleByOpenCard()
}
} }
} }
@ -312,6 +294,54 @@ 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)) {
time.Sleep(time.Second)
this.PlayerHandleEnd(this.data.Blue.Info.Uid, &pb.CatchbugsHandleEndReq{
Roomid: this.data.Rid,
})
}
}
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的区域 旋转 //技能效果1 随机2x2的区域 旋转
func Skill1Effect(cards []*pb.DBCatchBugsCard) (cardsTemp []*pb.DBCatchBugsCard) { func Skill1Effect(cards []*pb.DBCatchBugsCard) (cardsTemp []*pb.DBCatchBugsCard) {
var ( var (