Commit f8408529b103c034e9daaf309e2ea96c5e2f0429

Authored by zhouhaihai
1 parent 44dd6cae

冒险商店

@@ -12,6 +12,7 @@ function Adv:ctor(owner) @@ -12,6 +12,7 @@ function Adv:ctor(owner)
12 assert(owner, "Adv instance must have owner(role)") 12 assert(owner, "Adv instance must have owner(role)")
13 self.owner = owner 13 self.owner = owner
14 self.maps = {} 14 self.maps = {}
  15 + self.shopStatus = {}
15 self.battle = nil 16 self.battle = nil
16 self.backEvents = {} --发给客户端的事件组 17 self.backEvents = {} --发给客户端的事件组
17 18
@@ -35,6 +36,8 @@ function Adv:initByInfo(advInfo) @@ -35,6 +36,8 @@ function Adv:initByInfo(advInfo)
35 self.lchoose = advInfo.lch or {} 36 self.lchoose = advInfo.lch or {}
36 self.waitArtifact = advInfo.waitAF 37 self.waitArtifact = advInfo.waitAF
37 self.cacheUnlock = advInfo.cacheUnlock or {} 38 self.cacheUnlock = advInfo.cacheUnlock or {}
  39 + self.shopStatus = advInfo.shopStatus or {}
  40 +
38 self.maps = {} 41 self.maps = {}
39 for id, map in ipairs(advInfo.maps or {}) do 42 for id, map in ipairs(advInfo.maps or {}) do
40 self.maps[id] = AdvMap.new(self, id, map) 43 self.maps[id] = AdvMap.new(self, id, map)
@@ -59,6 +62,7 @@ function Adv:initByChapter(chapterId, level, isToNext, notNotify) @@ -59,6 +62,7 @@ function Adv:initByChapter(chapterId, level, isToNext, notNotify)
59 self.mapStack = {1} -- 最后一个为当前的地图 62 self.mapStack = {1} -- 最后一个为当前的地图
60 self.lchoose = self.lchoose or {} 63 self.lchoose = self.lchoose or {}
61 self.cacheUnlock = self.cacheUnlock or {} 64 self.cacheUnlock = self.cacheUnlock or {}
  65 + self.shopStatus = self.shopStatus or {}
62 66
63 -- 随机出地图 67 -- 随机出地图
64 local mapId = self:randomMapId(chapterId, level) 68 local mapId = self:randomMapId(chapterId, level)
@@ -92,6 +96,7 @@ function Adv:clear() @@ -92,6 +96,7 @@ function Adv:clear()
92 self.battle = nil 96 self.battle = nil
93 self.waitArtifact = nil 97 self.waitArtifact = nil
94 self.cacheUnlock = {} 98 self.cacheUnlock = {}
  99 + self.shopStatus = {}
95 end 100 end
96 101
97 function Adv:saveDB(notNotify) 102 function Adv:saveDB(notNotify)
@@ -107,6 +112,7 @@ function Adv:saveDB(notNotify) @@ -107,6 +112,7 @@ function Adv:saveDB(notNotify)
107 advInfo.lch = self.lchoose 112 advInfo.lch = self.lchoose
108 advInfo.waitAF = self.waitArtifact 113 advInfo.waitAF = self.waitArtifact
109 advInfo.cacheUnlock = self.cacheUnlock 114 advInfo.cacheUnlock = self.cacheUnlock
  115 + advInfo.shopStatus = self.shopStatus
