run.go 2.1 KB

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