276b1da9
 
  zhouhaihai
 
爬塔接口
 | 
1
2
3
4
5
6
7
8
9
10 
 | 
  local ipairs = ipairs
  local table = table
  local math = math
  local redisproxy = redisproxy
  local MsgPack = MsgPack
  
  
  local _M = {}
  
  
 
 | 
276b1da9
 
  zhouhaihai
 
爬塔接口
 | 
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 
 | 
  
  local function getUpdateTime(lastCount, lastTime)
  	local nextCount, nextTime = lastCount, skynet.timex()
  	if lastTime then
  		local addCount = math.floor((skynet.timex() - lastTime) / (globalCsv.tower_count_up * 60))
  		nextCount = math.min(lastCount + addCount, globalCsv.tower_count_limit)
  		nextTime = lastTime + addCount * (globalCsv.tower_count_up * 60)
  	end
  	return nextCount, nextTime
  end
  
  function _M.startBattleRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local id = msg.id
 
 | 
03c619fb
 
  chenyueqi
 
电波塔属性塔功能部分功能草稿
 | 
26
27 
 | 
  	local towerType = math.floor(id / 10000)
  
 
 | 
761b3ea8
 
  chenyueqi
 
再改一波电波塔整容相关信息
 | 
28 
 | 
  	if not id or towerType < 0 or towerType > 3 then return 0 end
 
 | 
03c619fb
 
  chenyueqi
 
电波塔属性塔功能部分功能草稿
 | 
29 
 | 
  	if not role:isFuncUnlock(FuncUnlock.Tower) then return 1 end
 
 | 
276b1da9
 
  zhouhaihai
 
爬塔接口
 | 
30
31
32 
 | 
  
  	local towerInfo = role:getProperty("towerInfo")
  
 
 | 
03c619fb
 
  chenyueqi
 
电波塔属性塔功能部分功能草稿
 | 
33 
 | 
  	if towerType == 0 and (towerInfo.l or 1) ~= id then return 2 end  -- 层数不对
 
 | 
27dd1a36
 
  chenyueqi
 
电波塔分塔开放条件读表
 | 
34
35
36 
 | 
  	if towerType == 1 and ((towerInfo.l1 or 10001) ~= id or (towerInfo.l or 1) <= globalCsv.tower_open[towerType]) then return 2 end  -- 层数不对
  	if towerType == 2 and ((towerInfo.l2 or 20001) ~= id or (towerInfo.l or 1) <= globalCsv.tower_open[towerType]) then return 2 end  -- 层数不对
  	if towerType == 3 and ((towerInfo.l3 or 30001) ~= id or (towerInfo.l or 1) <= globalCsv.tower_open[towerType]) then return 2 end  -- 层数不对
 
 | 
276b1da9
 
  zhouhaihai
 
爬塔接口
 | 
37 
 | 
  
 
 | 
761b3ea8
 
  chenyueqi
 
再改一波电波塔整容相关信息
 | 
38
39
40
41
42
43
44
45
46
47
48
49
50
51 
 | 
  	if not csvdb["tower_battleCsv"][id] then return 4 end
  
  	local teams = role:getTowerTeamFormat(towerType + 1)
  	if not next(teams) then return 5 end
  
  	if towerType ~= 0 then
  		for _, heroId in pairs(teams.heros) do
  			local hero = role.heros[heroId]
  			if not hero then return 6 end
  			local unit = csvdb["unitCsv"][hero:getProperty("type")]
  			if unit.camp ~= towerType then return 7 end
  		end
  	end
  
 
 | 
276b1da9
 
  zhouhaihai
 
爬塔接口
 | 
52 
 | 
  	local curCount, nextTime = getUpdateTime(towerInfo.c, towerInfo.t)
 
 | 
498ca200
 
  测试
 
取消爬塔次数
 | 
53 
 | 
  	--if curCount < 1 then return end -- 没有次数返回
 
 | 
276b1da9
 
  zhouhaihai
 
爬塔接口
 | 
54
55
56 
 | 
  
  	--搞起来
  	towerInfo.c = curCount - 1
 
 | 
81a00cac
 
  zhouhaihai
 
爬塔买满次数
 | 
57
58
59 
 | 
  	if curCount == globalCsv.tower_count_limit then --满的情况下的消耗了 恢复时间从当下开始
  		nextTime = skynet.timex()
  	end
 
 | 
276b1da9
 
  zhouhaihai
 
爬塔接口
 | 
