Blame view

src/adv/AdvTask.lua 4.74 KB
4faef572   zhouhaihai   冒险任务,冒险扫荡, 冒险中继
1
2
3
  local AdvTask = {}
  
  
286a8f95   zhouhaihai   刷新任务和主线 分开
4
  local advTaskChange = {}
4faef572   zhouhaihai   冒险任务,冒险扫荡, 冒险中继
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
  function AdvTask.bind(Adv)
  	Adv.TaskType = {
  		Arrive 		= 1, --到达N层
  		Kill		= 2, --消灭指定怪物N个
  		Item		= 3, --获得指定道具N个
  		Choose		= 4, --完成指定抉择点N次
  		Shop		= 5, --和指定商人交易N次
  		Build		= 6, --和指定建筑交互N次
  		KillAll		= 7, --消灭本层所有怪物
  	}
  
  	-- 检查任务状态 在新领取任务的时候回进行检查
  	local function checkTaskStatus(self, taskData, status, count, cond)
  		count = count or 0
  		if status == -1 or not taskData then
  			return
  		end
  		local function checkCondValue()
  			if taskData.value2 ~= "" then
  				local conds = taskData.value2:toArray(true, "=")
  				for _, one in pairs(conds) do
  					if one == cond then
  						return true
  					end
  				end
  			end
  			return true
  		end	
  
  		local checkTaskFunc = {}
  		checkTaskFunc[Adv.TaskType.Arrive] = function()
  			if self.level > status then
  				if self.level >= taskData.value1 then
  					return -1
  				else
  					return self.level
  				end
  			end
  		end
  		checkTaskFunc[Adv.TaskType.KillAll] = function()
  			if  #self.battle.player:getTeam(2) == 0 then
  				return -1
  			end
  		end
  
  		if checkTaskFunc[taskData.condition] then
  			status = checkTaskFunc[taskData.condition]()
  		else
  			if count == 0 or not checkCondValue() then return end --没有变化
  			status = status + count
  			if status >= taskData.value1 then
  				status = -1
  			end
  		end
  		return status
  	end 
  
  	function Adv:initLayerTask()
  		self.advTask = {}
286a8f95   zhouhaihai   刷新任务和主线 分开
64
65
  		advTaskChange.t = true
  		advTaskChange.m = true
4faef572   zhouhaihai   冒险任务,冒险扫荡, 冒险中继
66
67
68
69
70
71
  		if not next(self.advMTask) then
  			self.advMTask = {
  				id = 1,
  				status = 0,
  				lock = 1,
  			}
4faef572   zhouhaihai   冒险任务,冒险扫荡, 冒险中继
72
73
74
75
  		end
  		self.advMTask.id = self.advMTask.id or 1
  		local mainTaskData = csvdb["adv_questCsv"][self.advMTask.id]
  		if mainTaskData and self.advMTask.lock then 
4d943586   zhouhaihai   直通 advt gm
76
  			if self.chapterId == mainTaskData.chapter and self.level >= mainTaskData.level then --到达指定关卡解锁当前任务
4faef572   zhouhaihai   冒险任务,冒险扫荡, 冒险中继
77
78
79
80
81
82
  				self.advMTask.lock = nil
  				self.advMTask.status = 0
  				local ts = checkTaskStatus(self, mainTaskData, self.advMTask.status, 0)
  				if ts then
  					self.advMTask.status = ts
  				end
4faef572   zhouhaihai   冒险任务,冒险扫荡, 冒险中继
83
84
85
86
87
  			end
  		end
  	end
  
  	function Adv:checkTask(taskType, count, cond)
4d943586   zhouhaihai   直通 advt gm
88
  		local chapter = self.chapterId
4faef572   zhouhaihai   冒险任务,冒险扫荡, 冒险中继
89
90
91
92
93
94
  		for taskId, status in pairs(self.advTask) do
  			local taskData = csvdb["event_questCsv"][taskId]
  			if taskData and taskData.levelchapter == chapter and taskType == taskData.condition then
  				local ts = checkTaskStatus(self, taskData, status, count, cond)
  				if ts then
  					self.advTask[taskId] = ts
286a8f95   zhouhaihai   刷新任务和主线 分开
95
  					advTaskChange.t = true
