scene只能绑定对应的娃娃机编号

This commit is contained in:
by 2024-09-05 10:28:43 +08:00
parent 88bbca47f1
commit 68a8e010cf
3 changed files with 11 additions and 14 deletions

View File

@ -35,15 +35,11 @@ func MSDollMachineListHandler(session *netlib.Session, packetId int, data interf
} }
// 获取空闲娃娃机标识 // 获取空闲娃娃机标识
func GetFreeDollMachineId() int { func GetFreeDollMachineId(id int32) int {
// 获取互斥锁 if MachineMap[int(id)] != nil && MachineMap[int(id)].MachineStatus == 1 {
MachineMapLock.Lock() return int(id)
defer MachineMapLock.Unlock() } else {
for i, v := range MachineMap { return 0
if v.Status == false {
v.Status = true
return i
}
} }
return 0 return 0
} }

View File

@ -67,7 +67,8 @@ func (this *PolicyClawdoll) OnTick(s *base.Scene) {
sceneEx, ok := s.ExtraData.(*SceneEx) sceneEx, ok := s.ExtraData.(*SceneEx)
if ok { if ok {
if sceneEx.machineId == 0 { if sceneEx.machineId == 0 {
sceneEx.machineId = action.GetFreeDollMachineId() machineId := s.DBGameFree.GetId() % 6080000
sceneEx.machineId = action.GetFreeDollMachineId(machineId)
} }
if sceneEx.machineId != 0 { if sceneEx.machineId != 0 {
machineStatus := action.GetDollMachineStatus(sceneEx.machineId) machineStatus := action.GetDollMachineStatus(sceneEx.machineId)

View File

@ -169,7 +169,7 @@ func DollMachineGrabResult(session *netlib.Session, conn *machinedoll.Conn, snid
num := int64(1) num := int64(1)
for { for {
// 读取数据 // 读取数据
logger.Logger.Trace("监听抓取结果返回!") //logger.Logger.Trace("监听抓取结果返回!")
buf := make([]byte, 1024) buf := make([]byte, 1024)
n, err := conn.Read(buf) n, err := conn.Read(buf)
if err != nil { if err != nil {
@ -178,7 +178,7 @@ func DollMachineGrabResult(session *netlib.Session, conn *machinedoll.Conn, snid
} }
// 将读取到的数据按照 221 进行分割 // 将读取到的数据按照 221 进行分割
parts := bytes.Split(buf[:n], []byte{221}) parts := bytes.Split(buf[:n], []byte{221})
fmt.Println("获取到的返回值:", parts) //fmt.Println("获取到的返回值:", parts)
instruction := []byte{0xAA, 0x05, 0x02, 0x50, 0x09, 0x00} instruction := []byte{0xAA, 0x05, 0x02, 0x50, 0x09, 0x00}
instruction1 := []byte{0xAA, 0x05, 0x02, 0x50, 0x09, 0x01} 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] // 去除最后一个字节,该字节为分隔符 part = part[:len(part)-1] // 去除最后一个字节,该字节为分隔符
//fmt.Println("比较返回结果 part = ", part) //fmt.Println("比较返回结果 part = ", part)
if bytes.Contains(part, instruction) && num != 1 { 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}) _, err = conn.Write([]byte{0xAA, 0x04, 0x01, 0x50, 0x09, 0x5c, 0xdd})
if err != nil { if err != nil {
fmt.Println("Failed to read response from server:", err) //fmt.Println("Failed to read response from server:", err)
return return
} }
session.Send(int(machine.DollMachinePacketID_PACKET_MSDollMachineoPerateResult), &machine.MSDollMachineoPerateResult{ session.Send(int(machine.DollMachinePacketID_PACKET_MSDollMachineoPerateResult), &machine.MSDollMachineoPerateResult{