From 68a8e010cfeb5e3399c85ac78bcbc7b54f7f8145 Mon Sep 17 00:00:00 2001 From: by <123456@qq.com> Date: Thu, 5 Sep 2024 10:28:43 +0800 Subject: [PATCH] =?UTF-8?q?scene=E5=8F=AA=E8=83=BD=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E5=AF=B9=E5=BA=94=E7=9A=84=E5=A8=83=E5=A8=83=E6=9C=BA=E7=BC=96?= =?UTF-8?q?=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gamesrv/action/action_machine.go | 14 +++++--------- gamesrv/clawdoll/scenepolicy_clawdoll.go | 3 ++- machine/action/action_server.go | 8 ++++---- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/gamesrv/action/action_machine.go b/gamesrv/action/action_machine.go index c577f4e..fb287f2 100644 --- a/gamesrv/action/action_machine.go +++ b/gamesrv/action/action_machine.go @@ -35,15 +35,11 @@ func MSDollMachineListHandler(session *netlib.Session, packetId int, data interf } // 获取空闲娃娃机标识 -func GetFreeDollMachineId() int { - // 获取互斥锁 - MachineMapLock.Lock() - defer MachineMapLock.Unlock() - for i, v := range MachineMap { - if v.Status == false { - v.Status = true - return i - } +func GetFreeDollMachineId(id int32) int { + if MachineMap[int(id)] != nil && MachineMap[int(id)].MachineStatus == 1 { + return int(id) + } else { + return 0 } return 0 } diff --git a/gamesrv/clawdoll/scenepolicy_clawdoll.go b/gamesrv/clawdoll/scenepolicy_clawdoll.go index 68f055c..3d31f96 100644 --- a/gamesrv/clawdoll/scenepolicy_clawdoll.go +++ b/gamesrv/clawdoll/scenepolicy_clawdoll.go @@ -67,7 +67,8 @@ func (this *PolicyClawdoll) OnTick(s *base.Scene) { sceneEx, ok := s.ExtraData.(*SceneEx) if ok { if sceneEx.machineId == 0 { - sceneEx.machineId = action.GetFreeDollMachineId() + machineId := s.DBGameFree.GetId() % 6080000 + sceneEx.machineId = action.GetFreeDollMachineId(machineId) } if sceneEx.machineId != 0 { machineStatus := action.GetDollMachineStatus(sceneEx.machineId) diff --git a/machine/action/action_server.go b/machine/action/action_server.go index 48252c6..afa8cd6 100644 --- a/machine/action/action_server.go +++ b/machine/action/action_server.go @@ -169,7 +169,7 @@ func DollMachineGrabResult(session *netlib.Session, conn *machinedoll.Conn, snid num := int64(1) for { // 读取数据 - logger.Logger.Trace("监听抓取结果返回!") + //logger.Logger.Trace("监听抓取结果返回!") buf := make([]byte, 1024) n, err := conn.Read(buf) if err != nil { @@ -178,7 +178,7 @@ func DollMachineGrabResult(session *netlib.Session, conn *machinedoll.Conn, snid } // 将读取到的数据按照 221 进行分割 parts := bytes.Split(buf[:n], []byte{221}) - fmt.Println("获取到的返回值:", parts) + //fmt.Println("获取到的返回值:", parts) instruction := []byte{0xAA, 0x05, 0x02, 0x50, 0x09, 0x00} instruction1 := []byte{0xAA, 0x05, 0x02, 0x50, 0x09, 0x01} // 遍历分割结果,打印出每个部分 @@ -187,11 +187,11 @@ func DollMachineGrabResult(session *netlib.Session, conn *machinedoll.Conn, snid part = part[:len(part)-1] // 去除最后一个字节,该字节为分隔符 //fmt.Println("比较返回结果 part = ", part) if bytes.Contains(part, instruction) && num != 1 { - fmt.Printf("Part %d: %s\n", i+1, part) + //fmt.Printf("Part %d: %s\n", i+1, part) //回应数据 _, err = conn.Write([]byte{0xAA, 0x04, 0x01, 0x50, 0x09, 0x5c, 0xdd}) if err != nil { - fmt.Println("Failed to read response from server:", err) + //fmt.Println("Failed to read response from server:", err) return } session.Send(int(machine.DollMachinePacketID_PACKET_MSDollMachineoPerateResult), &machine.MSDollMachineoPerateResult{