AdvCommon.lua
1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
-- 工具函数--第一象限 < 10000 < 第二象限 < 20000 < 第四象限 < 30000 < 第三象限
local AdvCommon = {}
function AdvCommon.getIdByCr(c, r)
local crId = math.abs(r) + math.abs(c) * 100 -- row + column * 100
if c < 0 then
crId = crId + 10000
end
if r < 0 then
crId = crId + 20000
end
return crId
end
function AdvCommon.getCrById(crId)
local c = math.floor(crId % 10000 / 100)
local r = crId % 100
local last = math.floor(crId / 10000)
if last == 3 then
c, r = -c, -r
elseif last == 1 then
c = -c
elseif last == 2 then
r = -r
end
return c, r
end
--检查 是否满足层数限制条件 -- if checktype == 1 then check value in range a=b else check value in array a=b=c
function AdvCommon.checkIsIn(checkValue, checkType, checkRange)
if not checkValue then return end
if checkType == 1 then
local limits = checkRange:toNumMap()
for min, max in pairs(limits) do
if checkValue >= min and checkValue <= max then
return true
end
end
else
local limit = checkRange:toArray(true, "=")
for _, _l in ipairs(limit) do
if _l == checkValue then
return true
end
end
end
end
function AdvCommon.isEndless(chapterId)
return math.floor(chapterId / 100) == 2
end
function AdvCommon.getEndlessDataLv(chapterId, level)
local chapterData = csvdb["adv_chapterCsv"][chapterId]
if level > globalCsv.adv_endless_custom_layer then
level = (level - globalCsv.adv_endless_custom_layer) % chapterData.limitlevel
if level == 0 then
level = chapterData.limitlevel
end
level = level + globalCsv.adv_endless_custom_layer
end
return level
end
return AdvCommon