Blame view

src/models/RoleTask.lua 4.26 KB
be83d162   zhouahaihai   登陆成功。 增加数据结构修正功能
1
2
  
  
03a6166a   zhouhaihai   餐厅优化
3
  -- 增加  checkTaskEnter 内的参数 记得增加注释
be83d162   zhouahaihai   登陆成功。 增加数据结构修正功能
4
  local TaskType = {
03a6166a   zhouhaihai   餐厅优化
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  	HangPass = 1,				-- 挂机通关			- id
  	AdvPass = 2,				-- 冒险通过关			- id
  	LoveBreak = 3,				-- 好感度进阶			- heroType	loveL
  	Wake = 4,					-- 觉醒				- heroType	wakeL
  	AddHero = 5,				-- 增加角色			- heroType	wakeL
  	AddEquip = 6,				-- 获得装备			- equipId
  	DecoRune = 7,	 			-- 分解符文			- count
  	SaleEquip = 8,				-- 出售装备			- count
  	MakeFood = 9,				-- 制作料理			- id	count
  	HangGet = 10,				-- 挂机收货
  	FoodMGet = 11,				-- 食材获取
  
  	--todo
  	PvpWin = 100,				-- pvp胜利
00e663bd   zhouhaihai   剧情相关
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
  }
  
  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")},
bd15e9bc   zhouhaihai   购买剧情
36
  		[TaskType.AddHero] = {v(3), f("heroType"), f("wakeL")},
00e663bd   zhouhaihai   剧情相关
37
38
39
40
41
  	}
  }
  
  local TaskListeners = {
  	StoryListener,
be83d162   zhouahaihai   登陆成功。 增加数据结构修正功能
42
43
44
45
46
47
  }
  
  local RoleTask = {}
  
  function RoleTask.bind(Role)
  
00e663bd   zhouhaihai   剧情相关
48
49
  	-- 任务相关入口
  	function Role:checkTaskEnter(taskType, params, notNotify)
03a6166a   zhouhaihai   餐厅优化
50
51
52
53
  		params = params or {}
  		if type(taskType) == "string" then
  			taskType = TaskType[taskType]
  		end
00e663bd   zhouhaihai   剧情相关
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
  		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
be83d162   zhouahaihai   登陆成功。 增加数据结构修正功能
73
74
  	end
  
be83d162   zhouahaihai   登陆成功。 增加数据结构修正功能
75
76
77
78
79
80
81
82
83
  	function Role:checkDailyTask()
  	end
  
  	function Role:checkWeekTask()
  	end
  
  	function Role:checkAchievTask()
  	end
  
00e663bd   zhouhaihai   剧情相关
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
153
154
155
156
157
158
159
160
  	--剧情相关----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-------------
be83d162   zhouahaihai   登陆成功。 增加数据结构修正功能
161
162
163
  end
  
  return RoleTask