上传游戏配置

This commit is contained in:
liwei1dao 2023-11-10 18:53:26 +08:00
parent 3ec6774fca
commit 0464f296e8
2 changed files with 111 additions and 108 deletions

View File

@ -43,6 +43,6 @@ func (this *apiComp) HandleEnd(session comm.IUserSession, req *pb.CatchbugsHandl
} }
return return
} }
session.SendMsg(string(this.module.GetType()), "handle", &pb.CatchbugsHandleEndResp{}) session.SendMsg(string(this.module.GetType()), "handleend", &pb.CatchbugsHandleEndResp{})
return return
} }

View File

@ -20,6 +20,7 @@ type Room struct {
round int32 round int32
isReplenish bool isReplenish bool
handleplayer string handleplayer string
handleplayers int32
} }
func (this *Room) GameStart() (err error) { func (this *Room) GameStart() (err error) {
@ -28,12 +29,10 @@ func (this *Room) GameStart() (err error) {
this.module.Errorln(err) this.module.Errorln(err)
return return
} }
if err = this.Broadcast("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,
}); err != nil { }, true)
this.module.Errorln(err)
}
return return
} }
@ -45,21 +44,22 @@ func (this *Room) PlayerReadyEnd(uid string) (err error) {
this.data.Blue.Ready = true this.data.Blue.Ready = true
} }
if this.handleplayer == "" {
if this.data.Rules.Headstart == 0 { if this.data.Rules.Headstart == 0 {
this.handleplayer = this.data.Red.Info.Uid this.handleplayer = this.data.Red.Info.Uid
} else { } else {
this.handleplayer = this.data.Blue.Info.Uid this.handleplayer = this.data.Blue.Info.Uid
} }
}
if this.data.Red.Ready && this.data.Blue.Ready { //两个人都准备了 if this.data.Red.Ready && this.data.Blue.Ready { //两个人都准备了
this.data.Red.Ready = false this.data.Red.Ready = false
this.data.Blue.Ready = false this.data.Blue.Ready = false
if err = this.Broadcast("roundstart", &pb.CatchbugsRoundStartPush{ this.SendAllSessions("roundstart", &pb.CatchbugsRoundStartPush{
Round: this.round, Round: this.round,
Handleplayer: this.handleplayer, Handleplayer: this.handleplayer,
}); err != nil { }, true)
this.module.Errorln(err) this.handleplayers = 0
}
} }
return return
} }
@ -105,15 +105,13 @@ func (this *Room) PlayerHandle(uid string, handle *pb.CatchbugsHandleReq) (err e
} }
} }
if err = this.Broadcast("opencard", &pb.CatchbugsOpenCardPush{ this.SendAllSessions("opencard", &pb.CatchbugsOpenCardPush{
Roomid: this.data.Rid, Roomid: this.data.Rid,
Handleplayer: uid, Handleplayer: uid,
Index: handle.Index, Index: handle.Index,
Number: number, Number: number,
Issucc: issucc, Issucc: issucc,
}); err != nil { }, true)
this.module.Errorln(err)
}
return return
} }
@ -127,59 +125,14 @@ func (this *Room) PlayerHandleEnd(uid string, handle *pb.CatchbugsHandleEndReq)
var ( var (
card []*pb.DBCatchBugsCard card []*pb.DBCatchBugsCard
) )
this.handleplayers++
if this.data.Red.Info.Uid == uid { if this.data.Red.Info.Uid == 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
} }
state := this.checkGameOver() state := this.checkGameOver()
if state == 2 || this.round == 3 {
this.ReplenishCard()
card = this.data.Card
if err = this.Broadcast("tableschange", &pb.CatchbugsTablesChangePush{
Changetype: 1,
Card: card,
}); err != nil {
this.module.Errorln(err)
}
} else {
this.round++
}
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
if err = this.Broadcast("tableschange", &pb.CatchbugsTablesChangePush{
Changetype: 0,
Card: card,
}); err != nil {
this.module.Errorln(err)
}
break
case 2:
this.data.Card = Skill2Effect(this.data.Card)
card = this.data.Card
if err = this.Broadcast("tableschange", &pb.CatchbugsTablesChangePush{
Changetype: 0,
Card: card,
}); err != nil {
this.module.Errorln(err)
}
break
case 4:
this.data.Card = Skill4Effect(this.data.Card)
card = this.data.Card
if err = this.Broadcast("tableschange", &pb.CatchbugsTablesChangePush{
Changetype: 0,
Card: card,
}); err != nil {
this.module.Errorln(err)
}
break
}
}
if state == 3 { if state == 3 {
winuid := "" winuid := ""
if len(this.data.Red.Cards) > len(this.data.Blue.Cards) { if len(this.data.Red.Cards) > len(this.data.Blue.Cards) {
@ -205,18 +158,63 @@ func (this *Room) PlayerHandleEnd(uid string, handle *pb.CatchbugsHandleEndReq)
"integral": this.data.Blue.Integral, "integral": this.data.Blue.Integral,
}) })
} }
if err = this.Broadcast("gameover", &pb.CatchbugsGameOverPush{ this.SendAllSessions("gameover", &pb.CatchbugsGameOverPush{
Winuid: winuid, Winuid: winuid,
Redintegral: this.data.Red.Integral, Redintegral: this.data.Red.Integral,
Blueintegral: this.data.Blue.Integral, Blueintegral: this.data.Blue.Integral,
}); err != nil { }, true)
this.module.Errorln(err)
}
} else { } else {
if err = this.Broadcast("roundend", &pb.CatchbugsRoundEndPush{}); err != nil { if state == 2 { //需要补拍
this.module.Errorln(err) this.ReplenishCard()
card = this.data.Card
this.SendAllSessions("tableschange", &pb.CatchbugsTablesChangePush{
Changetype: 1,
Card: card,
}, false)
this.SendAllSessions("roundend", &pb.CatchbugsRoundEndPush{}, true)
} 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)
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)
}
}
} }
return return
@ -260,11 +258,13 @@ func (this *Room) ReplenishCard() {
func (this *Room) AiHanle(stype string) { func (this *Room) AiHanle(stype string) {
switch stype { switch stype {
case "gameready": case "gameready", "roundend":
go this.PlayerReadyEnd(this.data.Blue.Info.Uid) this.PlayerReadyEnd(this.data.Blue.Info.Uid)
break break
case "roundstart": case "roundstart":
go func() { if this.handleplayer != this.data.Blue.Info.Uid {
return
}
randoms := []int32{2, 3, 4, 5, 6} randoms := []int32{2, 3, 4, 5, 6}
random := randoms[comm.GetRandW(randoms)] random := randoms[comm.GetRandW(randoms)]
cardsSlice := []int32{} cardsSlice := []int32{}
@ -287,19 +287,22 @@ func (this *Room) AiHanle(stype string) {
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,
}) })
}()
break break
} }
} }
func (this *Room) Broadcast(stype string, msg proto.Message) (err error) { func (this *Room) SendAllSessions(stype string, msg proto.Message, ispush bool) {
if err = this.module.SendMsgToSession(string(this.module.GetType()), stype, msg, this.sessions...); err != nil { for _, v := range this.sessions {
this.module.Errorln(err) v.SendMsg(string(this.module.GetType()), stype, msg)
} }
if this.data.Blue.Isai { //是ai if ispush {
this.AiHanle(stype) for _, v := range this.sessions {
v.Push()
}
}
if this.data.Blue.Isai {
go this.AiHanle(stype)
} }
return
} }
//技能效果1 随机2x2的区域 旋转 //技能效果1 随机2x2的区域 旋转