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
|
d232676a
zhouhaihai
功能解锁 冒险返回
|
26
27
|
if not role:isFuncUnlock(FuncUnlock.Tower) then return end
|
276b1da9
zhouhaihai
爬塔接口
|
28
29
30
|
local towerInfo = role:getProperty("towerInfo")
|
a2f78911
zhouhaihai
垃圾判断
|
31
|
if towerInfo.l ~= id then return end -- 层数不对
|
276b1da9
zhouhaihai
爬塔接口
|
32
33
34
|
if not csvdb["tower_battleCsv"][id] then return end
local curCount, nextTime = getUpdateTime(towerInfo.c, towerInfo.t)
|
498ca200
liuzujun
取消爬塔次数
|
35
|
--if curCount < 1 then return end -- 没有次数返回
|
276b1da9
zhouhaihai
爬塔接口
|
36
37
38
|
--搞起来
towerInfo.c = curCount - 1
|
81a00cac
zhouhaihai
爬塔买满次数
|
39
40
41
|
if curCount == globalCsv.tower_count_limit then --满的情况下的消耗了 恢复时间从当下开始
nextTime = skynet.timex()
end
|
276b1da9
zhouhaihai
爬塔接口
|
42
43
44
45
46
|
towerInfo.t = nextTime
local key = tostring(math.random())
towerInfo.k = key
role:updateProperty({field = "towerInfo", value = towerInfo})
|
53e8037e
zhouhaihai
任务
|
47
|
role:checkTaskEnter("TowerBattle", {level = towerInfo.l})
|
f22a33af
zhouhaihai
自己的日志
|
48
|
role:mylog("tower_action", {desc = "startBattle", int1 = id})
|
276b1da9
zhouhaihai
爬塔接口
|
49
50
51
52
53
54
55
56
57
58
59
60
|
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")
|
d6a66c74
zhouhaihai
校验失败也返回
|
61
62
63
64
|
if towerInfo.l ~= id or not towerInfo.k or towerInfo.k ~= key then
SendPacket(actionCodes.Tower_endBattleRpc, MsgPack.pack({errorCode = 1}))
return true
end
|
276b1da9
zhouhaihai
爬塔接口
|
65
|
local curTower = csvdb["tower_battleCsv"][id]
|
50ecb4c1
zhouhaihai
增加return 判断
|
66
|
if not curTower then return 2 end
|
276b1da9
zhouhaihai
爬塔接口
|
67
|
|
edf2ee12
zhouhaihai
防作弊
|
68
69
70
71
72
73
74
75
76
|
-- 防作弊
if not role:checkBattleCheat("tower", {
isWin = msg.starNum and msg.starNum > 0,
info = msg.info
}) then
SendPacket(actionCodes.Tower_endBattleRpc, MsgPack.pack({errorCode = 1}))
return true
end
|
276b1da9
zhouhaihai
爬塔接口
|
77
78
79
|
local curCount, nextTime = getUpdateTime(towerInfo.c, towerInfo.t)
|
7bb30dca
zhouhaihai
修改发奖
|
80
|
local reward, change
|
276b1da9
zhouhaihai
爬塔接口
|
81
82
|
if msg.starNum and msg.starNum > 0 then --win
curCount = math.min(curCount + 1, globalCsv.tower_count_limit) -- 返还次数
|
59835765
zhouhaihai
排行榜
|
83
84
85
|
--排行榜
role:setTowerRank(towerInfo.l)
|
276b1da9
zhouhaihai
爬塔接口
|
86
|
towerInfo.l = towerInfo.l + 1
|
7bb30dca
zhouhaihai
修改发奖
|
87
|
reward, change = role:award(curTower.reward, {log = {desc = "towerBattle", int1 = id}})
|
53e8037e
zhouhaihai
任务
|
88
|
role:checkTaskEnter("TowerPass", {level = towerInfo.l - 1})
|
276b1da9
zhouhaihai
爬塔接口
|
89
90
91
92
93
94
|
end
towerInfo.c = curCount
towerInfo.t = nextTime
towerInfo.k = nil
role:updateProperty({field = "towerInfo", value = towerInfo})
|
3133cb76
zhouhaihai
日志
|
95
|
|
d4e9b817
zhouhaihai
战斗 日志
|
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
local rank = redisproxy:ZREVRANK(RANK_TOWER, role:getProperty("id"))
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,
})
|
f22a33af
zhouhaihai
自己的日志
|
110
|
role:mylog("tower_action", {desc = "endBattle", short1 = msg.starNum > 0 and 1 or 0, int1 = id})
|
d4e9b817
zhouhaihai
战斗 日志
|
111
|
|
7bb30dca
zhouhaihai
修改发奖
|
112
|
SendPacket(actionCodes.Tower_endBattleRpc, MsgPack.pack({reward = reward, change = change}))
|
276b1da9
zhouhaihai
爬塔接口
|
113
114
115
|
return true
end
|
81a00cac
zhouhaihai
爬塔买满次数
|
116
117
|
function _M.bugCountRpc(agent, data)
local role = agent.role
|
498ca200
liuzujun
取消爬塔次数
|
118
119
|
local msg = MsgPack.unpack(data)
local buyCount = msg.count
|
81a00cac
zhouhaihai
爬塔买满次数
|
120
121
122
123
|
local towerInfo = role:getProperty("towerInfo")
local curCount, nextTime = getUpdateTime(towerInfo.c, towerInfo.t)
local needCount = globalCsv.tower_count_limit - curCount
|
498ca200
liuzujun
取消爬塔次数
|
124
125
126
|
if needCount > buyCount then
needCount = buyCount
end
|
81a00cac
zhouhaihai
爬塔买满次数
|
127
128
129
130
131
132
|
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
日志
|
133
|
role:costItems(cost, {log = {desc = "towerCount"}})
|
498ca200
liuzujun
取消爬塔次数
|
134
|
curCount = curCount + needCount
|
81a00cac
zhouhaihai
爬塔买满次数
|
135
136
137
138
|
end
towerInfo.c = curCount
towerInfo.t = nextTime
role:updateProperty({field = "towerInfo", value = towerInfo})
|
f22a33af
zhouhaihai
自己的日志
|
139
|
role:mylog("tower_action", {desc = "bugCount"})
|
81a00cac
zhouhaihai
爬塔买满次数
|
140
141
142
|
SendPacket(actionCodes.Tower_bugCountRpc, '')
return true
end
|
276b1da9
zhouhaihai
爬塔接口
|
143
144
145
|
function _M.rankRpc(agent , data)
local role = agent.role
|
59835765
zhouhaihai
排行榜
|
146
147
148
|
SendPacket(actionCodes.Tower_rankRpc, MsgPack.pack(role:getTowerRank()))
return true
end
|
276b1da9
zhouhaihai
爬塔接口
|
149
|
|
59835765
zhouhaihai
排行榜
|
150
151
152
153
154
|
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
爬塔接口
|
155
156
157
158
|
return true
end
return _M
|