Browse Source

扫荡券和埋点

SCFC 1 year ago
parent
commit
bb6fecb4ae

+ 34 - 5
script/module/MaiDian/MaiDianLogic.lua

@@ -24,6 +24,27 @@ local function MaiDian_WriteLog(sztext)
     Log.write(Log.LOGID_OSS_MAIDIAN, sztext)
 end
 
+-- 排序
+local function MainDian_Sort(l, r)
+    if "table" == type(l) then
+        table.print_lua_table(l)
+    end
+
+    if "table" == type(r) then
+        table.print_lua_table(r)
+    end
+
+    if "number" == type(r) then
+        print(" MainDian_Sort r ="..r)
+    end
+
+    if "number" == type(l) then
+        print(" MainDian_Sort l ="..l)
+    end
+
+    return l.key < r.key
+end
+
 -- 定时写日志
 function MaiDian_OnTime()
     if not tMaiDianPlay or not _G.next(tMaiDianPlay) then
@@ -39,20 +60,28 @@ function MaiDian_OnTime()
                 tTotalInfo[nType] = {}
             end
 
-           local nOldValue = tTotalInfo[nType][v] or 0
+            if not tTotalInfo[nType][v] then
+                tTotalInfo[nType][v] = {
+                    key = v,
+                    nValue = 0
+                }
+            end
 
-            tTotalInfo[nType][v] = nOldValue + 1
+            tTotalInfo[nType][v].nValue = tTotalInfo[nType][v].nValue + 1
         end
     end
 
     for nType, tData in ipairs(tTotalInfo) do
-        local sztext = " nType = "..nType
-        for key, value in pairs(tData) do
-            sztext = sztext.."{"..key..","..value.."},"
+        table.sort(tData, MainDian_Sort)
+        local sztext = " nType = "..nType.." "
+        for key, v in pairs(tData) do
+            sztext = sztext.."{"..key..","..v.nValue.."},"
         end
+        print("[MaiDian_OnTime] sztext = "..sztext)
         MaiDian_WriteLog(sztext)
     end
 
+    print("[MaiDian_OnTime] 写日志结束 ")
     -- 重置
     tMaiDianPlay = {}
 end

+ 13 - 0
script/module/bag/ItemLogic.lua

@@ -28,6 +28,7 @@ local DropExchangeLogic = require("absAct.DropExchangeLogic")
 local HeroGrowUp = require("absAct.HeroGrowUp")
 local BuyExcel = require("excel.buy")
 local LostTempleLogic = require("lostTemple.lostTempleLogic")
+local BattleLogic = require("battle.BattleLogic")
 
 cmd 		= {}
 
@@ -360,6 +361,18 @@ function cmd.mergeHero(data, human, value)
 
     -- return false
  end
+
+ -- 使用增加主线关卡扫荡次数道具
+ function cmd.AddFreeMopup(data, human)
+    if 0 >= data.left then
+        return false
+    end
+
+    BattleLogic.BattleLogic_AddMopup(human, data.id, data.cnt)
+
+    -- 把剩余数量改成0,才能消耗
+    data.left = 0
+ end
 -----------------------------------------------------------------------------
 
 -- 仅使用道具,不扣道具

+ 94 - 4
script/module/battle/BattleLogic.lua

@@ -692,6 +692,33 @@ local function BattleLogic_GetBattleAdopt(human, nBattleType)
     end
 end
 
+-- 获取额外增加扫荡次数
+local function BattleLogic_GetAddFreeMopupNum(human)
+    if not human then
+        return -1
+    end
+
+    if not human.db.mopupAddFreeCnt then
+        human.db.mopupAddFreeCnt = 0
+    end
+
+    return human.db.mopupAddFreeCnt
+end
+
+-- 设置额外增加扫荡次数
+local function BattleLogic_SetAddFreeMopupNum(human, nValue)
+    if not human then
+        return
+    end
+
+    print("[BattleLogic_SetAddFreeMopupNum] 消耗的额外次数 nValue = "..nValue)
+    human.db.mopupAddFreeCnt = human.db.mopupAddFreeCnt + nValue
+
+    if 0 > human.db.mopupAddFreeCnt then
+        human.db.mopupAddFreeCnt = 0
+    end
+end
+
 function getBattleRoleList(nBattleType, worldMapId)
     if not BATTLE_LEVEL_PLAYER_LIST then
         BATTLE_LEVEL_PLAYER_LIST = {}
@@ -1370,6 +1397,11 @@ function query(human)
         msgRet.canMopup = human.db.mopupDoCnt < BATTLE_MOPUP_CNT and 1 or 0
     end
 
