diff --git a/src/GlobalVar.lua b/src/GlobalVar.lua index b1fff91..58d2e4d 100644 --- a/src/GlobalVar.lua +++ b/src/GlobalVar.lua @@ -259,3 +259,17 @@ RedPointTags = { PvpCR = 1, PvpHR = 2, } + +RefreshType = { + RefreshType_Daily = 1, -- 日刷新 + RefreshType_Weekly = 2, -- 周刷新 + RefreshType_Monthly = 3, -- 月刷新 +} + +CardType = { + NormalMonthCard = 1, --普通月卡 + SuperMonthCard = 2, --超级月卡 + PrivilegeCard = 3, --特权卡 + GrowFund = 4, --成长助力 + BattleCard = 5, --赛季卡 +} \ No newline at end of file diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index f4e2f08..ab9e589 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -183,6 +183,7 @@ actionCodes = { Store_ayncPurchaseRpc = 555, Store_myCardRechargeRpc = 556, Store_iosRechargeRpc = 557, + Store_shopBuyRpc = 558, Email_listRpc = 600, diff --git a/src/RedisKeys.lua b/src/RedisKeys.lua index d8b52aa..af9b23b 100644 --- a/src/RedisKeys.lua +++ b/src/RedisKeys.lua @@ -11,6 +11,7 @@ R_RUNEIDS = "role:%d:runeIds" -- 玩家拥有符文自增id R_RUNE = "role:%d:rune:%d" -- 符文详细信息 R_EMAIL = "role:%d:emailIds" --邮件列表 R_EMAIL_ITEM = "email:%d:%d" --邮件 +R_STORE = "role:%d:store" -- 商店 -- rank diff --git a/src/actions/StoreAction.lua b/src/actions/StoreAction.lua index e494456..5364f7b 100644 --- a/src/actions/StoreAction.lua +++ b/src/actions/StoreAction.lua @@ -254,4 +254,52 @@ function _M.dinerBuyRpc(agent , data) return true end +function _M.shopBuyRpc(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_normalCsv"][id] + if not dataSet then return end + + local buyRecord = role.storeData:getProperty("Store_buyRecord") + if math.illegalNum(count, 1, (dataSet.limit == 0 and math.huge or dataSet.limit - (buyRecord[id] or 0))) then return 1 end + + local cost = {[dataSet.icon] = dataSet.cost * count} + + local desc = "unknown" + if dataSet.shop == 1 then -- 普通商店 + desc = "dailyShop" + local dailySDD = role.dailyData:getProperty("dailySDD") + if dailySDD[id] then -- 折扣 + cost = math.ceil(dataSet.cost * (1 - dataSet.disount / 100)) + end + elseif dataSet.shop == 2 then -- 美食商店 + desc = "dinerShop" + elseif dataSet.shop == 3 then -- 竞技场商店 + desc = "pvpShop" + end + + if not role:checkItemEnough(cost) then return end + + if dataSet.limit ~= 0 then + buyRecord[id] = (buyRecord[id] or 0) + count + role.storeData:updateProperty({field = "Store_buyRecord", value = buyRecord}) + end + + role:costItems(cost, {log = {desc = desc, int1 = id, int2 = count}}) + + local gift = {} + for _id, _count in pairs(dataSet.gift:toNumMap()) do + gift[_id] = _count * count + end + local reward = role:award(gift, {log = {desc = desc, int1 = id, int2 = count}}) + + role:log("role_action", {desc = desc, int1 = id, int2 = count}) + + SendPacket(actionCodes.Store_shopBuyRpc, 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 7bfcf14..138491f 100644 --- a/src/models/Daily.lua +++ b/src/models/Daily.lua @@ -63,8 +63,8 @@ function Daily:refreshDailyData(notify) -- 每日折扣搞一下 local dailySDD = {} local sddPool = {} - for id, data in pairs(csvdb["shop_diamondCsv"]) do - if data.disount ~= 0 then + for id, data in pairs(csvdb["shop_normalCsv"]) do + if data.shop == 1 and data.disount ~= 0 then table.insert(sddPool, id) end end diff --git a/src/models/RolePlugin.lua b/src/models/RolePlugin.lua index e1ece96..00f0371 100644 --- a/src/models/RolePlugin.lua +++ b/src/models/RolePlugin.lua @@ -11,6 +11,7 @@ function RolePlugin.bind(Role) self:loadHeros() self:loadDiner() self:loadActivity() + self:loadStoreInfo() end function Role:reloadWhenLogin() @@ -529,6 +530,18 @@ function RolePlugin.bind(Role) -- 放role 里面了 end + function Role:loadStoreInfo() + local roleId = self:getProperty("id") + local dataKey = string.format(R_STORE, roleId) + self.storeData = require("models.Store").new({key = dataKey}) + self.storeData.owner = self + if not redisproxy:exists(dataKey) then + self.storeData:create() + else + self.storeData:load() + end + end + function Role:addEquip(equipType, equipLv, count, pms) pms = pms or {} if count ~= count then return end @@ -1511,8 +1524,13 @@ function RolePlugin.bind(Role) return end + if not role.storeData:checkRechargeRecord(rechargeData.limit, id) then + return 1 + end + local diamondCount = 0 - if rechargeData.type == 0 then -- 钻石 + local reward = {} + if rechargeData.shop == 1 then -- 钻石 local rechargeF = self:getProperty("rechargeF") diamondCount = rechargeData.diamond + rechargeData.diamondExtra if not rechargeF[id] then @@ -1521,11 +1539,15 @@ function RolePlugin.bind(Role) self:updateProperty({field = "rechargeF", value = rechargeF}) end self:gainDiamond({count = diamondCount, isRecharge = true, log = {desc = "recharge", int1 = id}}) - elseif rechargeData.type == 1 then --月卡 + elseif rechargeData.shop == 1 then --通行证商店 + reward = self:award(rechargeData.itemFirst, {log = {desc = "recharge", int1 = id}}) + self.storeData:onBuyCard(rechargeData.type, rechargeData.time) return - elseif rechargeData.type == 2 then -- 赛季通行证 + elseif rechargeData.shop == 2 then -- 礼包商店 + reward = self:award(rechargeData.itemFirst, {log = {desc = "recharge", int1 = id}}) return else + skynet.error("invalid recharge shop type " .. id) return end @@ -1535,7 +1557,7 @@ function RolePlugin.bind(Role) self:log("role_action", {desc = "recharge", int1 = id, int2 = rmb, key1 = params.transactionId, key2 = params.order, long1 = params.pay_time}) - return diamondCount + return diamondCount, reward end end diff --git a/src/models/Store.lua b/src/models/Store.lua new file mode 100644 index 0000000..294f395 --- /dev/null +++ b/src/models/Store.lua @@ -0,0 +1,114 @@ +-- 商店数据 + +local Store = class("Store", require("shared.ModelBase")) + +function Store:ctor(properties) + Store.super.ctor(self, properties) +end + +Store.schema = { + Store_buyRecord = {"table", {}}, -- 购买商品记录 {id=count} + Store_rechargeRecord = {"table", {}}, -- 充值记录 {id=count} + Store_growFund = {"number", 0}, -- 成长基金 + Store_growFundRecord = {"table", {}}, -- 成长基金领取记录 + Store_monthCardExTs = {"number", 0}, -- 月卡过期时间戳 + Store_smonthCardExTs = {"number", 0}, -- 超级月卡过期时间戳 + Store_battleCardExTs = {"number", 0}, -- 赛季卡过期时间戳 + Store_battleCardRecord = {"table", {}}, -- 赛季卡领取记录 +} + +function Store:updateProperty(params) + local type, default = table.unpack(self.schema[params.field]) + + if params.delta then + self:incrProperty(params.field, params.delta) + if not params.notNotify then + self.owner:notifyUpdateProperty(params.field, self:getProperty(params.field)) + end + return true + end + if params.value then + self:setProperty(params.field, params.value) + if not params.notNotify then + self.owner:notifyUpdateProperty(params.field, self:getProperty(params.field)) + end + return true + end + return false +end + +function Store:refreshData(notify, refreshType) + local buyRecord = self:getProperty("Store_buyRecord") + local result = {} + for id, data in pairs(csvdb["shop_normalCsv"]) do + if data.shop == 1 and refreshType == RefreshType.RefreshType_Daily then + buyRecord[id] = nil + end + if data.shop == 2 and refreshType == RefreshType.RefreshType_Weekly then + buyRecord[id] = nil + end + end + self:setProperty("Store_buyRecord", buyRecord) + if notify then + --self.owner:notifyUpdateProperties(self:data()) + self:notifyUpdateProperty({field="Store_buyRecord", value=buyRecord}) + end +end + +function Store:refreshPvpBuyRecord(notify) + local buyRecord = self:getProperty("Store_buyRecord") + for id, data in pairs(csvdb["shop_normalCsv"]) do + if data.shop == 3 then + buyRecord[id] = nil + end + end + self:setProperty("Store_buyRecord", buyRecord) + if notify then + self:notifyUpdateProperty({field="Store_buyRecord", value=buyRecord}) + end +end + +-- 发送月卡邮件 +function Store:sendMonthCardEmail() +end + +-- 购买通行证 +function onBuyCard(type, duration) + local timeNow = skynet.timex() + if rechargeData.type == CardType.NormalMonthCard then + self:updateProperty({field = "Store_monthCardExTs", value = timeNow + duration}) + elseif rechargeData.type == CardType.SuperMonthCard then + self:updateProperty({field = "Store_smonthCardExTs", value = timeNow + duration}) + elseif rechargeData.type == CardType.PrivilegeCard then + elseif rechargeData.type == CardType.GrowFund then + self:updateProperty({field = "Store_growFundRecord", 1}) + elseif rechargeData.type == CardType.BattleCard then + self:updateProperty({field = "Store_battleCardRecord", 1}) + end +end + +function checkRechargeRecord(limit, id) + local rechargeRecord = self:getProperty("Store_rechargeRecord") + if limit ~= 0 and limit <= (rechargeRecord[id] or 0) then + skynet.error(string.format("recharge id:%d count over limit, user id:%d", id, self.owner:getProperty("id"))) + return false + end + rechargeRecord[id] = rechargeRecord[id] + 1 + self:updateProperty({field = "Store_rechargeRecord", value = rechargeRecord[id]}) + return true +end + +function Store:data() + return { + Store_buyRecord = self:getProperty("Store_buyRecord"), + Store_rechargeRecord = self:getProperty("Store_rechargeRecord"), + Store_growFund = self:getProperty("Store_growFund"), + Store_growFundRecord = self:getProperty("Store_growFundRecord"), + Store_monthCardExTs = self:getProperty("Store_monthCardExTs"), + Store_smonthCardExTs = self:getProperty("Store_smonthCardExTs"), + Store_battleCardExTs = self:getProperty("Store_battleCardExTs"), + Store_battleCardRecord = self:getProperty("Store_battleCardRecord"), + } +end + +return Store \ No newline at end of file -- libgit2 0.21.2