cardlibrary.pb.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. package proto
  2. import (
  3. "context"
  4. "bet24.com/log"
  5. "bet24.com/servers/micros/common"
  6. "github.com/smallnest/rpcx/client"
  7. )
  8. const ServiceName = "cardlibrary"
  9. var consulAddr = common.Default_Consul_Addr
  10. func getClient() client.XClient {
  11. return common.GetClientPool().GetClient(ServiceName, consulAddr)
  12. }
  13. type Request struct {
  14. Name string
  15. LibraryType int
  16. ControlChair int
  17. FirstOutChair int
  18. Doublings int
  19. UserId int
  20. }
  21. type Response struct {
  22. Data string
  23. RetCode int
  24. Success bool
  25. ControlCards []int
  26. Library []BalootCardLibrary
  27. }
  28. type CardConf struct {
  29. ValueDesc string
  30. Count int
  31. }
  32. type ProjectConf struct {
  33. ProjectDesc string
  34. Count int
  35. IsShunZi bool
  36. }
  37. type BalootCardLibrary struct {
  38. Cards []CardConf
  39. Projects []ProjectConf
  40. SameTypeCount int
  41. PublicCard string
  42. }
  43. func SetConsulAddr(addr string) {
  44. consulAddr = addr
  45. }
  46. func SayHello(name string) string {
  47. xclient := getClient()
  48. args := &Request{
  49. Name: name,
  50. }
  51. reply := &Response{}
  52. err := xclient.Call(context.Background(), "SayHello", args, reply)
  53. if err != nil {
  54. log.Debug("waterpool failed to call: %v", err)
  55. common.GetClientPool().RemoveClient(ServiceName)
  56. return ""
  57. }
  58. log.Debug("SayHello return %s", reply.Data)
  59. return reply.Data
  60. }
  61. // 牌库类型
  62. const (
  63. Baloot_LibraryType_Scenario = iota // 剧情牌
  64. Baloot_LibraryType_Invincible // 无敌牌
  65. Baloot_LibraryType_HighScore // 高分牌
  66. Baloot_LibraryType_Doubling // 加倍场牌
  67. Baloot_LibraryType_NewUser // 新手牌
  68. Baloot_LibraryType_Doubling_Scenario // 加倍场多项目体验牌
  69. )
  70. func GetControlCards(libraryType, controlChair, firstOutCard, doublings int) (bool, []int) {
  71. xclient := getClient()
  72. args := &Request{
  73. LibraryType: libraryType,
  74. ControlChair: controlChair,
  75. FirstOutChair: firstOutCard,
  76. Doublings: doublings,
  77. }
  78. reply := &Response{}
  79. err := xclient.Call(context.Background(), "GetControlCards", args, reply)
  80. if err != nil {
  81. log.Debug("cardlibrary failed to call: %v", err)
  82. common.GetClientPool().RemoveClient(ServiceName)
  83. }
  84. return reply.Success, reply.ControlCards
  85. }
  86. func GetUserControlCards(userId int) (bool, []BalootCardLibrary) {
  87. xclient := getClient()
  88. args := &Request{
  89. UserId: userId,
  90. }
  91. reply := &Response{}
  92. err := xclient.Call(context.Background(), "GetUserControlCards", args, reply)
  93. if err != nil {
  94. log.Debug("cardlibrary failed to call: %v", err)
  95. common.GetClientPool().RemoveClient(ServiceName)
  96. return false, []BalootCardLibrary{}
  97. }
  98. return reply.Success, reply.Library
  99. }
  100. func GetUserCardLibraryrWeightValue(userId int) int {
  101. xclient := getClient()
  102. args := &Request{
  103. UserId: userId,
  104. }
  105. reply := &Response{}
  106. err := xclient.Call(context.Background(), "GetUserCardLibraryrWeightValue", args, reply)
  107. if err != nil {
  108. log.Debug("cardlibrary failed to call: %v", err)
  109. common.GetClientPool().RemoveClient(ServiceName)
  110. return 0
  111. }
  112. return reply.RetCode
  113. }