From b18696718913f551466937a74a839ace34898035 Mon Sep 17 00:00:00 2001 From: sk <123456@qq.com> Date: Fri, 20 Dec 2024 16:09:26 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E5=8D=81=E4=B8=89=E5=BC=A0=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E5=88=86=E5=88=AB=E8=87=AA=E5=8A=A8=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E6=91=86=E7=89=8C=E6=97=B6=E9=95=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gamerule/thirteen/constants.go | 1 + gamesrv/thirteen/player.go | 10 +++++++- gamesrv/thirteen/scene.go | 1 + gamesrv/thirteen/scenepolicy.go | 42 +++++++++++++++++++++++++++++++- model/thirteen.go | 9 +++++++ mq/keyconf.go | 6 +++-- protocol/thirteen/thirteen.pb.go | 2 +- protocol/thirteen/thirteen.proto | 2 +- 8 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 model/thirteen.go diff --git a/gamerule/thirteen/constants.go b/gamerule/thirteen/constants.go index d3eb482..aeeded7 100644 --- a/gamerule/thirteen/constants.go +++ b/gamerule/thirteen/constants.go @@ -35,6 +35,7 @@ const ( ThirteenWaterPlayerOpReset = 4 // 重新选牌 ThirteenWaterPlayerJoin = 5 // 加入游戏 ThirteenWaterPlayerOpSelect = 6 // 预选牌 + ThirteenWaterPlayerOpAuto = 7 // 自动摆牌 1自动 2手动 ) const ( ThirteenWaterSceneWaitTimeout = time.Second * 2 //等待倒计时 diff --git a/gamesrv/thirteen/player.go b/gamesrv/thirteen/player.go index d59c380..b2baa63 100644 --- a/gamesrv/thirteen/player.go +++ b/gamesrv/thirteen/player.go @@ -1,6 +1,8 @@ package thirteen import ( + "time" + "mongo.games.com/goserver/core/logger" "mongo.games.com/game/gamerule/thirteen" @@ -25,7 +27,10 @@ type PlayerEx struct { odds int32 totalScore int64 defGroup *thirteen.Group - playerPool int // 个人水池分 + playerPool int // 个人水池分 + AutoState int // 是否自动模式 + AutoMill time.Duration // 自动时长 + HandMill time.Duration // 手动时长 } func (this *PlayerEx) Clear() { @@ -42,6 +47,9 @@ func (this *PlayerEx) Clear() { this.gainCoin = 0 this.taxCoin = 0 this.deterMine = false + this.AutoState = 0 + this.AutoMill = time.Duration(0) + this.HandMill = time.Duration(0) this.score = [7]int64{0, 0, 0, 0, 0, 0, 0} this.tableScore = [6]int64{} this.winThreePos = make(map[int]int64) diff --git a/gamesrv/thirteen/scene.go b/gamesrv/thirteen/scene.go index 2659e20..1d658f5 100644 --- a/gamesrv/thirteen/scene.go +++ b/gamesrv/thirteen/scene.go @@ -86,6 +86,7 @@ type SceneEx struct { ctrlType int // 1控赢 2控输 0不控 cardsArr [][13]int cardsGroup []map[int]*rule.Group + timestamp time.Time } func NewThirteenWaterSceneData(s *base.Scene) *SceneEx { diff --git a/gamesrv/thirteen/scenepolicy.go b/gamesrv/thirteen/scenepolicy.go index c97cb56..d4300c2 100644 --- a/gamesrv/thirteen/scenepolicy.go +++ b/gamesrv/thirteen/scenepolicy.go @@ -4,6 +4,7 @@ import ( "strconv" "time" + "go.mongodb.org/mongo-driver/bson/primitive" "mongo.games.com/goserver/core" "mongo.games.com/goserver/core/logger" @@ -11,6 +12,7 @@ import ( rule "mongo.games.com/game/gamerule/thirteen" "mongo.games.com/game/gamesrv/base" "mongo.games.com/game/model" + "mongo.games.com/game/mq" "mongo.games.com/game/proto" "mongo.games.com/game/protocol/thirteen" ) @@ -808,6 +810,11 @@ func (this *StateOp) OnEnter(s *base.Scene) { logger.Logger.Tracef("(this *StateOp) OnEnter, sceneid=%v", s.GetSceneId()) this.BaseState.OnEnter(s) ThirteenWaterBroadcastRoomState(s) + sceneEx, ok := s.ExtraData.(*SceneEx) + if !ok { + return + } + sceneEx.timestamp = time.Now() } // 玩家操作 @@ -869,6 +876,7 @@ func (this *StateOp) OnPlayerOp(s *base.Scene, p *base.Player, opcode int, param playerEx.Trusteeship = 0 playerEx.UnmarkFlag(base.PlayerState_Auto) playerEx.deterMine = true + playerEx.AutoState = 0 //如果所有玩家都确认牌之后 可以直接开始下一阶段 a := true for _, v := range sceneEx.players { @@ -942,6 +950,13 @@ func (this *StateOp) OnPlayerOp(s *base.Scene, p *base.Player, opcode int, param playerEx.deterMine = false returnFunc(thirteen.OpResultCode_OPRC_Sucess, true) + case rule.ThirteenWaterPlayerOpAuto: + if len(params) == 0 { + return true + } + + playerEx.AutoState = int(params[0]) + default: return false } @@ -958,6 +973,15 @@ func (this *StateOp) OnLeave(s *base.Scene) { for _, player := range sceneEx.players { if player != nil && player.IsGameing() { + + mq.Write(model.ThirteenAutoLog{ + Id: primitive.NewObjectID().Hex(), + LogId: sceneEx.logid, + SnId: player.SnId, + AutoTime: player.AutoMill.Milliseconds(), + HandTime: player.HandMill.Milliseconds(), + }, mq.BackThirteenAutoLog) + // 使用预选牌 if player.preCardsO != nil && player.preCardsO.PokerType != -1 && (player.cardsO == nil || player.cardsO.PokerType == -1) { player.cardsO = player.preCardsO @@ -1137,7 +1161,23 @@ func (this *StateOp) OnLeave(s *base.Scene) { func (this *StateOp) OnTick(s *base.Scene) { this.BaseState.OnTick(s) if sceneEx, ok := s.ExtraData.(*SceneEx); ok { - if time.Now().Sub(sceneEx.StateStartTime) > sceneEx.GetBaiPai() { + now := time.Now() + addTime := now.Sub(sceneEx.timestamp) + for _, v := range sceneEx.seats { + if v != nil && v.IsGameing() { + switch v.AutoState { + case 2: + v.AutoMill += addTime + case 1: + v.HandMill += addTime + default: + + } + } + } + sceneEx.timestamp = now + + if now.Sub(sceneEx.StateStartTime) > sceneEx.GetBaiPai() { s.ChangeSceneState(rule.ThirteenWaterSceneStateShowCards) } } diff --git a/model/thirteen.go b/model/thirteen.go new file mode 100644 index 0000000..731ae76 --- /dev/null +++ b/model/thirteen.go @@ -0,0 +1,9 @@ +package model + +type ThirteenAutoLog struct { + Id string + LogId string + SnId int32 + AutoTime int64 // 自动时长,毫秒 + HandTime int64 // 手动时长,毫秒 +} diff --git a/mq/keyconf.go b/mq/keyconf.go index 1bb8836..3dc3205 100644 --- a/mq/keyconf.go +++ b/mq/keyconf.go @@ -21,9 +21,11 @@ const ( BackOnlineGame = "back_onlinegame" ) -// mgrsrv +// go后端 -const () +const ( + BackThirteenAutoLog = "b_thirteenautolog" +) // worldsrv 消息 diff --git a/protocol/thirteen/thirteen.pb.go b/protocol/thirteen/thirteen.pb.go index 77cbe10..420d4fa 100644 --- a/protocol/thirteen/thirteen.pb.go +++ b/protocol/thirteen/thirteen.pb.go @@ -386,7 +386,7 @@ type CSThirteenPlayerOp struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - OpCode int32 `protobuf:"varint,1,opt,name=OpCode,proto3" json:"OpCode,omitempty"` // 1:确定牌 2站起状态 3test 4重新选牌 5加入游戏 6预选 + OpCode int32 `protobuf:"varint,1,opt,name=OpCode,proto3" json:"OpCode,omitempty"` // 1:确定牌 2站起状态 3test 4重新选牌 5加入游戏 6预选 7自动手动切换(1自动,2手动) // 确定牌时,两种参数规则,都可以 // 第一种:玩家从推荐牌型中选择一个,把Poker.IndexType发过来(减少数据传输) // 第二种:按头墩中墩尾墩顺序把牌发过来 diff --git a/protocol/thirteen/thirteen.proto b/protocol/thirteen/thirteen.proto index fe2bed2..bbe9905 100644 --- a/protocol/thirteen/thirteen.proto +++ b/protocol/thirteen/thirteen.proto @@ -73,7 +73,7 @@ message SCThirteenPlayerCards { //玩家操作 //PACKET_CSThirteenPlayerOp message CSThirteenPlayerOp { - int32 OpCode = 1; // 1:确定牌 2站起状态 3test 4重新选牌 5加入游戏 6预选 + int32 OpCode = 1; // 1:确定牌 2站起状态 3test 4重新选牌 5加入游戏 6预选 7自动手动切换(1自动,2手动) // 确定牌时,两种参数规则,都可以 // 第一种:玩家从推荐牌型中选择一个,把Poker.IndexType发过来(减少数据传输)