player_show.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. package mapPlayer
  2. import (
  3. "f1-game/internal/code"
  4. "f1-game/internal/data"
  5. "f1-game/internal/enum"
  6. "f1-game/internal/event"
  7. nameEvent "f1-game/internal/name/event"
  8. nameLocal "f1-game/internal/name/local"
  9. "f1-game/internal/pb"
  10. ao "f1-game/nodes/game/player/asset/origin"
  11. "f1-game/nodes/map/internal/db"
  12. mapFacade "f1-game/nodes/map/internal/facade"
  13. show "f1-game/nodes/map/player/show"
  14. ctime "github.com/cherry-game/cherry/extend/time"
  15. cfacade "github.com/cherry-game/cherry/facade"
  16. cproto "github.com/cherry-game/cherry/net/proto"
  17. )
  18. func (p *actorPlayer) initShow() {
  19. p.Local().Register(nameLocal.MapPlayer_ActiveShow, p.activeShow)
  20. p.Local().Register(nameLocal.MapPlayer_ShowView, p.showView)
  21. p.Local().Register(nameLocal.MapPlayer_MainCityChange, p.mainCityChange)
  22. // 城建升级触发(主要是主堡升级)
  23. p.EventRegister(nameEvent.Lord_FacilityUp, p.onFacilityUpRefreshShow)
  24. }
  25. // 主城外观激活
  26. func (p *actorPlayer) activeShow(session *cproto.Session, req *pb.I32) {
  27. var (
  28. playerTable = db.GetMapPlayerTable(p.playerID)
  29. showID = req.Value
  30. )
  31. showRow, found := data.MapMainCityShow.GetByMainCityShowID(showID)
  32. if !found {
  33. p.ResponseCode(session, code.ShowConfigNotExist)
  34. return
  35. }
  36. // 激活类型错误
  37. if showRow.ActiveType != enum.ShowActiveType_Item {
  38. p.ResponseCode(session, code.ShowActiveTypeError)
  39. return
  40. }
  41. // 已激活过 跳过
  42. _, found = playerTable.Shows.GetShow(showID)
  43. if found && showRow.ExpireTime <= 0 {
  44. p.ResponseCode(session, code.ShowAlreadyActive)
  45. return
  46. }
  47. // 扣除消耗道具
  48. _, errCode := mapFacade.Storage.AssetSubOne(p.playerID, showRow.ActiveCondition.Key, int64(showRow.ActiveCondition.Value), ao.ConscriptOutsideReturn, true)
  49. if code.IsFail(errCode) {
  50. p.ResponseCode(session, errCode)
  51. return
  52. }
  53. show := playerTable.Shows.ActiveShow(showID, showRow.ExpireTime, true)
  54. playerTable.Save2Queue()
  55. resp := show.ToShowProto(showID)
  56. p.Response(session, resp)
  57. }
  58. // 查看外显 消除红点
  59. func (p *actorPlayer) showView(session *cproto.Session, req *pb.I32) {
  60. var (
  61. playerTable = db.GetMapPlayerTable(p.playerID)
  62. showID = req.Value
  63. )
  64. show, found := playerTable.Shows.GetShow(showID)
  65. if !found {
  66. p.ResponseCode(session, code.ShowNotUnlock)
  67. return
  68. }
  69. if !show.IsViewed {
  70. show.IsViewed = true
  71. playerTable.Save2Queue()
  72. }
  73. p.ResponseCode(session, code.OK)
  74. }
  75. // 主城外观变更
  76. func (p *actorPlayer) mainCityChange(session *cproto.Session, req *pb.I32) {
  77. var (
  78. playerTable = db.GetMapPlayerTable(p.playerID)
  79. showID = req.Value
  80. )
  81. show, found := playerTable.Shows.GetShow(showID)
  82. if !found {
  83. p.ResponseCode(session, code.ShowNotUnlock)
  84. return
  85. }
  86. // 外显已过期
  87. if show.ExpireTime > 0 && show.ExpireTime <= ctime.Now().ToSecond() {
  88. p.ResponseCode(session, code.ShowExpire)
  89. return
  90. }
  91. // 发送变更事件
  92. p.PostEvent(event.NewMainCityShowChange(p.playerID, showID))
  93. // 更新主城外观ID
  94. playerTable.Shows.MainCityShowID = showID
  95. playerTable.Save2Queue()
  96. resp := &pb.I32{Value: showID}
  97. p.Response(session, resp)
  98. }
  99. func (p *actorPlayer) onFacilityUpRefreshShow(c cfacade.IEventData) {
  100. evt, ok := c.(*event.FacilityUp)
  101. if !ok {
  102. p.Warn("[onFacilityUpRefreshShow] fail, event: %+v", c)
  103. return
  104. }
  105. var (
  106. playerTable = db.GetMapPlayerTable(p.playerID)
  107. facilityID = evt.FacilityID()
  108. level = evt.Level()
  109. changeShowIDs = []int32{}
  110. )
  111. for _, showRow := range data.MapMainCityShow.List() {
  112. // 不是建筑激活 或 所需建筑ID不匹配
  113. if showRow.ActiveType != enum.ShowActiveType_Facility || showRow.ActiveCondition.Key != facilityID {
  114. continue
  115. }
  116. // 已经激活过 跳过
  117. _, found := playerTable.Shows.GetShow(showRow.MainCityShowID)
  118. if found {
  119. continue
  120. }
  121. // 当前等级不足
  122. if level < showRow.ActiveCondition.Value {
  123. continue
  124. }
  125. playerTable.Shows.ActiveShow(showRow.MainCityShowID, showRow.ExpireTime, false)
  126. changeShowIDs = append(changeShowIDs, showRow.MainCityShowID)
  127. }
  128. // 变更推送
  129. show.Service().ChangePush(playerTable, nil, changeShowIDs...)
  130. }