+    -- 判断额外增加的扫荡次数
+    if 0 < BattleLogic_GetAddFreeMopupNum(human) and 0 == msgRet.canMopup then
+        msgRet.canMopup = 1
+    end
+
     local monsterOutId = nowNodeConfig.monsterOutID
     if not monsterOutId then
         print("[BattleLogic query] monsterOutId 为空")
@@ -2619,6 +2651,7 @@ function mopupQuery(human)
 
     human.db.mopupDoCnt = human.db.mopupDoCnt or 0
     local nextDoCnt = human.db.mopupDoCnt + 1
+    nextDoCnt = nextDoCnt >= EliteDefine.BATTLE_MOPUP_MAX_LEN and EliteDefine.BATTLE_MOPUP_MAX_LEN or nextDoCnt
     -- local nodeConfig = BattleExcel.node[guajiID]
     local nodeConfig = tBattleConfig.node[guajiID]
     local dropID = nodeConfig.dropID
@@ -2650,11 +2683,18 @@ function mopupQuery(human)
     local mapConfig = tBattleConfig.map[nodeConfig.mapID]
     msgRet.name = mapConfig.name
     msgRet.item[0] = dropCnt
+    local nNowAddFreeCnt = BattleLogic_GetAddFreeMopupNum(human)
     if TequanShopLogic.isActiveMopup(human) then
         msgRet.leftCnt = BATTLE_MOPUP_CNT_VIP - human.db.mopupDoCnt
     else
         msgRet.leftCnt = BATTLE_MOPUP_CNT - human.db.mopupDoCnt
     end
+
+    -- 剩余次数小于0则为0,再加额外的
+    msgRet.leftCnt = msgRet.leftCnt < 0 and 0 or msgRet.leftCnt
+
+    -- 增加额外次数
+    msgRet.leftCnt = msgRet.leftCnt + nNowAddFreeCnt
     
     -- local mupopExcel = BattleExcel.mupop[nextDoCnt]
     local mupopExcel = tBattleConfig.mupop[nextDoCnt]
@@ -2673,12 +2713,19 @@ function mopupQuery(human)
     else
         msgRet.need = 0
     end
+
+    -- 如果有额外增加次数则需要为0
+    if 0 < nNowAddFreeCnt then
+        msgRet.need = 0
+    end
+
     msgRet.vip = TequanShopLogic.isActiveMopup(human) and 1 or 0
     msgRet.nowCnt = human.db.mopupDoCnt
     msgRet.exp = nodeConfig.hangExp
     msgRet.jinbi = nodeConfig.hangJinbi
     msgRet.greenExp = nodeConfig.hangGreenExp
     msgRet.qingbao = nodeConfig.hangQingbao
+    print("[mopupQuery] nowCnt = "..msgRet.nowCnt.." leftCnt = "..msgRet.leftCnt.." nNowAddFreeCnt = "..nNowAddFreeCnt)
     Msg.send(msgRet, human.fd)
 end
 
@@ -2698,27 +2745,34 @@ function mopupFight(human)
     human.db.mopupDoCnt = human.db.mopupDoCnt or 0
     human.db.mopupFreeCnt = human.db.mopupFreeCnt or 0
     local nextDoCnt = human.db.mopupDoCnt + 1
+    nextDoCnt = nextDoCnt >= EliteDefine.BATTLE_MOPUP_MAX_LEN and EliteDefine.BATTLE_MOPUP_MAX_LEN or nextDoCnt
     -- local mupopExcel = BattleExcel.mupop[nextDoCnt]
     local mupopExcel = tBattleConfig.mupop[nextDoCnt]
+    local nNowAddFreeCnt = BattleLogic_GetAddFreeMopupNum(human)
+
     if not mupopExcel then
         return Broadcast.sendErr(human, Lang.BATTLE_MOPUP_CNT_OVER)
     end
+
+    local bUseFree = false
     if not TequanShopLogic.isActiveMopup(human) then
-        if human.db.mopupDoCnt >= BATTLE_MOPUP_CNT then
+        if human.db.mopupDoCnt >= BATTLE_MOPUP_CNT and 0 >= nNowAddFreeCnt then
             return Broadcast.sendErr(human, Lang.BATTLE_MOPUP_CNT_OVER)
         end
         need = mupopExcel.cost
         -- 如果免费次数小于1次,则按免费算
         if human.db.mopupFreeCnt < BATTLE_MOPUP_FREE_CNT then
+            bUseFree = true
             need = 0
         end
     else
-        if human.db.mopupDoCnt >= BATTLE_MOPUP_CNT_VIP then
+        if human.db.mopupDoCnt >= BATTLE_MOPUP_CNT_VIP and 0 >= nNowAddFreeCnt then
             return Broadcast.sendErr(human, Lang.BATTLE_MOPUP_CNT_OVER)
         end
         need = mupopExcel.vipCost
         -- 如果免费次数小于3次,则按免费算
         if human.db.mopupFreeCnt < BATTLE_MOPUP_FREE_CNT_VIP then
