run.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package qznn
  2. import (
  3. "github.com/sirupsen/logrus"
  4. "nn.daxia.dev/gameproto"
  5. "nn.daxia.dev/nxd"
  6. )
  7. func (p *Game) Run(allReady bool, roomItem Room, issue string) {
  8. //发送消息给界面,每个玩家,可以选择的倍数情况
  9. userIDList, err := p.getRoomUserIDList(roomItem.ID)
  10. if err != nil {
  11. logrus.Error(err)
  12. return
  13. }
  14. p.SendStartMsg(userIDList, roomItem)
  15. //选庄
  16. logrus.Info("WaitChooseMaster")
  17. err = p.WaitChooseMaster(roomItem)
  18. if err != nil {
  19. logrus.Error(err)
  20. return
  21. }
  22. //选倍数
  23. logrus.Info("WaitChooseMul")
  24. err = p.WaitChooseMul(roomItem)
  25. if err != nil {
  26. logrus.Error(err)
  27. return
  28. }
  29. //开奖
  30. logrus.Info("Wait open")
  31. err = p.WaitOpen(roomItem)
  32. if err != nil {
  33. logrus.Error(err)
  34. return
  35. }
  36. logrus.Info("Finish")
  37. //判断是否在线,不在线就退出了
  38. for _, userID := range userIDList {
  39. if UserIsOnline(uint(userID)) {
  40. continue
  41. }
  42. p.locker.Lock()
  43. {
  44. p.EventInfo(userID, "Run", "玩家离线,踢走")
  45. }
  46. p.locker.Unlock()
  47. p.Leave(userID)
  48. }
  49. }
  50. func (p *Game) SendStartMsg(userIDList []int32, roomItem Room) {
  51. p.locker.Lock()
  52. defer p.locker.Unlock()
  53. for _, userID := range userIDList {
  54. userItem, exists := p.PlayerMap[userID]
  55. if !exists {
  56. logrus.Error("not exist:", userID)
  57. continue
  58. }
  59. if userItem.Status == PlayerStatusReady {
  60. p.EventInfo(userID, "发送开始消息", "发送开始消息")
  61. nxd.SendMsgToUserK(uint32(userID), gameproto.NotifyTypeEnum_NotifyTypeStart, &gameproto.Start{
  62. RoomID: uint32(roomItem.ID),
  63. ChooseMasterMulList: []uint32{0, 1, 2, 3},
  64. Issue: roomItem.Issue,
  65. CardList: GetNNCardListLimit(userItem.CardList, 3),
  66. })
  67. } else {
  68. p.EventInfo(userID, "发送开始消息", "通知开始,不参与")
  69. nxd.SendMsgToUserK(uint32(userID), gameproto.NotifyTypeEnum_NotifyTypeStart, &gameproto.Start{
  70. RoomID: uint32(roomItem.ID),
  71. ChooseMasterMulList: []uint32{},
  72. Issue: roomItem.Issue,
  73. CardList: nil,
  74. })
  75. }
  76. }
  77. }