using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using System;
|
using System.Linq;
|
|
|
public partial class AchievementManager : GameSystemManager<AchievementManager>
|
{
|
//成就类型:条件(可以是空):进度
|
Dictionary<int, Dictionary<string, int>> achivementDict = new Dictionary<int, Dictionary<string, int>>();
|
public event Action<int> OnAchievementUpdateEvent;
|
//key:第几个记录值 每个key存31个succid 0-30为0, 31-61为1..; value: 根据成就ID位判断是否已领取
|
Dictionary<int, int> achivementAwardDict = new Dictionary<int, int>();
|
public override void Init()
|
{
|
DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitialize;
|
}
|
|
public override void Release()
|
{
|
DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitialize;
|
}
|
|
void OnBeforePlayerDataInitialize()
|
{
|
}
|
|
public void UpdateAchievement(HA340_tagSCSuccessInfoList netPack)
|
{
|
List<int> types = new List<int>();
|
for (int i = 0; i < netPack.Count; i++)
|
{
|
var info = netPack.SuccessInfoList[i];
|
if (!achivementDict.ContainsKey(info.SuccType))
|
{
|
achivementDict[info.SuccType] = new Dictionary<string, int>();
|
}
|
|
string key = info.CLen > 0 ? info.Conds.ToString() : "";
|
achivementDict[info.SuccType][key] = (int)info.CurValue;
|
|
OnAchievementUpdateEvent?.Invoke(info.SuccType);
|
if (!types.Contains(info.SuccType))
|
{
|
types.Add(info.SuccType);
|
}
|
}
|
UpdateRedpoint(types);
|
}
|
|
public int GetAchievementProgress(int type)
|
{
|
if (achivementDict.ContainsKey(type))
|
{
|
var condKey = SuccessConfig.GetConditionString(type);
|
if (achivementDict[type].ContainsKey(condKey))
|
{
|
return achivementDict[type][condKey];
|
}
|
}
|
return 0;
|
|
}
|
|
public void UpdateAchievementAward(HA342_tagSCSuccessAwardRecordList netPack)
|
{
|
List<int> types = new List<int>();
|
for (int i = 0; i < netPack.RecordCnt; i++)
|
{
|
var record = netPack.RecordList[i];
|
achivementAwardDict[record.RecordIndex] = (int)record.Record;
|
var startID = record.RecordIndex * 31;
|
var endID = startID + 30;
|
for (int j = startID; j <= endID; j++)
|
{
|
if (SuccessConfig.HasKey(j))
|
{
|
var type = SuccessConfig.Get(j).Type;
|
if (!types.Contains(type))
|
{
|
types.Add(type);
|
}
|
}
|
}
|
}
|
OnAchievementUpdateEvent?.Invoke(-1);
|
UpdateRedpoint(types);
|
}
|
|
//成就是否已领取
|
//每个key存31个succid 0-30为0, 31-61为1..; 根据成就ID位判断是否已领取
|
public bool IsAchievementAwarded(int id)
|
{
|
var index = id / 31;
|
var bit = id % 31;
|
if (achivementAwardDict.ContainsKey(index))
|
{
|
return (achivementAwardDict[index] & (1 << bit)) != 0;
|
}
|
return false;
|
}
|
|
//获取成就状态 0: 未领取 1: 未达成 2: 已领取
|
public int GetAchievementState(int id)
|
{
|
var process = GetAchievementProgress(id);
|
var config = SuccessConfig.Get(id);
|
if (process < config.NeedCnt)
|
{
|
return 1;
|
}
|
if (IsAchievementAwarded(id))
|
{
|
return 2;
|
}
|
return 0;
|
}
|
|
|
//主线章节
|
Redpoint mainLevelRedpoint = new Redpoint(MainRedDot.RedPoint_DailyKey, MainRedDot.RedPoint_MainMissionKey);
|
//类型:红点id
|
Dictionary<int, int> redpointDict = new Dictionary<int, int>()
|
{
|
{1, MainRedDot.RedPoint_MainMissionKey}
|
};
|
|
void UpdateRedpoint(List<int> _types)
|
{
|
if (_types.IsNullOrEmpty())
|
{
|
_types = redpointDict.Keys.ToList();
|
}
|
|
foreach (var type in _types)
|
{
|
var redpoint = RedpointCenter.Instance.GetRedpoint(redpointDict[type]);
|
redpoint.state = RedPointState.None;
|
//根据ID判断是否有可领取的
|
var allAchivement = SuccessConfig.GetTypeToIDDict(type);
|
var process = GetAchievementProgress(type);
|
foreach (var id in allAchivement)
|
{
|
var config = SuccessConfig.Get(id);
|
if (config.NeedCnt <= process)
|
{
|
if (!IsAchievementAwarded(id))
|
{
|
redpoint.state = RedPointState.Simple;
|
break;
|
}
|
}
|
}
|
|
}
|
}
|
|
//根据类型获取所有成就ID, 且是排序后的 未领取>未达成>已领取
|
public List<int> GetAchievementIDs(int type)
|
{
|
var ids = SuccessConfig.GetTypeToIDDict(type);
|
ids.Sort(CmpIds);
|
return ids;
|
}
|
|
int CmpIds(int a, int b)
|
{
|
var stateA = GetAchievementState(a);
|
var stateB = GetAchievementState(b);
|
|
if (stateA != stateB)
|
{
|
return stateA - stateB;
|
}
|
|
return a - b;
|
}
|
|
public void SendGetAward(int id)
|
{
|
var config = SuccessConfig.Get(id);
|
//简单判断背包
|
if (PackManager.Instance.GetEmptyGridCount(PackType.Item) < config.AwardItemList.Length)
|
{
|
SysNotifyMgr.Instance.ShowTip("GeRen_lhs_202580");
|
return;
|
}
|
|
var pack = new CA504_tagCMPlayerGetReward();
|
pack.RewardType = 59;
|
pack.DataEx = (uint)id;
|
GameNetSystem.Instance.SendInfo(pack);
|
}
|
}
|