60
61
62
63
64 
 | 
  	towerInfo.t = nextTime
  	local key = tostring(math.random())
  	towerInfo.k = key
  
  	role:updateProperty({field = "towerInfo", value = towerInfo})
 
 | 
53e8037e
 
  zhouhaihai
 
任务
 | 
65 
 | 
  	role:checkTaskEnter("TowerBattle", {level = towerInfo.l})
 
 | 
f22a33af
 
  zhouhaihai
 
自己的日志
 | 
66 
 | 
  	role:mylog("tower_action", {desc = "startBattle", int1 = id})
 
 | 
276b1da9
 
  zhouhaihai
 
爬塔接口
 | 
67
68
69
70
71
72
73
74
75
76
77 
 | 
  	SendPacket(actionCodes.Tower_startBattleRpc, '')
  	return true
  end
  
  function _M.endBattleRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local id = msg.id
  	local key = msg.key
  	local passTime = msg.passTime
  
 
 | 
03c619fb
 
  chenyueqi
 
电波塔属性塔功能部分功能草稿
 | 
78
79
80 
 | 
  	local curTower = csvdb["tower_battleCsv"][id] 
  	if not curTower then return 2 end
  
 
 | 
4ee2fe31
 
  chenyueqi
 
电波塔bug
 | 
81 
 | 
  	local towerInfo = role:getProperty("towerInfo")
 
 | 
03c619fb
 
  chenyueqi
 
电波塔属性塔功能部分功能草稿
 | 
82
83
84
85 
 | 
  	local towerType = math.floor(id / 10000)
  	local towerLevel = {[0] = (towerInfo.l or 1), [1] = (towerInfo.l1 or 10001), [2] = (towerInfo.l2 or 20001), [3] = (towerInfo.l3 or 30001)}
  	local curLevel = towerLevel[towerType]
  
 
 | 
03c619fb
 
  chenyueqi
 
电波塔属性塔功能部分功能草稿
 | 
86 
 | 
  	if curLevel ~= id or not towerInfo.k or towerInfo.k ~= key then 
 
 | 
d6a66c74
 
  zhouhaihai
 
校验失败也返回
 | 
87
88
89 
 | 
  		SendPacket(actionCodes.Tower_endBattleRpc, MsgPack.pack({errorCode = 1}))
  		return true
  	end
 
 | 
276b1da9
 
  zhouhaihai
 
爬塔接口
 | 
90 
 | 
  
 
 | 
edf2ee12
 
  zhouhaihai
 
防作弊
 | 
91
92
93 
 | 
  	-- 防作弊
  	if not role:checkBattleCheat("tower", {
  		isWin = msg.starNum and msg.starNum > 0,
 
 | 
761b3ea8
 
  chenyueqi
 
再改一波电波塔整容相关信息
 | 
94
95 
 | 
  		info = msg.info,
  		tower = towerType + 1
 
 | 
edf2ee12
 
  zhouhaihai
 
防作弊
 | 
96
97
98
99
100 
 | 
  	}) then
  		SendPacket(actionCodes.Tower_endBattleRpc, MsgPack.pack({errorCode = 1}))
  		return true
  	end
  
 
 | 
276b1da9
 
  zhouhaihai
 
爬塔接口
 | 
101
102
103 
 | 
  	local curCount, nextTime = getUpdateTime(towerInfo.c, towerInfo.t)
  
  
 
 | 
7bb30dca
 
  zhouhaihai
 
修改发奖
 | 
104 
 | 
  	local reward, change
 
 | 
276b1da9
 
  zhouhaihai
 
爬塔接口
 | 
105
106 
 | 
  	if msg.starNum and msg.starNum > 0 then --win
  		curCount = math.min(curCount + 1, globalCsv.tower_count_limit) -- 返还次数
 
 | 
59835765
 
  zhouhaihai
 
排行榜
 | 
107 
 | 
  		--排行榜
 
 | 
4ee2fe31
 
  chenyueqi
 
电波塔bug
 | 
108 
 | 
  		role:setTowerRank(curLevel % 10000, towerType + 1)
 
 | 
59835765
 
  zhouhaihai
 
排行榜
 | 
109 
 | 
  
 
 | 
03c619fb
 
  chenyueqi
 
电波塔属性塔功能部分功能草稿
 | 
110 
 | 
  		curLevel = curLevel + 1
 
 | 
7bb30dca
 
  zhouhaihai
 
修改发奖
 | 
111 
 | 
  		reward, change = role:award(curTower.reward, {log = {desc = "towerBattle", int1 = id}})
 
 | 
8864df66
 
  chenyueqi
 
