RoleTask.lua
3.81 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
-- 增加 checkTaskEnter 内的参数 记得增增加注释
local TaskType = {
HangPass = 1, -- id
AdvPass = 2, -- id
LoveBreak = 3, -- heroType loveL
Wake = 4, -- heroType wakeL
AddHero = 5, -- heroType wakeL
}
local function v(value)
return {type = "value", value = value}
end
local function f(field)
return {type = "field", value = field}
end
local StoryListener = {
func = "checkStoryStatus",
listen = {
[TaskType.HangPass] = {v(1), f("id")},
[TaskType.AdvPass] = {v(4), f("id")},
[TaskType.LoveBreak] = {v(2), f("heroType")},
[TaskType.Wake] = {v(3), f("heroType"), f("wakeL")},
[TaskType.AddHero] = {v(3), f("heroType"), f("wakeL")},
}
}
local TaskListeners = {
StoryListener,
}
local RoleTask = {}
function RoleTask.bind(Role)
Role.TaskType = TaskType
-- 任务相关入口
function Role:checkTaskEnter(taskType, params, notNotify)
for _, listener in ipairs(TaskListeners) do
if listener and listener.listen and listener.listen[taskType] and listener["func"] then
local pms = {}
for _, v in ipairs(listener.listen[taskType]) do
if type(v) == "table" and v.type then
if v.type == "value" then
table.insert(pms, v.value)
elseif v.type == "field" then
table.insert(pms, params[v.value])
else
table.insert(pms, v)
end
else
table.insert(pms, v)
end
end
self[listener["func"]](self, notNotify, table.unpack(pms))
end
end
end
function Role:checkDailyTask()
end
function Role:checkWeekTask()
end
function Role:checkAchievTask()
end
--剧情相关----begin-------------
local function checkStoryStatusByHang(role, data, status, cond1) -- cond1 carbonId
if tonumber(data.unlockData) ~= cond1 then return end
status.s = 1
return true
end
local function checkStoryStatusByLove(role, data, status, cond1) -- cond1 heroType
if data.sort ~= cond1 then return end
local curL = role:getProperty("loveStatus"):getv(cond1, 0)
if curL < tonumber(data.unlockData) then return end
status.s = 1
return true
end
local function checkStoryStatusByMultStar(role, data, status, cond1, cond2) -- cond1 heroType, cond2 wakeL
local heroType = cond1
local need = data.unlockData:toArray(true, "=")
local had = false
for _, v in pairs(need) do
if v == heroType then
had = true
break
end
end
if not had then return end
if cond2 > (status["s" .. heroType] or 0) then
status["s" .. heroType] = cond2
end
local starC = 0
for _, v in pairs(need) do
starC = starC + (status["s" .. v] or 0)
end
if starC >= tonumber(data.unlockData2) then
table.clear(status)
status.s = 1
end
return true
end
local function checkStoryStatusByAdv(role, data, status, cond1) -- cond1 advId
if tonumber(data.unlockData) ~= cond1 then return end
status.s = 1
return true
end
local checkstoryStatusFunc = {
[1] = checkStoryStatusByHang,
[2] = checkStoryStatusByLove,
[3] = checkStoryStatusByMultStar,
[4] = checkStoryStatusByAdv,
}
function Role:checkStoryStatus(notNotify, stype, cond1, cond2, cond3)
local storyBookStatus = self:getProperty("storyB")
local change = {}
for id, data in pairs(csvdb["story_bookCsv"]) do
if stype == data.unlockType and checkstoryStatusFunc[stype] then
local curStatus = storyBookStatus[id] or {}
if not curStatus.s then -- 存在状态就是已经完成
local isChange = checkstoryStatusFunc[stype](self, data, curStatus, cond1, cond2, cond3)
if isChange then
storyBookStatus[id] = curStatus
table.insert(change, {type = "storyB", field = id, value = curStatus, isOnlyToC = true})
end
end
end
end
if next(change) then
self:setProperty("storyB", storyBookStatus) -- 统一写入数据库
if not notNotify then
self:changeUpdates(change)
end
end
end
--剧情相关----end-------------
end
return RoleTask