diff --git a/gamerule/clawdoll/constants.go b/gamerule/clawdoll/constants.go index 8c0386f..24907d3 100644 --- a/gamerule/clawdoll/constants.go +++ b/gamerule/clawdoll/constants.go @@ -30,6 +30,8 @@ const ( ClawDollSceneBilledTimeout = time.Second * 2 //结算 ClawDollSceneWaitPayCoinimeout = time.Second * 10 //等待下一局投币 + ClawDollSceneGrapTimeOut = time.Second * 5 //下抓防卡死强制变状态倒计时 + ClawDollScenePayCoinTimeOut = time.Second * 2 //投币防卡死强制变状态倒计时 ) // 玩家操作 diff --git a/gamesrv/clawdoll/action_clawdoll.go b/gamesrv/clawdoll/action_clawdoll.go index a86dc73..11a4e80 100644 --- a/gamesrv/clawdoll/action_clawdoll.go +++ b/gamesrv/clawdoll/action_clawdoll.go @@ -9,6 +9,7 @@ import ( "mongo.games.com/game/protocol/machine" "mongo.games.com/goserver/core/logger" "mongo.games.com/goserver/core/netlib" + "mongo.games.com/goserver/core/timer" "strconv" ) @@ -74,8 +75,9 @@ func MSDollMachineoCoinResultHandler(session *netlib.Session, packetId int, data switch msg.TypeId { case 1: + logger.Logger.Tracef("ClawDoll OnPlayerOp payCoin response, SnId= %v", p.SnId) if msg.Result == 1 { - logger.Logger.Tracef("上分成功!!!!!!!!!!!!snid = ", msg.Snid) + logger.Logger.Tracef("上分成功!!!!!!!!!!!!snid = %v", msg.Snid) sceneEx.playingSnid = p.SnId @@ -91,22 +93,29 @@ func MSDollMachineoCoinResultHandler(session *netlib.Session, packetId int, data ClawdollBroadcastPlayingInfo(s) } else { - logger.Logger.Tracef("上分失败!!!!!!!!!!!!snid = ", msg.Snid) + logger.Logger.Tracef("上分失败!!!!!!!!!!!!snid = %v", msg.Snid) } case 2: if msg.Result == 1 { // 获得娃娃卡 - logger.Logger.Tracef("下抓成功!!!!!!!!!!!!snid = ", msg.Snid) + logger.Logger.Tracef("下抓成功!!!!!!!!!!!!snid = %v", msg.Snid) } else { - logger.Logger.Tracef("下抓失败!!!!!!!!!!!!snid = ", msg.Snid) + logger.Logger.Tracef("下抓失败!!!!!!!!!!!!snid = %v", msg.Snid) } + logger.Logger.Tracef("ClawDoll StatePlayGame OnPlayerOp Grab response, SnId= %v", msg.Snid) + s.ChangeSceneState(rule.ClawDollSceneStateBilled) sceneEx.SetPlayingState(int32(rule.ClawDollSceneStateBilled)) ClawdollBroadcastRoomState(s) ClawdollSendPlayerInfo(s) + + if sceneEx.grabTimerHandle != timer.TimerHandle(0) { + timer.StopTimer(sceneEx.grabTimerHandle) + sceneEx.grabTimerHandle = timer.TimerHandle(0) + } } } return nil diff --git a/gamesrv/clawdoll/scene_clawdoll.go b/gamesrv/clawdoll/scene_clawdoll.go index 2e2c226..aa184cc 100644 --- a/gamesrv/clawdoll/scene_clawdoll.go +++ b/gamesrv/clawdoll/scene_clawdoll.go @@ -66,6 +66,9 @@ type SceneEx struct { machineId int //娃娃机ID machineConn *netlib.Session //娃娃机链接 machineStatus int32 //娃娃机链接状态 0:离线 1:在线 + + payCoinTimeHandle timer.TimerHandle //上分投币托管handle + grabTimerHandle timer.TimerHandle //下抓托管handle } // 游戏是否能开始 @@ -392,6 +395,7 @@ func (this *SceneEx) TimeOutPlayGrab() bool { if playerEx != nil { grapType := this.GetPlayGrabType(playerEx) this.OnPlayerSMGrabOp(this.playingSnid, int32(this.machineId), grapType) + } return true @@ -431,6 +435,34 @@ func (this *SceneEx) SendToMachine(pid int, msg interface{}) { } } +// 下抓托管handle +func (this *SceneEx) GrabTimerHandle() { + if this.grabTimerHandle != timer.TimerHandle(0) { + timer.StopTimer(this.grabTimerHandle) + this.grabTimerHandle = timer.TimerHandle(0) + } + + this.grabTimerHandle, _ = timer.StartTimer(timer.TimerActionWrapper(func(h timer.TimerHandle, ud interface{}) bool { + + logger.Logger.Tracef("ClawDoll SceneEx GrabTimerHandle: TimeOut: %v", rule.ClawDollSceneGrapTimeOut) + this.TimeOutPlayGrab() + return true + }), nil, rule.ClawDollSceneGrapTimeOut, 1) +} + +// 上分投币托管handle +func (this *SceneEx) PayCoinTimeHandle() { + if this.payCoinTimeHandle != timer.TimerHandle(0) { + timer.StopTimer(this.payCoinTimeHandle) + this.payCoinTimeHandle = timer.TimerHandle(0) + } + + this.payCoinTimeHandle, _ = timer.StartTimer(timer.TimerActionWrapper(func(h timer.TimerHandle, ud interface{}) bool { + logger.Logger.Tracef("ClawDoll SceneEx PayCoinTimeHandle: TimeOut: %v", rule.ClawDollScenePayCoinTimeOut) + return true + }), nil, rule.ClawDollScenePayCoinTimeOut, 1) +} + // actionType : 1 禁止推流 ForbidRTCStream // actionType : 2 恢复推流 ResumeRTCStream func operateTask(sceneEx *SceneEx, times int, actionType int, platform string) { diff --git a/gamesrv/clawdoll/scenepolicy_clawdoll.go b/gamesrv/clawdoll/scenepolicy_clawdoll.go index c735c89..ce10404 100644 --- a/gamesrv/clawdoll/scenepolicy_clawdoll.go +++ b/gamesrv/clawdoll/scenepolicy_clawdoll.go @@ -530,6 +530,8 @@ func (this *StateWait) OnPlayerOp(s *base.Scene, p *base.Player, opcode int, par // 1-前 2-后 3-左 4-右 5-投币 sceneEx.OnPlayerSMPerateOp(p.SnId, int32(sceneEx.machineId), rule.ButtonPayCoin) + logger.Logger.Trace("(ClawDoll this *StateWait) OnPlayerOp payCoin, sceneId=", s.GetSceneId(), " player=", p.SnId, " machineId=", sceneEx.machineId) + //sceneEx.OnPlayerSCOp(p, opcode, clawdoll.OpResultCode_OPRC_Success, params) } } @@ -575,6 +577,8 @@ func (this *StateStart) OnTick(s *base.Scene) { this.BaseState.OnTick(s) if sceneEx, ok := s.ExtraData.(*SceneEx); ok { if time.Now().Sub(sceneEx.StateStartTime) > rule.ClawDollSceneStartTimeout { + + logger.Logger.Trace("ClawDoll StateStart OnTick ChangeSceneState:", rule.ClawDollSceneStatePlayGame) //切换到等待操作状态 s.ChangeSceneState(rule.ClawDollSceneStatePlayGame) sceneEx.SetPlayingState(int32(rule.ClawDollSceneStatePlayGame)) @@ -636,7 +640,7 @@ func (this *PlayGame) OnEnter(s *base.Scene) { func (this *PlayGame) OnPlayerOp(s *base.Scene, p *base.Player, opcode int, params []int64) bool { - logger.Logger.Trace("StatePlayGame OnPlayerOp-----SnId:", p.SnId, " opcode: ", opcode, " params:", params) + logger.Logger.Trace("ClawDoll StatePlayGame OnPlayerOp-----SnId:", p.SnId, " opcode: ", opcode, " params:", params) if this.BaseState.OnPlayerOp(s, p, opcode, params) { return true @@ -664,7 +668,7 @@ func (this *PlayGame) OnPlayerOp(s *base.Scene, p *base.Player, opcode int, para grapType := sceneEx.GetPlayGrabType(playerEx) - logger.Logger.Trace("StatePlayGame OnPlayerOp-----SnId:", p.SnId, " grapType: ", grapType) + logger.Logger.Trace("ClawDoll StatePlayGame OnPlayerOp Grab-----SnId:", p.SnId, " grapType: ", grapType) //1-弱力抓 2 -强力抓 sceneEx.OnPlayerSMGrabOp(p.SnId, int32(sceneEx.machineId), grapType) @@ -681,7 +685,7 @@ func (this *PlayGame) OnPlayerOp(s *base.Scene, p *base.Player, opcode int, para } if params[0] < rule.ButtonFront || params[0] > rule.ButtonRight { - logger.Logger.Trace("StatePlayGame OnPlayerOp-----SnId:", p.SnId, " opcode: ", opcode, " params:", params) + logger.Logger.Trace("ClawDoll StatePlayGame OnPlayerOp-----SnId:", p.SnId, " opcode: ", opcode, " params:", params) return false } // 1-前 2-后 3-左 4-右 5-投币 @@ -696,9 +700,11 @@ func (this *PlayGame) OnTick(s *base.Scene) { if sceneEx, ok := s.ExtraData.(*SceneEx); ok { if time.Now().Sub(sceneEx.StateStartTime) > rule.ClawDollScenePlayTimeout { - if sceneEx.TimeOutPlayGrab() { + if sceneEx.Gaming && sceneEx.TimeOutPlayGrab() { sceneEx.Gaming = false - logger.Logger.Trace("PlayGame OnTick TimeOutPlayGrab SnId", sceneEx.playingSnid, " machineId:", sceneEx.machineId) + logger.Logger.Trace("PlayGame OnTick TimeOutPlayGrab SnId: ", sceneEx.playingSnid, " machineId:", sceneEx.machineId) + + sceneEx.GrabTimerHandle() } return