TaskItemDataNew.lua 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. --[[
  2. 每条任务的数据类
  3. ]]--
  4. local TaskItemDataNew = class("TaskItemDataNew", require("DataBase"))
  5. --银币消耗(30),金币消耗(31),银币获得(39),总战力(14),使用特定道具数量(21),累积获得卡片数量(41),英灵殿胜利次数(32)
  6. --需要转换数值显示形式的任务枚举
  7. local _needChangeEnum = {30, 31, 39, 14, 21, 41, 32}
  8. local _w = 10000; --一万
  9. function TaskItemDataNew:ctor()
  10. self._id = nil;
  11. self._taskType = nil;
  12. self._cfgData = nil;
  13. self._progress = nil;
  14. self._got = nil;
  15. self._beginTime = nil;
  16. end
  17. function TaskItemDataNew:Clear()
  18. self._id = nil;
  19. self._taskType = nil;
  20. self._cfgData = nil;
  21. self._progress = nil;
  22. self._got = nil;
  23. self._beginTime = nil;
  24. end
  25. function TaskItemDataNew:Destroy()
  26. if self.Clear then
  27. self:Clear()
  28. end
  29. self:UnRegisterNetEvents()
  30. end
  31. function TaskItemDataNew:UnRegisterNetEvents()
  32. end
  33. function TaskItemDataNew:RefreshTaskItem(_data)
  34. self._id = _data.task_id;
  35. self._taskType = _data.task_type;
  36. self._state = _data.state
  37. self:GetCfgData(self._id, self._taskType);
  38. if self._cfgData then
  39. self._progress = {};
  40. local _missionCondition = self._cfgData.MissionCondition;
  41. for _i = 1, #_missionCondition do
  42. local _conditions = _missionCondition[_i];
  43. --完成度在表格得MissionCondition字段中的list中每一个的第一个值都是不能重复的,不允许出现:2:1;3:6;2:5这种情况,里边出现了两个2
  44. local _keyCon = _conditions[1];
  45. local _totalCon = self:JudgeTotal(_conditions[1], _conditions[#_conditions])
  46. local _needChangeEnum = self:IsNeedChangeEnum(_keyCon);
  47. local _totalConStr = tostring(_totalCon);
  48. if _needChangeEnum and _w <= _totalCon then
  49. _totalConStr = CommonUtil.GetPreciseDecimalFloor(_totalCon/10000, 1) .. CommonUtil.Get_Wan_string()--"萬";--w
  50. end
  51. local _progress = {
  52. _key = _keyCon,
  53. _total = _totalCon; --该条件达成,需要完成多少
  54. _value = 0; --完成了多少
  55. _state = 0; --是否已经完成,这个完成指的是这一个条件得完成,跟整个任务得完成还不太一样,但是如果任务只有一个条件得话,那就是一样得
  56. _totalStr = _totalConStr; --这个是数值格式化之后的字符串(当数值很大的时候转换成**W代表**万)
  57. _valueStr = ";" --这个是完成的数值格式化之后的字符串
  58. };
  59. local _value, _state = self:GetProgressByKey(_progress._key, _data.progress);
  60. _progress._value = _value or 0;
  61. if _needChangeEnum and _w <= _progress._value then
  62. _progress._valueStr = CommonUtil.GetPreciseDecimalFloor(_progress._value/10000, 1) .. CommonUtil.Get_Wan_string()--"萬";--w
  63. else
  64. _progress._valueStr = tostring(_progress._value)
  65. end
  66. _progress._state = _state or 0;
  67. table.insert(self._progress, _progress);
  68. end
  69. self:GetProgressNumber();
  70. self._got = _data.state or 0; --是否已经领取 0 未完成 1 完成未领取 2 领取
  71. self._beginTime = _data.begin_time;
  72. end
  73. end
  74. --判断完成任务的需要总量
  75. function TaskItemDataNew:JudgeTotal(_type, _total)
  76. if _type == Enum.TaskType.Level_Battle_Count or _type == Enum.TaskType.Level_Hard_Battle_Count then --同关
  77. return 1;
  78. else
  79. return _total;
  80. end
  81. end
  82. --根据传进来得key查找服务器发过来得数据中对应得那个条件得进度
  83. function TaskItemDataNew:GetProgressByKey(_key, _progress)
  84. for _k, _v in ipairs(_progress) do
  85. if _v.key == _key then
  86. return _v.value, _v.state;
  87. end
  88. end
  89. end
  90. function TaskItemDataNew:GetCfgData(_id, _type)
  91. if self._cfgData then return; end
  92. if _type == Enum.TaskTag.Daily or _type == Enum.TaskTag.Weekly then
  93. self._cfgData = ManagerContainer.CfgMgr:GetMissionById(_id)
  94. elseif _type == Enum.TaskTag.Main then
  95. self._cfgData = ManagerContainer.CfgMgr:GetLineMissionById(_id)
  96. elseif _type == Enum.TaskTag.Hard then
  97. self._cfgData = ManagerContainer.CfgMgr:GetHardMissionCfgById(_id)
  98. elseif _type == Enum.TaskTag.HardGroup then
  99. self._cfgData = ManagerContainer.DataMgr.HardMissionDataMgr:GetGroupCfgByGroupID(_id)
  100. elseif _type == Enum.TaskTag.Hard_S then
  101. self._cfgData = ManagerContainer.CfgMgr:GetEMMissionCfgById(_id)
  102. elseif _type == Enum.TaskTag.HardGroup_S then
  103. self._cfgData = ManagerContainer.DataMgr.HardMission_S_DataMgr:GetGroupCfgByGroupID(_id)
  104. else
  105. LogError("未知任务类型:" .. tostring(_type));
  106. end
  107. end
  108. --获取进度的比值,策划说的目前每个任务只有一个条件,后续如果要扩展,需要他们提供多个条件的情况下进度的比值怎么计算,然后这里需要改动
  109. function TaskItemDataNew:GetProgressNumber()
  110. local _progress = self._progress[1];
  111. self._progressNum = _progress._value / _progress._total;
  112. end
  113. --获取进度信息,当前进度值,完成需要的总值
  114. function TaskItemDataNew:GetProgressData()
  115. local _progress = self._progress[1];
  116. return _progress._valueStr, _progress._totalStr;
  117. end
  118. --判断是否可以领取
  119. function TaskItemDataNew:JudgeCanGet()
  120. return self._got == Enum.TaskState.Got, self._got;
  121. end
  122. function TaskItemDataNew:IsNeedChangeEnum(_enum)
  123. for _i = 1, #_needChangeEnum do
  124. if _needChangeEnum[_i] == _enum then
  125. return true;
  126. end
  127. end
  128. return false;
  129. end
  130. return TaskItemDataNew