Commit 9962b061fa40582d9c186888aa71bcddab4e8f96

Authored by zhouahaihai
1 parent 5af8b4aa

补充 挂机

src/ProtocolCode.lua
... ... @@ -50,6 +50,7 @@ actionCodes = {
50 50 Hang_endBattleRpc = 254,
51 51 Hang_roleFormatRpc = 255,
52 52 Hang_getRewardRpc = 256,
  53 + Hang_quickRpc = 257,
53 54  
54 55 }
55 56  
... ...
src/actions/HangAction.lua
... ... @@ -24,11 +24,11 @@ local function checkReward(role)
24 24 local carbonData = csvdb["idle_battleCsv"][hangInfo.carbonId]
25 25 local nowTime = math.min(skynet.timex(), hangInfo.endTime or 0)
26 26  
27   - local coinCount = math.max(0, math.floor((nowTime - hangInfo.coinTime) / 5))
28   - hangInfo.coinTime = hangInfo.coinTime + coinCount * 5
  27 + local coinCount = math.max(0, math.floor((nowTime - hangInfo.coinTime) / globalCsv.idle_money_produce_cd))
  28 + hangInfo.coinTime = hangInfo.coinTime + coinCount * globalCsv.idle_money_produce_cd
29 29  
30   - local itemCount = math.max(0, math.floor((nowTime - hangInfo.itemTime) / 60))
31   - hangInfo.itemTime = hangInfo.itemTime + itemCount * 60
  30 + local itemCount = math.max(0, math.floor((nowTime - hangInfo.itemTime) / globalCsv.idle_item_produce_cd))
  31 + hangInfo.itemTime = hangInfo.itemTime + itemCount * globalCsv.idle_item_produce_cd
32 32  
33 33 local items = role:getProperty("hangBag")
34 34 items[ItemId.Gold] = (items[ItemId.Gold] or 0) + coinCount * carbonData.money
... ... @@ -38,9 +38,20 @@ local function checkReward(role)
38 38 for _, temp in pairs(carbonData.item:toArray()) do
39 39 table.insert(pool, temp:toArray(true, "="))
40 40 end
  41 + local curTypeCount = 0
  42 + for id, _ in pairs(items) do
  43 + if id ~= ItemId.Gold and id ~= ItemId.Exp then
  44 + curTypeCount = curTypeCount + 1
  45 + end
  46 + end
41 47 for i = 1, itemCount do
42 48 local cur = pool[math.randWeight(pool, 3)]
43   - items[cur[1]] = (items[cur[1]] or 0) + cur[2]
  49 + if items[cur[1]] or curTypeCount < role:getProperty("hangBagLimit") then
  50 + if not items[cur[1]] then
  51 + curTypeCount = curTypeCount + 1
  52 + end
  53 + items[cur[1]] = (items[cur[1]] or 0) + cur[2]
  54 + end
44 55 end
45 56  
46 57 if coinCount > 0 or itemCount > 0 then
... ... @@ -72,7 +83,7 @@ function _M.startRpc( agent, data )
72 83 hangInfo.coinTime = nowTime
73 84 hangInfo.itemTime = nowTime
74 85 if isNew then
75   - hangInfo.endTime = nowTime + 12 * 3600
  86 + hangInfo.endTime = nowTime + globalCsv.idle_producetime_max
76 87 end
77 88 if not hangPass[carbonId] then
78 89 hangInfo.bossTime = nowTime + carbonData.idle_time
... ... @@ -128,16 +139,13 @@ function _M.endBattleRpc(agent, data)
128 139  
129 140 -- reward
130 141 reward = {}
131   - local items = role:getProperty("hangBag")
132 142 local carbonData = csvdb["idle_battleCsv"][hangInfo.carbonId]
133   - items[ItemId.Gold] = (items[ItemId.Gold] or 0) + carbonData.money_clear
134   - items[ItemId.Exp] = (items[ItemId.Exp] or 0) + carbonData.exp_clear
135 143 reward[ItemId.Gold] = carbonData.money_clear
136 144 reward[ItemId.Exp] = carbonData.exp_clear
137 145 for itemId, count in pairs(carbonData.item_clear:toNumMap()) do
138   - items[itemId] = (items[itemId] or 0) + count
139 146 reward[itemId] = count
140 147 end
  148 + reward = role:award(reward, {})
141 149 end
142 150 hangInfo.key = nil
143 151 role:updateProperty({field = "hangInfo", value = hangInfo})
... ... @@ -178,7 +186,7 @@ function _M.getRewardRpc(agent , data)
178 186 table.clear(items)
179 187 local hangInfo = role:getProperty("hangInfo")
180 188 local nowTime = skynet.timex()
181   - hangInfo.endTime = nowTime + 12 * 3600
  189 + hangInfo.endTime = nowTime + globalCsv.idle_producetime_max
