From cccc9c705a0ca03fd7ee6186dddaec8a992ce58c Mon Sep 17 00:00:00 2001 From: zhouhaihai Date: Wed, 4 Dec 2019 17:24:46 +0800 Subject: [PATCH] 商城 --- src/ProtocolCode.lua | 4 ++++ src/actions/StoreAction.lua | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/models/Daily.lua | 23 ++++++++++++++++++++++- src/models/Role.lua | 10 ++++++++++ src/models/RolePlugin.lua | 6 +++++- 5 files changed, 148 insertions(+), 2 deletions(-) create mode 100644 src/actions/StoreAction.lua diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index 51fc6d9..21ef125 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -138,6 +138,10 @@ actionCodes = { Pvp_rankListRpc = 506, Pvp_recordListRpc = 507, + + Store_rechargeRpc = 550, + Store_dailyBuyRpc = 551, + Store_dinerBuyRpc = 552, } rpcResponseBegin = 10000 diff --git a/src/actions/StoreAction.lua b/src/actions/StoreAction.lua new file mode 100644 index 0000000..dd97555 --- /dev/null +++ b/src/actions/StoreAction.lua @@ -0,0 +1,107 @@ +local _M = {} + +function _M.rechargeRpc(agent , data) + local role = agent.role + local msg = MsgPack.unpack(data) + local id = msg.id + local dataSet = csvdb["shop_rechargeCsv"][id] + if not dataSet then return end + local diamondCount + if dataSet.type == 0 then -- 钻石 + local rechargeF = role:getProperty("rechargeF") + diamondCount = dataSet.diamond + dataSet.diamondExtra + if not rechargeF[id] then + diamondCount = diamondCount + dataSet.diamondFirst + rechargeF[id] = 1 + role:updateProperty({field = "rechargeF", value = rechargeF}) + end + role:gainDiamond({count = diamondCount, isRecharge = true}) + elseif dataSet.type == 1 then --月卡 + return + elseif dataSet.type == 2 then -- 赛季通行证 + return + else + return + end + + -- 累充 + local rmb = dataSet.rmb + role:updateProperty({field = "rmbC", delta = rmb}) + + SendPacket(actionCodes.Store_rechargeRpc, MsgPack.pack({diamond = diamondCount})) + return true +end + + +function _M.dailyBuyRpc(agent , data) + local role = agent.role + local msg = MsgPack.unpack(data) + local id = msg.id + local count = msg.count or 1 + + local dataSet = csvdb["shop_diamondCsv"][id] + if not dataSet then return 1 end + + local dailySDC = role.dailyData:getProperty("dailySDC") + + if math.illegalNum(count, 1, (dataSet.limit == 0 and math.huge or dataSet.limit - (dailySDC[id] or 0))) then return 1 end + + local cost = dataSet.cost + if dataSet.type == 0 then + local dailySDD = role.dailyData:getProperty("dailySDD") + if dailySDD[id] then -- 折扣 + cost = math.ceil(cost * (1 - dataSet.disount / 100)) + end + elseif dataSet.type == 1 then + else + return 3 + end + + if not role:costDiamond({count = cost * count}) then + return 4 + end + + if dataSet.limit ~= 0 then + dailySDC[id] = (dailySDC[id] or 0) + count + role.dailyData:updateProperty({field = "dailySDC", value = dailySDC}) + end + local reward = role:award(dataSet.gift) + + SendPacket(actionCodes.Store_dailyBuyRpc, MsgPack.pack({reward = reward})) + return true +end + + +function _M.dinerBuyRpc(agent , data) + local role = agent.role + local msg = MsgPack.unpack(data) + local id = msg.id + local count = msg.count or 1 + + local dataSet = csvdb["shop_dinerCsv"][id] + if not dataSet then return end + + local dinerS = role:getProperty("dinerS") + if math.illegalNum(count, 1, (dataSet.limit == 0 and math.huge or dataSet.limit - (dinerS[id] or 0))) then return 1 end + + local cost = {[ItemId.DinerCoin] = dataSet.cost} + if not role:checkItemEnough(cost) then return end + + if dataSet.limit ~= 0 then + dinerS[id] = (dinerS[id] or 0) + count + role:updateProperty({field = "dinerS", value = dinerS}) + end + + role:costItems(cost) + + local gift = {} + for _id, _count in pairs(dataSet.gift:toNumMap()) do + gift[_id] = _count * count + end + local reward = role:award(gift) + + SendPacket(actionCodes.Store_dinerBuyRpc, 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 37f7156..83c6225 100644 --- a/src/models/Daily.lua +++ b/src/models/Daily.lua @@ -19,6 +19,9 @@ Daily.schema = { giveFP = {"table", {}}, -- 给谁送过心心 getFP = {"table", {}}, -- 领过谁的心心 pvpFree = {"number", 0}, -- pvp使用免费次数 + + dailySDC = {"table", {}}, -- daily shop diamond count {[id] = count} -- 每日商城购买次数统计 + dailySDD = {"table", {}}, -- daily shop diamond disount {[id] = 1} -- 每日商城折扣统计 } function Daily:updateProperty(params) @@ -43,12 +46,28 @@ end function Daily:refreshDailyData(notify) redisproxy:del(FRIEND_POINT:format(self.owner:getProperty("id"))) + local dataMap = {} for field, schema in pairs(self.schema) do if field ~= "key" then local typ, def = table.unpack(schema) - self:setProperty(field, def) + dataMap[field] = def + end + end + -- 每日折扣搞一下 + local dailySDD = {} + local sddPool = {} + for id, data in pairs(csvdb["shop_diamondCsv"]) do + if data.type == 0 and data.disount ~= 0 then + table.insert(sddPool, id) end end + for i = 1, math.min(#sddPool, globalCsv.shop_diamond_disount_count) do + local idx = math.randomInt(1, #sddPool) + dailySDD[sddPool[idx]] = 1 + table.remove(sddPool, idx) + end + dataMap["dailySDD"] = dailySDD + self:setProperties(dataMap) if notify then self.owner:notifyUpdateProperties(self:data()) end @@ -67,6 +86,8 @@ function Daily:data() giveFP = self:getProperty("giveFP"), getFP = self:getProperty("getFP"), pvpFree = self:getProperty("pvpFree"), + dailySDC = self:getProperty("dailySDC"), + dailySDD = self:getProperty("dailySDD"), } end diff --git a/src/models/Role.lua b/src/models/Role.lua index 7c42822..4a7c707 100644 --- a/src/models/Role.lua +++ b/src/models/Role.lua @@ -106,6 +106,11 @@ Role.schema = { achiveT = {"table", {}}, -- 成就计数统计 achivement_type {id = status} achiveV = {"table", {}}, -- 成就领奖统计 achivement {id = status} + + rechargeF = {"table", {}}, -- 是否首次充值某一项 -- —{[id] = 1} -- 不存在就是没有充值过 + dinerS = {"table", {}}, -- 美食币商城 购买记录 {[id] = count} + + rmbC = {"number", 0}, -- 人民币重置额 } @@ -250,6 +255,11 @@ function Role:data() wTask = self:getProperty("wTask"), achiveT = self:getProperty("achiveT"), achiveV = self:getProperty("achiveV"), + + rechargeF = self:getProperty("rechargeF"), + dinerS = self:getProperty("dinerS"), + + rmbC = self:getProperty("rmbC"), } end diff --git a/src/models/RolePlugin.lua b/src/models/RolePlugin.lua index 8c34c09..d65d50f 100644 --- a/src/models/RolePlugin.lua +++ b/src/models/RolePlugin.lua @@ -36,8 +36,12 @@ function RolePlugin.bind(Role) if isCrossWeek(ltime, now) then - self:setProperty("wTask", {}) + self:setProperties({ + wTask = {}, + dinerS = {}, + }) response.wTask = {} + response.dinerS = {} end if notify then -- libgit2 0.21.2