DailyTaskDataManager.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using ET;
  4. namespace GFGGame
  5. {
  6. public class DailyTaskDataManager : SingletonBase<DailyTaskDataManager>
  7. {
  8. private Dictionary<int, int> _livenessBoxInfos = new Dictionary<int, int>();
  9. public void Clear()
  10. {
  11. _livenessBoxInfos.Clear();
  12. }
  13. public void UpdateLivenessBoxInfo(int boxId, int state)
  14. {
  15. if (!_livenessBoxInfos.ContainsKey(boxId))
  16. {
  17. _livenessBoxInfos.Add(boxId, state);
  18. }
  19. else
  20. {
  21. _livenessBoxInfos[boxId] = state;
  22. }
  23. }
  24. /// <summary>
  25. /// 根据宝箱id获取宝箱状态
  26. /// </summary>0不可领取,1可领取,2已领取
  27. /// <param name="boxId"></param>
  28. /// <returns></returns>
  29. public int GetBoxStateById(int boxId)
  30. {
  31. //已领取
  32. if (_livenessBoxInfos.ContainsKey(boxId) && _livenessBoxInfos[boxId] == ConstBonusStatus.GOT) return 2;
  33. //获取宝箱配置
  34. var cfg = TaskActiveRewardCfgArray.Instance.GetCfg(boxId);
  35. if (cfg == null)
  36. {
  37. Log.Error($"出现了没有配置的宝箱id{boxId}");
  38. return ConstBonusStatus.CAN_NOT_GET;
  39. }
  40. //判断是否满足领取条件
  41. return RoleDataManager.DailyLiveness >= cfg.count ? ConstBonusStatus.CAN_GET : ConstBonusStatus.CAN_NOT_GET;
  42. }
  43. /// <summary>
  44. /// 获取下一个奖励宝箱的活跃度
  45. /// </summary>
  46. /// <returns></returns>
  47. public int GetShowLivenessBoxNum(int taskFuncType)
  48. {
  49. var cfgs = TaskActiveRewardCfgArray.Instance.GetCfgsByfuncType(taskFuncType);
  50. foreach (var t in cfgs)
  51. {
  52. if (!_livenessBoxInfos.ContainsKey(t.id) || _livenessBoxInfos[t.id] != ConstBonusStatus.GOT)
  53. {
  54. return t.count;
  55. }
  56. }
  57. var index = cfgs.Count - 1;
  58. return cfgs[index].count;
  59. }
  60. public bool GetHadGetRewardNum(int taskFuncType)
  61. {
  62. foreach(var t in _livenessBoxInfos)
  63. {
  64. if(t.Value == ConstBonusStatus.CAN_GET)
  65. {
  66. var cfg = TaskActiveRewardCfgArray.Instance.GetCfg(t.Key);
  67. if (cfg == null) continue;
  68. if (taskFuncType != 0 && cfg.funcType != taskFuncType) continue;
  69. return true;
  70. }
  71. }
  72. return false;
  73. }
  74. }
  75. }