上传游戏配置

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
}
session.SendMsg(string(this.module.GetType()), "handle", &pb.CatchbugsHandleEndResp{})
session.SendMsg(string(this.module.GetType()), "handleend", &pb.CatchbugsHandleEndResp{})
return
}

View File

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