diff --git a/src/GlobalVar.lua b/src/GlobalVar.lua index 80490e0..4b918e2 100644 --- a/src/GlobalVar.lua +++ b/src/GlobalVar.lua @@ -46,7 +46,7 @@ ItemType = { -- 物品起始id ItemStartId = { - Hero = 1000, -- 英雄 + Hero = 300, -- 英雄 } --常用的物品id的枚举 ItemId = { diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index 24c3fa2..6ee3d7a 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -49,6 +49,7 @@ actionCodes = { Hang_startBattleRpc = 253, Hang_endBattleRpc = 254, Hang_roleFormatRpc = 255, + Hang_getRewardRpc = 256, } diff --git a/src/actions/HangAction.lua b/src/actions/HangAction.lua index 3f759ac..edc585e 100644 --- a/src/actions/HangAction.lua +++ b/src/actions/HangAction.lua @@ -22,12 +22,12 @@ local function checkReward(role) return end local carbonData = csvdb["idle_battleCsv"][hangInfo.carbonId] - local nowTime = skynet.timex() + local nowTime = math.min(skynet.timex(), hangInfo.endTime or 0) - local coinCount = math.floor((nowTime - hangInfo.coinTime) / 5) + local coinCount = math.max(0, math.floor((nowTime - hangInfo.coinTime) / 5)) hangInfo.coinTime = hangInfo.coinTime + coinCount * 5 - local itemCount = math.floor((nowTime - hangInfo.itemTime) / 60) + local itemCount = math.max(0, math.floor((nowTime - hangInfo.itemTime) / 60)) hangInfo.itemTime = hangInfo.itemTime + itemCount * 60 local items = role:getProperty("hangBag") @@ -44,8 +44,7 @@ local function checkReward(role) end if coinCount > 0 or itemCount > 0 then - role:updateProperty({field = "hangBag", value = items}) - role:updateProperty({field = "hangInfo", value = hangInfo}) + return true end end @@ -62,16 +61,23 @@ function _M.startRpc( agent, data ) local hangPass = role:getProperty("hangPass") if carbonData.prepose ~= "" and carbonData.prepose ~= 0 and not hangPass[carbonData.prepose] then return end - checkReward(role) + if checkReward(role) then + role:updateProperty({field = "hangBag", value = role:getProperty("hangBag")}) + end local hangInfo = role:getProperty("hangInfo") - table.clear(hangInfo) + local isNew = not hangInfo.carbonId hangInfo.carbonId = carbonId local nowTime = skynet.timex() hangInfo.coinTime = nowTime hangInfo.itemTime = nowTime + if isNew then + hangInfo.endTime = nowTime + 12 * 3600 + end if not hangPass[carbonId] then - hangInfo.bossTime = nowTime + 100 + hangInfo.bossTime = nowTime + carbonData.idle_time + else + hangInfo.bossTime = nil end role:updateProperty({field = "hangInfo", value = hangInfo}) @@ -83,7 +89,10 @@ end function _M.checkRpc(agent, data) local role = agent.role -- local msg = MsgPack.unpack(data) - checkReward(role) + if checkReward(role) then + role:updateProperty({field = "hangBag", value = role:getProperty("hangBag")}) + role:updateProperty({field = "hangInfo", value = role:getProperty("hangInfo")}) + end SendPacket(actionCodes.Hang_checkRpc, MsgPack.pack({})) return true end @@ -98,7 +107,6 @@ function _M.startBattleRpc(agent, data) local key = tostring(math.random()) hangInfo.key = key local nowTime = skynet.timex() - hangInfo.bossTime = nowTime + 100 role:updateProperty({field = "hangInfo", value = hangInfo}) SendPacket(actionCodes.Hang_startBattleRpc, MsgPack.pack({key = key})) return true @@ -121,7 +129,7 @@ function _M.endBattleRpc(agent, data) -- reward reward = {} local items = role:getProperty("hangBag") - local carbonData = csvdb["idle_battleCsv"][carbonId] + 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 @@ -161,4 +169,25 @@ function _M.roleFormatRpc(agent , data) return true end +function _M.getRewardRpc(agent , data) + local role = agent.role + checkReward(role) + local items = role:getProperty("hangBag") + if not next(items) then return end + local reward = role:award(items, {}) + table.clear(items) + local hangInfo = role:getProperty("hangInfo") + local nowTime = skynet.timex() + hangInfo.endTime = nowTime + 12 * 3600 + hangInfo.coinTime = nowTime + hangInfo.itemTime = nowTime + role:updateProperty({field = "hangBag", value = items}) + role:updateProperty({field = "hangInfo", value = hangInfo}) + + SendPacket(actionCodes.Hang_getRewardRpc, MsgPack.pack({ + reward = reward + })) + return true +end + return _M \ No newline at end of file -- libgit2 0.21.2