上传代码

This commit is contained in:
liwei1dao 2023-11-14 10:25:18 +08:00
parent a28d16b1b9
commit b8f3e1a195

View File

@ -3,6 +3,7 @@ package catchbugs
import ( import (
"fmt" "fmt"
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/sys/configure" "go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs" cfg "go_dreamfactory/sys/configure/structs"
@ -34,7 +35,7 @@ func (this *Room) GameStart() (err error) {
this.SendAllSessions("gameready", &pb.CatchbugsGameReadyPush{ this.SendAllSessions("gameready", &pb.CatchbugsGameReadyPush{
ServicePath: fmt.Sprintf("%s/%s", this.module.service.GetType(), this.module.service.GetId()), ServicePath: fmt.Sprintf("%s/%s", this.module.service.GetType(), this.module.service.GetId()),
Room: this.data, Room: this.data,
}, true) })
return return
} }
@ -60,8 +61,9 @@ func (this *Room) PlayerReadyEnd(uid string) (err error) {
this.SendAllSessions("roundstart", &pb.CatchbugsRoundStartPush{ this.SendAllSessions("roundstart", &pb.CatchbugsRoundStartPush{
Round: this.round, Round: this.round,
Handleplayer: this.handleplayer, Handleplayer: this.handleplayer,
}, true) })
this.data.Red.Lastopencard = -1
this.data.Blue.Lastopencard = -1
} }
return return
} }
@ -82,7 +84,7 @@ func (this *Room) PlayerHandle(uid string, handle *pb.CatchbugsHandleReq) (err e
number int32 number int32
) )
if this.data.Red.Info.Uid == uid { if this.data.Red.Info.Uid == uid {
if this.data.Red.Lastopencard == 0 { if this.data.Red.Lastopencard == -1 {
this.data.Red.Lastopencard = handle.Index this.data.Red.Lastopencard = handle.Index
number = 0 number = 0
} else { } else {
@ -94,10 +96,10 @@ func (this *Room) PlayerHandle(uid string, handle *pb.CatchbugsHandleReq) (err e
} }
number = 1 number = 1
this.data.Red.Lastopencard = 0 this.data.Red.Lastopencard = -1
} }
} else { } else {
if this.data.Blue.Lastopencard == 0 { if this.data.Blue.Lastopencard == -1 {
this.data.Blue.Lastopencard = handle.Index this.data.Blue.Lastopencard = handle.Index
number = 0 number = 0
} else { } else {
@ -108,7 +110,7 @@ func (this *Room) PlayerHandle(uid string, handle *pb.CatchbugsHandleReq) (err e
this.data.Blue.Cards = append(this.data.Red.Cards, this.data.Card[this.data.Blue.Lastopencard].Cid) this.data.Blue.Cards = append(this.data.Red.Cards, this.data.Card[this.data.Blue.Lastopencard].Cid)
} }
number = 1 number = 1
this.data.Blue.Lastopencard = 0 this.data.Blue.Lastopencard = -1
} }
} }
@ -118,7 +120,7 @@ func (this *Room) PlayerHandle(uid string, handle *pb.CatchbugsHandleReq) (err e
Index: handle.Index, Index: handle.Index,
Number: number, Number: number,
Issucc: issucc, Issucc: issucc,
}, true) })
return return
} }
@ -149,57 +151,47 @@ func (this *Room) PlayerHandleEnd(uid string, handle *pb.CatchbugsHandleEndReq)
this.SendAllSessions("tableschange", &pb.CatchbugsTablesChangePush{ this.SendAllSessions("tableschange", &pb.CatchbugsTablesChangePush{
Changetype: 1, Changetype: 1,
Card: card, Card: card,
}, false) })
this.SendAllSessions("roundend", &pb.CatchbugsRoundEndPush{}, true) this.SendAllSessions("roundend", &pb.CatchbugsRoundEndPush{})
} else { }
if this.handleplayers == 2 { if this.handleplayers == 2 {
this.round++ this.round++
this.handleplayers = 0 this.handleplayers = 0
if this.round < 6 { if this.round <= 6 {
if this.round == 3 { if this.round%this.conf.Round == 0 { //触发技能
this.ReplenishCard() 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: 1, Changetype: 0,
Card: card, 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,
})
break
case 4:
this.data.Card = Skill4Effect(this.data.Card)
card = this.data.Card
this.SendAllSessions("tableschange", &pb.CatchbugsTablesChangePush{
Changetype: 0,
Card: card,
})
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()
} }
} else { } else {
this.SendAllSessions("roundend", &pb.CatchbugsRoundEndPush{}, true) this.gameover()
return
} }
} }
this.SendAllSessions("roundend", &pb.CatchbugsRoundEndPush{})
} }
return return
} }
@ -216,7 +208,7 @@ func (this *Room) checkGameOver() (state int32) {
return return
} }
} }
if this.round < 3 && !this.isReplenish { //需要补拍 if (this.round < 3 && !this.isReplenish) || this.round == 3 { //需要补拍
state = 2 state = 2
} else { } else {
state = 3 state = 3
@ -274,24 +266,20 @@ func (this *Room) AiHanle(stype string) {
break break
case "opencard": case "opencard":
if this.aihandlenumber < int32(len(this.aihandlecards)) { if this.aihandlenumber < int32(len(this.aihandlecards)) {
time.Sleep(time.Second)
this.AiHandleByOpenCard() this.AiHandleByOpenCard()
} }
} }
} }
func (this *Room) SendAllSessions(stype string, msg proto.Message, ispush bool) { func (this *Room) SendAllSessions(stype string, msg proto.Message) (err error) {
for _, v := range this.sessions { if err = this.module.SendMsgSyncToSession(string(this.module.GetType()), stype, msg, this.sessions...); err != nil {
v.SendMsg(string(this.module.GetType()), stype, msg) this.module.Errorln(err)
} return
if ispush {
for _, v := range this.sessions {
v.Push()
}
} }
if this.data.Blue.Isai { if this.data.Blue.Isai {
go this.AiHanle(stype) go this.AiHanle(stype)
} }
return
} }
func (this *Room) AiHandleByOpenCard() { func (this *Room) AiHandleByOpenCard() {
@ -302,7 +290,6 @@ func (this *Room) AiHandleByOpenCard() {
}) })
this.aihandlenumber++ this.aihandlenumber++
if this.aihandlenumber >= int32(len(this.aihandlecards)) { if this.aihandlenumber >= int32(len(this.aihandlecards)) {
time.Sleep(time.Second)
this.PlayerHandleEnd(this.data.Blue.Info.Uid, &pb.CatchbugsHandleEndReq{ this.PlayerHandleEnd(this.data.Blue.Info.Uid, &pb.CatchbugsHandleEndReq{
Roomid: this.data.Rid, Roomid: this.data.Rid,
}) })
@ -339,7 +326,7 @@ func (this *Room) gameover() {
Winuid: winuid, Winuid: winuid,
Redintegral: this.data.Red.Integral, Redintegral: this.data.Red.Integral,
Blueintegral: this.data.Blue.Integral, Blueintegral: this.data.Blue.Integral,
}, true) })
} }
//技能效果1 随机2x2的区域 旋转 //技能效果1 随机2x2的区域 旋转
@ -372,6 +359,7 @@ func Skill1Effect(cards []*pb.DBCatchBugsCard) (cardsTemp []*pb.DBCatchBugsCard)
ramdonCard = append(ramdonCard, cards[y*4+x+offsetX]) ramdonCard = append(ramdonCard, cards[y*4+x+offsetX])
ramdonCard = append(ramdonCard, cards[(y+offsetY)*4+x+offsetX]) ramdonCard = append(ramdonCard, cards[(y+offsetY)*4+x+offsetX])
ramdonCard = append(ramdonCard, cards[(y+offsetY)*4+x]) ramdonCard = append(ramdonCard, cards[(y+offsetY)*4+x])
log.Debugf("技能1 前的数据:", ramdonCard)
index0 := ramdonCard[0].Index index0 := ramdonCard[0].Index
for i, v := range ramdonCard { for i, v := range ramdonCard {
if i < len(ramdonCard)-1 { if i < len(ramdonCard)-1 {
@ -380,7 +368,12 @@ func Skill1Effect(cards []*pb.DBCatchBugsCard) (cardsTemp []*pb.DBCatchBugsCard)
v.Index = index0 v.Index = index0
} }
} }
log.Debugf("技能1 后的数据:", ramdonCard)
cardsTemp = cards cardsTemp = cards
cardsTemp = make([]*pb.DBCatchBugsCard, len(cards))
for _, v := range cards {
cardsTemp[v.Index] = v
}
return cardsTemp return cardsTemp
} }
@ -455,6 +448,9 @@ func Skill4Effect(cards []*pb.DBCatchBugsCard) (cardsTemp []*pb.DBCatchBugsCard)
v.Index = index0 v.Index = index0
} }
} }
cardsTemp = cards cardsTemp = make([]*pb.DBCatchBugsCard, len(cards))
for _, v := range cards {
cardsTemp[v.Index] = v
}
return return
} }