电波塔检查任务参数错误
 | 
112
113
114 
 | 
  		if towerType == 0 then
  			role:checkTaskEnter("TowerPass", {level = towerInfo.l})
  		end
 
 | 
03c619fb
 
  chenyueqi
 
电波塔属性塔功能部分功能草稿
 | 
115
116
117
118
119
120
121
122
123
124 
 | 
  	end
  
  	if towerType == 0 then
  		towerInfo.l = curLevel
  	elseif towerType == 1 then
  		towerInfo.l1 = curLevel
  	elseif towerType == 2 then
  		towerInfo.l2 = curLevel
  	elseif towerType == 3 then
  		towerInfo.l3 = curLevel
 
 | 
276b1da9
 
  zhouhaihai
 
爬塔接口
 | 
125
126
127
128
129
130 
 | 
  	end
  
  	towerInfo.c = curCount
  	towerInfo.t = nextTime
  	towerInfo.k = nil
  	role:updateProperty({field = "towerInfo", value = towerInfo})
 
 | 
3133cb76
 
  zhouhaihai
 
日志
 | 
131 
 | 
  
 
 | 
03c619fb
 
  chenyueqi
 
电波塔属性塔功能部分功能草稿
 | 
132
133
134 
 | 
  	local RankTower = {[0] = RANK_TOWER,[1] = RANK_TOWER1,[2] = RANK_TOWER2,[3] = RANK_TOWER3}
  	local rankName = RankTower[towerType]
  	local rank = redisproxy:ZREVRANK(rankName, role:getProperty("id"))
 
 | 
d4e9b817
 
  zhouhaihai
 
战斗 日志
 | 
135
136
137
138
139
140
141
142
143
144
145 
 | 
  	if not rank then
  		rank = -1
  	else
  		rank = rank + 1
  	end
  	role:checkBattle("tower", {
  		id = id,
  		isWin = msg.starNum and msg.starNum > 0,
  		info = msg.info,
  		reward = reward,
  		rank = rank,
 
 | 
761b3ea8
 
  chenyueqi
 
再改一波电波塔整容相关信息
 | 
146 
 | 
  		tower = towerType + 1
 
 | 
d4e9b817
 
  zhouhaihai
 
战斗 日志
 | 
147 
 | 
  	})
 
 | 
f22a33af
 
  zhouhaihai
 
自己的日志
 | 
148 
 | 
  	role:mylog("tower_action", {desc = "endBattle", short1 = msg.starNum > 0 and 1 or 0, int1 = id})
 
 | 
d4e9b817
 
  zhouhaihai
 
战斗 日志
 | 
149 
 | 
  
 
 | 
7bb30dca
 
  zhouhaihai
 
修改发奖
 | 
150 
 | 
  	SendPacket(actionCodes.Tower_endBattleRpc, MsgPack.pack({reward = reward, change = change}))
 
 | 
276b1da9
 
  zhouhaihai
 
爬塔接口
 | 
151
152
153 
 | 
  	return true
  end
  
 
 | 
81a00cac
 
  zhouhaihai
 
爬塔买满次数
 | 
154
155 
 | 
  function _M.bugCountRpc(agent, data)
  	local role = agent.role
 
 | 
498ca200
 
  测试
 
取消爬塔次数
 | 
156
157 
 | 
  	local msg = MsgPack.unpack(data)
  	local buyCount = msg.count
 
 | 
81a00cac
 
  zhouhaihai
 
爬塔买满次数
 | 
158
159
160
161 
 | 
  
  	local towerInfo = role:getProperty("towerInfo")
  	local curCount, nextTime = getUpdateTime(towerInfo.c, towerInfo.t)
  	local needCount = globalCsv.tower_count_limit - curCount
 
 | 
498ca200
 
  测试
 
取消爬塔次数
 | 
162
163
164 
 | 
  	if needCount > buyCount then
  		needCount = buyCount
  	end
 
 | 
81a00cac
 
  zhouhaihai
 
爬塔买满次数
 | 
165
166
167
168
169
170 
 | 
  	if needCount > 0 then -- 补充
  		local cost = globalCsv.tower_chance_item:toNumMap()
  		for k , v in pairs(cost) do
  			cost[k] = v * needCount
  		end
  		if not role:checkItemEnough(cost) then return end
 
 | 
3133cb76
 
  zhouhaihai
 
日志
 | 
171 
 | 
  		role:costItems(cost, {log = {desc = "towerCount"}})
 
 | 
498ca200
 
  测试
 
