using System.Collections; 
 | 
using System.Collections.Generic; 
 | 
using UnityEngine; 
 | 
using System; 
 | 
using LitJson; 
 | 
  
 | 
  
 | 
public class DailyQuestModel : GameSystemManager<DailyQuestModel> 
 | 
{ 
 | 
    const int EVERYDAY_REDPOINTID = 78001; 
 | 
    const int DAILYQUEST_REDPOINTIDBASE = 78100; 
 | 
    const int ACTIVEVALUE_REDPOINT = 78004; 
 | 
  
 | 
    Redpoint activeValueRedpoint = new Redpoint(EVERYDAY_REDPOINTID, ACTIVEVALUE_REDPOINT); //活跃度奖励红点 
 | 
  
 | 
    int m_DailyQuestTotalActiveValue = 0; 
 | 
    public int dailyQuestTotalActiveValue 
 | 
    { 
 | 
        get { return m_DailyQuestTotalActiveValue; } 
 | 
    } 
 | 
  
 | 
    Dictionary<int, DailyQuestTimes> dailyQuestTimes = new Dictionary<int, DailyQuestTimes>();//除了副本的其他任务放在这里 
 | 
    Dictionary<int, int> dailyActionToDailyQuestTable = new Dictionary<int, int>(); 
 | 
    List<int> DailyQuestLVList = new List<int>(); 
 | 
    Dictionary<int, DailyQuestOpenTime> dailyQuestOpenTimes = new Dictionary<int, DailyQuestOpenTime>(); 
 | 
    Dictionary<int, DailyQuestData> dailyQuests = new Dictionary<int, DailyQuestData>(); 
 | 
    List<DailyQuestActiveValueReward> dailyQuestActiveValueRewards = new List<DailyQuestActiveValueReward>(); 
 | 
  
 | 
  
 | 
    int m_CurrentRewardStageIndex = 0; 
 | 
    public int currentRewardStageIndex 
 | 
    { 
 | 
        get { return m_CurrentRewardStageIndex; } 
 | 
        private set { m_CurrentRewardStageIndex = value; } 
 | 
    } 
 | 
  
 | 
    int m_CurrentActiveValue = 0; 
 | 
    public int currentActiveValue 
 | 
    { 
 | 
        get { return m_CurrentActiveValue; } 
 | 
        private set 
 | 
        { 
 | 
            if (m_CurrentActiveValue != value) 
 | 
            { 
 | 
                m_CurrentActiveValue = value; 
 | 
  
 | 
                if (currentActiveValueUpdateEvent != null) 
 | 
                { 
 | 
                    currentActiveValueUpdateEvent(); 
 | 
                } 
 | 
            } 
 | 
        } 
 | 
    } 
 | 
  
 | 
    public event Action<int> dailyQuestProgressUpdateEvent; 
 | 
    public event Action currentActiveValueUpdateEvent; 
 | 
  
 | 
    public override void Init() 
 | 
    { 
 | 
        ParseConfig(); 
 | 
    } 
 | 
  
 | 
    public override void Release() 
 | 
    { 
 | 
    } 
 | 
  
 | 
    private void ParseConfig() 
 | 
    { 
 | 
        var allConfigs = DailyQuestConfig.GetValues(); 
 | 
        var redpointIndex = 1; 
 | 
        foreach (var config in allConfigs) 
 | 
        { 
 | 
            if (VersionConfig.Get().isBanShu && config.ID == 12) 
 | 
            { 
 | 
                continue; 
 | 
            } 
 | 
  
 | 
            var openTime = default(DailyQuestOpenTime); 
 | 
  
 | 
            switch (config.RelatedType) 
 | 
            { 
 | 
                case 1: 
 | 
                    var NeedLV = GetDailyQuestLV(config.ID); 
 | 
                    if (!DailyQuestLVList.Contains(NeedLV)) 
 | 
                    { 
 | 
                        bool bIsAdd = false; 
 | 
                        for (int i = 0; i < DailyQuestLVList.Count; i++) 
 | 
                        { 
 | 
                            if (NeedLV < DailyQuestLVList[i]) 
 | 
                            { 
 | 
                                DailyQuestLVList.Insert(i, NeedLV); 
 | 
                                bIsAdd = true; 
 | 
                                break; 
 | 
                            } 
 | 
                        } 
 | 
                        if (!bIsAdd) 
 | 
                        { 
 | 
                            DailyQuestLVList.Add(NeedLV); 
 | 
                        } 
 | 
  
 | 
                    } 
 | 
  
 | 
                    var activityOpenTime = DailyQuestOpenTimeConfig.Get(config.RelatedID); 
 | 
                    openTime = dailyQuestOpenTimes[config.ID] = new DailyQuestOpenTime(config.ID); 
 | 
                    openTime.ParseQuestNormalOpenTime(activityOpenTime); 
 | 
                    dailyActionToDailyQuestTable[config.RelatedID] = config.ID; 
 | 
                    break; 
 | 
                case 2: 
 | 
  
 | 
                    break; 
 | 
            } 
 | 
  
 | 
            dailyQuests[config.ID] = new DailyQuestData(config.ID, DAILYQUEST_REDPOINTIDBASE + redpointIndex++, EVERYDAY_REDPOINTID); 
 | 
        } 
 | 
  
 | 
        var allRewardKeys = DailyLivenessRewardConfig.GetKeys(); 
 | 
        m_DailyQuestTotalActiveValue = DailyLivenessRewardConfig.Get(allRewardKeys[allRewardKeys.Count - 1]).Liveness; 
 | 
  
 | 
        var values = DailyLivenessRewardConfig.GetValues(); 
 | 
        for (int i = 0; i < allRewardKeys.Count; i++) 
 | 
        { 
 | 
            var config = DailyLivenessRewardConfig.Get(allRewardKeys[i]); 
 | 
            dailyQuestActiveValueRewards.Add(new DailyQuestActiveValueReward(config.id)); 
 | 
        } 
 | 
  
 | 
        dailyQuestActiveValueRewards.Sort((x, y) => { return x.id.CompareTo(y.id); }); 
 | 
  
 | 
    } 
 | 
  
 | 
  
 | 
  
 | 
  
 | 
    public void OnDailyQuestCompletedTimesUpdate(HA315_tagMCDailyActionCnt _serverInfo) 
 | 
    { 
 | 
        for (int i = 0; i < _serverInfo.Count; i++) 
 | 
        { 
 | 
            var dailyAction = _serverInfo.ActionInfo[i]; 
 | 
            if (dailyAction.DayFinishCnt > 0) 
 | 
            { 
 | 
                dailyQuestTimes[(int)dailyAction.ActionID] = new DailyQuestTimes() 
 | 
                { 
 | 
                    completeTimes = dailyAction.DayFinishCnt, 
 | 
                    dayBuyTimes = dailyAction.DayBuyTimes, 
 | 
                    dayUseItemTimes = dailyAction.DayItemTimes, 
 | 
                }; 
 | 
            } 
 | 
            else 
 | 
            { 
 | 
                dailyQuestTimes[(int)dailyAction.ActionID] = new DailyQuestTimes() 
 | 
                { 
 | 
                    completeTimes = (int)dailyAction.WeekFinishCnt, 
 | 
                }; 
 | 
            } 
 | 
  
 | 
            if (dailyActionToDailyQuestTable.ContainsKey((int)dailyAction.ActionID)) 
 | 
            { 
 | 
                var dailyQuestId = dailyActionToDailyQuestTable[(int)dailyAction.ActionID]; 
 | 
                //UpdateDailyActionRedpoint(dailyQuestId); 
 | 
            } 
 | 
  
 | 
            if (dailyQuestProgressUpdateEvent != null) 
 | 
            { 
 | 
                dailyQuestProgressUpdateEvent((int)dailyAction.ActionID); 
 | 
            } 
 | 
        } 
 | 
    } 
 | 
  
 | 
    public int GetDailyQuestLV(int id) 
 | 
    { 
 | 
        var QuestConfig = DailyQuestConfig.Get(id); 
 | 
        var LVConfig = FuncOpenLVConfig.Get(QuestConfig.UnLockFuncID); 
 | 
        if (LVConfig == null) 
 | 
        {  
 | 
            Debug.LogError($"DailyQuestConfig.Get({id}) == null"); 
 | 
            return 9999999; 
 | 
        } 
 | 
        int NeedLV = 0; 
 | 
        if (LVConfig.LimitLV != 0) 
 | 
        { 
 | 
            NeedLV = LVConfig.LimitLV; 
 | 
        } 
 | 
        else if (LVConfig.LimitMissionID != 0) 
 | 
        { 
 | 
  
 | 
        } 
 | 
        return NeedLV; 
 | 
    } 
 | 
  
 | 
    public void OnDailyQuestActiveValueInfoUpdate(HA333_tagMCDailyActivityInfoList _activeValueInfo) 
 | 
    { 
 | 
        int OldCurrentActiveValue = currentActiveValue; 
 | 
        currentActiveValue = (int)_activeValueInfo.CurValue; 
 | 
        currentRewardStageIndex = (int)_activeValueInfo.StageIndex; 
 | 
  
 | 
        UpdateActiveValueRedpoint(); 
 | 
    } 
 | 
     
 | 
    private void UpdateActiveValueRedpoint() 
 | 
    { 
 | 
        var count = dailyQuestActiveValueRewards.Count; 
 | 
        var anyAwardable = false; 
 | 
        for (int i = 0; i < count; i++) 
 | 
        { 
 | 
            var reward = dailyQuestActiveValueRewards[i]; 
 | 
            if (!reward.got) 
 | 
            { 
 | 
                var config = DailyLivenessRewardConfig.Get(reward.id); 
 | 
                if (currentActiveValue >= config.Liveness) 
 | 
                { 
 | 
                    anyAwardable = true; 
 | 
                    break; 
 | 
                } 
 | 
            } 
 | 
        } 
 | 
  
 | 
        activeValueRedpoint.state = anyAwardable ? RedPointState.Simple : RedPointState.None; 
 | 
    } 
 | 
  
 | 
  
 | 
} 
 |