diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index 6ee3d7a..d5025ca 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -50,6 +50,7 @@ actionCodes = { Hang_endBattleRpc = 254, Hang_roleFormatRpc = 255, Hang_getRewardRpc = 256, + Hang_quickRpc = 257, } diff --git a/src/actions/HangAction.lua b/src/actions/HangAction.lua index edc585e..9c3b0fd 100644 --- a/src/actions/HangAction.lua +++ b/src/actions/HangAction.lua @@ -24,11 +24,11 @@ local function checkReward(role) local carbonData = csvdb["idle_battleCsv"][hangInfo.carbonId] local nowTime = math.min(skynet.timex(), hangInfo.endTime or 0) - local coinCount = math.max(0, math.floor((nowTime - hangInfo.coinTime) / 5)) - hangInfo.coinTime = hangInfo.coinTime + coinCount * 5 + local coinCount = math.max(0, math.floor((nowTime - hangInfo.coinTime) / globalCsv.idle_money_produce_cd)) + hangInfo.coinTime = hangInfo.coinTime + coinCount * globalCsv.idle_money_produce_cd - local itemCount = math.max(0, math.floor((nowTime - hangInfo.itemTime) / 60)) - hangInfo.itemTime = hangInfo.itemTime + itemCount * 60 + local itemCount = math.max(0, math.floor((nowTime - hangInfo.itemTime) / globalCsv.idle_item_produce_cd)) + hangInfo.itemTime = hangInfo.itemTime + itemCount * globalCsv.idle_item_produce_cd local items = role:getProperty("hangBag") items[ItemId.Gold] = (items[ItemId.Gold] or 0) + coinCount * carbonData.money @@ -38,9 +38,20 @@ local function checkReward(role) for _, temp in pairs(carbonData.item:toArray()) do table.insert(pool, temp:toArray(true, "=")) end + local curTypeCount = 0 + for id, _ in pairs(items) do + if id ~= ItemId.Gold and id ~= ItemId.Exp then + curTypeCount = curTypeCount + 1 + end + end for i = 1, itemCount do local cur = pool[math.randWeight(pool, 3)] - items[cur[1]] = (items[cur[1]] or 0) + cur[2] + if items[cur[1]] or curTypeCount < role:getProperty("hangBagLimit") then + if not items[cur[1]] then + curTypeCount = curTypeCount + 1 + end + items[cur[1]] = (items[cur[1]] or 0) + cur[2] + end end if coinCount > 0 or itemCount > 0 then @@ -72,7 +83,7 @@ function _M.startRpc( agent, data ) hangInfo.coinTime = nowTime hangInfo.itemTime = nowTime if isNew then - hangInfo.endTime = nowTime + 12 * 3600 + hangInfo.endTime = nowTime + globalCsv.idle_producetime_max end if not hangPass[carbonId] then hangInfo.bossTime = nowTime + carbonData.idle_time @@ -128,16 +139,13 @@ function _M.endBattleRpc(agent, data) -- reward reward = {} - local items = role:getProperty("hangBag") local carbonData = csvdb["idle_battleCsv"][hangInfo.carbonId] - items[ItemId.Gold] = (items[ItemId.Gold] or 0) + carbonData.money_clear - items[ItemId.Exp] = (items[ItemId.Exp] or 0) + carbonData.exp_clear reward[ItemId.Gold] = carbonData.money_clear reward[ItemId.Exp] = carbonData.exp_clear for itemId, count in pairs(carbonData.item_clear:toNumMap()) do - items[itemId] = (items[itemId] or 0) + count reward[itemId] = count end + reward = role:award(reward, {}) end hangInfo.key = nil role:updateProperty({field = "hangInfo", value = hangInfo}) @@ -178,7 +186,7 @@ function _M.getRewardRpc(agent , data) table.clear(items) local hangInfo = role:getProperty("hangInfo") local nowTime = skynet.timex() - hangInfo.endTime = nowTime + 12 * 3600 + hangInfo.endTime = nowTime + globalCsv.idle_producetime_max hangInfo.coinTime = nowTime hangInfo.itemTime = nowTime role:updateProperty({field = "hangBag", value = items}) @@ -190,4 +198,47 @@ function _M.getRewardRpc(agent , data) return true end + +function _M.quickRpc(agent , data) + local role = agent.role + + local hangInfo = role:getProperty("hangInfo") + if not hangInfo.carbonId then return end + local carbonData = csvdb["idle_battleCsv"][hangInfo.carbonId] + + local curCount = role.dailyData:getProperty("hangQC") + 1 + local costs = globalCsv.idle_quickproduce_cost:toArray(true, "=") + if not costs[curCount] then return end + if costs[curCount] > 0 then + if not role:checkItemEnough({[ItemId.Diamond] = costs[curCount]}) then return end + role:costItems({[ItemId.Diamond] = costs[curCount]}, {}) + end + + role.dailyData:updateProperty({field = "hangQC", value = curCount}) + + local time = globalCsv.idle_quickproduce_time + local reward = {} + + local coinCount = math.floor(time / globalCsv.idle_money_produce_cd) + local itemCount = math.floor(time / globalCsv.idle_item_produce_cd) + reward[ItemId.Gold] = (reward[ItemId.Gold] or 0) + coinCount * carbonData.money + reward[ItemId.Exp] = (reward[ItemId.Exp] or 0) + coinCount * carbonData.exp + + local pool = {} + for _, temp in pairs(carbonData.item:toArray()) do + table.insert(pool, temp:toArray(true, "=")) + end + for i = 1, itemCount do + local cur = pool[math.randWeight(pool, 3)] + reward[cur[1]] = (reward[cur[1]] or 0) + cur[2] + end + + reward = role:award(reward, {}) + + SendPacket(actionCodes.Hang_quickRpc, MsgPack.pack({ + reward = reward + })) + return true +end + return _M \ No newline at end of file diff --git a/src/models/Daily.lua b/src/models/Daily.lua index 874794b..1dcd79b 100644 --- a/src/models/Daily.lua +++ b/src/models/Daily.lua @@ -8,6 +8,7 @@ end Daily.schema = { commentHero = {"string", ""}, --单日评论食灵记录 type=1 + hangQC ={"number", 0}, -- 挂机快速次数 } function Daily:updateProperty(params) @@ -41,6 +42,7 @@ end function Daily:data() return { -- dailyTaskStatus = self:getProperty("dailyTaskStatus"), + hangQC = self:getProperty("hangQC"), } end diff --git a/src/models/Role.lua b/src/models/Role.lua index 6fbcb25..057a31c 100644 --- a/src/models/Role.lua +++ b/src/models/Role.lua @@ -31,8 +31,6 @@ Role.schema = { -- roleInfo level = {"number", 0}, - diamond = {"number", 0}, - reDiamond = {"number", 0}, items = {"string", ""}, loveStatus = {"string", ""}, --统计角色的最高 好感度等级 类型相关 -- type=loveL type=loveL @@ -47,7 +45,7 @@ Role.schema = { hangTeam = {"table", {}}, -- 挂机队伍 hangInfo = {"table", {}}, -- 当前挂机信息 hangBag = {"table", {}}, -- 背包 - hangBagLimit = {"number", 10}, --背包上限 + hangBagLimit = {"number", globalCsv.idle_field_origin}, --背包上限 } @@ -147,8 +145,6 @@ function Role:data() id = self:getProperty("id"), name = self:getProperty("name"), level = self:getProperty("level"), - diamond = self:getProperty("diamond"), - reDiamond = self:getProperty("reDiamond"), items = self:getProperty("items"):toNumMap(), loveStatus = self:getProperty("loveStatus"):toNumMap(), -- libgit2 0.21.2