取消爬塔次数
 | 
172 
 | 
  		curCount = curCount + needCount
 
 | 
81a00cac
 
  zhouhaihai
 
爬塔买满次数
 | 
173
174
175
176 
 | 
  	end
  	towerInfo.c = curCount
  	towerInfo.t = nextTime
  	role:updateProperty({field = "towerInfo", value = towerInfo})
 
 | 
f22a33af
 
  zhouhaihai
 
自己的日志
 | 
177 
 | 
  	role:mylog("tower_action", {desc = "bugCount"})
 
 | 
81a00cac
 
  zhouhaihai
 
爬塔买满次数
 | 
178
179
180 
 | 
  	SendPacket(actionCodes.Tower_bugCountRpc, '')
  	return true
  end
 
 | 
276b1da9
 
  zhouhaihai
 
爬塔接口
 | 
181
182
183 
 | 
  
  function _M.rankRpc(agent , data)
  	local role = agent.role
 
 | 
03c619fb
 
  chenyueqi
 
电波塔属性塔功能部分功能草稿
 | 
184
185
186 
 | 
  	local msg = MsgPack.unpack(data)
  	local towerType = msg.tower or 1
  	SendPacket(actionCodes.Tower_rankRpc, MsgPack.pack(role:getTowerRank(towerType)))
 
 | 
59835765
 
  zhouhaihai
 
排行榜
 | 
187
188 
 | 
  	return true
  end
 
 | 
276b1da9
 
  zhouhaihai
 
爬塔接口
 | 
189 
 | 
  
 
 | 
59835765
 
  zhouhaihai
 
排行榜
 | 
190
191
192
193 
 | 
  function _M.rankInfoRpc(agent , data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local roleId = msg.roleId
 
 | 
03c619fb
 
  chenyueqi
 
电波塔属性塔功能部分功能草稿
 | 
194
195
196
197
198
199
200
201
202
203
204 
 | 
  	local towerType = msg.tower or 1
  	SendPacket(actionCodes.Tower_rankInfoRpc, MsgPack.pack({format = role:getTowerRankOneInfo(roleId, towerType)}))
  	return true
  end
  
  function _M.activeTowerBonusRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local tType = msg.tower
  	local id = msg.id
  
 
 | 
e50d0cae
 
  chenyueqi
 
计算电波塔层数的加成效果
 | 
205 
 | 
  	local bnousCsv = csvdb["tower_battle_additionCsv"]
 
 | 
03c619fb
 
  chenyueqi
 
电波塔属性塔功能部分功能草稿
 | 
206
207
208
209
210
211
212
213
214
215
216
217 
 | 
  
  	if not tType or not id or not bnousCsv[tType] then return 0 end
  	local bnousData = bnousCsv[tType][id]
  	if not bnousData then return 1 end
  
  	local towerInfo = role:getProperty("towerInfo")
  	local towerBnous = role:getProperty("towerBnous")
  
  	if towerBnous[tType] and towerBnous[tType][id] then return 2 end
  	local towerLevel = {[1] = (towerInfo.l or 1), [2] = (towerInfo.l1 or 10001), [3] = (towerInfo.l2 or 20001), [4] = (towerInfo.l3 or 30001)}
  	local curLevel = towerLevel[tType]
  	
 
 | 
4e9566f2
 
  chenyueqi
 
电波塔加成算法解析字段方法修正
 | 
218 
 | 
  	if tType ~= 1 then
 
 | 
fd18bc26
 
  chenyueqi
 
电波塔战斗激活消息bug
 | 
219 
 | 
  		if curLevel <= globalCsv.tower_open[tType - 1] then return 4 end
 
 | 
4e9566f2
 
  chenyueqi
 
电波塔加成算法解析字段方法修正
 | 
220
221
222 
 | 
  	end
  
  	if (curLevel % 10000) <= bnousData.floor then return 3 end
 
 | 
03c619fb
 
  chenyueqi
 
电波塔属性塔功能部分功能草稿
 | 
223
224
225
226
227
228
229
230 
 | 
  
  	if not towerBnous[tType] then
  		towerBnous[tType] = {}
  	end
  	towerBnous[tType][id] = 1
  	role:updateProperty({field = "towerBnous", value = towerBnous})
  	role:getTowerBnousActive(true)
  	SendPacket(actionCodes.Tower_activeTowerBonusRpc, '')
 
 | 
276b1da9
 
  zhouhaihai
 
爬塔接口
 | 
231
232
233
234 
 | 
  	return true
  end
  
  return _M
 
 |