Blame view

src/actions/TowerAction.lua 4.18 KB
276b1da9   zhouhaihai   爬塔接口
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  local ipairs = ipairs
  local table = table
  local math = math
  local redisproxy = redisproxy
  local MsgPack = MsgPack
  
  
  local _M = {}
  
  
  function _M.roleFormatRpc(agent , data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local towerTeam = role:getProperty("towerF")
  	for slot, heroId in pairs(msg.heros) do
  		if not role.heros[heroId] then
  			return
  		end
  	end
f603a60f   zhouhaihai   支援技实装
20
21
22
23
24
25
26
  	local supports = {}
  	for slot, support in pairs(msg.supports) do
  		if slot ~= 1 and slot ~= 2 then return end
  		local level = role.dinerData:getProperty("dishTree"):getv(support, 0)
  		if level <= 0 then return end
  		supports[slot] = support
  	end
276b1da9   zhouhaihai   爬塔接口
27
28
29
30
31
32
  	table.clear(towerTeam)
  	towerTeam.heros = {}
  	for slot, heroId in pairs(msg.heros) do
  		towerTeam.heros[slot] = heroId
  	end
  	towerTeam.leader = msg.leader
f603a60f   zhouhaihai   支援技实装
33
  	towerTeam.supports = supports
276b1da9   zhouhaihai   爬塔接口
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
  
  	role:updateProperty({field = "towerF", value = towerTeam}) 
  	SendPacket(actionCodes.Tower_roleFormatRpc, '')
  	return true
  end
  
  
  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
  
  	local towerInfo = role:getProperty("towerInfo")
  
a2f78911   zhouhaihai   垃圾判断
58
  	if towerInfo.l ~= id then return end  -- 层数不对
276b1da9   zhouhaihai   爬塔接口
59
60
61
62
63
64
65
  
  	if not csvdb["tower_battleCsv"][id] then return end
  	local curCount, nextTime = getUpdateTime(towerInfo.c, towerInfo.t)
  	if curCount < 1 then return end -- 没有次数返回
  
  	--搞起来
  	towerInfo.c = curCount - 1
81a00cac   zhouhaihai   爬塔买满次数
66
67
68
  	if curCount == globalCsv.tower_count_limit then --满的情况下的消耗了 恢复时间从当下开始
  		nextTime = skynet.timex()
  	end
276b1da9   zhouhaihai   爬塔接口
69
70
71
72
73
  	towerInfo.t = nextTime
  	local key = tostring(math.random())
  	towerInfo.k = key
  
  	role:updateProperty({field = "towerInfo", value = towerInfo})
53e8037e   zhouhaihai   任务
74
  	role:checkTaskEnter("TowerBattle", {level = towerInfo.l})
276b1da9   zhouhaihai   爬塔接口
75
76
77
78
79
80
81
82
83
84
85
86
  	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
  
  	local towerInfo = role:getProperty("towerInfo")
50ecb4c1   zhouhaihai   增加return 判断
87
  	if towerInfo.l ~= id or not towerInfo.k or towerInfo.k ~= key then return 1 end
276b1da9   zhouhaihai   爬塔接口
88
  	local curTower = csvdb["tower_battleCsv"][id] 
50ecb4c1   zhouhaihai   增加return 判断
89
  	if not curTower then return 2 end
276b1da9   zhouhaihai   爬塔接口
90
91
92
93
94
95
96
  
  	local curCount, nextTime = getUpdateTime(towerInfo.c, towerInfo.t)
  
  
  	local reward
  	if msg.starNum and msg.starNum > 0 then --win
  		curCount = math.min(curCount + 1, globalCsv.tower_count_limit) -- 返还次数
59835765   zhouhaihai   排行榜
97
98
99
  		--排行榜
  		role:setTowerRank(towerInfo.l)
  
276b1da9   zhouhaihai   爬塔接口
100
101
  		towerInfo.l = towerInfo.l + 1
  		reward = role:award(curTower.reward)
53e8037e   zhouhaihai   任务
102
  		role:checkTaskEnter("TowerPass", {level = towerInfo.l - 1})
276b1da9   zhouhaihai   爬塔接口
103
104
105
106
107
108
109
110
111
112
  	end
  
  	towerInfo.c = curCount
  	towerInfo.t = nextTime
  	towerInfo.k = nil
  	role:updateProperty({field = "towerInfo", value = towerInfo})
  	SendPacket(actionCodes.Tower_endBattleRpc, MsgPack.pack({reward = reward}))
  	return true
  end
  
81a00cac   zhouhaihai   爬塔买满次数
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
  function _M.bugCountRpc(agent, data)
  	local role = agent.role
  
  	local towerInfo = role:getProperty("towerInfo")
  	local curCount, nextTime = getUpdateTime(towerInfo.c, towerInfo.t)
  	local needCount = globalCsv.tower_count_limit - curCount
  	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
  		role:costItems(cost)
  		curCount = globalCsv.tower_count_limit
  	end
  	towerInfo.c = curCount
  	towerInfo.t = nextTime
  	role:updateProperty({field = "towerInfo", value = towerInfo})
  	SendPacket(actionCodes.Tower_bugCountRpc, '')
  	return true
  end
276b1da9   zhouhaihai   爬塔接口
134
135
136
  
  function _M.rankRpc(agent , data)
  	local role = agent.role
59835765   zhouhaihai   排行榜
137
138
139
  	SendPacket(actionCodes.Tower_rankRpc, MsgPack.pack(role:getTowerRank()))
  	return true
  end
276b1da9   zhouhaihai   爬塔接口
140
  
59835765   zhouhaihai   排行榜
141
142
143
144
145
  function _M.rankInfoRpc(agent , data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local roleId = msg.roleId
  	SendPacket(actionCodes.Tower_rankInfoRpc, MsgPack.pack({format = role:getTowerRankOneInfo(roleId)}))
276b1da9   zhouhaihai   爬塔接口
146
147
148
149
  	return true
  end
  
  return _M