Commit f8408529b103c034e9daaf309e2ea96c5e2f0429

Authored by zhouhaihai
1 parent 44dd6cae

冒险商店

src/adv/Adv.lua
... ... @@ -12,6 +12,7 @@ function Adv:ctor(owner)
12 12 assert(owner, "Adv instance must have owner(role)")
13 13 self.owner = owner
14 14 self.maps = {}
  15 + self.shopStatus = {}
15 16 self.battle = nil
16 17 self.backEvents = {} --发给客户端的事件组
17 18  
... ... @@ -35,6 +36,8 @@ function Adv:initByInfo(advInfo)
35 36 self.lchoose = advInfo.lch or {}
36 37 self.waitArtifact = advInfo.waitAF
37 38 self.cacheUnlock = advInfo.cacheUnlock or {}
  39 + self.shopStatus = advInfo.shopStatus or {}
  40 +
38 41 self.maps = {}
39 42 for id, map in ipairs(advInfo.maps or {}) do
40 43 self.maps[id] = AdvMap.new(self, id, map)
... ... @@ -59,6 +62,7 @@ function Adv:initByChapter(chapterId, level, isToNext, notNotify)
59 62 self.mapStack = {1} -- 最后一个为当前的地图
60 63 self.lchoose = self.lchoose or {}
61 64 self.cacheUnlock = self.cacheUnlock or {}
  65 + self.shopStatus = self.shopStatus or {}
62 66  
63 67 -- 随机出地图
64 68 local mapId = self:randomMapId(chapterId, level)
... ... @@ -92,6 +96,7 @@ function Adv:clear()
92 96 self.battle = nil
93 97 self.waitArtifact = nil
94 98 self.cacheUnlock = {}
  99 + self.shopStatus = {}
95 100 end
96 101  
97 102 function Adv:saveDB(notNotify)
... ... @@ -107,6 +112,7 @@ function Adv:saveDB(notNotify)
107 112 advInfo.lch = self.lchoose
108 113 advInfo.waitAF = self.waitArtifact
109 114 advInfo.cacheUnlock = self.cacheUnlock
  115 + advInfo.shopStatus = self.shopStatus
110 116 advInfo.maps = {}
111 117  
112 118 self.battle:saveDB()
... ... @@ -792,9 +798,22 @@ local function clickTrader(self, room, block, params)
792 798 if not block.event.shop or not block.event.shop[buyId] then return end
793 799 if (block.event.status or ""):getv(buyId, 0) == 1 then return end -- 买过了
794 800  
795   - if not self:cost({[traderData.type] = block.event.shop[buyId][3]}, {}) then return end --不够
796   - self:backCost({[traderData.type] = block.event.shop[buyId][3]})
797   - local reward = self:award({[block.event.shop[buyId][1]] = block.event.shop[buyId][2]})
  801 + if traderData.purchasetime <= #((block.event.status or ""):toArray()) then return end
  802 +
  803 + local goodsData = csvdb["event_trader_goodsCsv"][block.event.shop[buyId][1]]
  804 + if not goodsData then return end
  805 +
  806 + local costCount = math.ceil(goodsData.price * (block.event.shop[buyId][2] or 100) / 100)
  807 + if not self:cost({[goodsData.currency] = costCount}, {}) then return end --不够
  808 + self:backCost({[goodsData.currency] = costCount})
  809 + local reward = self:award({[goodsData.item] = goodsData.num})
  810 + if goodsData.restrict == 1 then
  811 + self.shopStatus[goodsData.goods] = (self.shopStatus[goodsData.goods] or 0) + 1
  812 + elseif goodsData.restrict == 2 then
  813 + local advShop = self.owner:getProperty("advShop")
  814 + advShop[goodsData.goods] = (advShop[goodsData.goods] or 0) + 1
  815 + self.owner:updateProperty({field = "advShop", value = advShop})
  816 + end
