actor.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. package mapUnion
  2. import (
  3. capp "f1-game/internal/cherry_app"
  4. "f1-game/internal/code"
  5. "f1-game/internal/enum"
  6. nameActor "f1-game/internal/name/actor"
  7. nameLocal "f1-game/internal/name/local"
  8. nameRemote "f1-game/internal/name/remote"
  9. "f1-game/internal/pb"
  10. "f1-game/internal/sessions"
  11. cfacade "github.com/cherry-game/cherry/facade"
  12. "github.com/cherry-game/cherry/net/parser/pomelo"
  13. cproto "github.com/cherry-game/cherry/net/proto"
  14. )
  15. type (
  16. actor struct {
  17. pomelo.ActorBase
  18. }
  19. )
  20. func NewActor() *actor {
  21. return &actor{}
  22. }
  23. func (p *actor) AliasID() string {
  24. return nameActor.Map_Union
  25. }
  26. func Init(app cfacade.IApplication) {
  27. actor := NewActor()
  28. app.ActorSystem().CreateActor(actor.AliasID(), actor)
  29. }
  30. func (p *actor) OnInit() {
  31. p.Local().Register(nameLocal.MapUnion_ApplyOption, p.applyOption)
  32. p.Local().Register(nameLocal.MapUnion_UmengRelieve, p.umengRelieve)
  33. p.Local().Register(nameLocal.MapUnion_UnionRelieve, p.unionRelieve)
  34. }
  35. // 联盟外交邀请处理
  36. func (p *actor) applyOption(session *cproto.Session, req *pb.UnionApplyOp) {
  37. var (
  38. curLeagueID = sessions.GetLeagueID(session)
  39. playerID = sessions.GetPlayerID(session)
  40. sendApplyLeagueID = req.LeagueID
  41. applyType = req.ApplyType
  42. agree = req.Agree
  43. )
  44. // 未加入联盟
  45. if curLeagueID <= 0 {
  46. p.ResponseCode(session, code.LeagueNotJoin)
  47. return
  48. }
  49. // 参数错误
  50. if sendApplyLeagueID <= 0 || enum.IsNotLeagueDiplomacyType(applyType) {
  51. p.ResponseCode(session, code.IllegalArgument)
  52. return
  53. }
  54. // 发送到当前执行的联盟actor处理
  55. var (
  56. handleReq = &pb.LeagueDiplomacyHandle{
  57. PlayerID: playerID,
  58. HandleLeagueID: sendApplyLeagueID,
  59. ApplyType: applyType,
  60. Agree: agree,
  61. }
  62. path = cfacade.NewChildPath("", nameActor.League, curLeagueID)
  63. )
  64. errCode := capp.CallWait(path, nameRemote.MapLeague_DiplomacyApplyHandle, handleReq, nil)
  65. p.ResponseCode(session, errCode)
  66. }
  67. // 解除友盟外交关系
  68. func (p *actor) umengRelieve(session *cproto.Session, req *pb.I64) {
  69. var (
  70. curLeagueID = sessions.GetLeagueID(session)
  71. playerID = sessions.GetPlayerID(session)
  72. relieveLeagueID = req.Value
  73. )
  74. // 未加入联盟
  75. if curLeagueID <= 0 {
  76. p.ResponseCode(session, code.LeagueNotJoin)
  77. return
  78. }
  79. // 参数错误
  80. if relieveLeagueID <= 0 {
  81. p.ResponseCode(session, code.IllegalArgument)
  82. return
  83. }
  84. // 发送到当前执行的联盟actor处理
  85. var (
  86. handleReq = &pb.I64I64{
  87. Key: playerID,
  88. Value: relieveLeagueID,
  89. }
  90. resp = &pb.I64{}
  91. path = cfacade.NewChildPath("", nameActor.League, curLeagueID)
  92. )
  93. errCode := capp.CallWait(path, nameRemote.MapLeague_UmengRelieve, handleReq, resp)
  94. if code.IsFail(errCode) {
  95. p.ResponseCode(session, errCode)
  96. return
  97. }
  98. p.Response(session, resp)
  99. }
  100. // 解除联邦外交关系
  101. func (p *actor) unionRelieve(session *cproto.Session, _ *pb.None) {
  102. var (
  103. curLeagueID = sessions.GetLeagueID(session)
  104. playerID = sessions.GetPlayerID(session)
  105. )
  106. // 未加入联盟
  107. if curLeagueID <= 0 {
  108. p.ResponseCode(session, code.LeagueNotJoin)
  109. return
  110. }
  111. // 发送到当前执行的联盟actor处理
  112. var (
  113. handleReq = &pb.I64{
  114. Value: playerID,
  115. }
  116. resp = &pb.I64{}
  117. path = cfacade.NewChildPath("", nameActor.League, curLeagueID)
  118. )
  119. errCode := capp.CallWait(path, nameRemote.MapLeague_UnionRelieve, handleReq, resp)
  120. if code.IsFail(errCode) {
  121. p.ResponseCode(session, errCode)
  122. return
  123. }
  124. p.Response(session, resp)
  125. }