|
@@ -52,11 +52,26 @@ local function TreasureChestLogic_GetPointPrizeConf()
|
|
|
table.insert(tCacheBoxPrize[nType], v)
|
|
table.insert(tCacheBoxPrize[nType], v)
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
|
|
+ -- 变成有序
|
|
|
for _, v in pairs(tCacheBoxPrize) do
|
|
for _, v in pairs(tCacheBoxPrize) do
|
|
|
table.sort(v, function (l, r)
|
|
table.sort(v, function (l, r)
|
|
|
return l.nPro < r.nPro
|
|
return l.nPro < r.nPro
|
|
|
end)
|
|
end)
|
|
|
end
|
|
end
|
|
|
|
|
+
|
|
|
|
|
+ -- 整合权重
|
|
|
|
|
+ for _, data in ipairs(tCacheBoxPrize) do
|
|
|
|
|
+ local nAllWeight = 0
|
|
|
|
|
+ for _, v in ipairs(data) do
|
|
|
|
|
+ if nAllWeight == 0 then
|
|
|
|
|
+ nAllWeight = v.nPro
|
|
|
|
|
+ else
|
|
|
|
|
+ nAllWeight = nAllWeight + v.nPro
|
|
|
|
|
+ end
|
|
|
|
|
+
|
|
|
|
|
+ v.nAllPro = nAllWeight
|
|
|
|
|
+ end
|
|
|
|
|
+ end
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
return tCacheBoxPrize
|
|
return tCacheBoxPrize
|
|
@@ -130,6 +145,8 @@ local function TreasureChestLogic_UpdatePointPrize(human)
|
|
|
if CommonDefine.COMMON_PRIZE_STATE_NOGET == nState then
|
|
if CommonDefine.COMMON_PRIZE_STATE_NOGET == nState then
|
|
|
TreasureChestLogic_SetDBPointPrize(human, nID, CommonDefine.COMMON_PRIZE_STATE_CANGET)
|
|
TreasureChestLogic_SetDBPointPrize(human, nID, CommonDefine.COMMON_PRIZE_STATE_CANGET)
|
|
|
nNowPoint = nNowPoint - v.nPoint
|
|
nNowPoint = nNowPoint - v.nPoint
|
|
|
|
|
+ elseif CommonDefine.COMMON_PRIZE_STATE_CANGET == nState then
|
|
|
|
|
+ nNowPoint = nNowPoint - v.nPoint
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
@@ -144,23 +161,23 @@ local function TreasureChestLogic_OpenBox(nType, nBoxNum)
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
local nOpenNum = tBoxTypeConf[nType].nOpenNum
|
|
local nOpenNum = tBoxTypeConf[nType].nOpenNum
|
|
|
|
|
+ -- 获取的表是有序的
|
|
|
local tBoxTypePrize = tBoxPrize[nType]
|
|
local tBoxTypePrize = tBoxPrize[nType]
|
|
|
-
|
|
|
|
|
- -- 整合权重
|
|
|
|
|
- local nWeight, tWeightPrize = 0, {}
|
|
|
|
|
- for _, v in ipairs(tBoxTypePrize) do
|
|
|
|
|
- nWeight = nWeight + v.nPro
|
|
|
|
|
- tWeightPrize[nWeight] = v
|
|
|
|
|
- end
|
|
|
|
|
|
|
+ local nLen = #tBoxTypePrize
|
|
|
|
|
+ local nAllWeight = tBoxTypePrize[nLen].nAllPro
|
|
|
|
|
+ --print("[TreasureChestLogic_OpenBox] nAllWeight = "..nAllWeight)
|
|
|
|
|
|
|
|
local tOpenPrize = {}
|
|
local tOpenPrize = {}
|
|
|
for i = 1, nBoxNum, 1 do
|
|
for i = 1, nBoxNum, 1 do
|
|
|
for j = 1, nOpenNum, 1 do
|
|
for j = 1, nOpenNum, 1 do
|
|
|
-- 随机权重
|
|
-- 随机权重
|
|
|
- local nRandNum = math.random(1, nWeight)
|
|
|
|
|
- for nkey, v in pairs(tWeightPrize) do
|
|
|
|
|
- if nRandNum <= nkey then
|
|
|
|
|
|
|
+ local nRandNum = math.random(1, nAllWeight)
|
|
|
|
|
+ --print("[TreasureChestLogic_OpenBox] j = "..j.." nRandNum = "..nRandNum)
|
|
|
|
|
+ for _, v in pairs(tBoxTypePrize) do
|
|
|
|
|
+ --print("[TreasureChestLogic_OpenBox] nAllPro = "..v.nAllPro.." ID = "..v.tPrize[1].." num = "..v.tPrize[2].."\n")
|
|
|
|
|
+ if nRandNum <= v.nAllPro then
|
|
|
table.insert(tOpenPrize, v.tPrize)
|
|
table.insert(tOpenPrize, v.tPrize)
|
|
|
|
|
+ --print("[TreasureChestLogic_OpenBox] 获得的道具 nID = "..v.tPrize[1].." nNum = "..v.tPrize[2].." nKey "..v.nAllPro)
|
|
|
break
|
|
break
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|