diff --git a/src/GlobalVar.lua b/src/GlobalVar.lua index 58d2e4d..5d50020 100644 --- a/src/GlobalVar.lua +++ b/src/GlobalVar.lua @@ -272,4 +272,11 @@ CardType = { PrivilegeCard = 3, --特权卡 GrowFund = 4, --成长助力 BattleCard = 5, --赛季卡 +} + +HeroQuality = { + N = 1, + R = 2, + SR = 3, + SSR = 4, } \ No newline at end of file diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index ca3c931..f3cab31 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -88,6 +88,7 @@ actionCodes = { Hero_getResetRewardRpc = 219, Hero_drawHeroRpc = 220, Hero_repayHeroRpc = 221, + Hero_unlockPoolRpc = 222, Hang_startRpc = 251, Hang_checkRpc = 252, diff --git a/src/actions/GmAction.lua b/src/actions/GmAction.lua index 4acf279..974505f 100644 --- a/src/actions/GmAction.lua +++ b/src/actions/GmAction.lua @@ -515,8 +515,9 @@ end table.insert(helpDes, {"测试", "test", ""}) function _M.test(role, pms) local id = tonum(pms.pm1, 0) - local a = require("actions.StoreAction") - a.getGrowFundRewardRpc({role=role}, MsgPack.pack({id=id})) + --local hero = require ("actions.HeroAction") + --hero.unlockPoolRpc({role = role}, MsgPack.pack({type = id})) + role.storeData:resetStoreReored(id) return "成功" end @@ -525,12 +526,4 @@ function _M.ayncPurchase(role, params) return role:handlePurchase(params) or "" end -function _M.test(role, params) - local id = tonum(params.pm1, 0) - local store = require ("actions.StoreAction") - store.shopBuyRpc({role = role}, MsgPack.pack({id = id})) - return "成功" -end - - return _M \ No newline at end of file diff --git a/src/actions/HeroAction.lua b/src/actions/HeroAction.lua index 6739c49..3c961a0 100644 --- a/src/actions/HeroAction.lua +++ b/src/actions/HeroAction.lua @@ -681,9 +681,7 @@ function _M.getResetRewardRpc(agent, data) return true end - - -function _M.drawHeroRpc(agent, data) +function _M.unuse_drawHeroRpc(agent, data) local role = agent.role local msg = MsgPack.unpack(data) @@ -921,6 +919,153 @@ function _M.drawHeroRpc(agent, data) return true end +function _M.drawHeroRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + + if not role:isFuncUnlock(FuncUnlock.GetHero) then return end + local btype = msg.pool -- 1 2 3 卡池类型 + local subType = msg.subType or 1-- 定向卡池需要传 子类型 + local drawType = msg.type -- 1 单抽 2 十连 + local guide = msg.guide -- 是否是引导抽的 + if btype ~= 1 then + subType = 1 + end + + local buildTypeData = csvdb["build_typeCsv"][btype] + if not buildTypeData then return 1 end + + local drawCount = {1, 10} -- 抽取次数 + if not drawCount[drawType] then return 2 end + + -- 计算抽卡消耗品 + local cost = {} + local lastCount = drawCount[drawType] + for _, costType in ipairs({"draw_card", "draw_coin"}) do + if buildTypeData[costType] ~= "" then + local curCost = buildTypeData[costType]:toArray(true, "=") + local hadCount = role:getItemCount(curCost[1]) + local curCount = math.floor(hadCount / curCost[2]) + if curCount >= lastCount then + cost[curCost[1]] = curCost[2] * lastCount + lastCount = 0 + break + elseif curCount > 0 then + cost[curCost[1]] = curCost[2] * curCount + lastCount = lastCount - curCount + end + end + end + if lastCount > 0 then -- 钱不够 + return 3 + end + + -- 抽取的池子 + local poolMap = buildTypeData["pool"]:toNumMap() + local poolId = poolMap[subType] + if not poolId then return end + + --判断定向卡池是否开启 + if btype == 1 then + if not role:isTimeResetOpen(TimeReset["DrawType" .. subType]) then + local unlockPool = role.dailyData:getProperty("unlockPool") + if not unlockPool[subType] then + return 1 + end + end + end + + --TODO 活动覆盖 + + local unitPool = csvdb["build_unitCsv"][poolId] + if not unitPool then return 4 end + + -- 开始抽 + local resultPool = {} + local function fillDrawPool() + local condition = {"rare", "camp"} + local values = {} + + for idx, field in ipairs(condition) do + if not values[idx] then + local lpool = {} + local curIdx = 1 + while unitPool[field .. "_" .. curIdx] do + lpool[curIdx] = {unitPool[field .. "_" .. curIdx]} + curIdx = curIdx + 1 + end + + if next(lpool) then + values[idx] = math.randWeight(lpool, 1) + end + end + end + + for itemId, oneData in pairs(csvdb["build_poolCsv"]) do + if oneData["pool_" .. poolId] and oneData["pool_" .. poolId] ~= "" then + local itemData = csvdb["itemCsv"][itemId] + while itemData do + if itemData.type ~= ItemType.Hero then break end + local heroData = csvdb["unitCsv"][itemData.id - ItemStartId.Hero] + if not heroData then break end + local ok = true + for idx, field in ipairs(condition) do + if heroData[field] ~= values[idx] then ok = false break end + end + if not ok then break end + if oneData["pool_" .. poolId] > 0 then + resultPool[itemId] = {oneData["pool_" .. poolId]} -- itemId, count, 概率 + end + break + end + end + end + end + + role:costItems(cost, {log = {desc = "drawHero", short1 = btype, int1 = poolId}}) + + local ssrCount = 0 + local reward = {} + for i = 1, drawCount[drawType] do + resultPool = {} + while not next(resultPool) do + fillDrawPool() + end + + -- 引导必送 613 丝路德 + local itemId = guide and 613 or math.randWeight(resultPool, 1) + local itemData = csvdb["itemCsv"][itemId] + if itemData.quality == HeroQuality.SSR then + ssrCount = ssrCount + 1 + end + + if role:isHaveHero(itemData.id - ItemStartId.Hero) then + local fragId = itemData.id - ItemStartId.Hero + local heroData = csvdb["unitCsv"][fragId] + local count = globalCsv.draw_unit_tofragment[heroData.rare] + role:award({[fragId] = count}, {log = {desc = "drawHero", short1 = btype, int1 = poolId}}) + table.insert(reward, {id = fragId, count = count, from = itemId, fcount = 1}) + else + role:award({[itemId] = 1}, {log = {desc = "drawHero", short1 = btype, int1 = poolId}}) + table.insert(reward, {id = itemId, count = 1}) + end + end + + if btype == 1 or btype == 2 then + local repayHero = role:getProperty("repayHero") or 0 + repayHero = repayHero + drawCount[drawType] + role:updateProperty({field = "repayHero", value = repayHero}) + end + + role:checkTaskEnter("DrawHero", {pool = btype, count = drawCount[drawType]}) + if ssrCount > 0 then + role:checkTaskEnter("DrawSSR", {count = ssrCount}) + end + role:log("hero_action", {desc = "drawHero", short1 = btype, int1 = drawCount[drawType], int2 = poolId}) + SendPacket(actionCodes.Hero_drawHeroRpc, MsgPack.pack({reward = reward})) -- 这个 reward 是数组 + return true +end + function _M.repayHeroRpc(agent, data) local role = agent.role @@ -950,4 +1095,36 @@ function _M.repayHeroRpc(agent, data) return true end +function _M.unlockPoolRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + + if not role:isFuncUnlock(FuncUnlock.GetHero) then return end + local type = msg.type -- 指定定向卡池需要类型 1, 2, 3 + local needCost = true + --当前开启的类型不用解锁 + if role:isTimeResetOpen(TimeReset["DrawType" .. type]) then + needCost = false + end + --已经解锁的不需要重复解锁 + local unlockPool = role.dailyData:getProperty("unlockPool") + if unlockPool[type] then + needCost = false + end + + if needCost then + if not role:costDiamond({count = 300, log = {desc = "unlockPool", short1 = type}}) then + return + end + end + + unlockPool[type] = 1 + role.dailyData:updateProperty({field="unlockPool", value = unlockPool}) + role.dailyData:updateProperty({field="curPool", value = type}) + + role:log("hero_action", {desc = "unlockPool", short1=type}) + SendPacket(actionCodes.Hero_unlockPoolRpc, MsgPack.pack({})) + return true +end + return _M \ No newline at end of file diff --git a/src/actions/RoleAction.lua b/src/actions/RoleAction.lua index d82c4cd..4b98329 100644 --- a/src/actions/RoleAction.lua +++ b/src/actions/RoleAction.lua @@ -663,7 +663,8 @@ function _M.taskRpc(agent, data) { type = roleField[taskType], field = "a", value = active}, }) - role:updateProperty({field = "battlePoint", role:getProperty("battlePoint") + 100}) + local oldVal = role:getProperty("battlePoint") or 0 + role:updateProperty({field = "battlePoint", value = oldVal + taskData.active}) SendPacket(actionCodes.Role_taskRpc, MsgPack.pack(role:packReward(reward, change))) return true diff --git a/src/actions/StoreAction.lua b/src/actions/StoreAction.lua index d9468f0..4b8bca1 100644 --- a/src/actions/StoreAction.lua +++ b/src/actions/StoreAction.lua @@ -387,6 +387,11 @@ function _M.getBattlePassRewardRpc(agent, data) return 1 end + if role:getProperty("battlePoint") < config.condition then + skynet.error(string.format("user do not have enough battle point, user_id:%d", role:getProperty("id"))) + return 1 + end + local gift = "" if freeFlag == "0" then gift = config.giftFree diff --git a/src/models/Daily.lua b/src/models/Daily.lua index 5082d66..038ede4 100644 --- a/src/models/Daily.lua +++ b/src/models/Daily.lua @@ -26,7 +26,8 @@ Daily.schema = { advSupRe = {"number", 0}, -- 冒险支援效果刷新次数 goldBuyT = {"number", 0}, -- 金币购买次数 - unlockPool = {"table", {}} -- 解锁的属性卡池 + unlockPool = {"table", {}}, -- 解锁的属性卡池 + curPool = {"number", 0}, -- 属性卡池当前索引 } function Daily:updateProperty(params) @@ -99,6 +100,8 @@ function Daily:data() dailySDD = self:getProperty("dailySDD"), advSupRe = self:getProperty("advSupRe"), goldBuyT = self:getProperty("goldBuyT"), + unlockPool = self:getProperty("unlockPool"), + curPool = self:getProperty("curPool"), } end diff --git a/src/models/RoleTimeReset.lua b/src/models/RoleTimeReset.lua index 953b81a..e3834eb 100644 --- a/src/models/RoleTimeReset.lua +++ b/src/models/RoleTimeReset.lua @@ -66,6 +66,10 @@ function Role:updateTimeReset(now, notify) ResetFunc[funcName](self, notify, response, now) resetMode[funcName] = true end + if needResetId[resetId] then + -- 充值商城购买记录 + self.storeData:resetStoreReored(resetId) + end end for resetId, round in pairs(needResetId) do diff --git a/src/models/Store.lua b/src/models/Store.lua index 0ef66e0..b9372d3 100644 --- a/src/models/Store.lua +++ b/src/models/Store.lua @@ -194,6 +194,29 @@ function Store:notifyUpdateProperty(field, newValue, oldValue) SendPacket(actionCodes.Store_updateproperty, MsgPack.pack(datas)) end +function Store:resetStoreReored(resetId) + local payRecord = self:getProperty("payR") or {} + local buyRecord = self:getProperty("buyR") or {} + for k, v in pairs(payRecord) do + local config = csvdb["shop_rechargeCsv"][k] + if config then + if config.resetTime == resetId then + payRecord[k] = nil + end + end + end + self:updateProperty({field = "payR", value = payRecord}) + for k, v in pairs(buyRecord) do + local config = csvdb["shop_normalCsv"][k] + if config then + if config.resetTime == resetId then + buyRecord[k] = nil + end + end + end + self:updateProperty({field = "buyR", value = buyRecord}) +end + function Store:data() return { buyR = self:getProperty("buyR"), -- libgit2 0.21.2