4faef572   zhouhaihai   冒险任务,冒险扫荡, 冒险中继
96
97
98
99
100
101
102
103
104
  				end
  			end
  		end
  
  		local mainTaskData = csvdb["adv_questCsv"][self.advMTask.id]
  		if not self.advMTask.lock and mainTaskData and mainTaskData.chapter == chapter and taskType == mainTaskData.condition then
  			local ts = checkTaskStatus(self, mainTaskData, self.advMTask.status, count, cond)
  			if ts then
  				self.advMTask.status = ts
286a8f95   zhouhaihai   刷新任务和主线 分开
105
  				advTaskChange.m = true
4faef572   zhouhaihai   冒险任务,冒险扫荡, 冒险中继
106
107
108
109
110
111
112
113
114
115
116
117
118
119
  			end
  		end
  	end
  
  	-- 点击任务地块领取任务
  	function Adv:addTask(taskId)
  		local taskData = csvdb["event_questCsv"][taskId]
  		if taskData then
  			self.advTask[taskId] = 0
  			local ts = checkTaskStatus(self, taskData, self.advTask[taskId], 0)
  			if ts then
  				self.advTask[taskId] = ts
  			end
  
286a8f95   zhouhaihai   刷新任务和主线 分开
120
  			advTaskChange.t = true
4faef572   zhouhaihai   冒险任务,冒险扫荡, 冒险中继
121
122
123
124
125
126
127
128
129
130
131
132
133
134
  			return true
  		end
  	end
  
  	--完成层任务
  	function Adv:finishTask(taskId)
  		local ok, reward
  		if self.advTask[taskId] and self.advTask[taskId] == -1 then
  			local taskData = csvdb["event_questCsv"][taskId]
  			if not taskData then return end
  			if taskData.reward == 1 then
  				reward = self.owner:award(taskData.rewardValue)
  			end
  			self.advTask[taskId] = nil
4faef572   zhouhaihai   冒险任务,冒险扫荡, 冒险中继
135
  			ok = true
286a8f95   zhouhaihai   刷新任务和主线 分开
136
  			advTaskChange.t = true
4faef572   zhouhaihai   冒险任务,冒险扫荡, 冒险中继
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
  		end
  		return ok, reward
  	end
  
  	-- 完成主线任务
  	function Adv:finishMTask()
  		local ok, reward
  		if self.advMTask.status == -1 then  --已完成带领取
  			local mainTaskData = csvdb["adv_questCsv"][self.advMTask.id]
  			if not mainTaskData then return end
  			if mainTaskData.reward == 1 then
  				reward = self.owner:award(mainTaskData.rewardValue)
  			end
  			self.advMTask.id = self.advMTask.id + 1
  			self.advMTask.status = 0
  			local nextTaskData = csvdb["adv_questCsv"][self.advMTask.id]
4d943586   zhouhaihai   直通 advt gm
153
  			if not nextTaskData or self.chapterId ~= nextTaskData.chapter or self.level < nextTaskData.level then
4faef572   zhouhaihai   冒险任务,冒险扫荡, 冒险中继
154
155
156
157
158
159
160
  				self.advMTask.lock = true
  			else
  				local ts = checkTaskStatus(self, nextTaskData, self.advMTask.status, 0)
  				if ts then
  					self.advMTask.status = ts
  				end
  			end
4faef572   zhouhaihai   冒险任务,冒险扫荡, 冒险中继
161
  			ok = true
286a8f95   zhouhaihai   刷新任务和主线 分开
162
  			advTaskChange.m = true
4faef572   zhouhaihai   冒险任务,冒险扫荡, 冒险中继
163
164
165
166
167
  		end
  		return ok, reward
  	end
  
  	function Adv:updateTask(notNotify)
286a8f95   zhouhaihai   刷新任务和主线 分开
168
169
170
  		local properties = {}
  		if advTaskChange.t then
  			properties.advTask = self.advTask
4faef572   zhouhaihai   冒险任务,冒险扫荡, 冒险中继
171
  		end
286a8f95   zhouhaihai   刷新任务和主线 分开
172
173
174
175
176
177
178
  		if advTaskChange.m then
  			properties.advMTask = self.advMTask
  		end
  		if next(properties) then
  			self.owner:updateProperties(properties, notNotify)
  		end
  		advTaskChange = {}
4faef572   zhouhaihai   冒险任务,冒险扫荡, 冒险中继
179
180
181
182
183
  	end
  end
  
  
  return AdvTask