Commit e08b052f66d04acbc5422ba7276580ac901c7c45

Authored by jiyue
2 parents 40745a5b 49df162b

Merge branch 'cn/develop' into cn/player

@@ -154,6 +154,7 @@ ItemId = { @@ -154,6 +154,7 @@ ItemId = {
154 AdvKey = 80, -- 冒险钥匙 154 AdvKey = 80, -- 冒险钥匙
155 AdvPower = 4701, -- 拾荒体力 155 AdvPower = 4701, -- 拾荒体力
156 CrisisScore = 8010, -- 积分 156 CrisisScore = 8010, -- 积分
  157 + MonthCard = 31000, --兑换月卡的物品
157 } 158 }
158 159
159 TimeReset = { 160 TimeReset = {
src/ProtocolCode.lua
@@ -59,6 +59,7 @@ actionCodes = { @@ -59,6 +59,7 @@ actionCodes = {
59 Role_runeBuyRpc = 142, -- 铭文购买 59 Role_runeBuyRpc = 142, -- 铭文购买
60 Role_setFriendTeamRpc = 143, -- 设置好友切磋队伍 60 Role_setFriendTeamRpc = 143, -- 设置好友切磋队伍
61 Role_setBgRpc = 144, -- 设置看板娘 61 Role_setBgRpc = 144, -- 设置看板娘
  62 + Role_itemConvertMonthCardRpc = 145, -- 兑换月卡道具
62 63
63 Adv_startAdvRpc = 151, 64 Adv_startAdvRpc = 151,
64 Adv_startHangRpc = 152, 65 Adv_startHangRpc = 152,
@@ -273,6 +274,17 @@ actionCodes = { @@ -273,6 +274,17 @@ actionCodes = {
273 Seaport_taskRpc = 753, 274 Seaport_taskRpc = 753,
274 Seaport_shopRpc = 754, 275 Seaport_shopRpc = 754,
275 Seaport_resetRpc = 755, 276 Seaport_resetRpc = 755,
  277 +
  278 + Capsule_listRpc = 850, --扭蛋机列表
  279 + Capsule_joinRpc = 851, --扭蛋机详情
  280 + Capsule_registerRpc = 853, --报名扭蛋机 "报名"后,抽取按钮才会开放,未报名的玩家分在围观玩家中
  281 + Capsule_drawRpc = 854, --抽扭蛋机
  282 + --Capsule_switchRoomRpc = 855, --切换扭蛋机房间
  283 + Capsule_notifyChange = 856, -- 通知信息变动
  284 + Capsule_payReward = 857, -- 特殊赏 奖励通知
  285 + Capsule_exitRpc = 858, -- 退出
  286 + Capsule_getDataRpc = 859, --获取扭蛋机信息
  287 + Capsule_convertCapsuleRpc = 890, --兑换消耗票
276 } 288 }
277 289
278 rpcResponseBegin = 10000 290 rpcResponseBegin = 10000
@@ -63,6 +63,15 @@ FRIEND_RECOMMEND = "friend:recommend" -- sort set ç™»å½•æŽ’åº èŽ·å–æŽ¨è好å @@ -63,6 +63,15 @@ FRIEND_RECOMMEND = "friend:recommend" -- sort set ç™»å½•æŽ’åº èŽ·å–æŽ¨è好å
63 CHAT_OFFLINE = "chat:offline:%d" --消æ¯ç¦»çº¿ç¼“å­˜ 63 CHAT_OFFLINE = "chat:offline:%d" --消æ¯ç¦»çº¿ç¼“å­˜
64 64
65 WORK_BATTLE_COUNT = "global:workbattle" -- 世界次数统计 65 WORK_BATTLE_COUNT = "global:workbattle" -- 世界次数统计
  66 +
  67 +--Capsule 扭蛋机
  68 +CAPSULE_INFO= "capsule:info" --set
  69 +CAPSULE_PUBLIC = "capsule:%d:info" --hash
  70 +
  71 +CAPSULE_ID_ROLE = "role:%s:capsule:id" -- set
  72 +CAPSULE_ROLE = "role:%s:capsule:%d" --hash 独享
  73 +
  74 +
66 -- FRIEND_DINER_LIKE_KEY = "role:%d:diner:like" -- list 75 -- FRIEND_DINER_LIKE_KEY = "role:%d:diner:like" -- list
67 76
68 -- UNION_SET = "global:union" 77 -- UNION_SET = "global:union"
src/actions/CapsuleAction.lua 0 → 100644
@@ -0,0 +1,198 @@ @@ -0,0 +1,198 @@
  1 +local ipairs = ipairs
  2 +local table = table
  3 +local math = math
  4 +local next = next
  5 +local string = string
  6 +local redisproxy = redisproxy
  7 +local MsgPack = MsgPack
  8 +local getRandomName = getRandomName
  9 +local mcast_util = mcast_util
  10 +local string_format = string.format
  11 +local tonumber = tonumber
  12 +local require = require
  13 +
  14 +local _M = {}
  15 +
  16 +function _M.listRpc(agent, data)
  17 + local role = agent.role
  18 + local msg = MsgPack.unpack(data)
  19 + local typ = msg.typ
  20 + local coin = msg.coin
  21 +
  22 + local capsules = {}
  23 + if typ == 1 then
  24 + local ret = skynet.call(agent.capsule_serv, "lua", "list", coin)
  25 + if next(ret) then
  26 + for k, v in pairs(ret) do
  27 + capsules[k] = v
  28 + end
  29 + end
  30 + elseif typ == 0 then
  31 + local ret = role:getCapsuleList(coin)
  32 + if next(ret) then
  33 + for k, v in pairs(ret) do
  34 + capsules[k] = v
  35 + end
  36 + end
  37 + end
  38 +
  39 + SendPacket(actionCodes.Capsule_listRpc, MsgPack.pack(capsules))
  40 + return true
  41 +end
  42 +
  43 +function _M.joinRpc(agent, data)
  44 + local role = agent.role
  45 + local msg = MsgPack.unpack(data)
  46 + local roleId = role:getProperty("id")
  47 + local capsuleId = msg.capsule_id --如果刷新则需要传递当前扭蛋机id
  48 + local typ = msg.typ or 1
  49 +
  50 + local ret = {}
  51 + if typ == 1 then
  52 + ret = skynet.call(agent.capsule_serv, "lua", "join", roleId, capsuleId)
  53 + elseif typ == 0 then
  54 + ret = role:joinCapsule()
  55 + end
  56 + SendPacket(actionCodes.Capsule_joinRpc, MsgPack.pack(ret))
  57 + return true
  58 +end
  59 +
  60 +function _M.exitRpc(agent, data)
  61 + local role = agent.role
  62 + local msg = MsgPack.unpack(data)
  63 + local roleId = role:getProperty("id")
  64 + local capsuleId = msg.capsule_id --如果刷新则需要传递当前扭蛋机id
  65 + local typ = msg.typ or 1
  66 +
  67 + local ret = {}
  68 + if typ == 1 then
  69 + ret = skynet.call(agent.capsule_serv, "lua", "exit", roleId, capsuleId)
  70 + elseif typ == 0 then
  71 + ret = role:exitCapsule()
  72 + end
  73 +
  74 + SendPacket(actionCodes.Capsule_exitRpc, MsgPack.pack(ret))
  75 + return true
  76 +end
  77 +
  78 +function _M.registerRpc(agent, data)
  79 + local role = agent.role
  80 + local msg = MsgPack.unpack(data)
  81 + local roleId = role:getProperty("id")
  82 + local capsuleId = msg.capsule_id
  83 +
  84 + local ret = skynet.call(agent.capsule_serv, "lua", "register", roleId, capsuleId)
  85 + if not ret then return 1 end
  86 + SendPacket(actionCodes.Capsule_registerRpc, MsgPack.pack(ret))
  87 + return true
  88 +end
  89 +
  90 +function _M.drawRpc(agent, data)
  91 + local role = agent.role
  92 + local msg = MsgPack.unpack(data)
  93 + local roleId = role:getProperty("id")
  94 + local capsuleId = msg.capsule_id
  95 + local typ = msg.typ --0=独享,1= 公开
  96 + local full = msg.full or 0-- 0=单次,1=十连抽 2=全收
  97 + local cares = msg.cares
  98 +
  99 + local ret, token, reward, change, rewardByGoods, capsule
  100 +
  101 + --检查库存
  102 + if typ == 1 then
  103 + ret, token = skynet.call(agent.capsule_serv, "lua", "goods_stock", capsuleId)
  104 + else
  105 + ret, token = role:goodStock(capsuleId)
  106 + end
  107 + if ret == 0 then skynet.error("零库存 " .. capsuleId) return 0 end
  108 +
  109 + --检查余额
  110 + if not next(token) then skynet.error("代币未配置 " .. capsuleId) return 1 end
  111 + local cost, drawsNum = {}, 0
  112 + if full == 0 then
  113 + drawsNum = 1
  114 + elseif full == 1 then
  115 + if ret < 10 then
  116 + drawsNum = ret
  117 + else
  118 + drawsNum = 10
  119 + end
  120 + elseif full == 2 then
  121 + drawsNum = ret
  122 + end
  123 + cost[token[1]] = drawsNum * token[2]
  124 +
  125 + if not role:checkItemEnough(cost) then return 2 end
  126 + role:costItems(cost, {log = {desc = "CapsuleCoinCost", int1 = token[1], int2 = cost[token[1]]}})
  127 +
  128 + --开始抽奖
  129 + if typ == 1 then
  130 + ret, reward, rewardByGoods, capsule = skynet.call(agent.capsule_serv, "lua", "draw_capsule", roleId, capsuleId, full, cares)
  131 + else
  132 + ret, reward, rewardByGoods, capsule= role:drawCapsule(capsuleId, full, cares)
  133 + end
  134 + if ret < 5 then
  135 + return ret
  136 + end
  137 +
  138 + --dump(rewardByGoods)
  139 + --dump(capsule)
  140 +
  141 + if ret == 5 then
  142 + SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack({change = reward, capsule = capsule}))
  143 + return true
  144 + end
  145 +
  146 + -- rewardByGoods是抽到的扭蛋信息,reward是抽扭蛋后获得的所有奖励信息。
  147 + if rewardByGoods and next(rewardByGoods) then
  148 + reward, change = role:award(reward, {log = {desc = "CapsuleReward", int1 = tonumber(capsuleId), int2 = roleId}})
  149 + SendPacket(actionCodes.Capsule_drawRpc, MsgPack.pack({reward = rewardByGoods, capsule = capsule}))
  150 + else
  151 + return ret
  152 + end
  153 + return true
  154 +end
  155 +
  156 +function _M.getDataRpc(agent, data)
  157 + local role = agent.role
  158 + local msg = MsgPack.unpack(data)
  159 + local capsuleId = msg.capsule_id
  160 + local typ = msg.typ --0=独享,1= 公开
  161 + local roleId = role:getProperty("id")
  162 +
  163 + local capsule
  164 + if typ == 1 then
  165 + capsule = skynet.call(agent.capsule_serv, "lua", "capsule_data", roleId, capsuleId)
  166 + else
  167 + capsule = role:getCapsuleData(capsuleId)
  168 + end
  169 + if not capsule then return 1 end
  170 +
  171 + SendPacket(actionCodes.Capsule_getDataRpc, MsgPack.pack({capsule = capsule}))
  172 + return true
  173 +
  174 +end
  175 +
  176 +function _M.convertCapsuleRpc(agent, data)
  177 + local role = agent.role
  178 + local msg = MsgPack.unpack(data)
  179 + local coin = msg.coin
  180 + local count = msg.count or 1
  181 +
  182 + local cost, convert = {}
  183 + for k, v in pairs(globalCsv.ichibankuji_buy_cost)do
  184 + if k == coin then
  185 + convert = v:toArray(true, "=")
  186 + break
  187 + end
  188 + end
  189 + cost[convert[1]] = convert[2] * count
  190 + if not role:checkItemEnough(cost) then return 1 end
  191 + role:costItems(cost, {log = {desc = "CapsuleConvert", int1 = convert[1], int2 = cost[convert[1]]}})
  192 +
  193 + local reward, change = role:award({coin = count}, {log = {desc = "CapsuleConvert"}})
  194 + SendPacket(actionCodes.Capsule_convertCapsuleRpc, MsgPack.pack(role:packReward(reward, change)))
  195 + return true
  196 +end
  197 +
  198 +return _M
0 \ No newline at end of file 199 \ No newline at end of file
src/actions/GmAction.lua
@@ -9,7 +9,7 @@ function _M.clientRequest(agent, data) @@ -9,7 +9,7 @@ function _M.clientRequest(agent, data)
9 SendPacket(actionCodes.Gm_receiveResponse, bin) 9 SendPacket(actionCodes.Gm_receiveResponse, bin)
10 return true 10 return true
11 end 11 end
12 - local ret = action(role, msg) 12 + local ret = action(role, msg, agent.capsule_serv)
13 bin = MsgPack.pack({ cmd = ret }) 13 bin = MsgPack.pack({ cmd = ret })
14 SendPacket(actionCodes.Gm_receiveResponse, bin) 14 SendPacket(actionCodes.Gm_receiveResponse, bin)
15 return true 15 return true
@@ -1075,4 +1075,15 @@ function _M.clear_sea(role, pms) @@ -1075,4 +1075,15 @@ function _M.clear_sea(role, pms)
1075 return "成功" 1075 return "成功"
1076 end 1076 end
1077 1077
  1078 +table.insert(helpDes, {"重置扭蛋机", "reset_capsule", "typ"})
  1079 +function _M.reset_capsule(role, pms, capsule_serv)
  1080 + local typ = tonumber(pms.pm1)
  1081 + if typ == 1 then
  1082 + skynet.call(capsule_serv, "lua", "reset")
  1083 + else
  1084 + role:resetCapsule()
  1085 + end
  1086 + return "成功"
  1087 +end
  1088 +
1078 return _M 1089 return _M
1079 \ No newline at end of file 1090 \ No newline at end of file
src/actions/RoleAction.lua
@@ -1710,4 +1710,36 @@ function _M.setBgRpc(agent, data) @@ -1710,4 +1710,36 @@ function _M.setBgRpc(agent, data)
1710 return true 1710 return true
1711 end 1711 end
1712 1712
  1713 +function _M.itemConvertMonthCardRpc(agent, data)
  1714 + local role = agent.role
  1715 + local msg = MsgPack.unpack(data)
  1716 + local itemId = msg.item_id
  1717 + local typ = msg.typ
  1718 + local count = msg.count
  1719 + local exchangeId = msg.change_id
  1720 +
  1721 + if not ItemId[itemId] then return 1 end
  1722 +
  1723 + if not role:checkItemEnough({[itemId] = count}) then return 2 end
  1724 + role:costItems({[itemId] = count}, {log = {desc = "itemConvertmonthCard", int1 = count, int2 = count}})
  1725 +
  1726 + local rechargeData = csvdb["shop_rechargeCsv"][exchangeId]
  1727 + if not rechargeData then
  1728 + skynet.error("[recharge] recharge id not exist", exchangeId)
  1729 + return 3
  1730 + end
  1731 + local reward = {}
  1732 + for i = 1, count do
  1733 + local tmpreward, _ = role.storeData:onBuyCard(rechargeData.type, rechargeData.id , rechargeData.activity_id)
  1734 + if tmpreward then
  1735 + table.rewardMerge(reward, tmpreward)
  1736 + else
  1737 + return
  1738 + end
  1739 + end
  1740 +
  1741 + SendPacket(actionCodes.Role_itemConvertMonthCardRpc, MsgPack.pack(role:packReward(reward)))
  1742 + return status
  1743 +end
  1744 +
1713 return _M 1745 return _M
1714 \ No newline at end of file 1746 \ No newline at end of file
src/actions/StoreAction.lua
@@ -23,7 +23,7 @@ function _M.rechargeRpc(agent , data) @@ -23,7 +23,7 @@ function _M.rechargeRpc(agent , data)
23 skynet.timeout(10, function () 23 skynet.timeout(10, function ()
24 role:handlePurchase({ 24 role:handlePurchase({
25 order = partnerOrderId, 25 order = partnerOrderId,
26 - amount = dataSet.rmb * 100, 26 + amount = dataSet.rmb * 100 / globalCsv.QArecharge,
27 game_money = dataSet.diamond, 27 game_money = dataSet.diamond,
28 product_id = dataSet.productId, 28 product_id = dataSet.productId,
29 pay_time = skynet.timex(), 29 pay_time = skynet.timex(),
@@ -290,15 +290,17 @@ function _M.shopBuyRpc(agent , data) @@ -290,15 +290,17 @@ function _M.shopBuyRpc(agent , data)
290 return 1 290 return 1
291 end 291 end
292 292
293 - local cost = {[dataSet.icon] = dataSet.cost * count} 293 + local cost
  294 + if dataSet.disount == 0 then
  295 + cost = {[dataSet.icon] = math.ceil(dataSet.cost * count)}
  296 + else
  297 + cost = {[dataSet.icon] = math.ceil(dataSet.cost * count * ((dataSet.disount or 10) / 10))}
  298 + end
  299 +
294 300
295 local desc = "unknowShop" 301 local desc = "unknowShop"
296 if dataSet.shop == 1 then -- 普通商店 302 if dataSet.shop == 1 then -- 普通商店
297 desc = "dailyShop" 303 desc = "dailyShop"
298 - local dailySDD = role.dailyData:getProperty("dailySDD")  
299 - if dailySDD[id] then -- 折扣  
300 - cost = math.ceil(dataSet.cost * (1 - dataSet.disount / 100))  
301 - end  
302 elseif dataSet.shop == 2 then -- 美食商店 304 elseif dataSet.shop == 2 then -- 美食商店
303 desc = "dinerShop" 305 desc = "dinerShop"
304 elseif dataSet.shop == 3 then -- 竞技场商店 306 elseif dataSet.shop == 3 then -- 竞技场商店
@@ -313,7 +315,7 @@ function _M.shopBuyRpc(agent , data) @@ -313,7 +315,7 @@ function _M.shopBuyRpc(agent , data)
313 role.storeData:updateProperty({field = "buyR", value = buyRecord}) 315 role.storeData:updateProperty({field = "buyR", value = buyRecord})
314 limitStr = string.format("%s/%s", buyRecord[id], dataSet.limit) 316 limitStr = string.format("%s/%s", buyRecord[id], dataSet.limit)
315 end 317 end
316 - role:costItems(cost, {log = {desc = desc, int1 = id, int2 = count, short1 = dataSet.shop}}) 318 + role:costItems(cost, {log = {desc = desc, int1 = id, int2 = count, cint1= dataSet.shop}})
317 319
318 local gift = {} 320 local gift = {}
319 for _id, _count in pairs(dataSet.gift:toNumMap()) do 321 for _id, _count in pairs(dataSet.gift:toNumMap()) do
@@ -1713,7 +1713,7 @@ local function clickTrader(self, room, block, params) @@ -1713,7 +1713,7 @@ local function clickTrader(self, room, block, params)
1713 local goodsData = csvdb["event_trader_goodsCsv"][block.event.shop[buyId][1]] 1713 local goodsData = csvdb["event_trader_goodsCsv"][block.event.shop[buyId][1]]
1714 if not goodsData then return false, 5 end 1714 if not goodsData then return false, 5 end
1715 1715
1716 - local costCount = math.ceil(goodsData.price * (1 - (block.event.shop[buyId][2] or 100) / 100)) 1716 + local costCount = math.ceil(goodsData.price * (1 - (block.event.shop[buyId][2] or 0) / 100))
1717 if not self:cost({[goodsData.currency] = costCount}, {log = {desc = "clickTrader", int1 = block.event.id}}) then return false, 6 end --不够 1717 if not self:cost({[goodsData.currency] = costCount}, {log = {desc = "clickTrader", int1 = block.event.id}}) then return false, 6 end --不够
1718 self:backCost({[goodsData.currency] = costCount}) 1718 self:backCost({[goodsData.currency] = costCount})
1719 self:award({[goodsData.item] = goodsData.num}, {log = {desc = "clickTrader", int1 = block.event.id}}, {}) 1719 self:award({[goodsData.item] = goodsData.num}, {log = {desc = "clickTrader", int1 = block.event.id}}, {})
@@ -254,11 +254,12 @@ skynet.register_protocol { @@ -254,11 +254,12 @@ skynet.register_protocol {
254 } 254 }
255 255
256 -- function CMD.start(gate, fd, ip) 256 -- function CMD.start(gate, fd, ip)
257 -function CMD.start(session, source, gate, fd, ip, hotfixs) 257 +function CMD.start(session, source, gate, capsuled, fd, ip, hotfixs)
258 ignoreHeartbeat = false 258 ignoreHeartbeat = false
259 259
260 agentInfo.client_fd = fd 260 agentInfo.client_fd = fd
261 agentInfo.gate_serv = gate 261 agentInfo.gate_serv = gate
  262 + agentInfo.capsule_serv = capsuled
262 agentInfo.ip = ip 263 agentInfo.ip = ip
263 264
264 agent_util:reset() 265 agent_util:reset()
@@ -282,6 +283,8 @@ function CMD.close() @@ -282,6 +283,8 @@ function CMD.close()
282 mcast_util.usub_union() 283 mcast_util.usub_union()
283 local role = agentInfo.role 284 local role = agentInfo.role
284 if not role then return end 285 if not role then return end
  286 +
  287 + skynet.call(agentInfo.capsule_serv, "lua", "exit", role:getProperty("id"))
285 role:log("onLogout", {logtime = skynet.timex()-role:getProperty("ltime")}) 288 role:log("onLogout", {logtime = skynet.timex()-role:getProperty("ltime")})
286 role:mylog("logout", {int1 = skynet.timex()-role:getProperty("ltime")}) 289 role:mylog("logout", {int1 = skynet.timex()-role:getProperty("ltime")})
287 role:onOfflineEvent() 290 role:onOfflineEvent()
src/models/Capsule.lua 0 → 100644
@@ -0,0 +1,811 @@ @@ -0,0 +1,811 @@
  1 +--扭蛋机
  2 +local MsgPack = MsgPack
  3 +local Capsule = class("Capsule", require("shared.ModelBase"))
  4 +
  5 +function Capsule:ctor(properties)
  6 + Capsule.super.ctor(self, properties)
  7 +end
  8 +
  9 +RewardType = {
  10 + GOODS = 1,
  11 + SPECIAL = 2,
  12 + INCENTIVE = 3,
  13 +}
  14 +
  15 +SpecialType = {
  16 + TOP = 1,
  17 + CORE = 2,
  18 + LAST = 3,
  19 + JOKER = 4,
  20 + KING = 5,
  21 +}
  22 +
  23 +CapsuleType = {
  24 + PRIVATE = 0,
  25 + PUBLIC = 1,
  26 +}
  27 +
  28 +--[[
  29 +--通知数据结构
  30 +{ [roleId] = { [good_id1] = { }, [good_id2] = { }, } }
  31 +]]--
  32 +
  33 +Capsule.schema = {
  34 + id = {"number", 0}, --扭蛋机key,配置读取
  35 + room = {"number", 0}, --房间号, 配置读取
  36 + name = {"string"},
  37 + typ = {"number", 1}, -- 1=共享,2=独享
  38 + coin = {"number", 0}, --货币代号
  39 + token = {"table", {}}, --抽一次,货币=消耗
  40 + register = {"table", {}}, --人数 {["id"]=0}, 0 围观, 1 已报名
  41 + record = {"table", {}}, --抽取记录 列表
  42 + recordByRole = {"table", {}}, -- 抽取记录,hash, {roleid=record}
  43 + rank = {"table", {}}, --排行
  44 + goods = {"table", {}}, --奖励池
  45 + specials = {"table", {}}, --特殊赏
  46 + incentive = {"table", {}}, --激励奖
  47 + incentiveRecord = {"table", {}}, --激励奖记录
  48 + specialsRecord= {"table", {}}, --特殊赏领取记录
  49 + resetTimes = {"number", 0}, --每日一次手动重置的机会
  50 + hideTime = {"number", 0} , --隐藏时间
  51 + drawEndTime = {"number", 0}, --抽完时间
  52 +}
  53 +
  54 +function Capsule:getResetFields()
  55 + return {
  56 + id = self:getProperty("id"),
  57 + room = self:getProperty("room"),
  58 + typ = self:getProperty("typ"),
  59 + coin = 0,
  60 + token = {},
  61 + register = {},
  62 + record = {},
  63 + recordByRole = {},
  64 + rank = {},
  65 + goods = {},
  66 + specials = {},
  67 + incentive = {},
  68 + incentiveRecord = {},
  69 + specialsRecord= {},
  70 + resetTimes = 0,
  71 + hideTime = 0,
  72 + drawEndTime = 0,
  73 + }
  74 +end
  75 +
  76 +function Capsule:init()
  77 + local id = self:getProperty("id")
  78 + local room = self:getProperty("room")
  79 + self:setProperties(self:getResetFields())
  80 +
  81 + local ichibankuji = csvdb["ichibankuji_mainCsv"][id][room]
  82 +
  83 + --奖励池
  84 + local goods_id = ichibankuji["goods_id"]
  85 + local goods, specials, incentive = {}, {}, {}
  86 + for _, data in pairs(csvdb["ichibankuji_goodsCsv"]) do
  87 + for _, val in pairs(data) do
  88 + if val.key == goods_id then
  89 + goods[goods_id..val.id] = clone(val)
  90 + end
  91 + end
  92 + end
  93 + for _, v in pairs(goods) do
  94 + v.weight = (v.weight or 0) * v.amount
  95 + end
  96 +
  97 + --特殊赏
  98 + local special_ids = ichibankuji["special_id"]
  99 + if special_ids ~= "" then
  100 + for _, special_id in ipairs(special_ids:toArray(true, "=")) do
  101 + local val = csvdb["ichibankuji_specialCsv"][special_id]
  102 + if type(val.type) == "number" then
  103 + specials[special_id] = {np= 1, amount = val.amount, award = val.award, quality = tonumber(val.type), showIndex = val.showIndex}
  104 + elseif type(val.type) == "string" then
  105 + local pos = val.type:find("=")
  106 + if pos then
  107 + for k, v in pairs(val.type:toNumMap()) do
  108 + specials[special_id] = {np= v, amount = val.amount, award = val.award, quality = k, showIndex = val.showIndex}
  109 + end
  110 + else
  111 + specials[special_id] = {np= 1, amount = val.amount, award = val.award, quality = tonumber(val.type), showIndex = val.showIndex}
  112 + end
  113 + end
  114 + end
  115 + end
  116 +
  117 + --激励奖
  118 + local incentive_ids = ichibankuji["incentive_id"]
  119 + if incentive_ids ~= "" then
  120 + for _, incentive_id in ipairs(incentive_ids:toArray(true, "=")) do
  121 + local val = csvdb["ichibankuji_incentiveCsv"][incentive_id]
  122 + if type(val.type) == "number" then
  123 + incentive["last"] = {np=val.type, award = val.award}
  124 + elseif type(val.type) == "string" then
  125 + for k, v in pairs(val.type:toNumMap()) do
  126 + if k == 2 then
  127 + incentive["amount"] = {np= v, award = val.award}
  128 + elseif k==3 then
  129 + incentive["probabilities"] = {np= v, award = val.award}
  130 + end
  131 + end
  132 + end
  133 + end
  134 + end
  135 + --货币类型
  136 + local coin = ichibankuji["token"]:toArray(true, "=")
  137 + self:setProperties({coin = coin[1] or 0, token = coin, hideTime = ichibankuji.hide_time, goods = goods, specials = specials, incentive = incentive})
  138 +
  139 +end
  140 +
  141 +function Capsule:isShow()
  142 + if skynet.timex() >= self:getProperty("hideTime") then
  143 + return false
  144 + end
  145 + return true
  146 +end
  147 +
  148 +function Capsule:refreshing(now)
  149 + local id = self:getProperty("id")
  150 + local room = self:getProperty("room")
  151 + local ichibankuji = csvdb["ichibankuji_mainCsv"][id][room]
  152 + local reset = tostring(ichibankuji.reset)
  153 +
  154 + if reset == "0" then
  155 + return false
  156 + elseif reset == "1" then
  157 + if self:getProperty("resetTimes") == 1 then
  158 + return true
  159 + end
  160 + return false
  161 + else
  162 + local resetArr = reset:toArray(true, "=")
  163 + if not next(resetArr) then return false end
  164 +
  165 + if resetArr[1] == "2" then
  166 + if self:getGoodsAmount() > 0 then return false end
  167 +
  168 + local drawEndTime = self:getProperty("drawEndTime") or 0
  169 + if drawEndTime == 0 then return false end
  170 +
  171 + if now - drawEndTime >= resetArr[2] then
  172 + return true
  173 + end
  174 + return false
  175 +
  176 + elseif resetArr[1] == "3" then
  177 +
  178 + elseif resetArr[1] == "4" then
  179 + if now >= resetArr[2] then return true end
  180 + end
  181 + end
  182 +
  183 + return false
  184 +end
  185 +
  186 +function Capsule:getOnlineCount()
  187 + local register = self:getProperty("register") or {}
  188 + local reg, onlookers = 0, 0
  189 + for _, v in pairs(register) do
  190 + if v == 1 then
  191 + reg = reg + 1
  192 + else
  193 + onlookers = onlookers + 1
  194 + end
  195 + end
  196 + return {[0]=onlookers, [1]=reg, [2] = reg+onlookers}
  197 +end
  198 +
  199 +function Capsule:join(roleId)
  200 + --一个房间最多人数 TODO
  201 + local register = self:getProperty("register") or {}
  202 + register[roleId] = 0
  203 + self:setProperty("register", register)
  204 + return self:data(roleId)
  205 +end
  206 +
  207 +function Capsule:getRegisterByRoleId(roleId)
  208 + local register = self:getProperty("register") or {}
  209 + return register[roleId] or 0
  210 +end
  211 +
  212 +function Capsule:isRegister(roleId)
  213 + return self:getRegisterByRoleId(roleId) == 1
  214 +end
  215 +
  216 +function Capsule:register(roleId)
  217 + local register = self:getProperty("register") or {}
  218 + register[roleId] = 1
  219 + self:setProperty("register", register)
  220 + return self:data(roleId)
  221 +end
  222 +
  223 +function Capsule:exit(roleId)
  224 + local register = self:getProperty("register") or {}
  225 + if next(register) then
  226 + register[roleId] = nil
  227 + return true
  228 + end
  229 + return false
  230 +end
  231 +
  232 +function Capsule:confirmed(cares)
  233 + local goods = self:getProperty("goods") or {}
  234 + local specials = self:getProperty("specials") or {}
  235 + local change = {}
  236 + for k, v in pairs(cares) do
  237 + if v.typ == 1 then
  238 + if goods[k] and goods[k].amount ~= v.count then
  239 + change[k] = {typ=1, count = goods[k].amount}
  240 + end
  241 + else
  242 + if specials[k] and specials[k].amount ~= v.count then
  243 + change[k] = {typ=1, count = specials[k].amount}
  244 + end
  245 + end
  246 + end
  247 + return change
  248 +end
  249 +
  250 +function Capsule:getGoodsAmount()
  251 + local goods = self:getProperty("goods") or {}
  252 + local amount = 0
  253 + for _, v in pairs(goods) do
  254 + amount = amount + v.amount
  255 + end
  256 + return amount
  257 +end
  258 +
  259 +function Capsule:getSpecialByType(typ)
  260 + local specials = self:getProperty("specials") or {}
  261 + for k, v in pairs(specials) do
  262 + if v.quality == typ then
  263 + return k, v
  264 + end
  265 + end
  266 + return nil
  267 +end
  268 +
  269 +function Capsule:checkSpecialFlag(typ)
  270 + local spKey, special = self:getSpecialByType(typ)
  271 + if not special then return nil end
  272 +
  273 + if special["amount"] <= 0 then return nil end
  274 + return spKey, special
  275 +end
  276 +
  277 +local function getSpecialRoleNotify(rewardRecord, count, award, spKey, typ, now)
  278 + local rewardByRole = {}
  279 + while(count > 0 and next(rewardRecord)) do
  280 + local roleId = math.randWeight(rewardRecord, "amount")
  281 + if roleId then
  282 +
  283 + local tmp = rewardRecord[roleId]
  284 + tmp["amount"] = tmp["amount"] - 1
  285 +
  286 + if tmp["amount"] <= 0 then rewardRecord[roleId] = nil end
  287 +
  288 + tmp = rewardByRole[roleId] or {}
  289 + if not next(tmp) then
  290 + local name = getNameByRoleId(roleId)
  291 + tmp[spKey] = {name = name, good_id = spKey, typ = RewardType.SPECIAL, award = award, amount = 1, quality = typ, create_time= now}
  292 + else
  293 + if not tmp[spKey] then
  294 + local name = getNameByRoleId(roleId)
  295 + tmp[spKey] = {name = name, good_id = spKey, typ = RewardType.SPECIAL, award = award, amount = 1, quality = typ, create_time= now}
  296 + else
  297 + tmp[spKey].amount = tmp[spKey].amount + 1
  298 + end
  299 + end
  300 + rewardByRole[roleId] = tmp
  301 +
  302 + count = count - 1
  303 + end
  304 + end
  305 + return rewardByRole, count
  306 +end
  307 +
  308 +
  309 +local rewardToNtyFunc = function(notify, tmpReward)
  310 + for key, val in pairs(tmpReward or {}) do
  311 + if not notify[key] then
  312 + notify[key] = clone(val)
  313 + else
  314 + for k, v in pairs(val) do
  315 + if not notify[key][k] then
  316 + notify[key][k] = v
  317 + else
  318 + notify[key][k] = notify[key][k].amount + v.amount
  319 + end
  320 + end
  321 +
  322 + end
  323 + end
  324 +end
  325 +
  326 +local function getRecordAmount(record)
  327 + return #record
  328 +end
  329 +
  330 +
  331 +function Capsule:getTop(record, recordAmount,now)
  332 + local spKey, special = self:checkSpecialFlag(SpecialType.TOP)
  333 + if not special then return nil end
  334 + local specials = self:getProperty("specials") or {}
  335 + local specialsRecord = self:getProperty("specialsRecord") or {}
  336 +
  337 + if recordAmount < special["np"] then return nil end
  338 +
  339 + local topRecord = {}
  340 + local count = special["np"]
  341 + for _, v in ipairs(record) do
  342 + if count <= 0 then break end
  343 +
  344 + local tmpCount = 0
  345 + if count >= v.amount then
  346 + count = count - v.amount
  347 + tmpCount = v.amount
  348 + else
  349 + tmpCount = count
  350 + count = 0
  351 + end
  352 +
  353 + if not topRecord[v.roleId]then
  354 + topRecord[v.roleId] = {amount = v.amount }
  355 + else
  356 + topRecord[v.roleId] = {amount = (topRecord[v.roleId]["amount"] or 0) + tmpCount}
  357 + end
  358 + end
  359 +
  360 + local rewardByRole, count = getSpecialRoleNotify(topRecord, special["amount"], special["award"], spKey, SpecialType.TOP,now)
  361 +
  362 + special["amount"] = count
  363 + specials[spKey] = special
  364 +
  365 + rewardToNtyFunc(specialsRecord, rewardByRole)
  366 +
  367 + self:setProperties({specialsRecord = specialsRecord, specials = specials})
  368 + return rewardByRole
  369 +
  370 +end
  371 +
  372 +--TODO
  373 +function Capsule:getCore(record, recordAmount,now)
  374 + local spKey, special = self:checkSpecialFlag(SpecialType.CORE)
  375 + if not special then return nil end
  376 +
  377 + local specials = self:getProperty("specials") or {}
  378 + local specialsRecord = self:getProperty("specialsRecord") or {}
  379 +
  380 +
  381 +
  382 + local np = special["np"]
  383 + if np > recordAmount then return nil end
  384 +
  385 +
  386 + local left = math.ceil((np - recordAmount)/2) or 0
  387 + local count = np
  388 + local roleRecord = {}
  389 + for i, v in ipairs(record) do
  390 + if count <= 0 then break end
  391 + if i > left then
  392 + local tmpCount = 0
  393 + if count >= v.amount then
  394 + count = count - v.amount
  395 + tmpCount = v.amount
  396 + else
  397 + tmpCount = count
  398 + count = 0
  399 + end
  400 +
  401 + if not roleRecord[v.roleId]then
  402 + roleRecord[v.roleId] = {amount = v.amount }
  403 + else
  404 + roleRecord[v.roleId] = {amount = (roleRecord[v.roleId]["amount"] or 0) + tmpCount}
  405 + end
  406 + end
  407 +
  408 + end
  409 +
  410 + local rewardByRole, count = getSpecialRoleNotify(roleRecord, special["amount"], special["award"], spKey, SpecialType.CORE,now)
  411 +
  412 + special["amount"] = count
  413 + specials[spKey] = special
  414 +
  415 + rewardToNtyFunc(specialsRecord, rewardByRole)
  416 + self:setProperties({specialsRecord = specialsRecord, specials = specials})
  417 + return rewardByRole
  418 +end
  419 +
  420 +function Capsule:getLast(record,now)
  421 + local spKey, special = self:checkSpecialFlag(SpecialType.LAST)
  422 + if not special then return nil end
  423 +
  424 + local specials = self:getProperty("specials") or {}
  425 + local specialsRecord = self:getProperty("specialsRecord") or {}
  426 +
  427 + table.sort(record, function(a, b) return a.create_time > b.create_time end)
  428 +
  429 + local np = special["np"]
  430 + local count = np
  431 + local roleRecord = {}
  432 + for _, v in ipairs(record) do
  433 + if count <= 0 then break end
  434 +
  435 + local tmpCount = 0
  436 + if count >= v.amount then
  437 + count = count - v.amount
  438 + tmpCount = v.amount
  439 + else
  440 + tmpCount = count
  441 + count = 0
  442 + end
  443 +
  444 + if not roleRecord[v.roleId]then
  445 + roleRecord[v.roleId] = {amount = v.amount }
  446 + else
  447 + roleRecord[v.roleId] = {amount = (roleRecord[v.roleId]["amount"] or 0) + tmpCount}
  448 + end
  449 + end
  450 +
  451 + local rewardByRole, count = getSpecialRoleNotify(roleRecord, special["amount"], special["award"], spKey, SpecialType.LAST,now)
  452 +
  453 + special["amount"] = count
  454 + specials[spKey] = special
  455 +
  456 + rewardToNtyFunc(specialsRecord, rewardByRole)
  457 + self:setProperties({specialsRecord = specialsRecord, specials = specials})
  458 + return rewardByRole
  459 +end
  460 +
  461 +function Capsule:getJoker(record,now)
  462 + local spKey, special = self:checkSpecialFlag(SpecialType.JOKER)
  463 + if not special then return nil end
  464 +
  465 + local specials = self:getProperty("specials") or {}
  466 + local specialsRecord = self:getProperty("specialsRecord") or {}
  467 +
  468 + local roleRecord = {}
  469 + for _, v in ipairs(record) do
  470 + if not roleRecord[v.roleId]then
  471 + roleRecord[v.roleId] = {amount = v.amount }
  472 + else
  473 + roleRecord[v.roleId] = {amount = (roleRecord[v.roleId]["amount"] or 0) + v.amount}
  474 + end
  475 + end
  476 +
  477 + local rewardByRole, count = getSpecialRoleNotify(roleRecord, special["amount"], special["award"], spKey, SpecialType.JOKER,now)
  478 +
  479 + special["amount"] = count
  480 + specials[spKey] = special
  481 +
  482 + rewardToNtyFunc(specialsRecord, rewardByRole)
  483 + self:setProperties({specialsRecord = specialsRecord, specials = specials})
  484 + return rewardByRole
  485 +end
  486 +
  487 +function Capsule:getKing(record,now)
  488 + local spKey, special = self:checkSpecialFlag(SpecialType.KING)
  489 + if not special then return nil end
  490 +
  491 + local specials = self:getProperty("specials") or {}
  492 + local specialsRecord = self:getProperty("specialsRecord") or {}
  493 +
  494 + local roleRecord = {}
  495 + for _, v in ipairs(record) do
  496 + if not roleRecord[v.roleId]then
  497 + roleRecord[v.roleId] = {amount = v.amount }
  498 + else
  499 + roleRecord[v.roleId] = {amount = (roleRecord[v.roleId]["amount"] or 0) + v.amount}
  500 + end
  501 + end
  502 +
  503 + local rewardByRole, count = getSpecialRoleNotify(roleRecord, special["amount"], special["award"], spKey, SpecialType.KING,now)
  504 + special["amount"] = count
  505 + specials[spKey] = special
  506 +
  507 + rewardToNtyFunc(specialsRecord, rewardByRole)
  508 + self:setProperties({specialsRecord = specialsRecord, specials = specials})
  509 + return rewardByRole
  510 +end
  511 +
  512 +function Capsule:checkSpecialReward(now, goodsAmount)
  513 + local specials = self:getProperty("specials") or {}
  514 + if not next(specials) then return nil end
  515 + local record = self:getProperty("record") or {}
  516 +
  517 + if not next(record) then return nil end
  518 + table.sort(record, function(a, b) return a.create_time < b.create_time end )
  519 +
  520 + local recordAmount = getRecordAmount(record)
  521 +
  522 + local notify = self:getTop(record, recordAmount,now) or {}
  523 +
  524 + if goodsAmount == 0 then
  525 + local coreReward = self:getCore(record, recordAmount, now)
  526 + rewardToNtyFunc(notify, coreReward)
  527 +
  528 + local lastReward = self:getLast(record, now)
  529 + rewardToNtyFunc(notify, lastReward)
  530 +
  531 + local jokerReward = self:getJoker(record, now)
  532 + rewardToNtyFunc(notify, jokerReward)
  533 +
  534 + local kingReward = self:getKing(record, now)
  535 + rewardToNtyFunc(notify, kingReward)
  536 + end
  537 +
  538 + return notify
  539 +end
  540 +
  541 +function Capsule:checkIncentive(roleId, name, now)
  542 + local goods = self:getProperty("goods") or {}
  543 + local recordByRole = self:getProperty("recordByRole") or {}
  544 + local roleRecord = recordByRole[roleId] or {}
  545 + local incentiveRecord = self:getProperty("incentiveRecord") or {}
  546 + local incentiveByRole = incentiveRecord[roleId] or {}
  547 + local incentive = self:getProperty("incentive")
  548 +
  549 +
  550 + local notify = {}
  551 + -- 最后一抽 TODO
  552 + if incentive["last"] then
  553 + local last = true
  554 + for k, v in pairs(goods) do
  555 + if v and v.amount then
  556 + last = false
  557 + break
  558 + end
  559 + end
  560 + if last then
  561 + notify["last"] = {name = name, good_id = "last", typ = RewardType.INCENTIVE, award = incentive["last"]["award"], amount = 1, quality = 1, create_time= now}
  562 + end
  563 + end
  564 +
  565 + --次数
  566 + if incentive["amount"] then
  567 + local amount = 0
  568 + for _, v in pairs(roleRecord) do
  569 + if (v.calculated or 0) == 0 then
  570 + amount = amount + v.amount
  571 + end
  572 + end
  573 +
  574 + local count = math.floor(amount / incentive["amount"]["np"])
  575 + local tmpCount = count * incentive["amount"]["np"]
  576 + notify["amount"] = {name = name, roleId= roleId, good_id = "amount", typ = RewardType.INCENTIVE, award = incentive["amount"]["award"], amount = count, quality = 2, create_time= now}
  577 +
  578 + --填充v.calculated 字段,标识已经用于每x抽的计算中。
  579 + for _, v in pairs(roleRecord) do
  580 + if tmpCount <= 0 then break end
  581 +
  582 + v.calculated = v.calculated or 0
  583 + if v.calculated ~= v.amount then
  584 + if tmpCount <= v.amount then
  585 + v.calculated = tmpCount
  586 + tmpCount = 0
  587 + else
  588 + v.calculated = v.amount
  589 + tmpCount = tmpCount - v.amount
  590 + end
  591 + end
  592 +
  593 + end
  594 + end
  595 +
  596 + --概率
  597 + if incentive["probabilities"] then
  598 + local probabilities = math.randomInt(1, 100)
  599 + if probabilities <= incentive["probabilities"]["np"] then
  600 + notify["probabilities"] = {name = name, good_id = "probabilities", typ = RewardType.INCENTIVE, award = incentive["probabilities"]["award"], amount = 1, quality = 3, create_time= now}
  601 +
  602 + end
  603 + end
  604 + table.insert(incentiveByRole, notify)
  605 + incentiveRecord[roleId] = incentiveByRole
  606 + self:setProperty("incentiveRecord", incentiveRecord)
  607 +
  608 + --TODO 先屏蔽
  609 + return {}
  610 +end
  611 +
  612 +function Capsule:drawByCount(roleId, count)
  613 + if count <= 0 then return nil end
  614 +
  615 + local goods = self:getProperty("goods") or {}
  616 + local record = self:getProperty("record") or {}
  617 + local recordByRole = self:getProperty("recordByRole") or {}
  618 + local roleRecord = recordByRole[roleId] or {}
  619 +
  620 + local id = self:getProperty("id")
  621 + local room = self:getProperty("room")
  622 + local ichibankuji = csvdb["ichibankuji_mainCsv"][id][room]
  623 + local goods_id = ichibankuji["goods_id"]
  624 + local now = skynet.timex()
  625 +
  626 + --奖励, 通知信息
  627 + local notify= {}
  628 + notify[roleId] = {}
  629 +
  630 + local name = getNameByRoleId(roleId)
  631 + while (goods and next(goods) and count > 0) do
  632 + local good_id = math.randWeight(goods, "weight")
  633 + if not good_id then break end
  634 +
  635 + local good = goods[good_id] or {}
  636 + if good and good.amount > 0 then
  637 + good.amount = good.amount - 1
  638 +
  639 + --插入记录
  640 + local tmpNotify = {roleId = roleId, name= name, good_id = good_id, typ = RewardType.GOODS, award = good.award, amount = 1, quality = good.quality, create_time= now}
  641 + table.insert(record, tmpNotify)
  642 +
  643 + --作为奖励记录+通知
  644 + if not notify[roleId][good_id] then
  645 + notify[roleId][good_id] = tmpNotify
  646 + else
  647 + notify[roleId][good_id].amount = notify[roleId][good_id].amount + 1
  648 + end
  649 +
  650 + --记录角色的抽奖记录 计算激励奖需要用到
  651 + if not roleRecord[good_id] then
  652 + roleRecord[good_id] = tmpNotify
  653 + else
  654 + roleRecord[good_id].amount = roleRecord[good_id].amount + 1
  655 + end
  656 +
  657 + good.weight = good.weight - csvdb["ichibankuji_goodsCsv"][goods_id][good.id].weight
  658 + count = count - 1
  659 + end
  660 +
  661 + end
  662 + recordByRole[roleId] = roleRecord
  663 + self:setProperties({recordByRole = recordByRole, record = record, goods = goods})
  664 +
  665 + local tmpNotify = self:checkIncentive(roleId, name, now)
  666 + for k, v in pairs(tmpNotify) do
  667 + if not notify[roleId][k] then
  668 + notify[roleId][k] = v
  669 + else
  670 + notify[roleId][k].amount = notify[roleId][k].amount + v.amount
  671 + end
  672 + end
  673 +
  674 + local speciNotify = self:checkSpecialReward(now)
  675 + rewardToNtyFunc(notify, speciNotify)
  676 +
  677 + local reward, rewardByGoods = {}, {}
  678 + for key, val in pairs(notify) do
  679 + if key == roleId then
  680 + for k, v in pairs(val) do
  681 + for id, count in pairs(v.award:toNumMap()) do
  682 + reward[id] = (reward[id] or 0) + count
  683 + end
  684 + rewardByGoods[k] = v
  685 + end
  686 + end
  687 +
  688 + end
  689 + return reward, rewardByGoods, notify
  690 +end
  691 +
  692 +function Capsule:drawAll(roleId)
  693 + local goods = self:getProperty("goods") or {}
  694 + local record = self:getProperty("record") or {}
  695 + local recordByRole = self:getProperty("recordByRole") or {}
  696 + local roleRecord = recordByRole[roleId] or {}
  697 + local now = skynet.timex()
  698 +
  699 + local name = getNameByRoleId(roleId)
  700 + local notify = {}
  701 + notify[roleId] = {}
  702 + for good_id, good in pairs(goods) do
  703 + if good.amount > 0 then
  704 + --插入记录
  705 + local tmpNotify = {roleId = roleId, name= name, good_id = good_id, typ = RewardType.GOODS, award = good.award, amount = good.amount, quality = good.quality, create_time = now}
  706 + for i = 1, good.amount do
  707 + table.insert(record, {roleId = roleId, name= name, good_id = good_id, typ = RewardType.GOODS, award = good.award, amount = 1, quality = good.quality, create_time = now})
  708 + end
  709 +
  710 + --作为奖励记录+通知
  711 + if not notify[roleId][good_id] then
  712 + notify[roleId][good_id] = tmpNotify
  713 + else
  714 + notify[roleId][good_id].amount = notify[roleId][good_id].amount + good.award
  715 + end
  716 +
  717 + --记录角色的抽奖记录
  718 + if not roleRecord[good_id] then
  719 + roleRecord[good_id] = tmpNotify
  720 + else
  721 + roleRecord[good_id].amount = roleRecord[good_id].amount + good.amount
  722 + end
  723 +
  724 + good.amount = 0
  725 + end
  726 +
  727 + end
  728 + recordByRole[roleId] = roleRecord
  729 + self:setProperties({recordByRole = recordByRole, record = record, goods = goods})
  730 +
  731 + local tmpNotify = self:checkIncentive(roleId, name, now)
  732 + for k, v in pairs(tmpNotify) do
  733 + if not notify[roleId][k] then
  734 + notify[roleId][k] = v
  735 + else
  736 + notify[roleId][k].amount = notify[roleId][k].amount + v.amount
  737 + end
  738 + end
  739 +
  740 + local goodsAmount = self:getGoodsAmount()
  741 + local speciNotify = self:checkSpecialReward(now, goodsAmount)
  742 + rewardToNtyFunc(notify, speciNotify)
  743 +
  744 + local reward, rewardByGoods = {}, {}
  745 + for key, val in pairs(notify) do
  746 + if key == roleId then
  747 + for k, v in pairs(val) do
  748 + for id, count in pairs(v.award:toNumMap()) do
  749 + reward[id] = (reward[id] or 0) + count
  750 + end
  751 + rewardByGoods[k] = v
  752 + end
  753 + end
  754 +
  755 + end
  756 +
  757 + if goodsAmount == 0 then
  758 + self:setProperty("drawEndTime", now)
  759 + end
  760 +
  761 + return reward, rewardByGoods, notify
  762 +end
  763 +
  764 +--@param
  765 +--[[
  766 +@roleId
  767 +@typ 0=独享,1=公开
  768 +@cares 关注{k=v}
  769 +]]--
  770 +
  771 +function Capsule:draw(roleId, full, cares)
  772 + if self:getProperty("typ") == 1 then
  773 + --是否报名
  774 + if self:isRegister(roleId) == false then return 4 end
  775 +
  776 + --关注的奖品的数量发生了变化
  777 + if cares then
  778 + local change = self:confirmed(cares)
  779 + if next(change) then return 5, change end
  780 + end
  781 + end
  782 +
  783 + if full == 0 then
  784 + return 6, self:drawByCount(roleId, 1)
  785 + elseif full == 1 then
  786 + return 6, self:drawByCount(roleId, 10)
  787 + elseif full == 2 then
  788 + return 6, self:drawAll(roleId)
  789 + end
  790 +end
  791 +
  792 +
  793 +function Capsule:data(roleId)
  794 + return {
  795 + id = self:getProperty("id"),
  796 + room = self:getProperty("room"),
  797 + typ = self:getProperty("typ"),
  798 + name = self:getProperty("name"),
  799 + coin = self:getProperty("coin"),
  800 + onlineCount = self:getOnlineCount(),
  801 + playerStatus = self:getRegisterByRoleId(roleId),
  802 + record = self:getProperty("record"),
  803 + rank = self:getProperty("rank"),
  804 + goods = self:getProperty("goods"),
  805 + specials = self:getProperty("specials"),
  806 + incentive = self:getProperty("incentive"),
  807 + specialsRecord= self:getProperty("specialsRecord"),
  808 + }
  809 +end
  810 +
  811 +return Capsule
0 \ No newline at end of file 812 \ No newline at end of file
src/models/Role.lua
@@ -28,6 +28,7 @@ function Role:ctor( properties ) @@ -28,6 +28,7 @@ function Role:ctor( properties )
28 self.runeBag = {} 28 self.runeBag = {}
29 self.friends = {} 29 self.friends = {}
30 self.sparkBag = {} 30 self.sparkBag = {}
  31 + self.capsules = {}
31 self.advData = nil 32 self.advData = nil
32 self.activity = nil 33 self.activity = nil
33 self._pushToken = nil 34 self._pushToken = nil
src/models/RoleCross.lua
@@ -210,6 +210,20 @@ RoleCross.bind = function (Role) @@ -210,6 +210,20 @@ RoleCross.bind = function (Role)
210 return "成功" 210 return "成功"
211 end 211 end
212 212
  213 + function Role:paySpecialReward(roleId, notify)
  214 + dump(notify)
  215 + if notify and next(notify) then
  216 + local reward = {}
  217 + for key, val in pairs(notify) do
  218 + for id, count in pairs(val.award:toNumMap()) do
  219 + reward[id] = (reward[id] or 0) + count
  220 + end
  221 +
  222 + end
  223 + self:award(reward, {log = {desc = "CapsuleReward", int1=roleId}})
  224 + end
  225 + end
  226 +
213 end 227 end
214 228
215 229
@@ -370,6 +384,22 @@ function CMD.redPTag(roleId, tag, pms) @@ -370,6 +384,22 @@ function CMD.redPTag(roleId, tag, pms)
370 end 384 end
371 end 385 end
372 386
  387 +function CMD.paySpecialReward(roleId, notify)
  388 + dump(notify)
  389 + if notify and next(notify) then
  390 + local reward = {}
  391 + for key, val in pairs(notify) do
  392 + for id, count in pairs(val.award:toNumMap()) do
  393 + reward[id] = (reward[id] or 0) + count
  394 + end
  395 +
  396 + end
  397 + local role = require("models.Role").new({key = string.format("%s",roleId), id = roleId})
  398 + role:award(reward, {log = {desc = "CapsuleReward", int1=roleId}})
  399 + end
  400 +
  401 +end
  402 +
373 RoleCross.handle = function(cmd, roleId, ...) 403 RoleCross.handle = function(cmd, roleId, ...)
374 SRole = SRole or require("models.Role") 404 SRole = SRole or require("models.Role")
375 if CMD[cmd] then 405 if CMD[cmd] then
src/models/RoleLog.lua
@@ -66,6 +66,8 @@ local ItemReason = { @@ -66,6 +66,8 @@ local ItemReason = {
66 shopBuy = 150, -- 商店购买 66 shopBuy = 150, -- 商店购买
67 monthCardReward = 151, --月卡奖励 67 monthCardReward = 151, --月卡奖励
68 smonthCardReward = 152, --特刊奖励 68 smonthCardReward = 152, --特刊奖励
  69 + itemConvertmonthCard = 153, --兑换月卡
  70 + itemConvertsmonthCard = 154, --兑换特刊
69 71
70 advHang = 301, -- 拾荒挂机 72 advHang = 301, -- 拾荒挂机
71 hangBattle = 302, -- 挂机战斗 73 hangBattle = 302, -- 挂机战斗
@@ -157,6 +159,10 @@ local ItemReason = { @@ -157,6 +159,10 @@ local ItemReason = {
157 seaportTask = 1403, -- 贸易港任务奖励 159 seaportTask = 1403, -- 贸易港任务奖励
158 160
159 returner = 1410, -- 回归者奖励 161 returner = 1410, -- 回归者奖励
  162 +
  163 + CapsuleReward = 1411, --扭蛋机奖励
  164 + CapsuleConvert = 1412, --扭蛋机 消耗票 兑换
  165 + CapsuleCoinCost = 1413, --抽扭蛋机消耗
160 } 166 }
161 167
162 168
src/models/RolePlugin.lua
@@ -19,6 +19,7 @@ function RolePlugin.bind(Role) @@ -19,6 +19,7 @@ function RolePlugin.bind(Role)
19 --self:loadRoleIncre() 19 --self:loadRoleIncre()
20 self:loadFriends() 20 self:loadFriends()
21 self:loadSparks() 21 self:loadSparks()
  22 + self:loadCapsules()
22 end 23 end
23 24
24 function Role:reloadWhenLogin() 25 function Role:reloadWhenLogin()
@@ -821,6 +822,41 @@ function RolePlugin.bind(Role) @@ -821,6 +822,41 @@ function RolePlugin.bind(Role)
821 end 822 end
822 end 823 end
823 824
  825 + function Role:loadCapsules()
  826 + local now = skynet.timex()
  827 + local roleId = self:getProperty("id")
  828 + local res = redisproxy:smembers(CAPSULE_ID_ROLE:format(roleId)) or {}
  829 + for _, key in pairs(res) do
  830 + local capsule = require("models.Capsule").new({ key = CAPSULE_ROLE:format(roleId,tonumber(key))})
  831 + capsule:load()
  832 + if capsule:isShow() then
  833 + if capsule:refreshing(now) then
  834 + capsule:init()
  835 + capsule:create()
  836 + end
  837 + self.capsules[key] = capsule
  838 + else
  839 + redisproxy:del(CAPSULE_ROLE:format(roleId, tonumber(key)))
  840 + redisproxy:srem(CAPSULE_ID_ROLE, key)
  841 + end
  842 + end
  843 +
  844 + for _, data in pairs(csvdb["ichibankuji_mainCsv"]) do
  845 + for _, val in pairs(data) do
  846 + if val.typ == 0 then
  847 + local key = val.id..val.room
  848 + if not self.capsules[key] then
  849 + local capsule = require("models.Capsule").new({ key = CAPSULE_ROLE:format(roleId, tonumber(key)), id= val.id, room = val.room, typ = 0, name=val.name})
  850 + capsule:init()
  851 + capsule:create()
  852 + self.capsules[key] = capsule
  853 + redisproxy.sadd(CAPSULE_ID_ROLE:format(roleId), key)
  854 + end
  855 + end
  856 + end
  857 + end
  858 + end
  859 +
824 -- 0 为操作成功 860 -- 0 为操作成功
825 function Role:addRune(params) 861 function Role:addRune(params)
826 if params.type and params.id then 862 if params.type and params.id then
@@ -1995,6 +2031,7 @@ function RolePlugin.bind(Role) @@ -1995,6 +2031,7 @@ function RolePlugin.bind(Role)
1995 function Role:onRecoverTimer(now) 2031 function Role:onRecoverTimer(now)
1996 self:updateTimeReset(now, true) 2032 self:updateTimeReset(now, true)
1997 self:checkNewEvent(now) 2033 self:checkNewEvent(now)
  2034 + self:checkCapsule(now)
1998 self:saveRoleData(now) 2035 self:saveRoleData(now)
1999 end 2036 end
2000 2037
@@ -2377,7 +2414,7 @@ function RolePlugin.bind(Role) @@ -2377,7 +2414,7 @@ function RolePlugin.bind(Role)
2377 return 1 2414 return 1
2378 end 2415 end
2379 2416
2380 - if not self.storeData:checkRechargeRecord(rechargeData.limit, id) then 2417 + if not self.storeData:checkRechargeRecord(rechargeData.limit, id) and rechargeData.shop ~= 2 then
2381 return 2 2418 return 2
2382 end 2419 end
2383 2420
@@ -2393,15 +2430,10 @@ function RolePlugin.bind(Role) @@ -2393,15 +2430,10 @@ function RolePlugin.bind(Role)
2393 end 2430 end
2394 self:gainDiamond({count = diamondCount, isRecharge = true, sid = params.sid, log = {desc = "recharge", int1 = id}}) 2431 self:gainDiamond({count = diamondCount, isRecharge = true, sid = params.sid, log = {desc = "recharge", int1 = id}})
2395 elseif rechargeData.shop == 2 then --通行证商店 2432 elseif rechargeData.shop == 2 then --通行证商店
2396 - --订阅奖励  
2397 - reward, _ = self:award(rechargeData.itemFirst, {isRecharge = true, log = {desc = "recharge", int1 = id}})  
2398 -  
2399 - --签收奖励 2433 + --签收 + 订阅奖励
2400 local tmpreward, _ = self.storeData:onBuyCard(rechargeData.type, rechargeData.time, rechargeData.id, rechargeData.activity_id) 2434 local tmpreward, _ = self.storeData:onBuyCard(rechargeData.type, rechargeData.time, rechargeData.id, rechargeData.activity_id)
2401 if tmpreward then 2435 if tmpreward then
2402 - for k, v in pairs(tmpreward) do  
2403 - reward[k] = (reward[k] or 0) + v  
2404 - end 2436 + table.rewardMerge(reward, tmpreward)
2405 end 2437 end
2406 elseif rechargeData.shop == 3 then -- 礼包商店 2438 elseif rechargeData.shop == 3 then -- 礼包商店
2407 reward, _ = self:award(rechargeData.itemFirst, {isRecharge = true, log = {desc = "recharge", int1 = id}}) 2439 reward, _ = self:award(rechargeData.itemFirst, {isRecharge = true, log = {desc = "recharge", int1 = id}})
@@ -3121,7 +3153,73 @@ function RolePlugin.bind(Role) @@ -3121,7 +3153,73 @@ function RolePlugin.bind(Role)
3121 return itemRandomOccupy 3153 return itemRandomOccupy
3122 end 3154 end
3123 3155
  3156 + function Role:getCapsuleList(coin)
  3157 + local capsules = {}
  3158 + for k, v in pairs(self.capsules) do
  3159 + if v:getProperty("coin") == coin then
  3160 + local onlineCount= v:getOnlineCount()
  3161 + capsules[k] = {id=v:getProperty("id"), room=v:getProperty("room"), typ=v:getProperty("typ"), people=onlineCount[2], coin= v:getProperty("coin")}
  3162 + end
  3163 + end
  3164 + return capsules
  3165 + end
  3166 +
  3167 + function Role:drawCapsule(capsuleId, full, cares)
  3168 + local capsule = self.capsules[capsuleId] or {}
  3169 + if next(capsule) then
  3170 + local roleId = self:getProperty("id")
  3171 + return capsule:draw(roleId, full, cares)
  3172 + end
  3173 + return 3
  3174 + end
  3175 +
  3176 + function Role:joinCapsule(capsuleId)
  3177 + local capsule = self.capsules[capsuleId] or {}
  3178 + return capsule:data()
  3179 + end
3124 3180
  3181 + function Role:checkCapsule(now)
  3182 + for _, v in pairs(self.capsules) do
  3183 + if v:refreshing(now) then
  3184 + v:init()
  3185 + v:create()
  3186 + end
  3187 + end
  3188 + end
  3189 +
  3190 + function Role:goodStock(capsuleId)
  3191 + local capsule = self.capsules[capsuleId] or {}
  3192 + return capsule:getGoodsAmount(), capsule:getProperty("token")
  3193 + end
  3194 +
  3195 + function Role:getCapsuleData(capsuleId)
  3196 + local capsule = self.capsules[capsuleId] or {}
  3197 + return capsule:data()
  3198 + end
  3199 +
  3200 + function Role:resetCapsule()
  3201 + local roleId = self:getProperty("id")
  3202 + local res = redisproxy:smembers(CAPSULE_ID_ROLE:format(roleId)) or {}
  3203 + for _, key in pairs(res) do
  3204 + redisproxy:del(CAPSULE_ROLE:format(roleId, tonumber(key)))
  3205 + redisproxy:srem(CAPSULE_ID_ROLE, key)
  3206 + end
  3207 +
  3208 + for _, data in pairs(csvdb["ichibankuji_mainCsv"]) do
  3209 + for _, val in pairs(data) do
  3210 + if val.typ == 0 then
  3211 + local key = val.id..val.room
  3212 + if not self.capsules[key] then
  3213 + local capsule = require("models.Capsule").new({ key = CAPSULE_ROLE:format(roleId, tonumber(key)), id= val.id, room = val.room, typ = 0, name=val.name})
  3214 + capsule:init()
  3215 + capsule:create()
  3216 + self.capsules[key] = capsule
  3217 + redisproxy.sadd(CAPSULE_ID_ROLE:format(roleId), key)
  3218 + end
  3219 + end
  3220 + end
  3221 + end
  3222 + end
3125 end 3223 end
3126 3224
3127 return RolePlugin 3225 return RolePlugin
3128 \ No newline at end of file 3226 \ No newline at end of file
src/models/RoleTask.lua
@@ -697,7 +697,7 @@ function RoleTask.bind(Role) @@ -697,7 +697,7 @@ function RoleTask.bind(Role)
697 for _, hero in pairs(self.heros) do 697 for _, hero in pairs(self.heros) do
698 local unitData = csvdb["unitCsv"][hero:getProperty("type")] 698 local unitData = csvdb["unitCsv"][hero:getProperty("type")]
699 if unitData then 699 if unitData then
700 - if cfg.condition2 <= unitData.rare then 700 + if cfg.condition2 == unitData.rare then
701 count = count + 1 701 count = count + 1
702 end 702 end
703 end 703 end
@@ -758,11 +758,14 @@ function RoleTask.bind(Role) @@ -758,11 +758,14 @@ function RoleTask.bind(Role)
758 end 758 end
759 elseif cfg.type == 15 then -- 通关关卡 759 elseif cfg.type == 15 then -- 通关关卡
760 if (calTask[id] or 0) == 0 then 760 if (calTask[id] or 0) == 0 then
761 - local hangPass = self:getProperty("hangPass")  
762 - local diff = math.floor(cfg.condition2 / 10000)  
763 - if (hangPass[diff] or 0) >= cfg.condition1 then 761 + if self:checkHangPass(cfg.condition2) then
764 calTask[id] = 1 762 calTask[id] = 1
765 - end 763 + end
  764 + --local hangPass = self:getProperty("hangPass")
  765 + --local diff = math.floor(cfg.condition2 / 10000)
  766 + --if (hangPass[diff] or 0) >= cfg.condition2 then
  767 + -- calTask[id] = 1
  768 + --end
766 end 769 end
767 elseif cfg.type == 22 then -- 电台任务出勤人数 770 elseif cfg.type == 22 then -- 电台任务出勤人数
768 calTask[id] = (calTask[id] or 0) + (param1 or 0) 771 calTask[id] = (calTask[id] or 0) + (param1 or 0)
src/models/Store.lua
@@ -343,6 +343,8 @@ end @@ -343,6 +343,8 @@ end
343 343
344 --获取月卡每日奖励 344 --获取月卡每日奖励
345 function Store:getMonthCardDailyReward(id) 345 function Store:getMonthCardDailyReward(id)
  346 + if not id then return nil end
  347 +
346 if self:isMonthCardExpire() or self:getProperty("monthCardReceive") == 1 then return nil, nil end 348 if self:isMonthCardExpire() or self:getProperty("monthCardReceive") == 1 then return nil, nil end
347 349
348 local before_ex = self:getProperty("monthCardEx") 350 local before_ex = self:getProperty("monthCardEx")
@@ -369,6 +371,8 @@ end @@ -369,6 +371,8 @@ end
369 371
370 --获取特刊每日奖励 372 --获取特刊每日奖励
371 function Store:getSMonthCardDailyReward(id) 373 function Store:getSMonthCardDailyReward(id)
  374 + if not id then return nil end
  375 +
372 local before_ex = SuperMonthCard["periods"](self, id) 376 local before_ex = SuperMonthCard["periods"](self, id)
373 local reward, change, cur_ex= SuperMonthCard["itemDaily"](self, id) 377 local reward, change, cur_ex= SuperMonthCard["itemDaily"](self, id)
374 378
@@ -404,21 +408,15 @@ function Store:onBuyCard(type, duration, id, actid) @@ -404,21 +408,15 @@ function Store:onBuyCard(type, duration, id, actid)
404 end 408 end
405 self:updateProperty({field = "monthCardEx", value = self:getProperty("monthCardEx") + 30}) 409 self:updateProperty({field = "monthCardEx", value = self:getProperty("monthCardEx") + 30})
406 410
  411 + local reward = {}
407 --初回特典 仅首次购买月卡时赠送SSR级角色"拉塔托娅" 412 --初回特典 仅首次购买月卡时赠送SSR级角色"拉塔托娅"
408 - local reward = {}  
409 local tmpreward, _ = self:firstBuyMonthCard(id) 413 local tmpreward, _ = self:firstBuyMonthCard(id)
410 - if tmpreward then  
411 - for k, v in pairs(tmpreward) do  
412 - reward[k] = (reward[k] or 0) + v  
413 - end  
414 - end 414 + if tmpreward then table.rewardMerge(reward, tmpreward) end
415 415
  416 + --订阅奖励
416 tmpreward = SuperMonthCard["itemFirst"](self, id) 417 tmpreward = SuperMonthCard["itemFirst"](self, id)
417 - if next(tmpreward) then  
418 - for k, v in pairs(tmpreward) do  
419 - reward[k] = (reward[k] or 0) + v  
420 - end  
421 - end 418 + if next(tmpreward) then table.rewardMerge(reward, tmpreward) end
  419 +
422 return reward 420 return reward
423 elseif type == CardType.SuperMonthCard then 421 elseif type == CardType.SuperMonthCard then
424 if SuperMonthCard["buy"](self, id) then 422 if SuperMonthCard["buy"](self, id) then
@@ -832,6 +830,8 @@ function Store:data() @@ -832,6 +830,8 @@ function Store:data()
832 bpInfo = self:getProperty("bpInfo"), 830 bpInfo = self:getProperty("bpInfo"),
833 totalRR = self:getProperty("totalRR"), 831 totalRR = self:getProperty("totalRR"),
834 monthCardId = self:getProperty("monthCardId"), 832 monthCardId = self:getProperty("monthCardId"),
  833 + firstMonthCard = self:getProperty("firstMonthCard"),
  834 + monthCardReceive = self:getProperty("monthCardReceive"),
835 smonthCards = self:getProperty("smonthCards"), 835 smonthCards = self:getProperty("smonthCards"),
836 smonthCardReceive = self:getProperty("smonthCardReceive"), 836 smonthCardReceive = self:getProperty("smonthCardReceive"),
837 dailyShop = self:getProperty("dailyShop"), 837 dailyShop = self:getProperty("dailyShop"),
src/services/agent_ctrl.lua
@@ -188,7 +188,7 @@ function _M:query_agent(fd, uid, isQueue) @@ -188,7 +188,7 @@ function _M:query_agent(fd, uid, isQueue)
188 end 188 end
189 189
190 local agent = get_a(pack) 190 local agent = get_a(pack)
191 - local ok = pcall(skynet.call, agent, "lua", "start", gate_serv, fd, self.f2i[fd]) 191 + local ok = pcall(skynet.call, agent, "lua", "start", gate_serv, capsuled, fd, self.f2i[fd])
192 if not ok then 192 if not ok then
193 query_agent_response(fd, {ret = "INNER_ERROR"}) 193 query_agent_response(fd, {ret = "INNER_ERROR"})
194 return 194 return
@@ -223,7 +223,7 @@ function _M:query_agent(fd, uid, isQueue) @@ -223,7 +223,7 @@ function _M:query_agent(fd, uid, isQueue)
223 end 223 end
224 end 224 end
225 225
226 - local ok = pcall(skynet.call, agent, "lua", "start", gate_serv, fd, self.f2i[fd], hotfixList) 226 + local ok = pcall(skynet.call, agent, "lua", "start", gate_serv, capsuled, fd, self.f2i[fd], hotfixList)
227 if not ok then 227 if not ok then
228 self.factory:push(agent) 228 self.factory:push(agent)
229 query_agent_response(fd, {ret = "INNER_ERROR"}) 229 query_agent_response(fd, {ret = "INNER_ERROR"})
src/services/capsuled.lua 0 → 100644
@@ -0,0 +1,237 @@ @@ -0,0 +1,237 @@
  1 +require "ProtocolCode"
  2 +require "shared.init"
  3 +require "GlobalVar"
  4 +require "RedisKeys"
  5 +require "skynet.manager"
  6 +skynet = require "skynet"
  7 +csvdb = require "shared.csvdata"
  8 +redisproxy = require "shared.redisproxy"
  9 +datacenter = require "skynet.datacenter"
  10 +
  11 +local capsules = {}
  12 +local CMD = {}
  13 +
  14 +NotifyChangeType = {
  15 + JOIN = 1,
  16 + EXIT = 2,
  17 + DRAW = 3,
  18 + SPECIAL = 4,
  19 +}
  20 +
  21 +skynet.register_protocol {
  22 + name = "role",
  23 + id = 101,
  24 + pack = skynet.pack,
  25 + unpack = skynet.unpack,
  26 +}
  27 +
  28 +local function rpcRole(roleId, funcName, ...)
  29 + local fields = ...
  30 + local agent = datacenter.get("agent", roleId)
  31 + if agent and agent.serv then
  32 + if funcName == "getProperties" then
  33 + return true, skynet.call(agent.serv, "role", funcName, fields)
  34 + else
  35 + return true, skynet.call(agent.serv, "role", funcName, ...)
  36 + end
  37 + else
  38 + local roleCross = require("models.RoleCross")
  39 + if funcName == "getProperties" then
  40 + return false, roleCross.handle(funcName, roleId, fields)
  41 + else
  42 + return false, roleCross.handle(funcName, roleId, ...)
  43 + end
  44 + end
  45 +end
  46 +
  47 +function getNameByRoleId(roleId)
  48 + local status, name = rpcRole(roleId, "getProperty", "name")
  49 + return name
  50 +
  51 +end
  52 +
  53 +function broadCastCapsule(roleId, capsuleId, broadInfo)
  54 + local capsule = capsules[capsuleId] or {}
  55 + local register = capsule:getProperty("register") or {}
  56 + if next(capsule) then
  57 + for id, _ in pairs(register) do
  58 + if id ~= roleId then
  59 + rpcRole(id, "SendPacket", actionCodes.Capsule_notifyChange, MsgPack.pack(broadInfo)) -- 通知对方
  60 + end
  61 + end
  62 + end
  63 +end
  64 +
  65 +function broadCastSpecial(roleId, capsuleId, broadInfo)
  66 + local capsule = capsules[capsuleId] or {}
  67 + local register = capsule:getProperty("register") or {}
  68 + if next(capsule) then
  69 + for id, _ in pairs(register) do
  70 + if id ~= roleId then
  71 + if broadInfo[id] then
  72 + rpcRole(id, "paySpecialReward", id, broadInfo[id])
  73 + end
  74 + end
  75 + end
  76 + end
  77 +end
  78 +
  79 +local function add(roleId, capsuleId)
  80 + local capsule = capsules[capsuleId] or {}
  81 + if next(capsule) then
  82 + capsule:join(roleId)
  83 + broadCastCapsule(roleId, capsuleId, {notifyType= NotifyChangeType.JOIN, roleId = roleId})
  84 + return capsule:data(roleId)
  85 + end
  86 + print("id 不存在: ".. capsuleId)
  87 + return nil
  88 +end
  89 +
  90 +local function capsuleRefreshing()
  91 + for _, v in pairs(capsules) do
  92 + if v:refreshing() then
  93 + v:init()
  94 + v:create()
  95 + end
  96 + end
  97 +end
  98 +
  99 +--扭蛋机刷新
  100 +local function check_capsules()
  101 + pcall(capsuleRefreshing)
  102 + skynet.timeout(60, check_capsules)
  103 +end
  104 +
  105 +function CMD.reset()
  106 + local now = skynet.timex()
  107 + local res = redisproxy:smembers(CAPSULE_INFO) or {}
  108 + for _, key in pairs(res) do
  109 + redisproxy:del(CAPSULE_PUBLIC:format(key))
  110 + redisproxy:srem(CAPSULE_INFO, key)
  111 + end
  112 +
  113 + for _, data in pairs(csvdb["ichibankuji_mainCsv"]) do
  114 + for _, val in ipairs(data) do
  115 + if val.type == 1 then
  116 + local key = val.id..val.room
  117 + if not capsules[key] then
  118 + local capsule = require("models.Capsule").new({ key = CAPSULE_PUBLIC:format(key), id= val.id, room = val.room, typ = 1, name=val.name})
  119 + capsule:init()
  120 + capsule:create()
  121 + capsules[key] = capsule
  122 + redisproxy:sadd(CAPSULE_INFO, key)
  123 + end
  124 + end
  125 + end
  126 + end
  127 +end
  128 +
  129 +function CMD.start()
  130 + local now = skynet.timex()
  131 + local res = redisproxy:smembers(CAPSULE_INFO) or {}
  132 + for _, key in pairs(res) do
  133 + local capsule = require("models.Capsule").new({ key = CAPSULE_PUBLIC:format(key)})
  134 + capsule:load()
  135 + if capsule:isShow() then
  136 + if capsule:refreshing(now) then
  137 + capsule:init()
  138 + capsule:create()
  139 + end
  140 + capsules[key] = capsule
  141 + else
  142 + redisproxy:del(CAPSULE_PUBLIC:format(key))
  143 + redisproxy:srem(CAPSULE_INFO, key)
  144 + end
  145 + end
  146 +
  147 + for _, data in pairs(csvdb["ichibankuji_mainCsv"]) do
  148 + for _, val in ipairs(data) do
  149 + if val.type == 1 then
  150 + local key = val.id..val.room
  151 + if not capsules[key] then
  152 + local capsule = require("models.Capsule").new({ key = CAPSULE_PUBLIC:format(key), id= val.id, room = val.room, typ = 1, name=val.name})
  153 + capsule:init()
  154 + capsule:create()
  155 + capsules[key] = capsule
  156 + redisproxy:sadd(CAPSULE_INFO, key)
  157 + end
  158 + end
  159 + end
  160 + end
  161 +
  162 + check_capsules()
  163 +end
  164 +
  165 +function CMD.list(coin)
  166 + local tmpCapsules = {}
  167 + for k, v in pairs(capsules) do
  168 + if v:getProperty("coin") == coin then
  169 + local onlineCount= v:getOnlineCount()
  170 + tmpCapsules[k] = {id=v:getProperty("id"), room=v:getProperty("room"), typ=v:getProperty("typ"), people=onlineCount[2], coin= v:getProperty("coin")}
  171 + end
  172 + end
  173 + return tmpCapsules
  174 +end
  175 +
  176 +function CMD.join(roleId, capsuleId)
  177 + if capsuleId then
  178 + return add(roleId, capsuleId)
  179 + end
  180 + return nil
  181 +end
  182 +
  183 +
  184 +function CMD.exit(roleId, capsuleId)
  185 + if capsuleId then
  186 + local capsule = capsules[capsuleId] or {}
  187 + if next(capsule) then
  188 + capsule:exit(roleId)
  189 + broadCastCapsule(roleId, capsuleId, {notifyType = NotifyChangeType.EXIT, roleId = roleId})
  190 + end
  191 + else
  192 + for _, capsule in pairs(capsules) do
  193 + if next(capsule) then
  194 + capsule:exit(roleId)
  195 + broadCastCapsule(roleId, capsuleId, {notifyType = NotifyChangeType.EXIT, roleId = roleId})
  196 + end
  197 + end
  198 + end
  199 +end
  200 +
  201 +function CMD.draw_capsule(roleId, capsuleId, full, drawsNum, cares)
  202 + local capsule = capsules[capsuleId] or {}
  203 + if next(capsule) then
  204 + local ret, reward, rewardByGoods, notify = capsule:draw(roleId, full, drawsNum, cares)
  205 + if ret > 5 then
  206 + --broadCastCapsule(roleId, capsuleId, {notifyType = NotifyChangeType.DRAW, notify = notify})
  207 + broadCastSpecial(roleId, capsuleId, notify)
  208 + end
  209 + return ret, reward, rewardByGoods, capsule:data(roleId)
  210 + end
  211 + return 2
  212 +end
  213 +
  214 +function CMD.register(roleId, capsuleId)
  215 + local capsule = capsules[capsuleId] or {}
  216 + return capsule:register(roleId)
  217 +end
  218 +
  219 +function CMD.goods_stock(capsuleId)
  220 + local capsule = capsules[capsuleId] or {}
  221 + return capsule:getGoodsAmount(), capsule:getProperty("token")
  222 +end
  223 +
  224 +function CMD.capsule_data(roleId, capsuleId)
  225 + local capsule = capsules[capsuleId] or {}
  226 + return capsule:data(roleId)
  227 +end
  228 +
  229 +skynet.start(function()
  230 + skynet.dispatch("lua", function(session, address, cmd, ...)
  231 + local f = CMD[string.lower(cmd)]
  232 + skynet.ret(skynet.pack(f(...)))
  233 + end)
  234 +
  235 + skynet.register("capsuled")
  236 + globalCsv = csvdb["GlobalDefineCsv"]
  237 +end)
0 \ No newline at end of file 238 \ No newline at end of file
src/services/watchdog.lua
@@ -66,6 +66,8 @@ function CMD.start(conf) @@ -66,6 +66,8 @@ function CMD.start(conf)
66 skynet.call(gate_serv, "lua", "open" , conf) 66 skynet.call(gate_serv, "lua", "open" , conf)
67 67
68 skynet.call(pvpd, "lua", "start") 68 skynet.call(pvpd, "lua", "start")
  69 +
  70 + skynet.call(capsuled, "lua", "start")
69 -- 开启agent状态检测定时器 71 -- 开启agent状态检测定时器
70 check_agent_status() 72 check_agent_status()
71 -- 创建广播服务 73 -- 创建广播服务
@@ -126,4 +128,5 @@ skynet.start(function() @@ -126,4 +128,5 @@ skynet.start(function()
126 skynet.newservice("services/chated") 128 skynet.newservice("services/chated")
127 -- 网关服务 129 -- 网关服务
128 gate_serv = skynet.newservice("gate") 130 gate_serv = skynet.newservice("gate")
  131 + capsuled = skynet.newservice("services/capsuled")
129 end) 132 end)
src/shared/functions.lua
@@ -865,3 +865,9 @@ function table.array2Table(arr) @@ -865,3 +865,9 @@ function table.array2Table(arr)
865 return ret 865 return ret
866 end 866 end
867 867
  868 +
  869 +function table.rewardMerge(dest, src)
  870 + for k, v in pairs(src) do
  871 + dest[k] = (dest[k] or 0) + v
  872 + end
  873 +end
868 \ No newline at end of file 874 \ No newline at end of file