CommonTaskGoal.lua 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. CommonTaskGoal = {}
  2. --- 检查道具ID和道具类型是否符合条件
  3. --- (适用于target2配置道具ID target配置道具类型的校验)
  4. function CommonTaskGoal.CheckItemIdsAndTypeByGoodsId(goal_id, goal_count, goods_id)
  5. if string.isNullOrEmpty(goods_id) or tonumber(goods_id) < 1 then
  6. return goal_count
  7. end
  8. local config = ConfigDataManager.getById("cfg_task_target", goal_id)
  9. local goal_id_str = config.taskgoalparam2
  10. if not string.isNullOrEmpty(goal_id_str) then
  11. local id_list = string.split(goal_id_str, "#")
  12. if not table.contains(id_list, tostring(goods_id)) then
  13. return goal_count
  14. end
  15. end
  16. local goods_type_str = ConfigDataManager.getTableValue("cfg_item", "type", "id", goods_id)
  17. local goods_type = string.isNullOrEmpty(goods_type_str) and 0 or tonumber(goods_type_str)
  18. local goal_type = config.taskgoalparam
  19. if not string.isNullOrEmpty(goal_type) then
  20. if tonumber(goal_type) ~= goods_type then
  21. return goal_count
  22. end
  23. end
  24. return goal_count + 1
  25. end
  26. --- 触发以后就直接增加一次任务进度
  27. --- is_add 触发刷新的时候传递,(领取任务后立即执行的一次刷新,增加一个is_add来区别是否主动触发)
  28. function CommonTaskGoal.OnlyAddCountWhenTrigger(goal_count, is_add)
  29. return goal_count + (is_add and 1 or 0)
  30. end
  31. function CommonTaskGoal.EquipAppendAndStrengthen(actor, goal_id, goal_count, args_name)
  32. local goal_part_str = ConfigDataManager.getTableValue("cfg_task_target", "taskgoalparam", "id", goal_id)
  33. local goal_lv_str = ConfigDataManager.getTableValue("cfg_task_target", "taskgoalparam2", "id", goal_id)
  34. local goal_part = string.isNullOrEmpty(goal_part_str) and 0 or tonumber(goal_part_str)
  35. local goal_lv = string.isNullOrEmpty(goal_lv_str) and 0 or tonumber(goal_lv_str)
  36. local all_equip = getputonequipinfo(actor)
  37. if table.isEmpty(all_equip) then
  38. return 0
  39. end
  40. local all_data = EquipAndAppear.getLuaItemExtData(actor)
  41. if table.isEmpty(all_data) then
  42. return 0
  43. end
  44. local max_count = 0
  45. for _, equip in pairs(all_equip) do
  46. local equip_data = all_data[equip.id]
  47. if table.isEmpty(equip_data) then
  48. goto continue
  49. end
  50. local args_lv = equip_data[args_name] or 0
  51. if args_lv < goal_lv then
  52. goto continue
  53. end
  54. if goal_part > 0 then
  55. local part = gameequip.pos(equip.equipindex)
  56. if tonumber(part) ~= goal_part then
  57. goto continue
  58. end
  59. end
  60. max_count = max_count + 1
  61. :: continue ::
  62. end
  63. return max_count
  64. end