service.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. package season
  2. import (
  3. capp "f1-game/internal/cherry_app"
  4. "f1-game/internal/code"
  5. "f1-game/internal/data"
  6. "f1-game/internal/enum"
  7. "f1-game/internal/extend/math"
  8. "f1-game/internal/facade"
  9. nameActor "f1-game/internal/name/actor"
  10. nameRemote "f1-game/internal/name/remote"
  11. "f1-game/internal/pb"
  12. mapCall "f1-game/nodes/map/internal/call"
  13. "f1-game/nodes/map/internal/db"
  14. ctime "github.com/cherry-game/cherry/extend/time"
  15. cfacade "github.com/cherry-game/cherry/facade"
  16. clog "github.com/cherry-game/cherry/logger"
  17. )
  18. func Service() *service {
  19. return &service{}
  20. }
  21. type service struct {
  22. facade.PlayerServiceBase[*db.MapPlayerTable]
  23. }
  24. // 退出联盟记录已经结算的霸业任务状态
  25. func (p *service) LeagueQuitSeasonQuestRecord(playerID, leagueID int64) {
  26. var (
  27. playerTable = db.GetMapPlayerTable(playerID)
  28. rsp = &pb.SeasonQuestInfo{}
  29. )
  30. req := p.GetSeasonQuestLeagueIDMap(playerTable)
  31. errCode := capp.CallWait(cfacade.NewPath("", nameActor.Map_Season), nameRemote.MapSeason_QuestInfo, req, rsp)
  32. if code.IsFail(errCode) {
  33. clog.Warnf("[leagueQuitSeasonQuestRecord] CallWait failed, leagueID: %d, errCode: %d", leagueID, errCode)
  34. return
  35. }
  36. now := ctime.Now().ToMillisecond()
  37. // 标记任务为已领取
  38. for _, quest := range rsp.Quests {
  39. // 跳过未结算的
  40. if quest.EndTime == 0 || quest.EndTime > now {
  41. continue
  42. }
  43. seasonQuestRow, ok := data.SeasonQuest.GetByID(quest.QuestID)
  44. if !ok {
  45. continue
  46. }
  47. if !seasonQuestRow.QuestType.IsLeague() {
  48. continue
  49. }
  50. if playerTable.Season.LeagueQuestMap.Contains(quest.QuestID) {
  51. continue
  52. }
  53. // 只处理新的已结算的霸业任务
  54. playerTable.Season.LeagueQuestMap.Put(quest.QuestID, leagueID)
  55. playerTable.SetChangeData()
  56. }
  57. if playerTable.IsChangeData() {
  58. playerTable.Save2Queue()
  59. }
  60. clog.Infof("[leagueQuitSeasonQuestRecord] success. playerID: %d, leagueID: %d, leagueQuestMapSize: %d",
  61. playerID, leagueID, playerTable.Season.LeagueQuestMap.Size())
  62. }
  63. func (*service) GetSeasonQuestLeagueID(playerTable *db.MapPlayerTable, questID int32) int64 {
  64. // 优先取记录中的联盟ID,退盟的时候记录之前完成的状态
  65. leagueID := playerTable.Season.LeagueQuestMap.GetValue(questID)
  66. if leagueID == 0 {
  67. leagueID = playerTable.LeagueID
  68. }
  69. return leagueID
  70. }
  71. // 获取赛季霸业任务结算状态
  72. func (*service) GetSeasonQuestLeagueIDMap(playerTable *db.MapPlayerTable) *pb.I32I64Map {
  73. rsp := &pb.I32I64Map{
  74. Value: map[int32]int64{},
  75. }
  76. for _, quest := range data.SeasonQuest.List() {
  77. if !quest.QuestType.IsLeague() {
  78. continue
  79. }
  80. // 优先取记录中的联盟ID,退盟的时候记录之前完成的状态
  81. leagueID := playerTable.Season.LeagueQuestMap.GetValue(quest.ID)
  82. if leagueID == 0 {
  83. leagueID = playerTable.LeagueID
  84. }
  85. rsp.Value[quest.ID] = leagueID
  86. }
  87. return rsp
  88. }
  89. // 更新玩家赛季积分
  90. func (p *service) UpdatePlayerSeasonScore(playerID, addFeat, addLeagueContribute int64) {
  91. var (
  92. playerTable = db.GetMapPlayerTable(playerID)
  93. curFeatScore = playerTable.Season.SeasonScore.FeatScore
  94. curContributeScore = playerTable.Season.SeasonScore.ContributionScore
  95. )
  96. // 获得功勋 且 当前功勋获得的赛季积分未达到上限
  97. if addFeat > 0 && curFeatScore < data.Const.FeatToSeasonScoreLimit {
  98. addFeatScore := int32(data.Const.CalFeatValueToSeasonScore(addFeat))
  99. addFeatScore = math.Min(addFeatScore, data.Const.FeatToSeasonScoreLimit-curFeatScore)
  100. if addFeatScore > 0 {
  101. playerTable.Season.SeasonScore.FeatScore += addFeatScore
  102. playerTable.SetChangeData()
  103. }
  104. }
  105. // 获得联盟贡献 且 当前联盟贡献获得的赛季积分未达到上限
  106. if addLeagueContribute > 0 && curContributeScore < data.Const.ConToSeasonScoreLimit {
  107. addContributScore := int32(data.Const.CalConValueToSeasonScore(addLeagueContribute))
  108. addScore := math.Min(addContributScore, data.Const.ConToSeasonScoreLimit-curContributeScore)
  109. if addScore > 0 {
  110. playerTable.Season.SeasonScore.ContributionScore += addScore
  111. playerTable.SetChangeData()
  112. }
  113. }
  114. if playerTable.IsChangeData() {
  115. playerTable.Save2Queue()
  116. // 更新赛季积分排行榜
  117. totalSeasonScore := playerTable.GetSeasonScore()
  118. rank := playerTable.ToRankPlayer(totalSeasonScore)
  119. mapCall.Rank.UpdatePlayerRank(enum.Rank_103, rank)
  120. }
  121. }