娃娃机状态修改

This commit is contained in:
kxdd 2024-08-27 15:13:32 +08:00
parent dcc68130d2
commit cbd00bf0f8
4 changed files with 79 additions and 32 deletions

View File

@ -15,7 +15,7 @@ const (
const ( const (
ClawDollSceneWaitTimeout = time.Second * 6 //等待倒计时 ClawDollSceneWaitTimeout = time.Second * 6 //等待倒计时
ClawDollSceneStartTimeout = time.Second * 5 //开始倒计时 ClawDollSceneStartTimeout = time.Second * 5 //开始倒计时
ClawDollScenePlayTimeout = time.Second * 30 //娃娃机下抓倒计时 ClawDollScenePlayTimeout = time.Second * 10 //娃娃机下抓倒计时
ClawDollSceneBilledTimeout = time.Second * 2 //结算 ClawDollSceneBilledTimeout = time.Second * 2 //结算
ClawDollSceneWaitPayCoinimeout = time.Second * 10 //等待下一局投币 ClawDollSceneWaitPayCoinimeout = time.Second * 10 //等待下一局投币

View File

@ -53,6 +53,11 @@ func (this *PlayerEx) CanGrab() bool {
// 游戏新一局 设置数据 // 游戏新一局 设置数据
func (this *PlayerEx) ReStartGame() { func (this *PlayerEx) ReStartGame() {
this.ReDataStartGame() this.ReDataStartGame()
this.UnmarkFlag(base.PlayerState_WaitNext)
this.UnmarkFlag(base.PlayerState_GameBreak)
this.MarkFlag(base.PlayerState_Ready)
this.gainCoin = 0 this.gainCoin = 0
this.taxCoin = 0 this.taxCoin = 0
this.odds = 0 this.odds = 0

View File

@ -58,7 +58,7 @@ type SceneEx struct {
// 游戏是否能开始 // 游戏是否能开始
func (this *SceneEx) CanStart() bool { func (this *SceneEx) CanStart() bool {
//人数>=1自动开始 //人数>=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 true
} }
return false return false
@ -67,7 +67,7 @@ func (this *SceneEx) CanStart() bool {
// 从房间删除玩家 // 从房间删除玩家
func (this *SceneEx) delPlayer(p *base.Player) { func (this *SceneEx) delPlayer(p *base.Player) {
if p, exist := this.players[p.SnId]; exist { if p, exist := this.players[p.SnId]; exist {
this.seats[p.GetPos()] = nil //this.seats[p.GetPos()] = nil
delete(this.players, p.SnId) delete(this.players, p.SnId)
this.RemoveWaitPlayer(p.SnId) this.RemoveWaitPlayer(p.SnId)
} }
@ -162,7 +162,6 @@ func NewClawdollSceneData(s *base.Scene) *SceneEx {
Scene: s, Scene: s,
logic: new(rule.Logic), logic: new(rule.Logic),
players: make(map[int32]*PlayerEx), players: make(map[int32]*PlayerEx),
seats: make([]*PlayerEx, s.GetPlayerNum()),
PlayerBackup: make(map[int32]*PlayerData), PlayerBackup: make(map[int32]*PlayerData),
waitPlayers: list.New(), waitPlayers: list.New(),
} }
@ -175,9 +174,40 @@ func (this *SceneEx) init() bool {
return true return true
} }
// 检查上分是否合法 // 检查上分投币是否合法
func (this *SceneEx) CheckPayOp(betVal int64, takeMul int64) bool { //游戏底分 func (this *SceneEx) CheckPayCoinOp(p *PlayerEx) bool {
if p == nil {
return false
}
if p.SnId == this.playingSnid {
return true 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() { func (this *SceneEx) Clear() {
@ -191,13 +221,6 @@ func (this *SceneEx) Clear() {
p.Clear(0) p.Clear(0)
} }
} }
for i := 0; i < this.GetPlayerNum(); i++ {
if this.seats[i] != nil {
this.seats[i].Clear(this.GetBaseScore())
}
}
} }
// 是否有玩家正在玩 // 是否有玩家正在玩

View File

@ -103,10 +103,11 @@ func (this *PolicyClawdoll) OnPlayerEnter(s *base.Scene, p *base.Player) {
playerEx.Clear(baseScore) playerEx.Clear(baseScore)
if sceneEx.playingSnid == 0 { if sceneEx.playingSnid == 0 {
//sceneEx.playingSnid = p.GetSnId()
}
p.MarkFlag(base.PlayerState_WaitNext) p.MarkFlag(base.PlayerState_WaitNext)
p.UnmarkFlag(base.PlayerState_Ready) p.UnmarkFlag(base.PlayerState_Ready)
sceneEx.playingSnid = p.GetSnId()
}
sceneEx.AddWaitPlayer(playerEx) 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) { func (this *PolicyClawdoll) SendRoomInfo(s *base.Scene, p *base.Player, sceneEx *SceneEx) {
pack := sceneEx.ClawdollCreateRoomInfoPacket(s, p) pack := sceneEx.ClawdollCreateRoomInfoPacket(s, p)
p.SendToClient(int(clawdoll.CLAWDOLLPacketID_PACKET_SC_CLAWDOLL_ROOMINFO), pack) 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 { func (this *BaseState) CanChangeCoinScene(s *base.Scene, p *base.Player) bool {
//playerEx, ok := p.ExtraData.(*PlayerEx) playerEx, ok := p.ExtraData.(*PlayerEx)
//if !ok { if !ok {
// return false return false
//} }
//
//if !playerEx.CanLeaveScene(s.GetSceneState().GetState()) { if !playerEx.CanLeaveScene(s.GetSceneState().GetState()) {
// return false return false
//} }
return true return true
} }
@ -335,17 +337,13 @@ func (this *StateWait) GetTimeout(s *base.Scene) int {
func (this *StateWait) OnEnter(s *base.Scene) { func (this *StateWait) OnEnter(s *base.Scene) {
this.BaseState.OnEnter(s) this.BaseState.OnEnter(s)
if sceneEx, ok := s.ExtraData.(*SceneEx); ok { if _, ok := s.ExtraData.(*SceneEx); ok {
if s.Gaming { if s.Gaming {
s.NotifySceneRoundPause() s.NotifySceneRoundPause()
} }
s.Gaming = false s.Gaming = false
ClawdollBroadcastRoomState(s, float32(0)) 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() { if sceneEx.CanStart() {
s.ChangeSceneState(rule.ClawDollSceneStateStart) 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 { func (this *StateStart) CanChangeTo(s base.SceneState) bool {
switch s.GetState() { switch s.GetState() {
case rule.ClawDollSceneStatePlayGame: case rule.ClawDollSceneStatePlayGame:
return true
case rule.ClawDollSceneStateWait: case rule.ClawDollSceneStateWait:
return true return true
} }
@ -526,6 +526,11 @@ func (this *PlayGame) OnPlayerOp(s *base.Scene, p *base.Player, opcode int, para
switch opcode { switch opcode {
case rule.ClawDollPlayerOpGo: case rule.ClawDollPlayerOpGo:
if !sceneEx.CheckGrapOp(playerEx) {
return false
}
if !playerEx.CanGrab() { if !playerEx.CanGrab() {
return false 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) sceneEx.OnPlayerSMGrabOp(p.SnId, int32(sceneEx.machineId), grapType)
case rule.ClawDollPlayerOpMove: case rule.ClawDollPlayerOpMove:
if !sceneEx.CheckMoveOp(playerEx) {
return false
}
if !playerEx.CanMove() { if !playerEx.CanMove() {
return false return false
} }
@ -581,7 +591,7 @@ func (this *StateBilled) GetState() int {
func (this *StateBilled) CanChangeTo(s base.SceneState) bool { func (this *StateBilled) CanChangeTo(s base.SceneState) bool {
switch s.GetState() { switch s.GetState() {
case rule.ClawDollSceneStateStart: case rule.ClawDollSceneWaitPayCoin:
return true return true
} }
return false return false
@ -636,6 +646,7 @@ func (this *StateWaitPayCoin) GetState() int {
func (this *StateWaitPayCoin) CanChangeTo(s base.SceneState) bool { func (this *StateWaitPayCoin) CanChangeTo(s base.SceneState) bool {
switch s.GetState() { switch s.GetState() {
case rule.ClawDollSceneStateStart: case rule.ClawDollSceneStateStart:
return true
case rule.ClawDollSceneStateWait: case rule.ClawDollSceneStateWait:
return true 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) sceneEx.OnPlayerSMPerateOp(p.SnId, int32(sceneEx.machineId), rule.ButtonPayCoin)
playerEx.ReStartGame()
s.ChangeSceneState(rule.ClawDollSceneStateStart) s.ChangeSceneState(rule.ClawDollSceneStateStart)
//sceneEx.OnPlayerSCOp(p, opcode, clawdoll.OpResultCode_OPRC_Success, params) //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 sceneEx, ok := s.ExtraData.(*SceneEx); ok {
if time.Now().Sub(sceneEx.StateStartTime) > rule.ClawDollSceneWaitPayCoinimeout { if time.Now().Sub(sceneEx.StateStartTime) > rule.ClawDollSceneWaitPayCoinimeout {
// 时间到重置scene数据 // 先设置时间
playingEx := sceneEx.players[sceneEx.playingSnid]
if playingEx != nil {
playingEx.ReStartGame()
}
// 后重置scene数据
sceneEx.WaitNextPlayer() sceneEx.WaitNextPlayer()
s.ChangeSceneState(rule.ClawDollSceneStateWait) s.ChangeSceneState(rule.ClawDollSceneStateWait)