+            bUseFree = true
             need = 0
         end
     end
@@ -2727,13 +2781,20 @@ function mopupFight(human)
         return
     end
 
-    if need <= 0 then
+    local bUseAddFree = false
+    if need <= 0 and bUseFree == true then
         human.db.mopupFreeCnt = human.db.mopupFreeCnt + 1
+    else
+        if nNowAddFreeCnt > 0 then
+            need = 0
+            BattleLogic_SetAddFreeMopupNum(human, -1)
+            bUseAddFree = true
+        end
     end
 
     ObjHuman.decZuanshi(human, - need, "battleMopup")
 
-    human.db.mopupDoCnt = human.db.mopupDoCnt + 1
+    human.db.mopupDoCnt = bUseAddFree == true and human.db.mopupDoCnt or human.db.mopupDoCnt + 1
 
     -- local guajiID = human.db.guajiID > #BattleExcel.node and #BattleExcel.node or human.db.guajiID
     local guajiID = nNowGuaJiID > #tBattleConfig.node and #tBattleConfig.node or nNowGuaJiID
@@ -2816,6 +2877,7 @@ end
 function updateDaily(human)
     human.db.mopupFreeCnt = 0
     human.db.mopupDoCnt = 0
+    human.db.mopupAddFreeCnt = 0
 end
 
 function getTongGuanReward(human, id)
@@ -3598,4 +3660,32 @@ function BattleLogic_IsLastLevels(human, nBattleType)
 
     local nValue = BattleLogic_GetBattleAdopt(human, nBattleType)
     return nValue == 1
+end
+
+-- 增加扫荡次数
+function BattleLogic_AddMopup(human, nGoodsID, nGoodsNum)
+    if not human or 0 >= nGoodsID or 0 >= nGoodsNum then
+        return
+    end
+
+    if EliteDefine.BATTLE_ADD_MOPUP_GOODID ~= nGoodsID then
+        return
+    end
+
+    -- 检测数量
+    if false == BagLogic.checkItemCnt(human, nGoodsID, nGoodsNum) then
+        return
+    end
+
+    -- 消耗物品
+    BagLogic.delItem(human, nGoodsID, nGoodsNum, "battle")
+
+    -- 增加次数
+    BattleLogic_SetAddFreeMopupNum(human, nGoodsNum)
+
+    Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[BattleLogic_AddMopup] 增加扫荡次数 name = "
+                ..human.db.name.." nAddNum ="..nGoodsNum)
+
+    print("[BattleLogic_AddMopup] 玩家增加扫荡次数 name = "
+            ..human.db.name.." nAddNum ="..nGoodsNum)
 end

+ 5 - 0
script/module/battle/EliteDefine.lua

@@ -19,3 +19,8 @@ COPY_SELECT_SUCC = 0
 COPY_SELECT_LEV = 1
 --未完成通过主线第80关
 COPY_SELECT_MAIN = 2
+
+-- 增加扫荡次数道具
+BATTLE_ADD_MOPUP_GOODID = 1012
+-- 最大扫荡配置
+BATTLE_MOPUP_MAX_LEN = 12

+ 1 - 1
script/module/battle/Proto.lua

@@ -337,4 +337,4 @@ GC_BATTLE_QUERY_ALL = {
 	{"list",15,Tongguan},--查询副本返回数据
 	{"curIndex",1,"int"},--想请求的记录条数会累加到最大关卡
 	{"isEnd",1,"byte"},--未领取奖励是否发送结束
-}
+}

+ 1 - 1
script/module/guide/GuideLogic.lua

@@ -715,7 +715,7 @@ function stepFinish(human, sid, noSend)
             setGuide(human, id, STATE_FINISH)
         else
             setGuideStep(human, step, sid)
-	        MainDianLogic.MaiDian_Begin(human, MaiDianDefine.MAIDIAN_TYPE_GUIDE, {nValue = step})
+	        MainDianLogic.MaiDian_Begin(human, MaiDianDefine.MAIDIAN_TYPE_GUIDE, {nValue = sid})
         end
     end
 

+ 1 - 0
script/module/role/RoleDBLogic.lua

@@ -279,6 +279,7 @@ function createDefaultRole(account)
 
         mopupDoCnt = nil,                       -- 战役已扫荡次数
         mopupFreeCnt = nil,                     -- 战役已免费扫荡次数
+		mopupAddFreeCnt = nil,					-- 战役额外增加扫荡次数
 		topupAcount = nil,                      -- 玩家充值总额
 		topupAcountDaily = nil,					-- 玩家每日充值总额
 		topupAccountMonth = nil,				-- 玩家每月充值总额