110 advInfo.maps = {} 116 advInfo.maps = {}
111 117
112 self.battle:saveDB() 118 self.battle:saveDB()
@@ -792,9 +798,22 @@ local function clickTrader(self, room, block, params) @@ -792,9 +798,22 @@ local function clickTrader(self, room, block, params)
792 if not block.event.shop or not block.event.shop[buyId] then return end 798 if not block.event.shop or not block.event.shop[buyId] then return end
793 if (block.event.status or ""):getv(buyId, 0) == 1 then return end -- 买过了 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 block.event.status = block.event.status:setv(buyId, 1) 817 block.event.status = block.event.status:setv(buyId, 1)
799 self:checkTask(Adv.TaskType.Shop, 1, block.event.id) 818 self:checkTask(Adv.TaskType.Shop, 1, block.event.id)
800 self:checkAchievement(Adv.AchievType.Shop, 1, block.event.id) 819 self:checkAchievement(Adv.AchievType.Shop, 1, block.event.id)
src/adv/AdvBlock.lua
@@ -79,12 +79,58 @@ function Block:randomEvent() @@ -79,12 +79,58 @@ function Block:randomEvent()
79 local data = csvdb["event_traderCsv"][self.event.id] 79 local data = csvdb["event_traderCsv"][self.event.id]
80 self.event.shop = {} 80 self.event.shop = {}
81 self.event.status = "" --购买次数状态 1 就是购买过了 -- 购买id就是shop索引 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 for i = 1, 10 do 130 for i = 1, 10 do
83 local numS, rangeS = "num" .. i, "range" .. i 131 local numS, rangeS = "num" .. i, "range" .. i
84 if data[numS] and data[rangeS] then 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 else 134 else
89 break 135 break
90 end 136 end
1 -Subproject commit 4f8cd94220fea86bbad962ae0023dd7484dccda2 1 +Subproject commit 9a3181fa2f55dd5a1247bfd99f596b0cbc96a828
src/models/Role.lua
@@ -70,12 +70,13 @@ Role.schema = { @@ -70,12 +70,13 @@ Role.schema = {
70 advAFWear = {"table", {}}, -- 当前拥有的神器 {[slot] = id} 70 advAFWear = {"table", {}}, -- 当前拥有的神器 {[slot] = id}
71 advDrawB = {"table", {}}, -- 冒险抽奖回馈 {[1] = 0, [2] = 100} -- 池子类型 = 点数 71 advDrawB = {"table", {}}, -- 冒险抽奖回馈 {[1] = 0, [2] = 100} -- 池子类型 = 点数
72 advStoryB = {"table", {}}, -- 冒险故事完成记录 (连锁事件绑定的故事) -- {storyId = 1} 72 advStoryB = {"table", {}}, -- 冒险故事完成记录 (连锁事件绑定的故事) -- {storyId = 1}
  73 + advShop = {"table", {}}, -- 冒险內的商店限制购买次数记录 {goodId = count}
73 74
74 --挂机相关 75 --挂机相关
75 hangPass = {"table", {}}, -- 挂机通过的最大关卡 76 hangPass = {"table", {}}, -- 挂机通过的最大关卡
76 hangTeam = {"table", {}}, -- 挂机队伍 77 hangTeam = {"table", {}}, -- 挂机队伍
77 hangTS = {"table", {}}, -- 挂机队伍他人可读的队伍信息 78 hangTS = {"table", {}}, -- 挂机队伍他人可读的队伍信息
78 - hangTB = {"table", {}}, -- 挂机队伍他人可用的战斗信息 79 + hangTB = {"table", {}}, -- 挂机队伍他人可用的战斗信息mao
79 hangTBV = {"number", 0}, -- 挂机队伍他人可用的战斗力 80 hangTBV = {"number", 0}, -- 挂机队伍他人可用的战斗力
80 81
81 hangInfo = {"table", {}}, -- 当前挂机信息 82 hangInfo = {"table", {}}, -- 当前挂机信息
@@ -251,6 +252,7 @@ function Role:data() @@ -251,6 +252,7 @@ function Role:data()
251 advAFGet = self:getProperty("advAFGet"), 252 advAFGet = self:getProperty("advAFGet"),
252 advAFWear = self:getProperty("advAFWear"), 253 advAFWear = self:getProperty("advAFWear"),
253 advDrawB = self:getProperty("advDrawB"), 254 advDrawB = self:getProperty("advDrawB"),
  255 + advShop = self:getProperty("advShop"),
254 256
255 hangPass = self:getProperty("hangPass"), 257 hangPass = self:getProperty("hangPass"),
256 hangTeam = self:getProperty("hangTeam"), 258 hangTeam = self:getProperty("hangTeam"),