上传代码

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