lua的table中实现了table.sort()方法,可以对table进行排序。如果遇到多个条件优先级不同排序的情况,用数值大小对应条件优先级大小可以,通过最终得到的数值大小进行比较
具体例子代码
优先级 --双倍类型>非双倍类型;天赋经验高>天赋经验低;类型大于天赋经验
table.sort(temp,function (a,b)
--双倍类型>非双倍类型;天赋经验高>天赋经验低
local a_sort = 0
local b_sort = 0
local if_a_more_than_b = a.talent_skill_exp > b.talent_skill_exp
a_sort = a_sort + ((a.table[1] == workingHeroList.study_main) and 100 or 0)
b_sort = b_sort + ((b.table[1] == workingHeroList.study_main) and 100 or 0)
a_sort = a_sort + (if_a_more_than_b and 10 or 0)
b_sort = b_sort + (if_a_more_than_b and 0 or 10)
return a_sort > b_sort
end)