From cbd00bf0f863a81b81590dabad7428361f38aba4 Mon Sep 17 00:00:00 2001 From: kxdd Date: Tue, 27 Aug 2024 15:13:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A8=83=E5=A8=83=E6=9C=BA=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gamerule/clawdoll/constants.go | 2 +- gamesrv/clawdoll/player_clawdoll.go | 5 +++ gamesrv/clawdoll/scene_clawdoll.go | 49 +++++++++++++++------ gamesrv/clawdoll/scenepolicy_clawdoll.go | 55 ++++++++++++++++-------- 4 files changed, 79 insertions(+), 32 deletions(-) diff --git a/gamerule/clawdoll/constants.go b/gamerule/clawdoll/constants.go index abcd61a..9bdb60f 100644 --- a/gamerule/clawdoll/constants.go +++ b/gamerule/clawdoll/constants.go @@ -15,7 +15,7 @@ const ( const ( ClawDollSceneWaitTimeout = time.Second * 6 //等待倒计时 ClawDollSceneStartTimeout = time.Second * 5 //开始倒计时 - ClawDollScenePlayTimeout = time.Second * 30 //娃娃机下抓倒计时 + ClawDollScenePlayTimeout = time.Second * 10 //娃娃机下抓倒计时 ClawDollSceneBilledTimeout = time.Second * 2 //结算 ClawDollSceneWaitPayCoinimeout = time.Second * 10 //等待下一局投币 diff --git a/gamesrv/clawdoll/player_clawdoll.go b/gamesrv/clawdoll/player_clawdoll.go index 68887da..ab0ff68 100644 --- a/gamesrv/clawdoll/player_clawdoll.go +++ b/gamesrv/clawdoll/player_clawdoll.go @@ -53,6 +53,11 @@ func (this *PlayerEx) CanGrab() bool { // 游戏新一局 设置数据 func (this *PlayerEx) ReStartGame() { this.ReDataStartGame() + + this.UnmarkFlag(base.PlayerState_WaitNext) + this.UnmarkFlag(base.PlayerState_GameBreak) + this.MarkFlag(base.PlayerState_Ready) + this.gainCoin = 0 this.taxCoin = 0 this.odds = 0 diff --git a/gamesrv/clawdoll/scene_clawdoll.go b/gamesrv/clawdoll/scene_clawdoll.go index d794269..b3423f4 100644 --- a/gamesrv/clawdoll/scene_clawdoll.go +++ b/gamesrv/clawdoll/scene_clawdoll.go @@ -58,7 +58,7 @@ type SceneEx struct { // 游戏是否能开始 func (this *SceneEx) CanStart() bool { //人数>=1自动开始 - if len(this.players) >= 0 && (this.GetRealPlayerNum() >= 0 || this.IsPreCreateScene()) { + if len(this.players) >= 1 && (this.GetRealPlayerNum() >= 1 || this.IsPreCreateScene() || this.IsHasPlaying()) { return true } return false @@ -67,7 +67,7 @@ func (this *SceneEx) CanStart() bool { // 从房间删除玩家 func (this *SceneEx) delPlayer(p *base.Player) { if p, exist := this.players[p.SnId]; exist { - this.seats[p.GetPos()] = nil + //this.seats[p.GetPos()] = nil delete(this.players, p.SnId) this.RemoveWaitPlayer(p.SnId) } @@ -162,7 +162,6 @@ func NewClawdollSceneData(s *base.Scene) *SceneEx { Scene: s, logic: new(rule.Logic), players: make(map[int32]*PlayerEx), - seats: make([]*PlayerEx, s.GetPlayerNum()), PlayerBackup: make(map[int32]*PlayerData), waitPlayers: list.New(), } @@ -175,9 +174,40 @@ func (this *SceneEx) init() bool { return true } -// 检查上分是否合法 -func (this *SceneEx) CheckPayOp(betVal int64, takeMul int64) bool { //游戏底分 - return true +// 检查上分投币是否合法 +func (this *SceneEx) CheckPayCoinOp(p *PlayerEx) bool { + if p == nil { + return false + } + + if p.SnId == this.playingSnid { + return true + } + return false +} + +// 检查移动是否合法 +func (this *SceneEx) CheckMoveOp(p *PlayerEx) bool { + if p == nil { + return false + } + + if p.SnId == this.playingSnid { + return true + } + return false +} + +// 下抓是否合法 +func (this *SceneEx) CheckGrapOp(p *PlayerEx) bool { + if p == nil { + return false + } + + if p.SnId == this.playingSnid { + return true + } + return false } func (this *SceneEx) Clear() { @@ -191,13 +221,6 @@ func (this *SceneEx) Clear() { p.Clear(0) } } - - for i := 0; i < this.GetPlayerNum(); i++ { - if this.seats[i] != nil { - this.seats[i].Clear(this.GetBaseScore()) - } - } - } // 是否有玩家正在玩 diff --git a/gamesrv/clawdoll/scenepolicy_clawdoll.go b/gamesrv/clawdoll/scenepolicy_clawdoll.go index 64884fa..419b8ce 100644 --- a/gamesrv/clawdoll/scenepolicy_clawdoll.go +++ b/gamesrv/clawdoll/scenepolicy_clawdoll.go @@ -103,11 +103,12 @@ func (this *PolicyClawdoll) OnPlayerEnter(s *base.Scene, p *base.Player) { playerEx.Clear(baseScore) if sceneEx.playingSnid == 0 { - p.MarkFlag(base.PlayerState_WaitNext) - p.UnmarkFlag(base.PlayerState_Ready) - sceneEx.playingSnid = p.GetSnId() + //sceneEx.playingSnid = p.GetSnId() } + p.MarkFlag(base.PlayerState_WaitNext) + p.UnmarkFlag(base.PlayerState_Ready) + sceneEx.AddWaitPlayer(playerEx) //给自己发送房间信息 @@ -247,6 +248,7 @@ func (this *PolicyClawdoll) CanChangeCoinScene(s *base.Scene, p *base.Player) bo func (this *PolicyClawdoll) SendRoomInfo(s *base.Scene, p *base.Player, sceneEx *SceneEx) { pack := sceneEx.ClawdollCreateRoomInfoPacket(s, p) + p.SendToClient(int(clawdoll.CLAWDOLLPacketID_PACKET_SC_CLAWDOLL_ROOMINFO), pack) } @@ -279,14 +281,14 @@ func (this *BaseState) CanChangeTo(s base.SceneState) bool { func (this *BaseState) CanChangeCoinScene(s *base.Scene, p *base.Player) bool { - //playerEx, ok := p.ExtraData.(*PlayerEx) - //if !ok { - // return false - //} - // - //if !playerEx.CanLeaveScene(s.GetSceneState().GetState()) { - // return false - //} + playerEx, ok := p.ExtraData.(*PlayerEx) + if !ok { + return false + } + + if !playerEx.CanLeaveScene(s.GetSceneState().GetState()) { + return false + } return true } @@ -335,17 +337,13 @@ func (this *StateWait) GetTimeout(s *base.Scene) int { func (this *StateWait) OnEnter(s *base.Scene) { this.BaseState.OnEnter(s) - if sceneEx, ok := s.ExtraData.(*SceneEx); ok { + if _, ok := s.ExtraData.(*SceneEx); ok { if s.Gaming { s.NotifySceneRoundPause() } s.Gaming = false ClawdollBroadcastRoomState(s, float32(0)) - - if sceneEx.CanStart() { - s.ChangeSceneState(rule.ClawDollSceneStateStart) - } } } @@ -404,6 +402,7 @@ func (this *StateWait) OnPlayerOp(s *base.Scene, p *base.Player, opcode int, par if sceneEx.CanStart() { s.ChangeSceneState(rule.ClawDollSceneStateStart) + sceneEx.playingSnid = playerEx.SnId } } @@ -425,6 +424,7 @@ func (this *StateStart) GetState() int { func (this *StateStart) CanChangeTo(s base.SceneState) bool { switch s.GetState() { case rule.ClawDollSceneStatePlayGame: + return true case rule.ClawDollSceneStateWait: return true } @@ -526,6 +526,11 @@ func (this *PlayGame) OnPlayerOp(s *base.Scene, p *base.Player, opcode int, para switch opcode { case rule.ClawDollPlayerOpGo: + + if !sceneEx.CheckGrapOp(playerEx) { + return false + } + if !playerEx.CanGrab() { return false } @@ -537,6 +542,11 @@ func (this *PlayGame) OnPlayerOp(s *base.Scene, p *base.Player, opcode int, para sceneEx.OnPlayerSMGrabOp(p.SnId, int32(sceneEx.machineId), grapType) case rule.ClawDollPlayerOpMove: + + if !sceneEx.CheckMoveOp(playerEx) { + return false + } + if !playerEx.CanMove() { return false } @@ -581,7 +591,7 @@ func (this *StateBilled) GetState() int { func (this *StateBilled) CanChangeTo(s base.SceneState) bool { switch s.GetState() { - case rule.ClawDollSceneStateStart: + case rule.ClawDollSceneWaitPayCoin: return true } return false @@ -636,6 +646,7 @@ func (this *StateWaitPayCoin) GetState() int { func (this *StateWaitPayCoin) CanChangeTo(s base.SceneState) bool { switch s.GetState() { case rule.ClawDollSceneStateStart: + return true case rule.ClawDollSceneStateWait: return true } @@ -674,6 +685,8 @@ func (this *StateWaitPayCoin) OnPlayerOp(s *base.Scene, p *base.Player, opcode i sceneEx.OnPlayerSMPerateOp(p.SnId, int32(sceneEx.machineId), rule.ButtonPayCoin) + playerEx.ReStartGame() + s.ChangeSceneState(rule.ClawDollSceneStateStart) //sceneEx.OnPlayerSCOp(p, opcode, clawdoll.OpResultCode_OPRC_Success, params) } @@ -703,7 +716,13 @@ func (this *StateWaitPayCoin) OnTick(s *base.Scene) { if sceneEx, ok := s.ExtraData.(*SceneEx); ok { if time.Now().Sub(sceneEx.StateStartTime) > rule.ClawDollSceneWaitPayCoinimeout { - // 时间到,重置scene数据 + // 先设置时间 + playingEx := sceneEx.players[sceneEx.playingSnid] + if playingEx != nil { + playingEx.ReStartGame() + } + + // 后重置scene数据 sceneEx.WaitNextPlayer() s.ChangeSceneState(rule.ClawDollSceneStateWait)