798 817 block.event.status = block.event.status:setv(buyId, 1)
799 818 self:checkTask(Adv.TaskType.Shop, 1, block.event.id)
800 819 self:checkAchievement(Adv.AchievType.Shop, 1, block.event.id)
... ...
src/adv/AdvBlock.lua
... ... @@ -79,12 +79,58 @@ function Block:randomEvent()
79 79 local data = csvdb["event_traderCsv"][self.event.id]
80 80 self.event.shop = {}
81 81 self.event.status = "" --购买次数状态 1 就是购买过了 -- 购买id就是shop索引
  82 + local needDiscount = data.discount -- 需要的折扣数量
  83 + local curHad = {}
  84 + local advShop = adv.owner:getProperty("advShop")
  85 + local function randomGoods(range, gcount)
  86 + local pool = range:toTableArray(true) -- {{id, weight}, ... }
  87 + local function randomOneGood()
  88 + for i = #pool, 1, -1 do
  89 + local curId = pool[i][1]
  90 + local curData = csvdb["event_trader_goodsCsv"][curId]
  91 + if not curData then
  92 + table.remove(pool, i)
  93 + else
  94 + if curData.restrict == 1 then -- 冒险内限制
  95 + if curData.restrictnum <= ((adv.shopStatus[curId] or 0) + (curHad[curId] or 0)) then
  96 + table.remove(pool, i)
  97 + end
  98 + elseif curData.restrict == 2 then -- 角色限制
  99 + if curData.restrictnum <= ((advShop[curId] or 0) + (curHad[curId] or 0)) then
  100 + table.remove(pool, i)
  101 + end
  102 + end
  103 + end
  104 + end
  105 + if #pool <= 0 then
  106 + return false
  107 + end
  108 + local idx = math.randWeight(pool, 2)
  109 + local getId = pool[idx][1]
  110 + local getData = svdb["event_trader_goodsCsv"][getId]
  111 + if getData.restrict ~= 0 then
  112 + curHad[curId] = (curHad[curId] or 0) + 1
  113 + end
  114 + if getData.discount ~= "" and needDiscount > 0 then
  115 + needDiscount = needDiscount - 1
  116 + table.insert(self.event.shop, {getId, getData.discount:randWeight()})
  117 + else
  118 + table.insert(self.event.shop, {getId})
  119 + end
  120 + return true
  121 + end
  122 +
  123 + for i = 1, gcount do
  124 + if not randomOneGood() then
  125 + break
  126 + end
  127 + end
  128 + end
  129 +
82 130 for i = 1, 10 do
83 131 local numS, rangeS = "num" .. i, "range" .. i
84 132 if data[numS] and data[rangeS] then
85   - for j = 1, data[numS] do
86   - table.insert(self.event.shop, data[rangeS]:randWeight(true))
87   - end
  133 + randomGoods(data[rangeS], data[numS])
88 134 else
89 135 break
90 136 end
... ...
1   -Subproject commit 4f8cd94220fea86bbad962ae0023dd7484dccda2
  1 +Subproject commit 9a3181fa2f55dd5a1247bfd99f596b0cbc96a828
... ...
src/models/Role.lua
... ... @@ -70,12 +70,13 @@ Role.schema = {
70 70 advAFWear = {"table", {}}, -- 当前拥有的神器 {[slot] = id}
71 71 advDrawB = {"table", {}}, -- 冒险抽奖回馈 {[1] = 0, [2] = 100} -- 池子类型 = 点数
72 72 advStoryB = {"table", {}}, -- 冒险故事完成记录 (连锁事件绑定的故事) -- {storyId = 1}
  73 + advShop = {"table", {}}, -- 冒险內的商店限制购买次数记录 {goodId = count}
73 74  
74 75 --挂机相关
75 76 hangPass = {"table", {}}, -- 挂机通过的最大关卡
76 77 hangTeam = {"table", {}}, -- 挂机队伍
77 78 hangTS = {"table", {}}, -- 挂机队伍他人可读的队伍信息
78   - hangTB = {"table", {}}, -- 挂机队伍他人可用的战斗信息
  79 + hangTB = {"table", {}}, -- 挂机队伍他人可用的战斗信息mao
79 80 hangTBV = {"number", 0}, -- 挂机队伍他人可用的战斗力
80 81  
81 82 hangInfo = {"table", {}}, -- 当前挂机信息
... ... @@ -251,6 +252,7 @@ function Role:data()
251 252 advAFGet = self:getProperty("advAFGet"),
252 253 advAFWear = self:getProperty("advAFWear"),
253 254 advDrawB = self:getProperty("advDrawB"),
  255 + advShop = self:getProperty("advShop"),
254 256  
255 257 hangPass = self:getProperty("hangPass"),
256 258 hangTeam = self:getProperty("hangTeam"),
... ...