player_season.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package mapPlayer
  2. import (
  3. actorRemote "f1-game/internal/actor_remote"
  4. "f1-game/internal/code"
  5. "f1-game/internal/data"
  6. "f1-game/internal/enum"
  7. "f1-game/internal/event"
  8. nameActor "f1-game/internal/name/actor"
  9. nameEvent "f1-game/internal/name/event"
  10. nameLocal "f1-game/internal/name/local"
  11. nameRemote "f1-game/internal/name/remote"
  12. "f1-game/internal/pb"
  13. ao "f1-game/nodes/game/player/asset/origin"
  14. mapCall "f1-game/nodes/map/internal/call"
  15. "f1-game/nodes/map/internal/db"
  16. "f1-game/nodes/map/player/season"
  17. cfacade "github.com/cherry-game/cherry/facade"
  18. cproto "github.com/cherry-game/cherry/net/proto"
  19. )
  20. func (p *actorPlayer) initSeason() {
  21. p.Local().Register(nameLocal.MapPlayer_SeasonQuestInfo, p.seasonQuestInfo)
  22. p.Local().Register(nameLocal.MapPlayer_SeasonQuestReward, p.seasonQuestReward)
  23. p.EventRegister(nameEvent.Map_PlayerCastleSuccess, p.updateSeasonScore)
  24. }
  25. // 获取赛季霸业任务信息
  26. func (p *actorPlayer) seasonQuestInfo(session *cproto.Session, _ *pb.None) {
  27. var (
  28. playerTable = db.GetMapPlayerTable(p.playerID)
  29. rsp = &pb.SeasonQuestInfo{}
  30. )
  31. req := season.Service().GetSeasonQuestLeagueIDMap(playerTable)
  32. errCode := p.CallWait(cfacade.NewPath("", nameActor.Map_Season), nameRemote.MapSeason_QuestInfo, req, rsp)
  33. if code.IsFail(errCode) {
  34. p.ResponseCode(session, code.SeasonQuestInfoError)
  35. return
  36. }
  37. // 标记已领取的任务
  38. for id, quest := range rsp.Quests {
  39. if playerTable.Season.RewardedQuests.Contains(id) {
  40. quest.IsRewarded = true
  41. }
  42. }
  43. p.Response(session, rsp)
  44. }
  45. // 领取赛季霸业任务奖励
  46. func (p *actorPlayer) seasonQuestReward(session *cproto.Session, req *pb.I32) {
  47. if req.Value < 1 {
  48. p.ResponseCode(session, code.IllegalArgument)
  49. return
  50. }
  51. seasonQuestRow, ok := data.SeasonQuest.GetByID(req.Value)
  52. if !ok {
  53. p.ResponseCode(session, code.ConfigNotFound_SeasonQuest)
  54. return
  55. }
  56. var (
  57. questID = req.Value
  58. playerTable = db.GetMapPlayerTable(p.playerID)
  59. )
  60. if playerTable.Season.RewardedQuests.Contains(questID) {
  61. p.ResponseCode(session, code.SeasonQuestRewardRepeat)
  62. return
  63. }
  64. checkReq := &pb.I32I64{
  65. Key: questID,
  66. Value: season.Service().GetSeasonQuestLeagueID(playerTable, questID),
  67. }
  68. errCode := p.CallWait(cfacade.NewPath("", nameActor.Map_Season), nameRemote.MapSeason_QuestCheck, checkReq, nil)
  69. if code.IsFail(errCode) {
  70. p.ResponseCode(session, errCode)
  71. return
  72. }
  73. // 标记任务为已领取
  74. playerTable.Season.RewardedQuests.Add(req.Value)
  75. playerTable.Save2Queue()
  76. // 发放奖励
  77. actorRemote.GamePlayer.AssetAddAsync(playerTable.GameNodeID, p.playerID, seasonQuestRow.Rewards, ao.None)
  78. p.ResponseCode(session, code.OK)
  79. }
  80. // 更新霸业积分
  81. func (p *actorPlayer) updateSeasonScore(e cfacade.IEventData) {
  82. evt, ok := e.(*event.PlayerCastleSuccess)
  83. if !ok {
  84. p.Warn("[updateSeasonScore] event error. playerID=%d, event=%+v", p.playerID, e)
  85. return
  86. }
  87. var (
  88. leagueID = evt.LeagueID()
  89. configID = evt.ConfigID()
  90. )
  91. castleRow, found := data.MapCastle.GetByConfigID(configID)
  92. if !found {
  93. p.Warn("[updateSeasonScore] castle not found. playerID=%d, configID=%d", p.playerID, configID)
  94. return
  95. }
  96. playerTable := db.GetMapPlayerTable(p.playerID)
  97. curScore := playerTable.Season.SeasonScore.LeagueScoreMap.GetValue(leagueID)
  98. curScore += castleRow.SupremacyScore
  99. playerTable.Season.SeasonScore.LeagueScoreMap.Put(leagueID, curScore)
  100. playerTable.Save2Queue()
  101. // 更新赛季积分排行榜
  102. totalSeasonScore := playerTable.GetSeasonScore()
  103. rank := playerTable.ToRankPlayer(totalSeasonScore)
  104. mapCall.Rank.UpdatePlayerRank(enum.Rank_103, rank)
  105. }