From f8408529b103c034e9daaf309e2ea96c5e2f0429 Mon Sep 17 00:00:00 2001 From: zhouhaihai <781184096@qq.com> Date: Wed, 19 Feb 2020 18:10:34 +0800 Subject: [PATCH] 冒险商店 --- src/adv/Adv.lua | 25 ++++++++++++++++++++++--- src/adv/AdvBlock.lua | 52 +++++++++++++++++++++++++++++++++++++++++++++++++--- src/csvdata | 2 +- src/models/Role.lua | 4 +++- 4 files changed, 75 insertions(+), 8 deletions(-) diff --git a/src/adv/Adv.lua b/src/adv/Adv.lua index 6cb97ca..ab1ff20 100644 --- a/src/adv/Adv.lua +++ b/src/adv/Adv.lua @@ -12,6 +12,7 @@ function Adv:ctor(owner) assert(owner, "Adv instance must have owner(role)") self.owner = owner self.maps = {} + self.shopStatus = {} self.battle = nil self.backEvents = {} --发给客户端的事件组 @@ -35,6 +36,8 @@ function Adv:initByInfo(advInfo) self.lchoose = advInfo.lch or {} self.waitArtifact = advInfo.waitAF self.cacheUnlock = advInfo.cacheUnlock or {} + self.shopStatus = advInfo.shopStatus or {} + self.maps = {} for id, map in ipairs(advInfo.maps or {}) do self.maps[id] = AdvMap.new(self, id, map) @@ -59,6 +62,7 @@ function Adv:initByChapter(chapterId, level, isToNext, notNotify) self.mapStack = {1} -- 最后一个为当前的地图 self.lchoose = self.lchoose or {} self.cacheUnlock = self.cacheUnlock or {} + self.shopStatus = self.shopStatus or {} -- 随机出地图 local mapId = self:randomMapId(chapterId, level) @@ -92,6 +96,7 @@ function Adv:clear() self.battle = nil self.waitArtifact = nil self.cacheUnlock = {} + self.shopStatus = {} end function Adv:saveDB(notNotify) @@ -107,6 +112,7 @@ function Adv:saveDB(notNotify) advInfo.lch = self.lchoose advInfo.waitAF = self.waitArtifact advInfo.cacheUnlock = self.cacheUnlock + advInfo.shopStatus = self.shopStatus advInfo.maps = {} self.battle:saveDB() @@ -792,9 +798,22 @@ local function clickTrader(self, room, block, params) if not block.event.shop or not block.event.shop[buyId] then return end if (block.event.status or ""):getv(buyId, 0) == 1 then return end -- 买过了 - if not self:cost({[traderData.type] = block.event.shop[buyId][3]}, {}) then return end --不够 - self:backCost({[traderData.type] = block.event.shop[buyId][3]}) - local reward = self:award({[block.event.shop[buyId][1]] = block.event.shop[buyId][2]}) + if traderData.purchasetime <= #((block.event.status or ""):toArray()) then return end + + local goodsData = csvdb["event_trader_goodsCsv"][block.event.shop[buyId][1]] + if not goodsData then return end + + local costCount = math.ceil(goodsData.price * (block.event.shop[buyId][2] or 100) / 100) + if not self:cost({[goodsData.currency] = costCount}, {}) then return end --不够 + self:backCost({[goodsData.currency] = costCount}) + local reward = self:award({[goodsData.item] = goodsData.num}) + if goodsData.restrict == 1 then + self.shopStatus[goodsData.goods] = (self.shopStatus[goodsData.goods] or 0) + 1 + elseif goodsData.restrict == 2 then + local advShop = self.owner:getProperty("advShop") + advShop[goodsData.goods] = (advShop[goodsData.goods] or 0) + 1 + self.owner:updateProperty({field = "advShop", value = advShop}) + end block.event.status = block.event.status:setv(buyId, 1) self:checkTask(Adv.TaskType.Shop, 1, block.event.id) self:checkAchievement(Adv.AchievType.Shop, 1, block.event.id) diff --git a/src/adv/AdvBlock.lua b/src/adv/AdvBlock.lua index 7d59f32..fc17201 100644 --- a/src/adv/AdvBlock.lua +++ b/src/adv/AdvBlock.lua @@ -79,12 +79,58 @@ function Block:randomEvent() local data = csvdb["event_traderCsv"][self.event.id] self.event.shop = {} self.event.status = "" --购买次数状态 1 就是购买过了 -- 购买id就是shop索引 + local needDiscount = data.discount -- 需要的折扣数量 + local curHad = {} + local advShop = adv.owner:getProperty("advShop") + local function randomGoods(range, gcount) + local pool = range:toTableArray(true) -- {{id, weight}, ... } + local function randomOneGood() + for i = #pool, 1, -1 do + local curId = pool[i][1] + local curData = csvdb["event_trader_goodsCsv"][curId] + if not curData then + table.remove(pool, i) + else + if curData.restrict == 1 then -- 冒险内限制 + if curData.restrictnum <= ((adv.shopStatus[curId] or 0) + (curHad[curId] or 0)) then + table.remove(pool, i) + end + elseif curData.restrict == 2 then -- 角色限制 + if curData.restrictnum <= ((advShop[curId] or 0) + (curHad[curId] or 0)) then + table.remove(pool, i) + end + end + end + end + if #pool <= 0 then + return false + end + local idx = math.randWeight(pool, 2) + local getId = pool[idx][1] + local getData = svdb["event_trader_goodsCsv"][getId] + if getData.restrict ~= 0 then + curHad[curId] = (curHad[curId] or 0) + 1 + end + if getData.discount ~= "" and needDiscount > 0 then + needDiscount = needDiscount - 1 + table.insert(self.event.shop, {getId, getData.discount:randWeight()}) + else + table.insert(self.event.shop, {getId}) + end + return true + end + + for i = 1, gcount do + if not randomOneGood() then + break + end + end + end + for i = 1, 10 do local numS, rangeS = "num" .. i, "range" .. i if data[numS] and data[rangeS] then - for j = 1, data[numS] do - table.insert(self.event.shop, data[rangeS]:randWeight(true)) - end + randomGoods(data[rangeS], data[numS]) else break end diff --git a/src/csvdata b/src/csvdata index 4f8cd94..9a3181f 160000 --- a/src/csvdata +++ b/src/csvdata @@ -1 +1 @@ -Subproject commit 4f8cd94220fea86bbad962ae0023dd7484dccda2 +Subproject commit 9a3181fa2f55dd5a1247bfd99f596b0cbc96a828 diff --git a/src/models/Role.lua b/src/models/Role.lua index 6cd26a9..63d3e1c 100644 --- a/src/models/Role.lua +++ b/src/models/Role.lua @@ -70,12 +70,13 @@ Role.schema = { advAFWear = {"table", {}}, -- 当前拥有的神器 {[slot] = id} advDrawB = {"table", {}}, -- 冒险抽奖回馈 {[1] = 0, [2] = 100} -- 池子类型 = 点数 advStoryB = {"table", {}}, -- 冒险故事完成记录 (连锁事件绑定的故事) -- {storyId = 1} + advShop = {"table", {}}, -- 冒险內的商店限制购买次数记录 {goodId = count} --挂机相关 hangPass = {"table", {}}, -- 挂机通过的最大关卡 hangTeam = {"table", {}}, -- 挂机队伍 hangTS = {"table", {}}, -- 挂机队伍他人可读的队伍信息 - hangTB = {"table", {}}, -- 挂机队伍他人可用的战斗信息 + hangTB = {"table", {}}, -- 挂机队伍他人可用的战斗信息mao hangTBV = {"number", 0}, -- 挂机队伍他人可用的战斗力 hangInfo = {"table", {}}, -- 当前挂机信息 @@ -251,6 +252,7 @@ function Role:data() advAFGet = self:getProperty("advAFGet"), advAFWear = self:getProperty("advAFWear"), advDrawB = self:getProperty("advDrawB"), + advShop = self:getProperty("advShop"), hangPass = self:getProperty("hangPass"), hangTeam = self:getProperty("hangTeam"), -- libgit2 0.21.2