diff --git a/src/actions/SeaportAction.lua b/src/actions/SeaportAction.lua index ed5c882..f41736c 100644 --- a/src/actions/SeaportAction.lua +++ b/src/actions/SeaportAction.lua @@ -28,23 +28,39 @@ function _M.donateRpc(agent, data) local DonateCsv = csvdb["seaport_purchaseCsv"] if not DonateCsv[phase] or not DonateCsv[phase][id] then return 2 end - local data = DonateCsv[phase][id] - local needs = data.need_item:toArray(true,"=") + local ddata = DonateCsv[phase][id] + local needs = ddata.need_item:toArray(true,"=") if itemId ~= needs[1] then return 3 end if itemCount % needs[2] ~= 0 then return 4 end local group = itemCount / needs[2] - local rewards = data.award:toNumMap() + local rewards = ddata.award:toNumMap() for id, value in pairs(rewards) do rewards[id] = value * group end - local rediskey = {SEAPORT_TRADE_TASK_1,SEAPORT_TRADE_TASK_2} - redisproxy:hincrby(rediskey[phase],id,itemCount) + if phase == 1 then + local old = tonumber(redisproxy:hget(SEAPORT_TRADE_TASK_1,id)) or 0 + local need = ddata.need_num - old + if need >= itemCount then + redisproxy:hincrby(SEAPORT_TRADE_TASK_1,id,itemCount) + else + redisproxy:hincrby(SEAPORT_TRADE_TASK_1,id,need) + for _, temp in pairs(DonateCsv[2]) do + local items = temp.need_item:toArray(true,"=") + if items[1] == itemId then + redisproxy:hincrby(SEAPORT_TRADE_TASK_2,temp.id,itemCount - need) + break + end + end + end + else + redisproxy:hincrby(SEAPORT_TRADE_TASK_2,id,itemCount) + end role:costItems({[itemId] = itemCount}, {log = {desc = "seaportDonate", int1 = phase, int2 = id}}) - local reward, change = role:award(rewards, {log = {desc = "seaportDonate", int1 = data.phase, int2 = data.id}}) + local reward, change = role:award(rewards, {log = {desc = "seaportDonate", int1 = ddata.phase, int2 = ddata.id}}) role:mylog("role_action", {desc = "seaportDonate", int1 = itemId, int2 = itemCount}) diff --git a/src/services/globald.lua b/src/services/globald.lua index 021f035..a619f7b 100644 --- a/src/services/globald.lua +++ b/src/services/globald.lua @@ -155,22 +155,27 @@ end -- @desc: 检查海港贸易开启、关闭 local function check_trade_seaport_status() - local delta = 1615579200 + 1000 - local nowTime = delta or skynet.timex() + local nowTime = skynet.timex() local nextTime = dayLater(nowTime) - local interval = nextTime - nowTime + 1 + local interval = 100 * (nextTime - nowTime + 1) local curTm = os.date("*t", nowTime) - if curTm.wday == 7 and curTm.hour == 4 then - redisproxy:hset("autoincrement_set", "seaportTime0", nowTime) - redisproxy:hset("autoincrement_set", "seaportTime1", 1) - redisproxy:del(SEAPORT_TRADE_TASK_1) - redisproxy:del(SEAPORT_TRADE_TASK_2) + if curTm.wday == 7 and curTm.hour >= 4 then -- 周六 + local oldTime = tonumber(redisproxy:hget("autoincrement_set", "seaportTime0")) or 0 + local cur4Time = specTime({hour = 4},nowTime) + if cur4Time ~= oldTime then + redisproxy:hset("autoincrement_set", "seaportTime0", cur4Time) + redisproxy:hset("autoincrement_set", "seaportTime1", 1) + redisproxy:del(SEAPORT_TRADE_TASK_1) + redisproxy:del(SEAPORT_TRADE_TASK_2) + end end - if curTm.wday == 1 and curTm.hour == 4 then - redisproxy:hset("autoincrement_set", "seaportTime2", 1) + if curTm.wday == 1 and curTm.hour >= 4 then -- 周日 + if (tonumber(redisproxy:hget("autoincrement_set", "seaportTime1")) or 0) == 1 then + redisproxy:hset("autoincrement_set", "seaportTime2", 1) + end end - if curTm.wday == 2 and curTm.hour == 4 then + if curTm.wday == 2 and curTm.hour >= 4 then -- 周一 -- redisproxy:hset("autoincrement_set", "seaportTime0", 0) redisproxy:hset("autoincrement_set", "seaportTime1", 0) redisproxy:hset("autoincrement_set", "seaportTime2", 0) -- libgit2 0.21.2