182 190 hangInfo.coinTime = nowTime
183 191 hangInfo.itemTime = nowTime
184 192 role:updateProperty({field = "hangBag", value = items})
... ... @@ -190,4 +198,47 @@ function _M.getRewardRpc(agent , data)
190 198 return true
191 199 end
192 200  
  201 +
  202 +function _M.quickRpc(agent , data)
  203 + local role = agent.role
  204 +
  205 + local hangInfo = role:getProperty("hangInfo")
  206 + if not hangInfo.carbonId then return end
  207 + local carbonData = csvdb["idle_battleCsv"][hangInfo.carbonId]
  208 +
  209 + local curCount = role.dailyData:getProperty("hangQC") + 1
  210 + local costs = globalCsv.idle_quickproduce_cost:toArray(true, "=")
  211 + if not costs[curCount] then return end
  212 + if costs[curCount] > 0 then
  213 + if not role:checkItemEnough({[ItemId.Diamond] = costs[curCount]}) then return end
  214 + role:costItems({[ItemId.Diamond] = costs[curCount]}, {})
  215 + end
  216 +
  217 + role.dailyData:updateProperty({field = "hangQC", value = curCount})
  218 +
  219 + local time = globalCsv.idle_quickproduce_time
  220 + local reward = {}
  221 +
  222 + local coinCount = math.floor(time / globalCsv.idle_money_produce_cd)
  223 + local itemCount = math.floor(time / globalCsv.idle_item_produce_cd)
  224 + reward[ItemId.Gold] = (reward[ItemId.Gold] or 0) + coinCount * carbonData.money
  225 + reward[ItemId.Exp] = (reward[ItemId.Exp] or 0) + coinCount * carbonData.exp
  226 +
  227 + local pool = {}
  228 + for _, temp in pairs(carbonData.item:toArray()) do
  229 + table.insert(pool, temp:toArray(true, "="))
  230 + end
  231 + for i = 1, itemCount do
  232 + local cur = pool[math.randWeight(pool, 3)]
  233 + reward[cur[1]] = (reward[cur[1]] or 0) + cur[2]
  234 + end
  235 +
  236 + reward = role:award(reward, {})
  237 +
  238 + SendPacket(actionCodes.Hang_quickRpc, MsgPack.pack({
  239 + reward = reward
  240 + }))
  241 + return true
  242 +end
  243 +
193 244 return _M
194 245 \ No newline at end of file
... ...
src/models/Daily.lua
... ... @@ -8,6 +8,7 @@ end
8 8  
9 9 Daily.schema = {
10 10 commentHero = {"string", ""}, --单日评论食灵记录 type=1
  11 + hangQC ={"number", 0}, -- 挂机快速次数
11 12 }
12 13  
13 14 function Daily:updateProperty(params)
... ... @@ -41,6 +42,7 @@ end
41 42 function Daily:data()
42 43 return {
43 44 -- dailyTaskStatus = self:getProperty("dailyTaskStatus"),
  45 + hangQC = self:getProperty("hangQC"),
44 46 }
45 47 end
46 48  
... ...
src/models/Role.lua
... ... @@ -31,8 +31,6 @@ Role.schema = {
31 31  
32 32 -- roleInfo
33 33 level = {"number", 0},
34   - diamond = {"number", 0},
35   - reDiamond = {"number", 0},
36 34 items = {"string", ""},
37 35 loveStatus = {"string", ""}, --统计角色的最高 好感度等级 类型相关 -- type=loveL type=loveL
38 36  
... ... @@ -47,7 +45,7 @@ Role.schema = {
47 45 hangTeam = {"table", {}}, -- 挂机队伍
48 46 hangInfo = {"table", {}}, -- 当前挂机信息
49 47 hangBag = {"table", {}}, -- 背包
50   - hangBagLimit = {"number", 10}, --背包上限
  48 + hangBagLimit = {"number", globalCsv.idle_field_origin}, --背包上限
51 49  
52 50 }
53 51  
... ... @@ -147,8 +145,6 @@ function Role:data()
147 145 id = self:getProperty("id"),
148 146 name = self:getProperty("name"),
149 147 level = self:getProperty("level"),
150   - diamond = self:getProperty("diamond"),
151   - reDiamond = self:getProperty("reDiamond"),
152 148 items = self:getProperty("items"):toNumMap(),
153 149 loveStatus = self:getProperty("loveStatus"):toNumMap(),
154 150  
... ...