From b8765251cc7053c047bf7cd91041d467ab3421d8 Mon Sep 17 00:00:00 2001 From: by <123456@qq.com> Date: Tue, 13 Aug 2024 11:33:38 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=A8=83=E5=A8=83=E6=9C=BA?= =?UTF-8?q?=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gamesrv/action/action_machine.go | 32 +++++++++++++++++++++--- gamesrv/clawdoll/scenepolicy_clawdoll.go | 9 +++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/gamesrv/action/action_machine.go b/gamesrv/action/action_machine.go index 92d56e6..3e9fa3b 100644 --- a/gamesrv/action/action_machine.go +++ b/gamesrv/action/action_machine.go @@ -4,22 +4,48 @@ import ( "mongo.games.com/game/protocol/machine" "mongo.games.com/goserver/core/logger" "mongo.games.com/goserver/core/netlib" + "sync" ) -var MachineMap = make(map[int]string) +var MachineMap = make(map[int]*DollMachine) +var MachineMapLock = sync.Mutex{} + +type DollMachine struct { + Id int + Status bool + VideoAddr string +} func MSDollMachineList(session *netlib.Session, packetId int, data interface{}) error { logger.Logger.Tracef("TestHandler %v", data) - MachineMap = make(map[int]string) + MachineMap = make(map[int]*DollMachine) if msg, ok := data.(*machine.MSDollMachineList); ok { for i, info := range msg.Data { - MachineMap[i+1] = info.VideoAddr + MachineMap[i+1] = &DollMachine{ + Id: i + 1, + Status: false, + VideoAddr: info.VideoAddr, + } logger.Logger.Tracef("MachineMap[%v] = %v", i, info.VideoAddr) } } return nil } +// 获取空闲娃娃机标识 +func GetFreeDollMachineId() int { + // 获取互斥锁 + MachineMapLock.Lock() + defer MachineMapLock.Unlock() + for i, v := range MachineMap { + if v.Status == false { + v.Status = true + return i + } + } + return 0 +} + func init() { netlib.Register(int(machine.DollMachinePacketID_PACKET_MSDollMachineList), &machine.MSDollMachineList{}, MSDollMachineList) } diff --git a/gamesrv/clawdoll/scenepolicy_clawdoll.go b/gamesrv/clawdoll/scenepolicy_clawdoll.go index 46bc199..4e115c7 100644 --- a/gamesrv/clawdoll/scenepolicy_clawdoll.go +++ b/gamesrv/clawdoll/scenepolicy_clawdoll.go @@ -1,6 +1,7 @@ package clawdoll import ( + "mongo.games.com/game/gamesrv/action" "mongo.games.com/game/protocol/clawdoll" "time" @@ -61,6 +62,14 @@ func (this *PolicyClawdoll) OnTick(s *base.Scene) { if s.SceneState != nil { s.SceneState.OnTick(s) } + + sceneEx, ok := s.ExtraData.(*SceneEx) + if ok { + if sceneEx.machineId == 0 { + sceneEx.machineId = action.GetFreeDollMachineId() + } + } + } func (this *PolicyClawdoll) OnPlayerEnter(s *base.Scene, p *base.Player) {