package season import ( capp "f1-game/internal/cherry_app" "f1-game/internal/code" "f1-game/internal/data" "f1-game/internal/enum" "f1-game/internal/extend/math" "f1-game/internal/facade" nameActor "f1-game/internal/name/actor" nameRemote "f1-game/internal/name/remote" "f1-game/internal/pb" mapCall "f1-game/nodes/map/internal/call" "f1-game/nodes/map/internal/db" ctime "github.com/cherry-game/cherry/extend/time" cfacade "github.com/cherry-game/cherry/facade" clog "github.com/cherry-game/cherry/logger" ) func Service() *service { return &service{} } type service struct { facade.PlayerServiceBase[*db.MapPlayerTable] } // 退出联盟记录已经结算的霸业任务状态 func (p *service) LeagueQuitSeasonQuestRecord(playerID, leagueID int64) { var ( playerTable = db.GetMapPlayerTable(playerID) rsp = &pb.SeasonQuestInfo{} ) req := p.GetSeasonQuestLeagueIDMap(playerTable) errCode := capp.CallWait(cfacade.NewPath("", nameActor.Map_Season), nameRemote.MapSeason_QuestInfo, req, rsp) if code.IsFail(errCode) { clog.Warnf("[leagueQuitSeasonQuestRecord] CallWait failed, leagueID: %d, errCode: %d", leagueID, errCode) return } now := ctime.Now().ToMillisecond() // 标记任务为已领取 for _, quest := range rsp.Quests { // 跳过未结算的 if quest.EndTime == 0 || quest.EndTime > now { continue } seasonQuestRow, ok := data.SeasonQuest.GetByID(quest.QuestID) if !ok { continue } if !seasonQuestRow.QuestType.IsLeague() { continue } if playerTable.Season.LeagueQuestMap.Contains(quest.QuestID) { continue } // 只处理新的已结算的霸业任务 playerTable.Season.LeagueQuestMap.Put(quest.QuestID, leagueID) playerTable.SetChangeData() } if playerTable.IsChangeData() { playerTable.Save2Queue() } clog.Infof("[leagueQuitSeasonQuestRecord] success. playerID: %d, leagueID: %d, leagueQuestMapSize: %d", playerID, leagueID, playerTable.Season.LeagueQuestMap.Size()) } func (*service) GetSeasonQuestLeagueID(playerTable *db.MapPlayerTable, questID int32) int64 { // 优先取记录中的联盟ID,退盟的时候记录之前完成的状态 leagueID := playerTable.Season.LeagueQuestMap.GetValue(questID) if leagueID == 0 { leagueID = playerTable.LeagueID } return leagueID } // 获取赛季霸业任务结算状态 func (*service) GetSeasonQuestLeagueIDMap(playerTable *db.MapPlayerTable) *pb.I32I64Map { rsp := &pb.I32I64Map{ Value: map[int32]int64{}, } for _, quest := range data.SeasonQuest.List() { if !quest.QuestType.IsLeague() { continue } // 优先取记录中的联盟ID,退盟的时候记录之前完成的状态 leagueID := playerTable.Season.LeagueQuestMap.GetValue(quest.ID) if leagueID == 0 { leagueID = playerTable.LeagueID } rsp.Value[quest.ID] = leagueID } return rsp } // 更新玩家赛季积分 func (p *service) UpdatePlayerSeasonScore(playerID, addFeat, addLeagueContribute int64) { var ( playerTable = db.GetMapPlayerTable(playerID) curFeatScore = playerTable.Season.SeasonScore.FeatScore curContributeScore = playerTable.Season.SeasonScore.ContributionScore ) // 获得功勋 且 当前功勋获得的赛季积分未达到上限 if addFeat > 0 && curFeatScore < data.Const.FeatToSeasonScoreLimit { addFeatScore := int32(data.Const.CalFeatValueToSeasonScore(addFeat)) addFeatScore = math.Min(addFeatScore, data.Const.FeatToSeasonScoreLimit-curFeatScore) if addFeatScore > 0 { playerTable.Season.SeasonScore.FeatScore += addFeatScore playerTable.SetChangeData() } } // 获得联盟贡献 且 当前联盟贡献获得的赛季积分未达到上限 if addLeagueContribute > 0 && curContributeScore < data.Const.ConToSeasonScoreLimit { addContributScore := int32(data.Const.CalConValueToSeasonScore(addLeagueContribute)) addScore := math.Min(addContributScore, data.Const.ConToSeasonScoreLimit-curContributeScore) if addScore > 0 { playerTable.Season.SeasonScore.ContributionScore += addScore playerTable.SetChangeData() } } if playerTable.IsChangeData() { playerTable.Save2Queue() // 更新赛季积分排行榜 totalSeasonScore := playerTable.GetSeasonScore() rank := playerTable.ToRankPlayer(totalSeasonScore) mapCall.Rank.UpdatePlayerRank(enum.Rank_103, rank) } }